/* ─── Taste-Skill Design System ───
 *  Refined palette · Premium typography · Purposeful motion
 *  Inspired by: https://github.com/leonxlnx/taste-skill
 */

:root {
    --primary: #0f172a;
    --primary-light: #1e293b;
    --accent: #0d9488;
    --accent-light: #2dd4bf;
    --accent-subtle: rgba(13, 148, 136, 0.08);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #273548;
    --border: #334155;
    --border-light: rgba(148, 163, 184, 0.12);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.1);
    --success: #22c55e;
    --success-bg: rgba(34, 197, 94, 0.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.1);
    --info: #0ea5e9;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 40px;
    --space-8: 64px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
        'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', 'Consolas', monospace;
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 400ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    color-scheme: dark;
}
html[data-theme="light"] {
    color-scheme: light;
}

html, body {
    width: 100%;
    height: 100%;
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.6;
    background-color: var(--background);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    display: flex;
    width: 100%;
    height: 100vh;
}

/* === SIDEBAR === */
.sidebar {
    width: 260px;
    background: var(--surface);
    padding: 24px 16px;
    border-right: 1px solid var(--border-light);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-header {
    margin-bottom: 24px;
    text-align: left;
    padding: 0 8px;
}

.sidebar-header h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-light);
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.sidebar-toggle {
    display: none;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    font-size: 13.5px;
    font-weight: 500;
    text-align: left;
    line-height: 1.3;
}

.nav-item:hover {
    background: var(--accent-subtle);
    color: var(--accent-light);
}

.nav-item.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

.nav-item .icon {
    font-size: 18px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
}

.nav-item .nav-label {
    flex: 1;
}

.nav-item .nav-arrow {
    font-size: 11px;
    transition: var(--transition-fast);
    color: inherit;
    opacity: 0.7;
}

.nav-parent.open .nav-arrow {
    transform: rotate(180deg);
}

.nav-parent .nav-sub {
    display: none;
    flex-direction: column;
    gap: 2px;
    margin: 2px 0 2px 18px;
    padding-left: 10px;
    border-left: 1px solid var(--border);
}

.nav-parent.open .nav-sub {
    display: flex;
}

.nav-sub-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    font-size: 13px;
    text-align: left;
}

.nav-sub-item:hover {
    background: var(--accent-subtle);
    color: var(--accent-light);
}

.nav-sub-item.active {
    background: var(--accent);
    color: #fff;
    font-weight: 600;
}

/* Theme toggle in sidebar footer */
.sidebar-footer-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 12px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 500;
    font-family: var(--font-sans);
    text-align: left;
    transition: var(--transition-fast);
    line-height: 1.3;
}

.sidebar-footer-btn:hover {
    background: var(--accent-subtle);
    color: var(--accent-light);
}

.sidebar-footer-btn .icon {
    font-size: 18px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
}

/* Sidebar hidden state for mobile toggle */
.sidebar.hidden {
    display: none;
}

/* === MOBILE TOP BAR (toggle + title, visible only on mobile) === */
.mobile-topbar {
    display: none;
}

/* === MAIN CONTENT === */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 32px 40px;
    background-color: var(--background);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 300ms cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.96); }
    to   { opacity: 1; transform: scale(1); }
}

.tab-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-light);
}

.tab-header h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

/* === BUTTONS === */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font-sans);
    transition: var(--transition-fast);
    line-height: 1.2;
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: color-mix(in srgb, var(--accent) 85%, white);
    box-shadow: 0 4px 12px rgba(13, 148, 136, 0.35);
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
    color: var(--accent-light);
}

.btn-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.flex-grow { flex: 1 1 auto; }

.btn-danger {
    background: var(--error);
    color: #fff;
}

.btn-danger:hover {
    background: color-mix(in srgb, var(--error) 85%, white);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.35);
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
}

/* === SEARCH SECTION === */
.search-section {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.search-section input {
    flex: 1;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-sans);
    transition: var(--transition-fast);
}

.search-section input::placeholder {
    color: var(--text-muted);
}

.search-section input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
}

/* === YEAR SUB-TABS === */
.year-subtabs {
    display: flex;
    gap: 4px;
    padding: 4px 0 12px;
    flex-wrap: wrap;
}
.year-tab {
    padding: 4px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12.5px;
    font-weight: 500;
    font-family: var(--font-sans);
    transition: var(--transition-fast);
}
.year-tab:hover {
    background: var(--surface-hover);
    color: var(--text-primary);
}
.year-tab.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* === TABLE === */
.table-container {
    background: var(--surface);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-light);
}

.sortable-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.sortable-table thead {
    background: var(--primary-light);
}

.sortable-table th {
    padding: 10px 12px;
    font-size: 12px;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    user-select: none;
    transition: var(--transition-fast);
}

.sortable-table th.sortable:hover {
    background: rgba(148, 163, 184, 0.06);
}

.sortable-table th.sort-asc::after {
    content: ' ▲';
    font-size: 0.65em;
    opacity: 0.7;
}

.sortable-table th.sort-desc::after {
    content: ' ▼';
    font-size: 0.65em;
    opacity: 0.7;
}

.sortable-table td {
    padding: 10px 12px;
    font-size: 13.5px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    line-height: 1.4;
}

.sortable-table tbody tr {
    transition: var(--transition-fast);
}

.sortable-table tbody tr:last-child td {
    border-bottom: none;
}

