/* Bitrix24 Inspired CRM Theme & Layout */
:root {
    --b24-primary: #0076fe;
    --b24-primary-hover: #0060d4;
    --b24-sidebar-bg: #1c2536;
    --b24-sidebar-text: #9ca3af;
    --b24-sidebar-hover: #2d3748;
    --b24-sidebar-active: #2b3952;
    --b24-header-bg: #ffffff;
    --b24-body-bg: #edf2f7;
    --b24-card-bg: #ffffff;
    --b24-border: #e2e8f0;
    --b24-text: #1f2937;
    --b24-text-muted: #64748b;

    /* Stage colors */
    --stage-draft: #94a3b8;
    --stage-sent: #0284c7;
    --stage-partial: #f59e0b;
    --stage-paid: #10b981;
    --stage-cancelled: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--b24-body-bg);
    color: var(--b24-text);
    display: flex;
    height: 100vh;
    overflow: hidden;
    font-size: 14px;
}

/* APP SHELL */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* SIDEBAR */
.sidebar {
    width: 250px;
    background-color: var(--b24-sidebar-bg);
    color: var(--b24-sidebar-text);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 20;
    box-shadow: 2px 0 8px rgba(0,0,0,0.05);
}

.sidebar-header {
    padding: 20px 22px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: background 0.15s ease;
}

.sidebar-header:hover {
    background: rgba(255, 255, 255, 0.06);
}

/* Логотип в шапке — только на телефоне (на широком экране есть боковое меню) */
.mobile-brand {
    display: none;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 2px 2px;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
}

