/* ============================================================
   ГОРИЗОНТ СЕРВИС — минималистичный современный стиль
   ============================================================ */

/* 1. ПЕРЕМЕННЫЕ */
:root {
    /* Основные цвета */
    --primary: #1e3a5f;
    --primary-hover: #152c47;
    --primary-light: #eef2f7;

    /* Фоны */
    --bg: #f8fafc;
    --card: #ffffff;
    --card-hover: #fafbfc;

    /* Границы — очень мягкие */
    --border: #eef1f4;
    --border-strong: #dbe1e8;

    /* Текст */
    --text: #0f172a;
    --text-muted: #64748b;
    --text-soft: #94a3b8;

    /* Статусы */
    --success: #16a34a;
    --warning: #ea580c;
    --danger: #dc2626;
    --info: #2563eb;

    /* Тени — мягкие, многослойные */
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.03);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.07);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.12);

    --radius: 10px;
    --radius-sm: 8px;
    --radius-lg: 14px;
}

/* 2. БАЗА */
* { box-sizing: border-box; }

body {
    display: flex;
    flex-direction: row;
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding-top: env(safe-area-inset-top, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
}

/* 3. САЙДБАР */
.sidebar {
    flex: 0 0 240px;
    background: #0f172a;
    color: white;
    padding: 20px 12px;
    transition: flex-basis 0.25s ease;
    overflow: hidden;
    height: 100vh;
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
}

.sidebar.collapsed { flex-basis: 68px; }

.sidebar h2 {
    color: white;
    margin: 0 0 24px 8px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
    white-space: nowrap;
}

.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar nav button {
    display: flex;
    align-items: center;
    width: 100%;
    margin: 0;
    padding: 9px 12px;
    background: transparent;
    color: #94a3b8;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 13.5px;
    text-align: left;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}

.sidebar nav button:hover {
    background: rgba(255, 255, 255, 0.06);
    color: white;
}

.menu-icon {
    margin-right: 12px;
    font-size: 16px;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
    /* Подсветка эмодзи на тёмном фоне */
    filter: brightness(1.15) saturate(1.2);
    text-shadow: 0 0 6px rgba(255, 255, 255, 0.08);
}

.sidebar.collapsed .menu-icon { margin-right: 0; }
.sidebar.collapsed nav button { padding: 9px 0; justify-content: center; }
.sidebar.collapsed h2 { display: none; }
.sidebar.collapsed nav button span:not(.menu-icon) { display: none; }

#toggle-sidebar {
    background: transparent;
    border: none;
    color: #94a3b8;
    font-size: 18px;
    cursor: pointer;
    margin-bottom: 16px;
    padding: 6px 10px;
    border-radius: 6px;
    align-self: flex-start;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
}

#toggle-sidebar:hover {
    background: rgba(255, 255, 255, 0.06);
    color: white;
}

#logout-btn {
    margin-top: auto;
    background: transparent;
    color: #94a3b8;
    border: none;
    padding: 9px 12px;
    border-radius: 6px;
    cursor: pointer;
    width: 100%;
    font-size: 13.5px;
    font-weight: 500;
    text-align: left;
    transition: background 0.15s, color 0.15s;
    font-family: inherit;
    display: flex;
    align-items: center;
}

#logout-btn .menu-icon {
    margin-right: 12px;
}

.sidebar.collapsed #logout-btn .menu-icon {
    margin-right: 0;
}

.sidebar.collapsed #logout-btn {
    padding: 9px 0;
    justify-content: center;
}

.sidebar.collapsed #logout-btn span:not(.menu-icon) {
    display: none;
}

#logout-btn:hover {
    background: rgba(220, 38, 38, 0.15);
    color: #fca5a5;
}

/* 4. ОСНОВНОЙ КОНТЕНТ */
main {
    flex: 1;
    padding: 32px 40px;
    min-width: 0;
    overflow-x: hidden;
    width: 100%;
}

h2 {
    font-size: 22px;
    font-weight: 600;
    margin: 0 0 24px;
    color: var(--text);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 12px;
}

h3 {
    font-size: 15px;
    font-weight: 600;
    margin: 24px 0 12px;
    color: var(--text);
    letter-spacing: -0.01em;
}

h4 {
    font-size: 13px;
    font-weight: 600;
    margin: 16px 0 8px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* 5. ФОРМЫ И ПОЛЯ */
form {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
}

input, select, textarea {
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--card);
    transition: border-color 0.15s, box-shadow 0.15s;
    outline: none;
}