.sortable-table tbody tr:hover {
    background: var(--accent-subtle);
}

.person-header {
    cursor: pointer;
    background: var(--primary-light);
    user-select: none;
}
.person-header:hover {
    background: var(--surface-hover);
}
.person-header.expanded {
    background: var(--surface-hover);
}
.person-header .col-expand {
    width: 50px;
}
.person-header .expand-icon {
    display: inline-block;
    width: 16px;
    text-align: center;
    margin-right: 6px;
    font-size: 11px;
    color: var(--text-muted);
    transition: var(--transition-fast);
}
.person-header .cert-count {
    color: var(--text-muted);
    font-weight: 400;
    font-size: 0.85em;
}
.person-child {
    background: var(--surface);
}
.person-child:hover {
    background: var(--accent-subtle);
}
.person-child td:first-child {
    padding-left: 32px;
}

.action-buttons {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* === ICON BUTTONS === */
.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent-subtle);
    color: var(--accent);
    font-size: 18px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.icon-button:hover {
    background: rgba(13, 148, 136, 0.2);
    color: var(--accent-light);
}

.icon-button:active {
    transform: scale(0.92);
}

.icon-button.danger {
    background: var(--error-bg);
    color: var(--error);
}

.icon-button.danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

.icon-button.success {
    background: var(--success-bg);
    color: var(--success);
}

.icon-button.success:hover {
    background: rgba(34, 197, 94, 0.2);
}

/* SVG icons */
.nav-item .icon svg {
    width: 20px;
    height: 20px;
    display: block;
}

.icon-button svg {
    width: 18px;
    height: 18px;
    display: block;
}

.icon-button.sm {
    width: 24px;
    height: 24px;
    border-radius: 5px;
}

.icon-button.sm svg {
    width: 13px;
    height: 13px;
}

.sidebar-toggle svg {
    width: 20px;
    height: 20px;
    display: block;
}

.btn-icon svg {
    width: 16px;
    height: 16px;
    display: inline-block;
    vertical-align: middle;
    margin-right: 4px;
}

/* === MODAL === */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 200ms ease;
}

.modal-content {
    position: relative;
    background: var(--surface);
    padding: 28px 32px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-lg);
    max-width: 1100px;
    width: 97%;
    max-height: 85vh;
    overflow-y: auto;
    animation: scaleIn 250ms cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-content h2 {
    margin-bottom: 20px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.close {
    position: absolute;
    top: 22px;
    right: 26px;
    float: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 22px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    line-height: 1;
}

.close:hover {
    color: var(--text-primary);
    background: var(--background);
}

/* === KEYBOARD NAVIGATION (focus-visible) === */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible),
textarea:focus:not(:focus-visible) {
    outline: none;
}

/* === FORM === */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

.form-group input,
.form-group select {
    height: 42px;
}

.form-group textarea {
    min-height: 42px;
}

.form-group input,
.form-group select,
.form-group textarea {
    min-width: 0;
    padding: 10px 12px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-sans);
    transition: var(--transition-fast);
    line-height: 1.4;
    box-sizing: border-box;
}

.form-group input:hover,
.form-group select:hover,
.form-group textarea:hover {
    border-color: color-mix(in srgb, var(--border) 70%, var(--accent));
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.15);
    background: var(--surface);
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border-light);
}

/* === LISTBOX === */
.listbox {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px;
}

.listbox-item {
    padding: 8px 10px;
    border-radius: 4px;
    margin-bottom: 2px;
    cursor: pointer;
    user-select: none;
    outline: none;
    transition: var(--transition-fast);
    font-size: 13.5px;
}

.listbox-item:hover {
    background: var(--accent-subtle);
}

.listbox-item.selected {
    background: rgba(13, 148, 136, 0.15);
    border: 1px solid rgba(13, 148, 136, 0.25);
    color: var(--accent-light);
    font-weight: 500;
}

.listbox-item:focus {
    box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.1);
}