.mobile-brand-badge {
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    border-radius: 8px;
    background: linear-gradient(135deg, #0080ff, #00d2ff);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 13.5px;
}

.mobile-brand-text {
    font-size: 13.5px;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.logo-badge {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: linear-gradient(135deg, #0080ff, #00d2ff);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 800;
    font-size: 18px;
    box-shadow: 0 4px 10px rgba(0, 128, 255, 0.4);
}

.logo-text {
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.2;
}

.logo-sub {
    font-size: 11px;
    color: #94a3b8;
}

.sidebar-nav {
    flex: 1;
    padding: 16px 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-section-title {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #64748b;
    padding: 10px 14px 4px 14px;
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    color: #cbd5e1;
    text-decoration: none;
    font-weight: 500;
    font-size: 13.5px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.nav-item:hover {
    background-color: var(--b24-sidebar-hover);
    color: #ffffff;
}

.nav-item.active {
    background-color: var(--b24-primary);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 118, 254, 0.35);
}

.nav-icon {
    font-size: 17px;
    width: 20px;
    text-align: center;
}

.nav-badge {
    margin-left: auto;
    background: rgba(255,255,255,0.15);
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.nav-item.active .nav-badge {
    background: #ffffff;
    color: var(--b24-primary);
}

.nav-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-popout-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.45);
    font-size: 11px;
    opacity: 0;
    transition: all 0.15s ease;
    margin-left: 4px;
    cursor: pointer;
}

.nav-item:hover .nav-popout-btn {
    opacity: 0.85;
}

.nav-popout-btn:hover {
    opacity: 1 !important;
    color: #ffffff !important;
    background: rgba(255, 255, 255, 0.25) !important;
}

.nav-item.active .nav-popout-btn {
    color: rgba(255, 255, 255, 0.7);
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,0.15);
}

.seller-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #3b82f6;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 13px;
}

.seller-info {
    font-size: 12px;
    line-height: 1.3;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.seller-name {
    color: #fff;
    font-weight: 600;
}

/* MAIN CONTENT AREA */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* TOP HEADER */
.top-header {
    background-color: var(--b24-header-bg);
    border-bottom: 1px solid var(--b24-border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
}

/* Bitrix24 Smart Filter Header */
.smart-search-container {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    max-width: 650px;
}

.search-input-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.search-input-wrapper input {
    width: 100%;
    height: 38px;
    padding: 0 36px 0 38px;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    background-color: #f8fafc;
    font-size: 13.5px;
    outline: none;
    transition: all 0.2s ease;
}

.search-input-wrapper input:focus {
    border-color: var(--b24-primary);
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(0, 118, 254, 0.15);
}

.search-icon {
    position: absolute;
    left: 13px;
    color: #94a3b8;
    font-size: 15px;
    pointer-events: none;
}

.clear-search-btn {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 14px;
    display: none;
}

.clear-search-btn:hover {
    color: #475569;
}

.btn-filter-trigger {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-filter-trigger:hover, .btn-filter-trigger.active {
    background: #e2e8f0;
    border-color: #94a3b8;
}

/* Header Action Buttons */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.view-toggle {
    display: flex;
    background: #f1f5f9;
    border-radius: 8px;
    padding: 3px;
    border: 1px solid #e2e8f0;
}

.view-toggle-btn {
    background: none;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
}

.view-toggle-btn.active {
    background: #ffffff;
    color: var(--b24-primary);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.btn-primary {
    background: linear-gradient(135deg, #0076fe, #0099ff);
    color: #fff;
    border: none;
    border-radius: 8px;
    white-space: nowrap;
    padding: 8px 18px;
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 6px rgba(0, 118, 254, 0.3);
    transition: all 0.2s;
}

.btn-primary:hover {
    background: linear-gradient(135deg, #0060d4, #0088ee);
    box-shadow: 0 4px 10px rgba(0, 118, 254, 0.4);
}

.btn-secondary {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #334155;
    border-radius: 8px;
    padding: 8px 16px;
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

/* BITRIX24 FILTER BAR / PRESETS */
.presets-bar {
    background: #ffffff;
    border-bottom: 1px solid var(--b24-border);
    padding: 8px 24px;
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    white-space: nowrap;
}

.preset-chip {
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 12.5px;
    font-weight: 500;
    color: #64748b;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.15s;
    user-select: none;
}

.preset-chip:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.preset-chip.active {
    background: #e0f2fe;
    color: #0369a1;
    border-color: #7dd3fc;
    font-weight: 600;
}

.active-filters-tags {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
}

.filter-tag {
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 11.5px;
    color: #334155;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.filter-tag .tag-close {
    cursor: pointer;
    color: #94a3b8;
}
.filter-tag .tag-close:hover {
    color: #ef4444;
}

/* EXPANDABLE FILTER DRAWER */
.filter-drawer {
    display: none;
    background: #ffffff;
    border-bottom: 1px solid var(--b24-border);
    padding: 16px 24px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    animation: slideDown 0.2s ease-out;
}

.filter-drawer.open {
    display: block;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 14px;
}

.filter-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
}

.filter-group select, .filter-group input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
    outline: none;
    background: #ffffff;
}

.filter-group select:focus, .filter-group input:focus {
    border-color: var(--b24-primary);
}

.filter-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    border-top: 1px solid #f1f5f9;
    padding-top: 12px;
}

/* CONTENT VIEW AREA */
.content-area {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
}

/* BITRIX24 KANBAN BOARD */
.kanban-board {
    display: flex;
    gap: 16px;
    height: 100%;
    overflow-x: auto;
    padding-bottom: 12px;
}

.kanban-column {
    flex: 0 0 290px;
    background: #ebedf0;
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    max-height: 100%;
    border-top: 4px solid #cbd5e1;
}

.kanban-column.col-draft { border-top-color: var(--stage-draft); }
.kanban-column.col-sent { border-top-color: var(--stage-sent); }
.kanban-column.col-partial { border-top-color: var(--stage-partial); }
.kanban-column.col-paid { border-top-color: var(--stage-paid); }
.kanban-column.col-cancelled { border-top-color: var(--stage-cancelled); }
.kanban-column.col-signed { border-top-color: var(--stage-paid); }
.kanban-column.col-rejected { border-top-color: var(--stage-cancelled); }

.kanban-col-header {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
}

.kanban-col-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kanban-col-title {
    font-weight: 700;
    font-size: 13.5px;
    color: #1e293b;
}

.kanban-col-count {
    background: rgba(0,0,0,0.08);
    padding: 1px 7px;
    border-radius: 12px;
    font-size: 11.5px;
    font-weight: 600;
}

.kanban-col-sum {
    font-size: 13px;
    font-weight: 700;
    color: #334155;
}

.kanban-cards-list {
    flex: 1;
    padding: 10px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.kanban-card {
    background: #ffffff;
    border-radius: 8px;
    padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform 0.15s, box-shadow 0.15s;
    cursor: pointer;
    position: relative;
}

.kanban-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.12);
}

.kanban-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.card-number {
    font-weight: 700;
    font-size: 13.5px;
    color: var(--b24-primary);
}

.card-date {
    font-size: 11.5px;
    color: #94a3b8;
}

.card-client {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    line-height: 1.3;
}

.card-items-preview {
    font-size: 11.5px;
    color: #64748b;
    line-height: 1.35;
    background: #f8fafc;
    padding: 4px 6px;
    border-radius: 4px;
}

.card-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #f1f5f9;
    padding-top: 8px;
}

.card-amount {
    font-size: 14.5px;
    font-weight: 800;
    color: #0f172a;
}

.card-actions-quick {
    display: flex;
    gap: 6px;
}

.card-btn-icon {
    background: #f1f5f9;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #475569;
    font-size: 13px;
    transition: all 0.15s;
}

.card-btn-icon:hover {
    background: #e2e8f0;
    color: var(--b24-primary);
}

/* TABLE VIEW */
.table-card {
    background: #ffffff;
    border-radius: 10px;
    border: 1px solid var(--b24-border);
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    /* Было overflow: hidden — на 1024 и 1280 px таблица счетов (ей нужно ~1040 px)
       обрезалась вместе с колонкой «Действия», и кнопки становились недоступны.
       Теперь таблица прокручивается по горизонтали. */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    background: #f8fafc;
    padding: 12px 14px;
    text-align: left;
    font-weight: 600;
    color: #475569;
    border-bottom: 1px solid var(--b24-border);
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.data-table tr:hover td {
    background-color: #f8fafc;
}

/* Status Badges */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    outline: none;
}

.status-pill.status-draft { background: #f1f5f9; color: #475569; }
.status-pill.status-sent { background: #e0f2fe; color: #0284c7; }
.status-pill.status-partial { background: #fef3c7; color: #d97706; }
.status-pill.status-paid { background: #d1fae5; color: #059669; }
.status-pill.status-cancelled { background: #fee2e2; color: #dc2626; }
.status-pill.status-signed { background: #d1fae5; color: #059669; }
.status-pill.status-rejected { background: #fee2e2; color: #dc2626; }

/* Status selector dropdown in table */
.status-select-table {
    border: none;
    background: transparent;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    border-radius: 12px;
    padding: 4px 8px;
}

/* Action button bar in table */
.actions-cell {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    vertical-align: middle;
}

/* Modern Clean Borderless Table Action Buttons */
.tbl-icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 7px;
    border: none;
    background: transparent;
    color: #64748b;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.15s ease;
    padding: 0;
    line-height: 1;
    text-decoration: none;
    box-sizing: border-box;
}

.tbl-icon-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
    transform: translateY(-1px);
}

.tbl-icon-btn-primary:hover {
    background: #f0f9ff;
    color: #0284c7;
}

.tbl-icon-btn-success:hover {
    background: #ecfdf5;
    color: #059669;
}

.tbl-icon-btn-indigo:hover {
    background: #eef2ff;
    color: #4f46e5;
}

.tbl-icon-btn-danger:hover {
    background: #fee2e2;
    color: #ef4444;
}

/* Table Pill Action Buttons (Clients table) */
.tbl-pill-btn {
    height: 30px;
    padding: 0 11px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    border: none;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    box-sizing: border-box;
}

.tbl-pill-btn-blue {
    background: #0076fe;
    color: #ffffff;
    box-shadow: 0 1px 2px rgba(0, 118, 254, 0.2);
}
.tbl-pill-btn-blue:hover {
    background: #0060d4;
    transform: translateY(-1px);
}

.tbl-pill-btn-subtle {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #334155;
}
.tbl-pill-btn-subtle:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #0f172a;
    transform: translateY(-1px);
}

/* Client Clickable Link */
.client-link {
    color: #0284c7;
    text-decoration: none;
    font-weight: 700;
    transition: color 0.15s, text-decoration 0.15s;
    cursor: pointer;
    display: inline-block;
}
.client-link:hover {
    color: #0369a1;
    text-decoration: underline;
}

.btn-sm {
    padding: 5px 10px !important;
    font-size: 12px !important;
    border-radius: 6px !important;
    font-weight: 600 !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 5px !important;
    cursor: pointer;
    border: none;
    transition: opacity 0.15s;
}
.btn-sm:hover {
    opacity: 0.9;
}

/* Backward compatibility for remaining .table-btn */
.table-btn {
    background: transparent;
    border: none;
    border-radius: 6px;
    padding: 6px 8px;
    font-size: 12.5px;
    color: #475569;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s;
}
.table-btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

/* Checkboxes in Data Tables */
.tbl-checkbox {
    width: 17px;
    height: 17px;
    border-radius: 4px;
    border: 1.5px solid #cbd5e1;
    cursor: pointer;
    accent-color: #0076fe;
    vertical-align: middle;
    margin: 0;
    transition: all 0.15s ease;
}
.tbl-checkbox:hover {
    border-color: #0076fe;
}

.td-checkbox, .th-checkbox {
    width: 40px !important;
    text-align: center !important;
    padding: 10px 8px !important;
}

/* Row selection highlight */
.data-table tr.row-selected td {
    background-color: #f0f7ff !important;
}

/* Floating Bulk Actions Bar */
.bulk-actions-bar {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(120px);
    background: #0f172a;
    color: #ffffff;
    border-radius: 12px;
    padding: 10px 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.15);
    z-index: 1500;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    opacity: 0;
    pointer-events: none;
    max-width: 92vw;
    box-sizing: border-box;
}

.bulk-actions-bar.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.bulk-counter-pill {
    background: rgba(255, 255, 255, 0.14);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.2px;
}

.bulk-bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.bulk-btn {
    height: 34px;
    padding: 0 13px;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    transition: all 0.15s ease;
}

.bulk-btn-success {
    background: #10b981;
    color: #ffffff;
}
.bulk-btn-success:hover {
    background: #059669;
}

.bulk-btn-primary {
    background: #0076fe;
    color: #ffffff;
}
.bulk-btn-primary:hover {
    background: #0060d4;
}

.bulk-btn-danger {
    background: #ef4444;
    color: #ffffff;
}
.bulk-btn-danger:hover {
    background: #dc2626;
}

.bulk-select-wrap select {
    height: 34px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: #1e293b;
    color: #ffffff;
    padding: 0 10px;
    font-size: 12.5px;
    cursor: pointer;
    outline: none;
}
.bulk-select-wrap select:focus {
    border-color: #0076fe;
}

.bulk-cancel-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 6px;
    transition: all 0.15s;
    white-space: nowrap;
}
.bulk-cancel-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

/* DASHBOARD STATS WIDGETS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: #ffffff;
    border-radius: 10px;
    padding: 18px 20px;
    border: 1px solid var(--b24-border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.stat-title {
    font-size: 12.5px;
    color: #64748b;
    font-weight: 500;
}

.stat-value {
    font-size: 22px;
    font-weight: 800;
    color: #0f172a;
}

.stat-badge {
    font-size: 11.5px;
    color: #10b981;
    font-weight: 600;
}

/* MODAL & SLIDE-OUT OVERLAYS */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.open {
    display: flex;
}

.modal-box {
    background: #ffffff;
    border-radius: 12px;
    max-width: 900px;
    width: 100%;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    overflow: hidden;
    animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-box.modal-xl {
    max-width: 1180px;
    height: 94vh;
}

.modal-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--b24-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #ffffff;
    min-height: 56px;
    box-sizing: border-box;
}

/* Шапка окна «Все счета клиента»: кнопки и крестик в один ряд */
.client-history-controls,
.client-history-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Подпись под суммой счёта с частичной оплатой */
.paid-hint {
    font-size: 11.5px;
    font-weight: 500;
    color: #b45309;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 6px;
    padding: 2px 7px;
    margin-top: 4px;
    display: inline-block;
    line-height: 1.35;
    white-space: nowrap;
}

.paid-hint strong {
    color: #92400e;
    font-weight: 700;
}

.paid-hint-empty {
    color: #b91c1c;
    background: #fef2f2;
    border-color: #fecaca;
}

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 8px;
    line-height: 1.3;
}

.modal-close-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #64748b;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: all 0.15s ease;
    flex-shrink: 0;
    padding: 0;
    margin: 0;
}

.modal-close-btn:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #ef4444;
}

/* Document Viewer Header Toolbar */
.doc-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    min-height: 58px;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    gap: 16px;
    box-sizing: border-box;
}

.doc-viewer-header .modal-title {
    font-size: 15px;
    font-weight: 600;
    color: #334155;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.doc-viewer-header .modal-title strong {
    color: #0284c7;
    font-weight: 700;
}

.doc-viewer-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.viewer-actions-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}