input:hover, select:hover, textarea:hover {
    border-color: #c4cdd6;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 58, 95, 0.08);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-soft);
}

textarea {
    resize: vertical;
    min-height: 60px;
    font-family: inherit;
}

/* 6. КНОПКИ */
button {
    padding: 9px 16px;
    font-size: 14px;
    font-weight: 500;
    font-family: inherit;
    background: var(--primary);
    color: white;
    border: 1px solid var(--primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
    letter-spacing: -0.005em;
}

button:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

button:active {
    transform: translateY(0.5px);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Вторичные кнопки (Отмена, Сбросить) */
button[type="button"]:not(#toggle-sidebar):not(#logout-btn):not(.modal-minimize):not(.modal-content .close) {
    background: var(--card);
    color: var(--text);
    border-color: var(--border-strong);
}

button[type="button"]:not(#toggle-sidebar):not(#logout-btn):not(.modal-minimize):not(.modal-content .close):hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* 7. КАРТОЧКИ */
.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin: 8px 0;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xs);
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.card:hover {
    border-color: var(--border-strong);
    box-shadow: var(--shadow-sm);
}

/* Клиенты */
.client-card { cursor: pointer; }

.client-card:hover {
    transform: translateY(-1px);
}

.client-card.has-contract {
    border-left: 3px solid var(--success);
    background: #f9fdfa;
}

.client-card.no-contract {
    border-left: 3px solid var(--danger);
    background: #fffbfb;
}

.client-card.cancelled-contract {
    border-left: 3px solid var(--warning);
    background: #fffdf8;
}

.client-card.deleted {
    background: #f8fafc;
    opacity: 0.55;
    border-left: 3px solid #94a3b8;
}

.client-card.deleted strong {
    text-decoration: line-through;
    color: var(--text-muted);
}

/* Задачи */
.task-card { cursor: pointer; }

.task-card:hover {
    transform: translateY(-1px);
}

.task-card.status-new {
    border-left: 3px solid #3b82f6;
    background: #fbfdff;
}

.task-card.status-in_progress {
    border-left: 3px solid #f59e0b;
    background: #fffef9;
}

.task-card.status-completed {
    border-left: 3px solid #10b981;
    background: #f9fdfa;
}

.task-card.status-closed {
    border-left: 3px solid #cbd5e1;
    background: #f8fafc;
    opacity: 0.85;
}

.task-card.status-closed strong {
    color: var(--text-muted);
}

.task-card.deleted {
    background: #f8fafc;
    opacity: 0.55;
    border-left: 3px solid #94a3b8;
}

.task-card.deleted strong {
    text-decoration: line-through;
    color: var(--text-muted);
}

.task-card.task-overdue,
.task-card.docs-overdue {
    background: #fef6f6 !important;
    border-left-color: var(--danger) !important;
}

/* 8. МОДАЛЬНЫЕ ОКНА */
.modal {
    position: fixed;
    z-index: 1000;
    inset: 0;
    background-color: rgba(15, 23, 42, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(4px);
    animation: modalFadeIn 0.15s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--card);
    padding: 28px 32px;
    border-radius: var(--radius-lg);
    max-width: 560px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    word-wrap: break-word;
    overflow-wrap: break-word;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.modal-content::-webkit-scrollbar {
    width: 6px;
}

.modal-content::-webkit-scrollbar-track {
    background: transparent;
    margin: 10px 0;
}

.modal-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(16px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-content h3 {
    margin: 0 0 20px;
    font-size: 19px;
    font-weight: 600;
    color: var(--text);
    padding-right: 60px;
    letter-spacing: -0.01em;
}

.modal-content form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-bottom: 0;
}

.modal-content label {
    display: block;
    font-weight: 500;
    font-size: 12.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
    margin-top: 4px;
    letter-spacing: 0.01em;
}

.modal-content input,
.modal-content select,
.modal-content textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
}

.modal-content button[type="submit"] {
    margin-top: 12px;
    padding: 11px;
    font-size: 14px;
    font-weight: 600;
    background: var(--primary);
    border-radius: var(--radius-sm);
}

.modal-content button[type="submit"]:hover {
    background: var(--primary-hover);
}

.modal-content .close {
    position: absolute;
    top: 18px;
    right: 18px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-soft);
    background: transparent;
    border: none;
    padding: 0;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}

.modal-content .close:hover {
    color: var(--text);
    background: var(--primary-light);
}

.modal-minimize {
    position: absolute;
    top: 18px;
    right: 56px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-soft);
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
    font-family: inherit;
}