/* === SCROLLBAR === */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* === RESPONSIVE (мобильный «нативный» каркас) === */
@media (max-width: 768px) {
    html, body {
        overflow: hidden;             /* скроллим контент внутри, без двойного скролла */
    }

    .container {
        flex-direction: column;
        height: 100vh;
        overflow: hidden;
    }

    /* --- Верхняя панель (только на мобильных) --- */
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        width: 100%;
        flex-shrink: 0;
        padding: max(12px, env(safe-area-inset-top)) 16px 12px;
        background: var(--surface);
        border-bottom: 1px solid var(--border-light);
        position: sticky;
        top: 0;
        z-index: 1020;
    }

    .mobile-topbar-title {
        font-size: 16px;
        font-weight: 700;
        letter-spacing: -0.02em;
        color: var(--accent-light);
    }

    .sidebar-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 42px;
        height: 42px;
        padding: 0;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        background: var(--background);
        color: var(--text-primary);
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        flex-shrink: 0;
    }
    .sidebar-toggle:active {
        background: var(--surface-hover);
    }

    /* --- Сайдбар: выдвижная панель (drawer) --- */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(85vw, 300px);
        z-index: 1050;
        height: 100%;
        padding: calc(24px + env(safe-area-inset-top)) 16px 24px;
        border-right: 1px solid var(--border);
        border-bottom: none;
        box-shadow: var(--shadow-lg);
        transform: translateX(0);
        transition: transform var(--transition-base);
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    .sidebar.hidden {
        display: flex;                 /* анимируем выдвижение вместо display:none */
        transform: translateX(-105%);
        box-shadow: none;
        pointer-events: none;
    }

    .sidebar-nav {
        flex-direction: column;
        overflow-x: visible;
    }

    .nav-item,
    .nav-sub-item {
        min-height: 46px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* --- Основной контент --- */
    .main-content {
        padding: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
    }
    .main-content > .tab-content {
        padding: 16px 12px calc(24px + env(safe-area-inset-bottom));
    }

    .tab-header {
        flex-wrap: wrap;
        gap: 12px;
        margin-bottom: 18px;
    }
    .tab-header h2 {
        font-size: 20px;
    }
    .btn-row,
    .search-section {
        flex-wrap: wrap;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    /* --- Таблицы: на всю ширину экрана, без горизонтального скролла --- */
    .table-container {
        margin-left: -12px;
        margin-right: -12px;
        width: calc(100% + 24px);
        border-radius: 0;
        border-left: none;
        border-right: none;
        overflow-x: auto;
    }
    .sortable-table {
        width: 100%;
    }
    .sortable-table th,
    .sortable-table td {
        white-space: normal;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    .sortable-table .action-buttons {
        flex-wrap: wrap;
    }
    .person-child td:first-child {
        padding-left: 12px;
    }

    .icon-button {
        width: 40px;
        height: 40px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    /* --- Модалки: нижняя панель (bottom sheet) --- */
    .modal.show {
        align-items: flex-end;
    }
    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 92vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        padding: 24px 20px calc(28px + env(safe-area-inset-bottom));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    .modal-content .close {
        top: 14px;
        right: 14px;
    }
}

/* Уважение к prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    .sidebar { transition: none; }
    .modal-content { animation: none; }
    .tab-content.active { animation: none; }
}

/* === ГРУППЫ НОРМ ДЛЯ ПРИВЯЗКИ === */
.norm-group {
    margin-bottom: 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: var(--surface);
}

.norm-group-header {
    padding: 10px 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    user-select: none;
    transition: background-color 0.2s;
    border-radius: 4px 4px 0 0;
}

.norm-group-header:hover {
    background-color: rgba(13, 148, 136, 0.1);
}

.norm-group-toggle {
    display: inline-block;
    width: 16px;
    text-align: center;
    font-size: 12px;
    color: var(--accent);
    transition: transform 0.2s;
}

.norm-group-header strong {
    flex: 1;
    color: var(--text-primary);
}

.norm-group-count {
    color: var(--text-secondary);
    font-size: 0.9em;
}

.norm-group-content {
    padding: 10px 15px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.15);
}

.norm-group-content label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    cursor: pointer;
    color: var(--text-secondary);
    transition: color 0.2s;
}

.norm-group-content label:hover {
    color: var(--text-primary);
}

.norm-group-content input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
}

/* Стили для таблицы строк коммерческого предложения */
#proposal-details-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

#proposal-details-table th {
    padding: 10px;
    text-align: left;
    background: var(--surface);
    color: var(--text-primary);
    border-bottom: 2px solid var(--border);
}

#proposal-details-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

#proposal-details-table input[type="text"],
#proposal-details-table input[type="number"] {
    padding: 8px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
}

#proposal-details-table input[type="text"]:focus,
#proposal-details-table input[type="number"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 5px rgba(13, 148, 136, 0.3);
}

#proposal-details-table input.error {
    border-color: var(--error);
}

/* Стили для панели массового добавления */
#bulk-paste-proposal-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 15px;
    margin-bottom: 15px;
}

#bulk-paste-proposal-text {
    width: 100%;
    padding: 10px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: inherit;
    resize: vertical;
    min-height: 100px;
}

#bulk-paste-proposal-text:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 5px rgba(13, 148, 136, 0.3);
}

/* Searchable select (выпадающий список с поиском) */
.searchable-select {
    position: relative;
    width: 100%;
}

.searchable-select input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 14px;
    box-sizing: border-box;
}

.searchable-select input[type="text"]:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 5px rgba(13, 148, 136, 0.3);
}

.searchable-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 200px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0 0 4px 4px;
    z-index: 1000;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.searchable-select-dropdown.show {
    display: block;
}

.searchable-select-item {
    padding: 8px 12px;
    cursor: pointer;
    color: var(--text-primary);
    font-size: 14px;
    transition: background-color 0.15s;
}

.searchable-select-item:hover {
    background-color: rgba(13, 148, 136, 0.15);
}

.searchable-select-empty {
    padding: 8px 12px;
    color: var(--text-secondary);
    font-size: 14px;
    text-align: center;
}

/* Large modal for crane */
.modal-lg .modal-content {
    max-width: 900px;
}

/* Компактные модалки по ширине контента */
#work-type-modal .modal-content,
#norm-modal .modal-content {
    max-width: 560px;
}

#certificate-modal .modal-content {
    max-width: 680px;
}

#verification-modal .modal-content {
    max-width: 760px;
}

#order-modal .modal-content,
#bind-norms-modal .modal-content {
    max-width: 900px;
}

/* Блок спецификаций в модалке договора */
#contract-specifications-block {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
}

#contract-specifications-table {
    width: 100%;
    border-collapse: collapse;
}

