/* ============================================
   Глобальные стили — Цифровая производственная платформа
   ============================================ */

/* ---------- CSS-переменные (дизайн-токены) ---------- */
:root {
    --color-primary: #001355;
    --color-primary-light: #2d4e8c;
    --color-bg: #f1f5f9;
    --color-surface: #ffffff;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    --color-border: #e2e8f0;
    --color-nav-bg: #f8fafc;
    --color-danger: #dc2626;
    --color-success: #059669;
    --color-warning: #d97706;
    --color-info: #3b82f6;

    --touch-min: 44px;
    --header-h-desktop: auto;
    --header-h-tablet: 56px;
    --header-h-mobile: 48px;
    --radius-sm: 6px;
    --radius-md: 12px;
    --shadow-card: 0 8px 32px rgba(0,0,0,0.1);
}

/* ---------- Сброс ---------- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 16px;
    background: var(--color-primary);
    min-height: 100vh;
    padding: 0;
}

/* ---------- Контейнер приложения ---------- */
#app-root {
    max-width: 98vw;
    margin: 0 auto;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    height: calc(100vh - 30px);
    display: flex;
    flex-direction: column;
    transition: background 0.3s, max-width 0.3s, border-radius 0.3s, box-shadow 0.3s;
}

#app-root.login-active {
    max-width: 100%;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    height: 100vh;
    overflow: visible;
    display: block;
}

/* ---------- Шапка ---------- */
.app-header {
    background: var(--color-primary);
    color: white;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--color-primary-light);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 20px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-header .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    white-space: nowrap;
    color: rgba(255,255,255,0.85);
}

/* ---------- Бургер-кнопка ---------- */
.burger-btn {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    min-height: var(--touch-min);
    min-width: var(--touch-min);
    padding: 8px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
}
.burger-btn:hover {
    background: rgba(255,255,255,0.1);
}

/* ---------- Навигация ---------- */
.nav-bar {
    background: var(--color-nav-bg);
    padding: 8px 16px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    gap: 10px;
    flex-wrap: nowrap;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    width: 100%;
    flex-shrink: 0;
    box-sizing: border-box;
}
.nav-bar::-webkit-scrollbar {
    height: 4px;
}
.nav-bar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 2px;
}

.nav-link {
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid #cbd5e1;
    transition: all 0.2s;
    font-size: 14px;
    min-height: var(--touch-min);
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    user-select: none;
}
.nav-link:hover {
    background: #f1f5f9;
}
.nav-link.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

/* ---------- Основная область ---------- */
.main-content {
    flex: 1;
    padding: 16px;
    overflow: auto;
    background: var(--color-bg);
    -webkit-overflow-scrolling: touch;
}

/* ---------- Уведомления (toast) ---------- */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 500;
    animation: slideIn 0.3s ease;
    pointer-events: none;
    user-select: none;
}
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
.toast.warning { background: var(--color-warning); }
.toast.info { background: var(--color-info); }
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(100%); opacity: 0; }
}

/* ---------- Форма логина ---------- */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: var(--color-primary);
}
.login-card {
    background: var(--color-surface);
    padding: 40px;
    border-radius: var(--radius-md);
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}
.login-card h2 {
    margin-bottom: 24px;
    color: var(--color-primary);
    font-size: 24px;
}
.login-card input {
    width: 100%;
    padding: 12px;
    margin-bottom: 16px;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    font-size: 16px;
}
.login-card input::placeholder {
    color: #6b7280;
}
.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 16px;
    cursor: pointer;
}
.login-card button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #9ca3af;
}
.login-card label {
    font-size: 14px;
    color: #4b5563;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
.login-card input[type="checkbox"] {
    width: auto;
    margin: 0;
    cursor: pointer;
    accent-color: var(--color-primary);
}
#login-error {
    color: var(--color-danger);
    margin-bottom: 10px;
    font-size: 14px;
    line-height: 1.4;
}