.modal-minimize:hover {
    color: var(--text);
    background: var(--primary-light) !important;
}

.modal-content button[type="button"]:not(.close):not(.modal-minimize) {
    margin-top: 4px;
    padding: 10px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border-strong);
    font-weight: 500;
}

.modal-content button[type="button"]:not(.close):not(.modal-minimize):hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* 9. ПАГИНАЦИЯ */
.pagination {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    color: var(--text-muted);
    font-size: 13px;
}

.pagination button {
    padding: 6px 12px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border-strong);
    font-size: 13px;
}

.pagination button:hover:not(:disabled) {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.pagination button:disabled {
    opacity: 0.35;
}

/* 10. ФИЛЬТРЫ */
.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px 14px;
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.filters input,
.filters select {
    padding: 8px 12px;
    font-size: 13.5px;
    border-color: var(--border);
}

.filters input:focus,
.filters select:focus {
    border-color: var(--primary);
}

.filter-toggle-btn {
    display: none;
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    background: var(--card);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
}

.filter-toggle-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

/* 11. ВКЛАДКИ ОБОРУДОВАНИЯ */
.equip-tabs {
    display: flex;
    gap: 2px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}
.equip-tabs::-webkit-scrollbar {
    display: none;
}

.equip-tab {
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: -1px;
    border-radius: 0;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s;
    font-family: inherit;
}

.equip-tab:hover {
    color: var(--text);
    background: transparent;
    border-color: transparent;
}

.equip-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* 12. ФОРМА ВХОДА */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #f8fafc 0%, #eef2f7 100%);
    width: 100%;
}

.login-box {
    background: var(--card);
    padding: 40px 36px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 380px;
    border: 1px solid var(--border);
}

.login-box h2 {
    text-align: center;
    margin: 0 0 28px;
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.login-box input {
    width: 100%;
    padding: 12px 14px;
    margin: 6px 0;
    font-size: 15px;
    border-radius: var(--radius-sm);
}

.login-box button {
    width: 100%;
    padding: 12px;
    font-size: 15px;
    font-weight: 600;
    margin-top: 16px;
    background: var(--primary);
}

.login-box button:hover {
    background: var(--primary-hover);
}

/* 13. КАРТА */
#map {
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    border: 1px solid var(--border);
}

.map-legend {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: var(--card);
    padding: 14px 18px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-size: 13px;
    max-width: 260px;
    z-index: 500;
    border: 1px solid var(--border);
}

.map-legend h4 {
    margin: 0 0 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-soft);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.map-legend .legend-row {
    display: flex;
    align-items: center;
    margin: 5px 0;
}

.map-legend .legend-color {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
}

/* 14. АВТОКОМПЛИТ */
.autocomplete-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    max-height: 280px;
    overflow-y: auto;
    z-index: 500;
    box-shadow: var(--shadow-md);
    margin-top: 4px;
}

.autocomplete-dropdown.active {
    display: block;
}

.autocomplete-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
    font-size: 14px;
}

.autocomplete-item:last-child {
    border-bottom: none;
}

.autocomplete-item:hover,
.autocomplete-item.selected {
    background: var(--primary-light);
}

/* 15. ВЛОЖЕНИЯ / КОММЕНТАРИИ / ИСТОРИЯ */
.attachment-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    flex-wrap: wrap;
}

.comment-item,
.history-item {
    border-bottom: 1px solid var(--border);
    padding: 12px 0;
}

.comment-item:last-child,
.history-item:last-child {
    border-bottom: none;
}

.comment-item small,
.history-item small {
    color: var(--text-soft);
    font-size: 12px;
    display: block;
    margin-bottom: 4px;
}