#contract-specifications-table th,
#contract-specifications-table td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    white-space: nowrap;
    text-align: center;
}

#contract-specifications-table th {
    background: var(--background);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

#contract-specifications-table td {
    font-size: 13px;
}

#contract-specifications-table .icon-button {
    width: 26px;
    height: 26px;
}

/* Заголовок модалки не заходит под крестик */
.modal-content h2 {
    padding-right: 40px;
}

/* Tab navigation for crane modal */
.crane-tabs,
.contract-tabs {
    margin: 15px 0;
}

.crane-tab-nav,
.contract-tab-nav {
    display: flex;
    gap: 2px;
    border-bottom: 2px solid var(--accent);
    margin-bottom: 12px;
    overflow-x: auto;
}

.crane-tab-btn,
.contract-tab-btn {
    padding: 8px 16px;
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-bottom: none;
    border-radius: 4px 4px 0 0;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
    color: var(--text-secondary);
    white-space: nowrap;
    transition: var(--transition-fast);
}

.crane-tab-btn:hover,
.contract-tab-btn:hover {
    background: var(--accent-subtle);
    color: var(--text-primary);
}

.crane-tab-btn.active,
.contract-tab-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.crane-tab-content,
.contract-tab-content {
    display: none;
}

.crane-tab-content.active,
.contract-tab-content.active {
    display: block;
}

/* Таблица ВИК */
.vik-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    background: transparent;
}

.vik-table th {
    background: var(--primary-light);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 11px;
    padding: 5px 8px;
    text-align: center;
    border-bottom: 1px solid var(--border-light);
}

.vik-table td {
    padding: 3px 6px;
    text-align: center;
    vertical-align: middle;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
}

.vik-table tbody tr:last-child td {
    border-bottom: none;
}

.vik-table tbody tr:hover td {
    background: rgba(13, 148, 136, 0.05);
}

.vik-table td:first-child {
    font-weight: 400;
    color: var(--text-secondary);
    width: 40px;
    background: none;
}

.vik-table td:nth-child(2) {
    font-weight: 400;
    color: var(--text-primary);
    text-align: left;
}

.vik-table input,
.vik-table textarea,
.vik-table select {
    background: var(--accent-subtle);
    border: 1px solid var(--border-light);
    padding: 3px 5px;
    color: var(--text-primary);
    font-size: 12px;
    text-align: center;
    box-sizing: border-box;
    width: 100%;
    border-radius: 3px;
    transition: var(--transition-fast);
}

.vik-table input:hover,
.vik-table textarea:hover,
.vik-table select:hover {
    border-color: var(--accent);
    background: rgba(13, 148, 136, 0.1);
}

.vik-table input:focus,
.vik-table textarea:focus,
.vik-table select:focus {
    border-color: var(--accent);
    outline: none;
    background: rgba(13, 148, 136, 0.08);
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.15);
}

.vik-table textarea {
    resize: vertical;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.2;
    font-family: inherit;
}

.vik-table td[rowspan] {
    vertical-align: middle;
}

.vik-table td .detail-term {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
    transition: all 0.3s ease;
}

.vik-table td .detail-term:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(13, 148, 136, 0.3);
}

/* === ТАБЛИЦЫ РАСЧЕТ НА ПРОЧНОСТЬ === */
.strength-block {
    margin-top: 16px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 12px;
    background: var(--surface);
}

.strength-block-title {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.strength-table-toolbar {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
}

.strength-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    background: transparent;
}

.strength-table th {
    background: var(--primary-light);
    color: var(--text-primary);
    font-weight: 600;
    font-size: 11px;
    padding: 5px 8px;
    text-align: center;
    border-bottom: 1px solid var(--border-light);
}

.strength-table td {
    padding: 3px 6px;
    text-align: center;
    vertical-align: middle;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
}

.strength-table tbody tr:last-child td {
    border-bottom: none;
}

.strength-table td:first-child {
    text-align: left;
    color: var(--text-primary);
}

.strength-table td:nth-child(2) {
    color: var(--text-secondary);
    text-align: center;
}

.strength-table td:nth-child(2) .katex {
    font-size: 13px;
}

.strength-table td:nth-child(2) .katex-display {
    margin: 2px 0;
}

.strength-table td:nth-child(2) .katex-display > .katex {
    font-size: 13px;
}

.strength-table td.strength-title {
    background: var(--primary-light);
    font-weight: 600;
    text-align: center;
    padding: 5px 8px;
    color: var(--text-primary);
}

.strength-table td.strength-note {
    font-weight: 600;
    text-align: center;
    padding: 4px 8px;
    color: var(--text-secondary);
}

.strength-table input {
    background: var(--accent-subtle);
    border: 1px solid var(--border-light);
    padding: 3px 5px;
    color: var(--text-primary);
    font-size: 12px;
    text-align: center;
    box-sizing: border-box;
    width: 100%;
    border-radius: 3px;
    transition: var(--transition-fast);
}

.strength-table input:hover {
    border-color: var(--accent);
    background: rgba(13, 148, 136, 0.1);
}

.strength-table input:focus {
    border-color: var(--accent);
    outline: none;
    background: rgba(13, 148, 136, 0.08);
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.15);
}

.strength-table .strength-material-value {
    display: block;
    padding: 4px 6px;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    min-height: 20px;
}