.doc-action-btn {
    height: 36px;
    padding: 0 13px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    box-sizing: border-box;
    flex-shrink: 0;
    line-height: 1;
    text-decoration: none;
    user-select: none;
}

.doc-action-btn i {
    font-size: 13px;
}

/* Secondary / outline */
.doc-action-btn-secondary {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #334155;
}
.doc-action-btn-secondary:hover {
    background: #f8fafc;
    border-color: #94a3b8;
    color: #0f172a;
}

/* Copy invoice */
.doc-action-btn-copy {
    background: #f5f3ff;
    border: 1px solid #ddd6fe;
    color: #6d28d9;
}
.doc-action-btn-copy:hover {
    background: #ede9fe;
    border-color: #c4b5fd;
    color: #5b21b6;
}

/* Package ZIP Download */
.doc-action-btn-pkg-dl {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #047857;
}
.doc-action-btn-pkg-dl:hover {
    background: #d1fae5;
    border-color: #6ee7b7;
    color: #065f46;
}

/* Package Email (Sky Blue) */
.doc-action-btn-pkg-email {
    background: #0284c7;
    border: 1px solid #0284c7;
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(2, 132, 199, 0.25);
}
.doc-action-btn-pkg-email:hover {
    background: #0369a1;
    border-color: #0369a1;
}