.comment-item p,
.history-item p {
    margin: 4px 0;
    font-size: 14px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* 16. ЦВЕТА СТРОК В ТАБЛИЦАХ ОБОРУДОВАНИЯ */
.equip-row-expired { background: #fef6f6; }
.equip-row-soon { background: #fffef9; }
.equip-row-ok { background: #f9fdfa; }

/* 17. КНОПКА «НАВЕРХ» */
#scroll-top-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--card);
    color: var(--text-muted);
    font-size: 18px;
    border: 1px solid var(--border-strong);
    cursor: pointer;
    z-index: 900;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: opacity 0.15s, background 0.15s, color 0.15s, transform 0.15s;
    padding: 0;
    line-height: 1;
}

#scroll-top-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
}

#scroll-top-btn.visible {
    display: flex;
}

/* 18. УВЕДОМЛЕНИЯ */
.notif-badge {
    background: var(--danger);
    color: white;
    border-radius: 10px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
    line-height: 16px;
    min-width: 18px;
    text-align: center;
    margin-left: auto;
}

.sidebar.collapsed .notif-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    margin-left: 0;
    padding: 1px 5px;
    font-size: 10px;
}

.sidebar nav button#notifications-btn {
    position: relative;
}

.notification-item {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
}

.notification-item:hover {
    background: var(--primary-light);
}

.notification-item.unread {
    background: #f0f7ff;
    border-left: 3px solid var(--info);
}

.notification-item .notif-title {
    font-weight: 600;
    font-size: 13.5px;
    color: var(--text);
    margin-bottom: 4px;
    word-wrap: break-word;
}

.notification-item .notif-text {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 4px;
    word-wrap: break-word;
}

.notification-item .notif-date {
    color: var(--text-soft);
    font-size: 12px;
}

.notification-item .notif-delete {
    float: right;
    background: transparent;
    color: var(--text-soft);
    border: none;
    padding: 2px 6px;
    font-size: 16px;
    cursor: pointer;
    border-radius: 4px;
    line-height: 1;
}

.notification-item .notif-delete:hover {
    background: #fee2e2;
    color: var(--danger);
}

/* 19. СОХРАНЕНИЕ ПЕРЕНОСОВ СТРОК */
.task-description,
.task-view-description {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* 20. КНОПКА «ЧЕРНОВИК» */
#draft-return-btn {
    position: fixed;
    bottom: 84px;
    right: 24px;
    padding: 11px 18px;
    background: #f59e0b;
    color: white;
    border: none;
    border-radius: 24px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    z-index: 950;
    display: none;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
    animation: draftPulse 2s ease-in-out infinite;
    font-family: inherit;
}

#draft-return-btn:hover {
    background: #d97706;
}

#draft-return-btn.visible {
    display: flex;
}

@keyframes draftPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}

/* 21. МОБИЛЬНАЯ АДАПТАЦИЯ */
@media (max-width: 768px) {
    body {
        flex-direction: column;
        overflow-y: auto !important;
    }

    body.menu-open {
        overflow: hidden !important;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: -280px;
        width: 260px;
        height: 100vh;
        z-index: 1300;
        transition: left 0.25s ease-in-out;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
        padding: calc(20px + env(safe-area-inset-top, 0)) 12px calc(20px + env(safe-area-inset-bottom, 0));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex-basis: auto;
    }

    .sidebar.mobile-open { left: 0; }
    .sidebar.collapsed { flex-basis: auto; width: 260px; }
    .sidebar.collapsed h2,
    .sidebar.collapsed nav button span:not(.menu-icon) { display: inline; }
    .sidebar.collapsed nav button { padding: 9px 12px; justify-content: flex-start; }
    .sidebar.collapsed .menu-icon { margin-right: 12px; }

    main {
        padding: calc(68px + env(safe-area-inset-top, 0)) 16px calc(20px + env(safe-area-inset-bottom, 0));
        margin-left: 0;
        width: 100%;
        max-width: 100%;
    }

    #toggle-sidebar {
        position: fixed;
        top: calc(12px + env(safe-area-inset-top, 0));
        left: calc(12px + env(safe-area-inset-left, 0));
        z-index: 1250;
        background: rgba(15, 23, 42, 0.85);
        color: white;
        border-radius: 8px;
        width: 40px;
        height: 40px;
        font-size: 18px;
        box-shadow: var(--shadow-sm);
        margin-bottom: 0;
        align-self: auto;
        padding: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: opacity 0.2s;
    }

    #toggle-sidebar.hidden {
        opacity: 0;
        pointer-events: none;
    }

    .mobile-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.5);
        z-index: 1250;
    }

    .mobile-overlay.active { display: block; }

    .modal-content {
        padding: 24px 20px;
        max-height: 95vh;
    }

    h2 { font-size: 18px; }

    .filters { padding: 10px; }
    .filters input, .filters select { width: 100%; }
    .filter-toggle-btn { display: block; }
    .filters.collapsible { display: none; }
    .filters.collapsible.open { display: flex; }

    #scroll-top-btn {
        bottom: calc(16px + env(safe-area-inset-bottom, 0));
        right: calc(16px + env(safe-area-inset-right, 0));
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    #draft-return-btn {
        bottom: calc(72px + env(safe-area-inset-bottom, 0));
        right: calc(16px + env(safe-area-inset-right, 0));
        padding: 10px 14px;
        font-size: 12px;
    }

    .modal-minimize {
        top: 14px;
        right: 52px;
    }

    .modal-content .close {
        top: 14px;
        right: 14px;
    }
}