/* === ТАБЛИЦА ОСНОВНЫЕ ЧАСТИ === */
.parts-table {
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.parts-table thead th {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.35;
    padding: 8px 6px;
    vertical-align: middle;
    background: transparent;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
}

.parts-table tbody td {
    padding: 4px 5px;
    background: transparent;
}

.parts-table .boiler-part-input {
    height: 30px;
    background: var(--background);
    border: 1px solid var(--border);
    font-size: 13px;
    border-radius: var(--radius-sm);
}

.parts-table .boiler-part-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.15);
}

/* === СВОДКА ДЕФЕКТОВ === */
#crane-defects-summary {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 10px;
    padding: 8px 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}

.defects-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 4px;
    background: rgba(45, 53, 97, 0.3);
    color: var(--text-primary);
}

.defects-badge.total { background: var(--primary-light); color: var(--accent-light); }
.defects-badge.ue   { background: rgba(46, 204, 113, 0.2); color: #2ecc71; }
.defects-badge.ne   { background: rgba(239, 68, 68, 0.15);  color: var(--error); }
.defects-badge.to   { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.defects-badge.pk   { background: rgba(52, 152, 219, 0.2); color: #3498db; }
.defects-badge.none { background: rgba(149, 165, 166, 0.2); color: #95a5a6; }

/* Группы параметров */
.params-group {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 16px 20px;
    margin-bottom: 14px;
}

.params-group-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent-light);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

.params-group .form-grid {
    margin-bottom: 0;
}

#mode-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border-radius: 6px;
    overflow: hidden;
    background: var(--surface);
    font-size: 13px;
}

#mode-table th {
    padding: 6px 10px;
    border: 1px solid var(--border);
    background: var(--primary-light);
    color: var(--text-primary);
    text-align: center;
    font-size: 12px;
    white-space: nowrap;
}

#mode-table td {
    padding: 4px 8px;
    border: 1px solid var(--border);
    text-align: center;
    font-size: 13px;
    color: var(--text-primary);
}

#mode-table td:first-child {
    font-weight: 600;
    color: var(--accent-light);
    background: var(--surface);
}

#mode-table td:nth-child(2) {
    font-weight: 600;
    color: var(--accent);
    background: var(--surface);
}

.mode-cell {
    cursor: default;
    background: var(--background);
}

.mode-cell:hover {
    background: var(--border) !important;
}

.mode-active {
    background: var(--accent) !important;
    color: var(--text-primary) !important;
    font-weight: bold;
    box-shadow: inset 0 0 0 2px var(--accent-light);
}

/* Accent button for generate */
.btn-accent {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font-sans);
    font-weight: 500;
    transition: var(--transition-fast);
}

.btn-accent:hover {
    background: color-mix(in srgb, var(--accent) 85%, white);
}

.aux-note {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: normal;
}

.aux-field {
    opacity: 0.75;
}

.scan-status {
    display: block;
    font-size: 11px;
    color: var(--accent-light);
    margin-top: 4px;
    word-break: break-all;
}

.scan-status a {
    color: var(--accent-light);
    text-decoration: underline;
}

.scan-status .no-file {
    color: var(--text-secondary);
    font-style: italic;
}

/* Toast notifications */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
    pointer-events: none;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: #fff;
    box-shadow: var(--shadow-lg);
    animation: toast-in 350ms cubic-bezier(0.16, 1, 0.3, 1), toast-out 300ms ease 3.7s forwards;
    word-break: break-word;
    pointer-events: auto;
}

.toast-error { background: var(--error); }
.toast-success { background: var(--success); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--accent); }

@keyframes toast-in {
    from { opacity: 0; transform: translateX(100%) scale(0.95); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}

@keyframes toast-out {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.95); }
}

/* === РАСШИРЕННЫЙ ПОИСК === */
.filter-panel {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    margin: 8px 0;
    overflow: hidden;
}
.filter-toggle {
    padding: 8px 14px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition-fast);
}
.filter-toggle:hover {
    background: var(--surface-hover);
}
.filter-toggle-icon {
    font-size: 10px;
    transition: transform 0.2s;
}
.filter-body {
    padding: 10px 14px 14px;
    border-top: 1px solid var(--border-light);
}
.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}
.filter-row label {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 12px;
    color: var(--text-muted);
}
.filter-row input,
.filter-row select {
    padding: 5px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--background);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-sans);
    min-width: 130px;
    transition: var(--transition-fast);
}
.filter-row input:focus,
.filter-row select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.12);
    outline: none;
}
.filter-row .btn-small {
    padding: 5px 12px;
    font-size: 12px;
    align-self: flex-end;
}

.filter-checkbox-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px 0;
}
.filter-checkbox-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    background: var(--background);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12.5px;
    color: var(--text-primary);
    transition: var(--transition-fast);
    user-select: none;
}
.filter-checkbox-item:hover {
    background: var(--surface-hover);
    border-color: var(--accent);
}
.filter-checkbox-item input {
    display: none;
}
.filter-checkbox-item.checked {
    background: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--accent-light);
}

/* ─── Light Mode ───
 *  Respects system preference. Toggle via data-theme="light" on <html>.
 *  Dual-mode by default — taste-skill §8
 */
