:root {
    --bg: #ffffff;
    --bg2: #f6f7fb;
    --text: #333333;
    --text2: #888888;
    --border: #f0f0f0;
    --border2: #dddddd;
    --card-bg: #f6f7fb;
    --header-border: #f0f0f0;
    --input-bg: #ffffff;
    --section-bg: #ffffff;
}
[data-theme="dark"] {
    --bg: #0f0f13;
    --bg2: #1a1a24;
    --text: #e8e8f0;
    --text2: #7a7a9a;
    --border: #2a2a3a;
    --border2: #3a3a4a;
    --card-bg: #1a1a24;
    --header-border: #2a2a3a;
    --input-bg: #1a1a24;
    --section-bg: #0f0f13;
}
* { box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { margin: 0; padding: 0; background-color: var(--bg); color: var(--text); transition: background 0.3s, color 0.3s; }
.header { padding: 20px 16px; border-bottom: 1px solid var(--header-border); background: var(--bg); }
.header h1 { margin: 0; font-size: 24px; font-weight: bold; display: flex; align-items: baseline; color: var(--text); }
.badge { font-size: 16px; color: var(--text2); margin-left: 15px; cursor: pointer; }
.badge.active { color: #007aff; border-bottom: 2px solid #007aff; padding-bottom: 4px; font-weight: 600; }

.grid-container {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 20px max(16px, env(safe-area-inset-right)) 20px max(16px, env(safe-area-inset-left));
    background: var(--bg);
}
.card {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 16px 10px;
    height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    position: relative;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    transition: transform 0.1s;
}
.card:active { transform: scale(0.96); }

.card-title {
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    line-height: 1.2;
    margin-top: 5px;
}
.icon {
    position: absolute;
    bottom: 12px;
    left: 12px;
    color: #c074e0;
    font-size: 18px;
}

.hidden { display: none !important; }

/* Экран раздела */
.section-container { 
    position: fixed; 
    top: 0; left: 0; right: 0; bottom: 0; 
    background: #f4f5f9; 
    z-index: 10; 
    display: flex;
    flex-direction: column;
}
.section-header { 
    padding: 16px; 
    display: flex; 
    align-items: center; 
    background: #fff;
    border-bottom: 1px solid #eee; 
}
.section-header button { 
    background: none; border: none; font-size: 16px; color: #007aff; cursor: pointer; margin-right: 16px; 
    display: flex; align-items: center; gap: 6px;
}
.section-header h2 { margin: 0; font-size: 18px; }

.section-content { 
    padding: 16px; 
    flex: 1;
    overflow-y: auto;
}

.btn {
    width: 100%;
    padding: 14px;
    background: #007aff;
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 12px;
}
.select-input, .input {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid #ccc;
    font-size: 16px;
    margin-bottom: 16px;
    background: #fff;
}
.box { background: #fff; padding: 16px; border-radius: 12px; margin-bottom: 16px; }

/* Списки */
.list-container { margin-bottom: 16px; }
.list-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
}
.list-item:last-child { border-bottom: none; }

.delete-btn {
    background: #ff3b30;
    color: #fff;
    border: none;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-small {
    padding: 10px;
    font-size: 14px;
}

.loader {
    text-align: center;
    padding: 40px;
    color: #888;
}

/* Новая секция проектов (Объектов) */
.objects-section {
    padding: 20px 16px 60px 16px;
}
.objects-title {
    font-size: 12px;
    font-weight: 600;
    color: #8e8e93;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 20px;
    padding-top: 20px;
    border-top: 1px solid #f2f2f7;
}
.object-item {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 4px;
    border-radius: 12px;
}
.object-item:active { background-color: #f2f2f7; opacity: 0.8; }

.object-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #32C5FF 0%, #29A2FF 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 20px;
    margin-right: 16px;
    box-shadow: 0 4px 12px rgba(50, 197, 255, 0.25);
}
.object-name {
    font-size: 15px;
    font-weight: 500;
    color: #1c1c1e;
}

.object-item.active .object-icon {
    background: linear-gradient(135deg, #007aff 0%, #0056b3 100%);
    box-shadow: 0 4px 15px rgba(0, 122, 255, 0.4);
}
.object-item.active .object-name {
    color: #007aff;
    font-weight: 700;
}

/* Эффект для сетки на мобильных */
@media (max-width: 360px) {
    .grid-container { gap: 8px; }
    .card-title { font-size: 11px; }
    .object-icon { width: 48px; height: 48px; font-size: 18px; }
}

/* Складские таблицы */
.inventory-table {
    width: 100%;
    border-collapse: collapse;
    margin: 15px 0;
    font-size: 14px;
}
.inventory-table th {
    background: #f1f1f7;
    padding: 10px;
    text-align: left;
    font-weight: 600;
}
.inventory-table td {
    padding: 12px 10px;
    border-bottom: 1px solid #eee;
}
.inventory-table input {
    width: 80px;
    height: 40px;
    padding: 8px;
    border: 1px solid #007aff;
    border-radius: 8px;
    text-align: center;
    font-size: 16px;
    font-family: inherit;
    font-weight: 600;
    -webkit-appearance: none;
    background: #fff;
}
.inventory-table td:nth-child(3) {
    min-width: 90px;
    text-align: center;
}
.inventory-table tr:last-child td { border: none; }

.categories-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 15px;
}
.cat-btn {
    background: #f9f9fc;
    border: 1px solid #e5e5ea;
    padding: 15px 10px;
    border-radius: 12px;
    text-align: center;
    font-weight: 600;
    transition: all 0.2s;
    cursor: pointer;
}
.cat-btn:active, .cat-btn.active {
    background: #007aff;
    color: #fff;
    border-color: #007aff;
}

/* Форма входа */
#login-overlay {
    position: fixed;
    inset: 0;
    background: #f0f2f5;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.login-box {
    background: #fff;
    border-radius: 16px;
    padding: 32px 28px;
    width: 90%;
    max-width: 340px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.12);
    text-align: center;
}
.login-box h2 { margin: 0 0 6px; font-size: 22px; color: #1a1a2e; }
.login-box p { margin: 0 0 20px; font-size: 14px; color: #666; }
.login-box input {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    margin-bottom: 12px;
    border: 1.5px solid #ddd;
    border-radius: 10px;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}
.login-box input:focus { border-color: #4a90e2; }
.login-box button[type="submit"] {
    width: 100%;
    padding: 13px;
    background: #4a90e2;
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 4px;
    transition: background 0.2s;
}
.login-box button[type="submit"]:hover { background: #357abd; }
.login-error { color: #e53935; font-size: 13px; min-height: 18px; margin-bottom: 8px; }
/* Кнопка темы день/ночь */
.theme-btn {
    background: none;
    border: 1.5px solid var(--border2);
    color: var(--text2);
    font-size: 18px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.4s;
    overflow: hidden;
    position: relative;
}
.theme-btn:hover { background: var(--bg2); }
.theme-btn .icon-sun,
.theme-btn .icon-moon {
    position: absolute;
    transition: transform 0.4s, opacity 0.4s;
    font-size: 17px;
}
.theme-btn .icon-moon { transform: translateY(30px); opacity: 0; }
[data-theme="dark"] .theme-btn .icon-sun  { transform: translateY(-30px); opacity: 0; }
[data-theme="dark"] .theme-btn .icon-moon { transform: translateY(0);     opacity: 1; color: #a78bfa; }
.logout-btn {
    background: none;
    border: 1.5px solid var(--border2);
    color: var(--text2);
    font-size: 16px;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: 8px;
    transition: background 0.2s, color 0.2s;
    flex-shrink: 0;
}
.logout-btn:hover { background: #fee2e2; border-color: #f87171; color: #dc2626; }
.header { display: flex; align-items: center; padding-right: max(16px, env(safe-area-inset-right)); }
.header h1 { flex: 1; }

/* Модалки */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}
.modal-window {
    background: #fff;
    width: 90%;
    max-width: 320px;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