/* Single Email (Primary Blue) */
.doc-action-btn-primary {
    background: #0076fe;
    border: 1px solid #0076fe;
    color: #ffffff;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 118, 254, 0.25);
}
.doc-action-btn-primary:hover {
    background: #0060d4;
    border-color: #0060d4;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--b24-border);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: #f8fafc;
}

/* FORM STYLES */
.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.form-grid-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 14px;
}

.form-group label {
    font-size: 12.5px;
    font-weight: 600;
    color: #334155;
}

.form-group input, .form-group select, .form-group textarea {
    padding: 9px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    font-size: 13.5px;
    outline: none;
    background: #ffffff;
    font-family: inherit;
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    border-color: var(--b24-primary);
    box-shadow: 0 0 0 3px rgba(0, 118, 254, 0.12);
}

/* Dynamic Items Editor Table */
.items-editor-table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 13px;
}

.items-editor-table th {
    background: #f1f5f9;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    font-weight: 600;
    color: #334155;
}

.items-editor-table td {
    padding: 6px 8px;
    border: 1px solid #e2e8f0;
}

.items-editor-table input, .items-editor-table select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 5px;
    font-size: 13px;
}

.btn-remove-row {
    background: #fee2e2;
    color: #ef4444;
    border: none;
    border-radius: 5px;
    width: 26px;
    height: 26px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}