@media (prefers-color-scheme: light) {
    :root, html:not([data-theme="dark"]) {
        --primary: #f8fafc;
        --primary-light: #f1f5f9;
        --accent: #0d9488;
        --accent-light: #0f766e;
        --accent-subtle: rgba(13, 148, 136, 0.08);
        --text-primary: #0f172a;
        --text-secondary: #475569;
        --text-muted: #94a3b8;
        --background: #f8fafc;
        --surface: #ffffff;
        --surface-hover: #f1f5f9;
        --border: #cbd5e1;
        --border-light: rgba(148, 163, 184, 0.25);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
        --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
        --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.1);
    }
}

html[data-theme="light"] {
    --primary: #eef2f6;
    --primary-light: #e2e8f0;
    --accent: #0d9488;
    --accent-light: #0f766e;
    --accent-subtle: rgba(13, 148, 136, 0.08);
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --background: #eef2f6;
    --surface: #f8fafc;
    --surface-hover: #f1f5f9;
    --border: #cbd5e1;
    --border-light: rgba(148, 163, 184, 0.25);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.08);
    --error-bg: rgba(239, 68, 68, 0.08);
    --success-bg: rgba(34, 197, 94, 0.08);
    --warning-bg: rgba(245, 158, 11, 0.08);
}

html[data-theme="dark"] {
    --primary: #0f172a;
    --primary-light: #1e293b;
    --accent: #0d9488;
    --accent-light: #2dd4bf;
    --accent-subtle: rgba(13, 148, 136, 0.08);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --background: #0f172a;
    --surface: #1e293b;
    --surface-hover: #273548;
    --border: #334155;
    --border-light: rgba(148, 163, 184, 0.12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.4);
    --error-bg: rgba(239, 68, 68, 0.1);
    --success-bg: rgba(34, 197, 94, 0.1);
    --warning-bg: rgba(245, 158, 11, 0.1);
}

/* Фиксированная раскладка таблиц */
.table-container table[style*="table-layout:fixed"] td:last-child,
.table-container table[style*="table-layout:fixed"] th:last-child {
    white-space: nowrap;
}

/* Кастомный селект типа крана */
.custom-type-select {
    position: relative;
    width: 100%;
}
.custom-type-input {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    box-sizing: border-box;
}
.custom-type-input:focus {
    border-color: var(--accent);
    outline: none;
}
.custom-type-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--bg-primary, #1a1a2e);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-top: 2px;
    max-height: 320px;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.custom-type-dropdown.open {
    display: block;
}
.type-group {
    background: var(--bg-secondary, var(--surface));
}
.type-group + .type-group {
    border-top: 1px solid var(--border, var(--border-light));
}
.type-group-header {
    padding: 8px 12px;
    font-weight: 600;
    font-size: 13px;
    color: var(--accent-light);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(13, 148, 136, 0.06);
    user-select: none;
}
.type-group-header:hover {
    background: rgba(13, 148, 136, 0.12);
}
.type-group-arrow {
    font-size: 10px;
    color: var(--text-secondary);
    transition: transform 0.15s;
}
.type-group-body {
    display: none;
    background: var(--bg-primary, #1a1a2e);
}
.type-item {
    padding: 6px 12px 6px 24px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    border-bottom: 1px solid rgba(45, 53, 97, 0.3);
}
.type-item:last-child {
    border-bottom: none;
}
.type-item:hover {
    background: rgba(13, 148, 136, 0.15);
    color: #fff;
}

/* Сведения о ремонтах */
#repair-info-container {
    padding: 0 16px;
}
#repair-info-container .repair-info-row,
#boiler-repair-info-container .repair-info-row {
    margin-bottom: 8px;
    display: flex;
    align-items: center;
}
#repair-info-container .repair-info-row input,
#boiler-repair-info-container .repair-info-row input {
    flex: 1;
    padding: 10px 12px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: all 0.3s ease;
    box-sizing: border-box;
}
#repair-info-container .repair-info-row input:focus,
#boiler-repair-info-container .repair-info-row input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(13, 148, 136, 0.3);
}
#repair-info-container .repair-info-row .icon-button,
#boiler-repair-info-container .repair-info-row .icon-button {
    flex-shrink: 0;
    margin-left: 8px;
}

#boiler-experts-container .expert-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
#boiler-experts-container .expert-row input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px;
    transition: border-color 0.2s;
}
#boiler-experts-container .expert-row input:focus {
    border-color: #0d9488;
    outline: none;
    box-shadow: 0 0 10px rgba(13, 148, 136, 0.3);
}
#boiler-experts-container .expert-row .btn-danger.btn-small {
    flex-shrink: 0;
}

#boiler-defectoscopists-container .defectoscopist-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
#boiler-defectoscopists-container .defectoscopist-row input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 13px;
    transition: border-color 0.2s;
}
#boiler-defectoscopists-container .defectoscopist-row input:focus {
    border-color: #0d9488;
    outline: none;
    box-shadow: 0 0 10px rgba(13, 148, 136, 0.3);
}

/* Приказы — всё в одной строке */
#orders-table {
    table-layout: fixed;
}
#orders-table th,
#orders-table td {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#orders-table th:nth-child(1),
#orders-table td:nth-child(1) { width: 45px; }
#orders-table th:nth-child(2),
#orders-table td:nth-child(2) { width: 120px; }
#orders-table th:nth-child(3),
#orders-table td:nth-child(3) { width: 110px; }
#orders-table th:nth-child(4),
#orders-table td:nth-child(4) { width: 120px; }
#orders-table th:nth-child(5),
#orders-table td:nth-child(5) { width: 120px; }
#orders-table th:nth-child(6),
#orders-table td:nth-child(6) { width: 170px; }
#orders-table th:nth-child(7),
#orders-table td:nth-child(7) { width: 150px; }