/* ---------- Модальное окно (админка) ---------- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}
.modal-content {
    background: var(--color-surface);
    padding: 20px;
    border-radius: var(--radius-md);
    width: 500px;
    max-width: 100%;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    max-height: 90vh;
    overflow-y: auto;
}
.modal-content input, .modal-content select {
    width: 100%;
    padding: 10px;
    margin: 8px 0;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
}
.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}
.modal-content.modal-sm {
    max-width: 400px;
}
.modal-content.modal-lg {
    max-width: 700px;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e2e8f0;
}
.modal-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: #1f2937;
    margin: 0;
}
.modal-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6b7280;
    min-height: var(--touch-min);
    min-width: var(--touch-min);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    transition: background 0.2s;
    line-height: 1;
}
.modal-close-btn:hover {
    background: #f3f4f6;
    color: #1f2937;
}

/* ============================================
   Адаптивность (все устройства)
   ============================================ */

/* ---------- Touch-цели — ВСЕГДА ---------- */
.btn, button, .nav-link, .burger-btn, .filter-select, .filter-input,
.login-card input, .modal-content input, .modal-content select {
    min-height: var(--touch-min);
}

/* ---------- Десктоп (>1024px) ---------- */
@media (min-width: 1025px) {
    .app-header {
        padding: 20px 30px;
    }
    .app-header h1 {
        font-size: 22px;
    }
    .nav-bar {
        padding: 10px 24px;
        gap: 12px;
    }
    .main-content {
        padding: 24px;
    }
}

/* ---------- Планшет (768–1024px) ---------- */
@media (max-width: 1024px) {
    .app-header {
        padding: 12px 20px;
    }
    .app-header h1 {
        font-size: 18px;
    }
    .app-header .user-info {
        font-size: 12px;
        gap: 8px;
    }
    .nav-bar {
        padding: 8px 16px;
        gap: 8px;
        flex-wrap: nowrap;
    }
    .nav-link {
        font-size: 13px;
        padding: 6px 12px;
    }
    .main-content {
        padding: 16px;
    }
    .data-table {
        font-size: 12px;
    }
    .data-table th,
    .data-table td {
        padding: 6px;
    }
}

/* ---------- Мобильные (<768px) ---------- */
@media (max-width: 767px) {
    /* Шапка — компактная */
    .app-header {
        padding: 8px 12px;
    }
    .app-header h1 {
        font-size: 15px;
    }
    .app-header .user-info {
        display: none;
    }

    /* Бургер виден */
    .burger-btn {
        display: flex;
    }

    /* Навигация: по умолчанию скрыта, открывается бургером */
    .nav-bar {
        display: none;
        flex-direction: column;
        padding: 12px;
        gap: 8px;
        border-bottom: 2px solid var(--color-border);
        box-shadow: 0 8px 16px rgba(0,0,0,0.15);
        max-height: calc(100vh - 70px);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .nav-bar.mobile-open {
        display: flex;
    }

    /* Шапка больше не position:relative (навигация не внутри) */

    .nav-link {
        width: 100%;
        justify-content: center;
        font-size: 15px;
        padding: 12px;
    }

    /* Показываем user-info в навигации на мобильных */
    .nav-bar .user-info-mobile {
        display: flex;
        justify-content: center;
        font-size: 12px;
        color: var(--color-text-muted);
        padding: 8px 0 4px;
        border-bottom: 1px solid var(--color-border);
        margin-bottom: 4px;
        width: 100%;
    }

    .main-content {
        padding: 12px;
    }

    .data-table {
        font-size: 12px;
    }
    .data-table th,
    .data-table td {
        padding: 6px 4px;
        white-space: nowrap;
    }

    /* Фильтры — сворачиваемые */
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .filters-bar .filter-group {
        width: 100%;
    }
    .btn {
        width: 100%;
        text-align: center;
    }

    .modal-content {
        width: 100%;
        margin: 0;
        border-radius: var(--radius-md);
        padding: 16px;
        max-height: 85vh;
    }

    /* Карточка логина */
    .login-card {
        padding: 24px 20px;
        margin: 0 12px;
    }
}

/* ---------- Маленькие телефоны (<576px) ---------- */
@media (max-width: 575px) {
    #app-root {
        max-width: 100%;
        height: 100vh;
        border-radius: 0;
    }
    .app-header h1 {
        font-size: 13px;
    }
}