/* Аккуратный вертикальный скроллбар страницы */
html {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
html::-webkit-scrollbar {
    width: 8px;
}
html::-webkit-scrollbar-track {
    background: transparent;
}
html::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
html::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ============================================================
   ТАБЛИЦА ЗАДАЧ (ПК) + КАРТОЧКИ (мобильный)
   ============================================================ */

.tasks-table {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-top: 8px;
}

.tasks-table-header {
    display: grid;
    grid-template-columns: 60px 110px 1fr 200px 150px 130px 170px;
    gap: 12px;
    padding: 11px 18px 11px 22px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 11.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
}

.task-row {
    position: relative;
    display: grid;
    grid-template-columns: 60px 110px 1fr 200px 150px 130px 170px;
    gap: 12px;
    padding: 12px 18px 12px 22px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.1s;
    align-items: center;
    font-size: 13.5px;
}

.task-row:last-child {
    border-bottom: none;
}

.task-row:hover {
    background: var(--card-hover);
}

.task-row.task-overdue {
    background: #fef6f6;
}

.task-row.task-overdue:hover {
    background: #fdeaea;
}

.task-row .cell {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-row .cell.num {
    font-weight: 600;
    color: var(--text);
}

.task-row .cell.date {
    color: var(--text-soft);
    font-size: 12.5px;
}

.task-row .cell.title {
    font-weight: 500;
    color: var(--text);
}

.task-row .cell.client,
.task-row .cell.engineer {
    color: var(--text-muted);
}

.task-row .cell.deadline {
    font-size: 12.5px;
    color: var(--text-muted);
    white-space: normal;
    line-height: 1.3;
}

.task-row .cell.deadline .lbl {
    color: var(--text-soft);
    display: block;
    font-size: 11px;
    margin-bottom: 1px;
}
.row-left-bar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
}


/* Бейдж статуса */
.badge-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.badge-status.new { background: #dbeafe; color: #1e40af; }
.badge-status.in_progress { background: #fef3c7; color: #92400e; }
.badge-status.completed { background: #fed7aa; color: #9a3412; }
.badge-status.closed { background: #d1fae5; color: #065f46; }
.badge-status.deleted { background: #e5e7eb; color: #6b7280; }
.badge-status.overdue { background: #fee2e2; color: #991b1b; }

/* Строка срока в ячейке */
.deadline-text {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.deadline-text.overdue {
    color: var(--danger);
    font-weight: 600;
}

/* ============================================================
   МОБИЛЬНЫЙ ВИД
   ============================================================ */

@media (max-width: 768px) {
    .tasks-table {
        background: transparent;
        border: none;
        border-radius: 0;
        overflow: visible;
    }

    .tasks-table-header {
        display: none;
    }

    .task-row {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "num     status"
            "title   title"
            "client  client"
            "eng     deadline";
        gap: 6px 12px;
        padding: 14px 16px 14px 18px;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 8px;
        background: var(--card);
        align-items: start;
    }

    .task-row:hover {
        background: var(--card);
    }

    .task-row .cell.num { grid-area: num; font-size: 12.5px; color: var(--text-soft); }
    .task-row .cell.date { display: none; }
    .task-row .cell.title { grid-area: title; white-space: normal; font-size: 15px; font-weight: 600; margin: 2px 0; }
    .task-row .cell.client { grid-area: client; white-space: normal; font-size: 13px; }
    .task-row .cell.engineer { grid-area: eng; font-size: 12.5px; }
    .task-row .cell.status { grid-area: status; justify-self: end; }
    .task-row .cell.deadline { grid-area: deadline; justify-self: end; text-align: right; font-size: 12px; }

    .task-row .cell.num::before {
        content: '';
    }
}