/* === ПОДВКЛАДКИ === */
.sub-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 20px;
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 4px;
    border: 1px solid var(--border-light);
}

.sub-tab {
    flex: 1;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: var(--transition-fast);
    text-align: center;
}

#verifications-tab .sub-tabs {
    margin-bottom: 12px;
    padding: 3px;
}

#verifications-tab .sub-tab {
    padding: 5px 12px;
    font-size: 12px;
}

.sub-tab:hover {
    color: var(--text-primary);
    background: var(--accent-subtle);
}

.sub-tab.active {
    background: var(--accent);
    color: #fff;
}

.sub-tab-content {
    display: none;
}

.sub-tab-content.active {
    display: block;
    animation: fadeIn 250ms ease;
}

/* === ПОВЕРКИ — ДНИ (WARNING/DANGER) === */
.sortable-table td.days-warning {
    color: var(--warning);
    font-weight: 600;
}

.sortable-table td.days-danger {
    color: var(--error);
    font-weight: 700;
}

/* === ПОВЕРКИ — FILE DROP ZONE === */
.file-drop-zone {
    border: 2px dashed var(--border);
    padding: 15px;
    border-radius: 6px;
    text-align: center;
    cursor: pointer;
    background: var(--surface);
    transition: all 0.2s ease;
}

.file-drop-zone:hover {
    border-color: var(--accent);
    background: rgba(13, 148, 136, 0.08);
}

.file-drop-zone.dragover {
    background: var(--accent);
    opacity: 0.8;
    border-color: var(--accent-light);
}

.file-drop-zone .drop-hint {
    color: var(--text-secondary);
    font-size: 14px;
}

.file-drop-zone .drop-hint small {
    display: block;
    font-size: 12px;
    color: #888;
    margin-top: 4px;
}

.file-drop-zone .file-name-display {
    margin-top: 10px;
    color: var(--accent-light);
    font-weight: bold;
    display: none;
}

/* === ПОВЕРКИ — ТАБЛИЦЫ === */
#verifications-il-table,
#verifications-lnk-table {
    table-layout: fixed;
}

#verifications-il-table th:nth-child(1),
#verifications-lnk-table th:nth-child(1) { width: 40px; }
#verifications-il-table th:nth-child(6),
#verifications-lnk-table th:nth-child(6) { width: 110px; }
#verifications-il-table th:nth-child(7),
#verifications-lnk-table th:nth-child(7) { width: 130px; }
#verifications-il-table th:nth-child(8),
#verifications-lnk-table th:nth-child(8) { width: 200px; }

/* === ПАГИНАЦИЯ === */
.pagination-container {
    display: flex;
    justify-content: center;
    padding: 12px 16px;
    background: var(--primary-light);
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
    border-top: 1px solid var(--border-light);
}

.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
}

.pagination button {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font-sans);
    transition: var(--transition-fast);
}

.pagination button:hover:not(:disabled):not(.active) {
    background: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--accent-light);
}

.pagination button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.pagination button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.pagination-ellipsis {
    padding: 0 4px;
    color: var(--text-muted);
    font-size: 13px;
}

.pagination-info {
    margin-left: 12px;
    color: var(--text-muted);
    font-size: 12px;
}

/* === ЛОГОТИП ВМЕСТО EMOJI === */
.sidebar-header h1 {
    font-size: 18px;
    letter-spacing: 1px;
}

.nav-item .icon {
    font-size: 16px;
    margin-right: 8px;
    display: inline-block;
    width: 20px;
    text-align: center;
}

/* === ОТСТУПЫ МЕЖДУ ТАБЛИЦЕЙ И ПАГИНАЦИЕЙ === */
.year-tabs + .table-wrapper,
.table-wrapper + .pagination-container {
    margin-top: 0;
}

/* ─── Вкладка Версий КП ─── */
.proposal-version-wrapper {
    display: inline-flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    transition: border-color 0.15s;
}
.proposal-version-wrapper:hover {
    border-color: var(--accent);
}
.proposal-version-wrapper.active {
    border-color: var(--accent);
    background: var(--accent-subtle);
}
.proposal-version-btn {
    padding: 4px 8px 4px 12px;
    font-size: 13px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    transition: color 0.15s;
}
.proposal-version-wrapper.active .proposal-version-btn {
    color: var(--accent-light);
    font-weight: 600;
}
.proposal-version-btn:hover {
    color: var(--text-primary);
}
.proposal-version-del {
    padding: 4px 8px 4px 4px;
    font-size: 14px;
    background: transparent;
    color: var(--text-muted);
    border: none;
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s;
}
.proposal-version-del:hover {
    color: var(--error);
}