.btn-remove-row:hover { background: #fca5a5; }

/* Totals Summary Panel in Editor */
.editor-totals-panel {
    background: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    padding: 16px 20px;
    margin-top: 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.totals-left {
    max-width: 55%;
}

.words-preview {
    font-size: 13px;
    color: #1e293b;
    margin-top: 4px;
    font-style: italic;
}

.totals-right {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 260px;
}

.total-line {
    display: flex;
    justify-content: space-between;
    font-size: 13.5px;
    color: #475569;
}

.total-line.final-line {
    font-size: 17px;
    font-weight: 800;
    color: #0f172a;
    border-top: 2px solid #cbd5e1;
    padding-top: 6px;
}

/* FACSIMILE PREVIEW CARDS (My Requisites) */
.facsimile-cards-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 20px;
}

.facsimile-preview-card {
    border: 2px dashed #cbd5e1;
    border-radius: 10px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    min-height: 220px;
    position: relative;
}

.facsimile-preview-img {
    max-height: 140px;
    max-width: 180px;
    object-fit: contain;
    margin-bottom: 12px;
}

/* DOCUMENT PREVIEW MODAL */
.doc-preview-wrapper {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 6px;
    background: #e2e8f0;
}

/* TOAST NOTIFICATION */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: #1e293b;
    color: #fff;
    padding: 12px 18px;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    font-size: 13.5px;
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: auto;
    animation: toastIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.success { border-left: 4px solid #10b981; }
.toast.error { border-left: 4px solid #ef4444; }
.toast.info { border-left: 4px solid #0284c7; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}


/* ========================================================
   MULTI-USER, AUTHOR TRACKING & INVITATION LINKS STYLES
   ======================================================== */

.user-switcher-container {
    position: relative;
}

.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #f1f5f9;
    padding: 4px 10px 4px 5px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    border: 1px solid #cbd5e1;
    transition: all 0.15s ease;
    user-select: none;
}

.user-pill:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
}

.user-avatar-circle {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.user-dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: #ffffff;
    border: 1px solid var(--b24-border);
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    min-width: 240px;
    display: none;
    z-index: 1000;
    overflow: hidden;
    animation: slideDown 0.15s ease-out;
}

.user-dropdown-menu.open {
    display: block;
}

.user-dropdown-header {
    padding: 10px 14px;
    font-size: 11.5px;
    color: #64748b;
    font-weight: 600;
    border-bottom: 1px solid #f1f5f9;
    background: #f8fafc;
}

.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 13px;
    font-weight: 500;
    color: #1e293b;
}

.user-dropdown-item:hover {
    background: #f1f5f9;
}

.user-dropdown-item.active {
    background: #e0f2fe;
    color: #0369a1;
    font-weight: 700;
}

.user-dropdown-divider {
    height: 1px;
    background: #f1f5f9;
    margin: 4px 0;
}

/* Author badge on cards and in tables */
.badge-author {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 10px;
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge-author-muslim { background: #0284c7; }
.badge-author-ilya { background: #10b981; }
.badge-author-vladislav { background: #8b5cf6; }

/* Package badge (Счет + Акт) */
.badge-pkg {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 700;
    color: #0369a1;
    background: #e0f2fe;
    border: 1px solid #bae6fd;
    padding: 2px 7px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s ease;
}
.badge-pkg:hover {
    background: #bae6fd;
    color: #075985;
}

/* Invite links cards */
.invite-cards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 14px;
}

.invite-card {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.invite-card-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.invite-card-info h4 {
    font-size: 14px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 2px;
}

.invite-card-info p {
    font-size: 11.5px;
    color: #64748b;
    word-break: break-all;
}

/* ========================================================
   MOBILE RESPONSIVE DESIGN (< 768px and < 1024px)
   ======================================================== */

.btn-mobile-menu {
    display: none;
    background: none;
    border: none;
    font-size: 19px;
    color: #334155;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
}

.btn-mobile-menu:hover {
    background: #f1f5f9;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    z-index: 99;
}

.sidebar-backdrop.active {
    display: block;
}

/* Responsive View Modes (Desktop Table vs Mobile Touch Cards) */
.desktop-table-view {
    display: block;
}

.mobile-cards-view {
    display: none;
}

/* Tablets and Mobile Screens */
@media (max-width: 1024px) {
    .smart-search-container {
        max-width: 420px;
    }
}

@media (max-width: 768px) {
    /* Global scroll constraints - Kill all horizontal overflow */
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
    }

    .app-container, .main-wrapper, .content-area {
        overflow-x: hidden !important;
        max-width: 100vw !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Show mobile hamburger */
    .btn-mobile-menu {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        order: 1 !important;
        width: 38px !important;
        height: 38px !important;
    }

    /* Off-canvas mobile sidebar */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    /* Шапка на телефоне — три ровных ряда, без наложений.
       display: contents убирает промежуточную коробку .header-actions:
       пилюля пользователя, переключатель вида и кнопка создания встают
       в общий поток шапки и слушаются order. */
    .top-header {
        padding: 8px 12px !important;
        display: flex !important;
        flex-wrap: wrap !important;
        align-items: center !important;
        gap: 8px !important;
    }

    .header-actions {
        display: contents !important;
    }

    /* Ряд 1: бургер — логотип — пользователь */
    .mobile-brand {
        order: 2 !important;
        display: flex !important;
        flex: 1 1 auto !important;
        min-width: 0 !important;
    }

    .user-switcher-container {
        order: 3 !important;
        flex: 0 0 auto !important;
    }

    .user-pill {
        padding: 4px 8px 4px 4px !important;
        font-size: 13px !important;
        max-width: 160px !important;
    }

    #user-name-display {
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    /* Меню профиля не должно уезжать за край экрана */
    .user-dropdown-menu {
        left: auto !important;
        right: 0 !important;
        max-width: calc(100vw - 24px) !important;
    }

    /* Ряд 2: поиск — фильтр — переключатель вида */
    .smart-search-container {
        order: 4 !important;
        flex: 1 1 200px !important;
        min-width: 0 !important;
        max-width: 100% !important;
        margin-top: 0 !important;
    }

    .view-toggle {
        order: 5 !important;
        flex: 0 0 auto !important;
        margin-left: 0 !important;
    }

    .view-toggle-btn span {
        display: none; /* оставляем только иконки */
    }

    .view-toggle-btn {
        padding: 6px 9px !important;
        font-size: 13px !important;
    }

    /* Ряд 3: кнопка создания — во всю ширину */
    #btn-primary-create {
        order: 6 !important;
        flex: 1 1 100% !important;
        width: 100% !important;
        margin-top: 0 !important;
        padding: 11px 16px !important;
        font-size: 13.5px !important;
        font-weight: 600 !important;
        justify-content: center !important;
        border-radius: 9px !important;
        box-shadow: 0 2px 6px rgba(0, 118, 254, 0.25) !important;
    }

    #btn-primary-create-text {
        display: inline !important;
    }

    .search-input-wrapper input {
        padding-top: 8px !important;
        padding-bottom: 8px !important;
        font-size: 13px !important;
    }

    .btn-filter-trigger {
        padding: 7px 11px !important;
        font-size: 12px !important;
    }

    /* Presets horizontal touch scroll - Hide ugly scrollbar */
    .presets-bar {
        padding: 8px 12px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
        white-space: nowrap !important;
    }

    .presets-bar::-webkit-scrollbar {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
    }

    .preset-chip {
        padding: 5px 12px !important;
        font-size: 12px !important;
        flex-shrink: 0 !important;
    }

    /* Content Area */
    .content-area {
        padding: 10px 10px 24px 10px !important;
    }

    /* Switch between Desktop Table and Mobile Touch Cards */
    .desktop-table-view {
        display: none !important;
    }

    .mobile-cards-view {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        width: 100% !important;
    }

    .table-card {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        overflow: visible !important;
    }

    /* Mobile Cards (2026 UI) */
    .mob-doc-card, .mob-client-card, .mob-log-card {
        background: #ffffff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        padding: 13px 13px 11px 13px;
        box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
        display: flex;
        flex-direction: column;
        gap: 8px;
        box-sizing: border-box;
        width: 100%;
    }

    .mob-doc-card:active, .mob-client-card:active {
        background-color: #f8fafc;
    }

    .mob-doc-top {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 8px;
    }

    .mob-doc-num-date {
        display: flex;
        align-items: baseline;
        gap: 8px;
    }

    .mob-doc-num {
        font-size: 15.5px;
        font-weight: 700;
        color: #0f172a;
        letter-spacing: -0.2px;
    }

    .mob-doc-date {
        font-size: 12px;
        color: #64748b;
        font-weight: 500;
    }

    .mob-doc-package-banner {
        background: #ecfdf5;
        border: 1px solid #a7f3d0;
        color: #065f46;
        padding: 6px 10px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 600;
        display: flex;
        align-items: center;
        gap: 7px;
        cursor: pointer;
    }

    .mob-doc-package-banner:hover {
        background: #d1fae5;
    }

    .mob-doc-link-banner {
        background: #eff6ff;
        border: 1px solid #bfdbfe;
        color: #1e40af;
        padding: 6px 10px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 500;
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .mob-doc-client {
        margin-top: 1px;
    }

    .mob-doc-client-name {
        font-size: 13.5px;
        font-weight: 600;
        color: #1e293b;
        line-height: 1.35;
        word-break: break-word;
    }

    .mob-doc-client-inn {
        font-size: 11.5px;
        color: #64748b;
        margin-top: 2px;
    }

    .mob-doc-meta {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-top: 7px;
        border-top: 1px dashed #e2e8f0;
        gap: 8px;
    }

    .mob-doc-sum {
        font-size: 17px;
        font-weight: 800;
        color: #0f172a;
        letter-spacing: -0.3px;
    }

    .mob-doc-status-wrap .status-select-table {
        min-height: 30px;
        font-size: 11.5px;
        font-weight: 600;
        padding: 4px 8px;
        border-radius: 20px;
    }

    .mob-doc-actions {
        display: flex;
        flex-direction: column;
        gap: 6px;
        margin-top: 3px;
        padding-top: 7px;
        border-top: 1px solid #f1f5f9;
    }

    .mob-primary-action-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 7px;
    }

    .mob-primary-action-row.single-btn {
        grid-template-columns: 1fr;
    }

    .mob-btn-action {
        white-space: nowrap;
        min-height: 38px;
        border-radius: 8px;
        font-size: 12px;
        font-weight: 600;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        cursor: pointer;
        border: none;
        padding: 6px 10px;
        transition: opacity 0.15s ease;
        box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    }

    .mob-btn-action:active {
        opacity: 0.85;
    }

    .mob-btn-green {
        background: #10b981;
        color: #ffffff;
    }

    .mob-btn-blue {
        background: #0076fe;
        color: #ffffff;
    }

    .mob-btn-teal {
        background: #0284c7;
        color: #ffffff;
    }

    .mob-btn-subtle {
        background: #f8fafc;
        color: #334155;
        border: 1px solid #cbd5e1;
    }

    .mob-sub-action-row {
        display: flex;
        gap: 5px;
        align-items: center;
    }

    .mob-sub-btn {
        flex: 1;
        min-height: 32px;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 7px;
        color: #475569;
        font-size: 11px;
        font-weight: 500;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        cursor: pointer;
        transition: background-color 0.15s ease;
    }

    .mob-sub-btn:active {
        background: #e2e8f0;
    }

    .mob-btn-delete {
        flex: 0 0 34px !important;
        color: #ef4444 !important;
        border-color: #fee2e2 !important;
        background: #fff5f5 !important;
    }

    /* Mobile Client Cards */
    .mob-client-card {
        gap: 9px;
    }

    .mob-client-top {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 8px;
    }

    .mob-client-name {
        font-size: 14.5px;
        font-weight: 700;
        color: #0f172a;
        line-height: 1.35;
    }

    .mob-client-meta {
        font-size: 11.5px;
        color: #64748b;
        margin-top: 2px;
    }

    .badge-client-type {
        display: inline-block;
        padding: 3px 8px;
        border-radius: 6px;
        background: #f1f5f9;
        color: #475569;
        font-size: 11px;
        font-weight: 600;
        white-space: nowrap;
    }

    .mob-client-contacts {
        display: flex;
        flex-direction: column;
        gap: 4px;
        font-size: 12px;
    }

    .mob-contact-link {
        color: #0076fe;
        text-decoration: none;
        display: inline-flex;
        align-items: center;
        gap: 6px;
        font-weight: 500;
    }

    .mob-client-addr {
        color: #64748b;
        font-size: 11.5px;
        display: flex;
        align-items: flex-start;
        gap: 6px;
        margin-top: 2px;
    }

    .mob-client-bank {
        background: #f8fafc;
        border-radius: 8px;
        padding: 8px 10px;
        font-size: 11.5px;
        color: #475569;
        border: 1px solid #f1f5f9;
    }

    .mob-client-actions {
        display: flex;
        gap: 6px;
        align-items: center;
        margin-top: 2px;
        flex-wrap: nowrap;
    }

    /* Кнопки-иконки держат свою ширину и не обкрадывают «Выставить счет» */
    .mob-client-actions .mob-sub-btn {
        flex: 0 0 38px !important;
        min-height: 38px !important;
        padding: 0 !important;
    }

    .mob-client-actions .mob-btn-delete {
        flex: 0 0 38px !important;
    }

    /* В карточке договора удаление — обычная широкая кнопка с подписью */
    .mob-btn-delete-wide {
        flex: 1 1 auto !important;
    }

    .mob-client-actions .mob-btn-action {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Mobile Log Cards */
    .mob-log-card {
        gap: 7px;
    }

    .mob-log-top {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .mob-log-doc {
        font-weight: 700;
        font-size: 13.5px;
        color: #0f172a;
    }

    .mob-log-time {
        font-size: 11px;
        color: #94a3b8;
    }

    .mob-log-recipient {
        font-size: 12.5px;
        color: #1e293b;
    }

    .mob-log-subject {
        font-size: 11.5px;
        color: #64748b;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mob-log-bottom {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding-top: 6px;
        border-top: 1px solid #f1f5f9;
    }

    /* Kanban on Mobile - vertical stack, no horizontal scroll */
    .kanban-board {
        flex-direction: column !important;
        overflow-x: hidden !important;
        width: 100% !important;
        gap: 14px !important;
        padding-bottom: 24px !important;
    }

    .kanban-column {
        flex: 1 1 100% !important;
        max-width: 100% !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Modals mobile full screen */
    .modal-overlay {
        padding: 0 !important;
        align-items: flex-end;
    }

    .modal-box {
        width: 100vw !important;
        max-width: 100vw !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }

    .modal-header {
        padding: 12px 16px;
        flex-shrink: 0 !important;
    }

    /* «Все счета клиента»: имя и крестик сверху, кнопки — вторым рядом.
       Иначе длинное имя клиента ломает шапку, а кнопки уезжают за край. */
    .client-history-header {
        display: grid !important;
        grid-template-columns: 1fr auto !important;
        grid-template-areas:
            "title close"
            "actions actions" !important;
        align-items: center !important;
        gap: 10px !important;
        padding: 10px 14px !important;
    }

    .client-history-header .modal-title {
        grid-area: title;
        min-width: 0;
        gap: 10px;
    }

    .client-history-header .modal-title > div:last-child {
        min-width: 0;
    }

    .client-history-header #client-history-name {
        display: block;
        font-size: 15px !important;
        line-height: 1.25;
    }

    .client-history-controls {
        display: contents !important;
    }

    .client-history-controls > .modal-close-btn {
        grid-area: close;
        justify-self: end;
    }

    .client-history-actions {
        grid-area: actions;
        display: grid !important;
        /* Две кнопки в ряд, пока обеим хватает места; на узком экране
           встают друг под другом, а не уезжают за край. */
        grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
        gap: 8px;
        width: 100%;
    }

    .client-history-actions button {
        width: 100%;
        min-width: 0;
        justify-content: center;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .doc-viewer-header {
        display: grid !important;
        grid-template-columns: 1fr auto !important;
        grid-template-areas:
            "title close"
            "actions actions" !important;
        padding: 10px 14px !important;
        gap: 10px !important;
    }
    .doc-viewer-header .modal-title {
        grid-area: title;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .doc-viewer-controls {
        display: contents !important;
    }
    .doc-viewer-controls .modal-close-btn {
        grid-area: close;
        justify-self: end;
    }
    .viewer-actions-group {
        grid-area: actions;
        width: 100%;
        overflow-x: auto;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
    }

    .modal-title {
        font-size: 15px;
    }

    .modal-body {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 14px;
    }

    .modal-footer {
        flex-shrink: 0 !important;
        padding: 12px 14px !important;
        background: #ffffff !important;
        border-top: 1px solid #e2e8f0 !important;
    }

    /* Form Grids on Mobile */
    .form-grid-2, .form-grid-3 {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
        margin-bottom: 10px !important;
    }

    .items-editor-table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .editor-totals-panel {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 14px !important;
        padding: 12px !important;
    }

    .totals-left, .totals-right {
        max-width: 100% !important;
        min-width: 100% !important;
    }

    .facsimile-cards-grid {
        grid-template-columns: 1fr !important;
    }

    /* Stats Grid */
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 12px 14px;
    }

    .stat-value {
        font-size: 18px;
    }
}


/* ============================================================
   Правки по итогам ручного тестирования 03.11.2026
   ============================================================ */

/* Таблице нужна минимальная ширина, иначе колонки сжимаются
   до нечитаемого состояния вместо горизонтальной прокрутки. */
@media (min-width: 769px) {
    .data-table {
        min-width: 1040px;
    }
}

/* Кнопки в подвале модального окна переносятся на узких экранах.
   На 320 px «Отмена» уезжала за левый край и была недоступна. */
.modal-footer {
    flex-wrap: wrap;
    row-gap: 8px;
}

/* На совсем узких экранах оставляем только значок логотипа,
   чтобы пилюля пользователя осталась в первом ряду */
@media (max-width: 374px) {
    .mobile-brand-text {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .modal-footer {
        justify-content: stretch;
    }
    .modal-footer button {
        flex: 1 1 auto;
        min-width: 120px;
        white-space: nowrap;
    }
}

/* Подвал бокового меню на узких экранах обрезал ФИО. */
.sidebar-footer,
.sidebar-user {
    min-width: 0;
}
.sidebar-footer *,
.sidebar-user * {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Поля ввода чисел: моноширинные цифры и выравнивание вправо,
   чтобы суммы было удобно сверять глазами. */
.num-input {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Подсветка незаполненного обязательного поля. */
.field-error {
    border-color: #ef4444 !important;
    background: #fef2f2 !important;
}

/* Выбор стадии прямо на карточке канбана (перетаскивания нет). */
.kanban-status-select {
    font-size: 11px;
    padding: 2px 4px;
    border: 1px solid var(--b24-border);
    border-radius: 4px;
    background: #fff;
    color: #475569;
    max-width: 120px;
    cursor: pointer;
}

/* Длинная сумма не должна слипаться с подписью «Всего к оплате:». */
.total-line {
    gap: 12px;
}
.total-line > span:last-child {
    white-space: nowrap;
}

/* Полоса пресетов прокручивается — показываем это тенью у правого края. */
.presets-bar {
    scrollbar-width: thin;
}

/* ================= ДОГОВОРЫ: КАРТОЧКА И СПРАВОЧНИКИ ================= */

.editor-section-title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #0284c7;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 5px;
    margin: 18px 0 12px 0;
}

.field-note {
    font-size: 11.5px;
    color: #64748b;
    margin-top: 4px;
}

/* Переключатель «Машины / Водители» */
.fleet-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    border-bottom: 1px solid #e2e8f0;
}

.fleet-tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    padding: 8px 14px;
    font-size: 13.5px;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.fleet-tab.active {
    color: #0284c7;
    border-bottom-color: #0284c7;
}

.fleet-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    margin-bottom: 8px;
    background: #ffffff;
}

.fleet-row-main {
    flex: 1;
    min-width: 0;
}

.fleet-row-title {
    font-weight: 700;
    font-size: 14px;
    color: #0f172a;
}

.fleet-row-sub {
    font-size: 12px;
    color: #64748b;
    margin-top: 2px;
    line-height: 1.4;
    word-break: break-word;
}

.fleet-row-actions {
    display: flex;
    gap: 6px;
    flex: 0 0 auto;
}

.fleet-empty {
    text-align: center;
    padding: 26px 16px;
    color: #64748b;
    font-size: 13.5px;
}

/* Статусы договоров */
.status-signed { background: #dcfce7; color: #166534; }
.status-done { background: #e0f2fe; color: #075985; }

@media (max-width: 768px) {
    .fleet-row {
        flex-direction: column;
    }

    .fleet-row-actions {
        width: 100%;
    }

    .fleet-row-actions button {
        flex: 1;
    }
}