/* === АДАПТИВНОСТЬ (МЕДИА-ЗАПРОСЫ) === */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100dvh;
        padding: 24px 16px;
        border-right: 1px solid var(--border-light);
        border-bottom: none;
        z-index: 1050;
        box-shadow: var(--shadow-lg);
        transition: transform 250ms cubic-bezier(0.16, 1, 0.3, 1);
        display: flex;
        flex-direction: column;
    }
    .sidebar.hidden {
        display: flex;           /* keep display flex for animation */
        transform: translateX(-100%);
        pointer-events: none;
    }

    .sidebar-header {
        display: block;
        margin-bottom: 20px;
    }

    .sidebar-nav {
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 52px;
        padding: 0 16px;
        background: var(--surface);
        border-bottom: 1px solid var(--border-light);
        z-index: 1060;
        box-shadow: var(--shadow-sm);
    }

    .sidebar-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        width: 36px;
        height: 36px;
        padding: 0;
        background: transparent;
        border: 1px solid var(--border-light);
        color: var(--text-secondary);
        border-radius: var(--radius-sm);
        cursor: pointer;
        transition: var(--transition-fast);
    }
    .sidebar-toggle:hover {
        border-color: var(--accent);
        color: var(--accent);
    }
    .sidebar-toggle svg {
        display: block;
    }

    .mobile-topbar-title {
        font-size: 16px;
        font-weight: 700;
        color: var(--accent-light);
        letter-spacing: -0.02em;
    }

    .main-content {
        margin-left: 0;
        padding: 52px 0 0;
    }

    .tab-header {
        padding: 16px 12px 12px;
        margin-bottom: 16px;
    }

    .tab-header h2 {
        font-size: 18px;
    }

    .search-section {
        padding: 0 12px;
        margin-bottom: 12px;
    }

    .table-container {
        margin: 0 0;
        border-radius: 0;
        border-left: none;
        border-right: none;
    }

    .pagination-container {
        padding: 12px;
    }

    /* Позволяем таблицам скроллиться по горизонтали */
    .table-container {
        overflow-x: auto;
    }

    .table-container table {
        min-width: 760px;
    }

    /* Мобильная модалка во весь экран */
    @media (max-width: 480px) {
        .modal-content {
            width: 100%;
            height: 100%;
            max-width: none;
            max-height: none;
            border-radius: 0;
            padding: 16px;
            box-sizing: border-box;
        }
        .modal.show {
            align-items: flex-start;
        }
    }

    .nav-item {
        padding: 12px 14px;
        font-size: 14px;
        min-height: 44px; /* touch target */
    }

    .nav-item .icon {
        margin-right: 4px;
    }

    .main-content {
        margin-left: 0;
        padding: 60px 12px 12px;
    }

    .btn, .icon-button {
        min-height: 44px;
        min-width: 44px;
    }

    .sidebar-footer-btn {
        min-height: 44px;
    }

    .modal-content {
        width: 95%;
        margin: 20px auto;
    }

    .table-wrapper {
        overflow-x: auto;
    }

    table {
        font-size: 12px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

/* Доп. правила для очень узких экранов: модалки во всю ширину/высоту и удобные формы */
@media (max-width: 480px) {
    /* Модалка занимает весь экран, чтобы избежать выхода полей за пределы */
    .modal-content {
        width: 100% !important;
        height: 100vh !important;
        max-width: none !important;
        max-height: none !important;
        border-radius: 0 !important;
        padding: 16px !important;
        box-sizing: border-box !important;
        overflow-y: auto !important;
    }

    /* При показе модалки размещаем её сверху, чтобы header был виден */
    .modal.show {
        align-items: flex-start !important;
        padding-top: 0 !important;
    }

    /* Сделать форму одноколоночной и элементы растягивать по ширине */
    .form-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .form-group input,
    .form-group select,
    .form-group textarea {
        width: 100% !important;
        min-width: 0 !important;
        box-sizing: border-box !important;
    }

    /* Обеспечиваем горизонтальную прокрутку для таблиц внутри модалок */
    .modal-content .table-container,
    .modal-content .table-wrapper,
    .modal-content .table-container > table {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    /* Убираем принудительный nowrap на узких экранах, но позволяем прокрутку */
    table {
        white-space: normal !important;
        word-break: break-word !important;
    }

    .table-container table {
        min-width: 640px; /* при необходимости таблица будет шире и прокручиваться */
    }

    /* Увеличим touch target для nav элементов */
    .nav-item {
        padding: 10px 12px !important;
    }

    /* Специально для крана: секции с большим количеством полей станут стеком */
    .crane-tab-content .form-grid,
    .contract-tab-content .form-grid,
    #crane-modal .form-grid,
    .modal-lg .form-grid {
        grid-template-columns: 1fr !important;
    }
}

/* === LOGIN SCREEN === */
.login-container {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    z-index: 9999;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-8) var(--space-6);
    width: 100%;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.login-card h1 {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: var(--space-6);
}

.login-card .form-group {
    margin-bottom: var(--space-4);
    text-align: left;
}

.login-card .form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
}

.login-card input[type="text"],
.login-card input[type="password"] {
    width: 100%;
    padding: 10px 12px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: border-color var(--transition-fast);
}

.login-card input:focus {
    border-color: var(--accent);
}

.login-btn {
    width: 100%;
    padding: 10px;
    margin-top: var(--space-2);
}

.login-error {
    color: var(--error);
    font-size: 0.85rem;
    min-height: 1.2em;
    margin-bottom: var(--space-2);
}

/* === USER INFO in sidebar === */
.sidebar-user-info {
    padding: 8px 12px;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.sidebar-user-info .user-name {
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 500;
}

.sidebar-user-info .user-role {
    font-size: 0.7rem;
    color: var(--text-muted);
    background: var(--accent-subtle);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}
