/* =============================================
   AQUA DELIVERY CRM — Optimized Stylesheet
   Windows 11 Fluent Design Light Theme
   ============================================= */

/* --- Custom Properties --- */
:root {
    --accent: #0067C0;
    --accent-hover: #1a7ad4;
    --accent-light: #60CDFF;
    --accent-subtle: rgba(0,103,192,.08);

    --bg-0: #F3F3F3;
    --bg-1: #FFFFFF;
    --bg-2: #F9F9F9;
    --bg-3: #FAFAFA;

    --fg-1: #1A1A1A;
    --fg-2: #5C5C5C;
    /* Трохи темніше вторинний текст — краще читається при втомі зору */
    --fg-3: #6B6B6B;
    --fg-4: #A8A8A8;

    --border: rgba(0,0,0,.058);
    --border-s: rgba(0,0,0,.12);
    --border-xs: rgba(0,0,0,.04);

    --success: #0F7B0F;  --success-bg: #DFF6DD;
    --warning: #9D5D00;  --warning-bg: #FFF4CE;
    --danger:  #C42B1C;  --danger-bg:  #FDE7E9;
    --info:    #0067C0;  --info-bg:    #D6EBFF;
    --purple:  #7B2CBF;  --purple-bg:  #F3EAFF;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
    --shadow:    0 2px 8px rgba(0,0,0,.04), 0 1px 2px rgba(0,0,0,.06);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.08);
    --shadow-xl: 0 16px 64px rgba(0,0,0,.14);

    --r: 6px;
    --r-md: 8px;
    --r-lg: 12px;

    --sidebar-w: 280px;
    --titlebar-h: 46px;

    --ease: cubic-bezier(.16,1,.3,1);
    --dur: .15s;
}

/* --- Reset --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font: 15px/1.5 'Segoe UI Variable','Segoe UI',system-ui,-apple-system,sans-serif;
    background: var(--bg-0);
    color: var(--fg-1);
    overflow: hidden;
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.2); }

/* --- Utility --- */
.text--danger  { color: var(--danger) !important; }
.text--success { color: var(--success) !important; }
.text--warning { color: var(--warning) !important; }
.text--muted   { color: var(--fg-3) !important; }
.link { color: var(--accent); cursor: pointer; }

/* =============================================
   TITLEBAR
   ============================================= */
.titlebar {
    position: fixed; inset: 0 0 auto;
    height: var(--titlebar-h);
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    z-index: 1000;
}

.tb-left, .tb-right { display: flex; align-items: center; gap: 10px; }

.tb-brand {
    padding-right: 12px;
    margin-right: 2px;
    border-right: 1px solid var(--border);
    display: flex;
    align-items: center;
}
.tb-brand-img {
    height: var(--titlebar-h);
    width: auto;
    display: block;
    object-fit: contain;
}

.tb-breadcrumb {
    font-size: 14px;
    color: var(--fg-3);
    display: flex;
    align-items: center;
    gap: 6px;
}
.tb-breadcrumb .sep { font-size: 13px; opacity: 0.85; }
.tb-breadcrumb span:last-child {
    color: var(--fg-1);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
}

/* Search */
.tb-center { flex: 0 1 420px; position: relative; }

.tb-search {
    width: 100%; height: 32px;
    border: 1px solid var(--border); border-radius: var(--r-md);
    padding: 0 12px 0 34px;
    font: 12px/32px inherit;
    background: var(--bg-2); color: var(--fg-1);
    outline: none;
    transition: border-color var(--dur), box-shadow var(--dur), background var(--dur);
}
.tb-search:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: #fff; }
.tb-search::placeholder { color: var(--fg-4); }

.tb-search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--fg-3); pointer-events: none; }

.tb-search-hint {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    font: 10px/1 inherit; color: var(--fg-4);
    background: var(--bg-1); border: 1px solid var(--border);
    border-radius: 4px; padding: 1px 6px;
    pointer-events: none;
}

.tb-search-wrap { position: relative; }
.tb-search-dropdown {
    position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px;
    max-height: 320px; overflow-y: auto;
    background: #fff; border: 1px solid var(--border); border-radius: var(--r-md);
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    z-index: 1000;
    display: none;
}
.tb-search-dropdown.show { display: block; }
.tb-search-dropdown__item {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    transition: background var(--dur);
}
.tb-search-dropdown__open-client {
    flex: 1;
    display: block; width: 100%; padding: 2px 0;
    text-align: left; border: none; background: none; cursor: pointer;
    font: inherit; color: var(--fg-1);
}
.tb-search-dropdown__item:last-child { border-bottom: none; }
.tb-search-dropdown__open-client:hover,
.tb-search-dropdown__open-client:focus { outline: none; }
.tb-search-dropdown__item:hover,
.tb-search-dropdown__item:focus-within { background: var(--bg-2); }
.tb-search-dropdown__item--name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
    margin-bottom: 4px;
    color: var(--fg-1);
}
.tb-search-dropdown__item--sub {
    font-size: 12px;
    line-height: 1.3;
    color: var(--fg-2);
    white-space: pre-line;
}
.tb-search-dropdown__create-order {
    white-space: nowrap;
    flex-shrink: 0;
    min-height: 32px;
    padding: 0 12px;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}
.tb-search-dropdown__create-order:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}
.tb-search-dropdown__empty { padding: 12px; color: var(--fg-4); font-size: 12px; text-align: center; }
.tb-search-dropdown__loading { padding: 12px; color: var(--fg-4); font-size: 12px; text-align: center; }

/* Buttons */
.tb-btn {
    width: 34px; height: 32px;
    border: none; background: none; border-radius: var(--r);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--fg-2);
    position: relative;
    transition: background var(--dur);
}
.tb-btn:hover { background: rgba(0,0,0,.04); }
.tb-btn svg { width: 16px; height: 16px; }

.tb-btn--burger { display: none; }
.tb-btn .dot {
    position: absolute; top: 6px; right: 6px;
    width: 7px; height: 7px;
    background: var(--danger); border-radius: 50%;
    border: 1.5px solid var(--bg-1);
}

/* WebSocket status (header) */
.tb-ws-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--r-md);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: var(--fg-2);
    background: var(--bg-2);
    border: 1px solid var(--border);
    flex-shrink: 0;
}
.tb-ws-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--fg-4);
}
.tb-ws-status--disabled .tb-ws-status-dot { background: #9ca3af; }
.tb-ws-status--nourl .tb-ws-status-dot { background: #f59e0b; }
.tb-ws-status--connecting .tb-ws-status-dot {
    background: #f59e0b;
    animation: tb-ws-pulse 1s ease-in-out infinite;
}
.tb-ws-status--online .tb-ws-status-dot {
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.22);
}
.tb-ws-status--offline .tb-ws-status-dot { background: #ef4444; }
@keyframes tb-ws-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.55; transform: scale(0.88); }
}

/* Повторне відкриття модалки вхідного дзвінка (після закриття) */
.tb-incoming-call-btn {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--r-md);
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-subtle);
    border: 1px solid rgba(0, 103, 192, 0.28);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--dur), border-color var(--dur);
}
.tb-incoming-call-btn:not([hidden]) {
    display: inline-flex;
}
.tb-incoming-call-btn:hover {
    background: rgba(0, 103, 192, 0.12);
    border-color: var(--accent);
}
.tb-incoming-call-btn svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}
.tb-incoming-call-btn__label {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tb-divider { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

/* User */
.tb-user {
    display: flex; align-items: center; gap: 8px;
    padding: 4px 10px 4px 4px; border-radius: var(--r-md);
    cursor: pointer; transition: background var(--dur);
}
.tb-user:hover { background: rgba(0,0,0,.04); }
.tb-user-info { line-height: 1.2; }
.tb-user-name { font: 500 12px/1.3 inherit; }
.tb-user-role { font-size: 10px; color: var(--fg-3); }

/* =============================================
   AVATAR
   ============================================= */
.avatar {
    width: 32px; height: 32px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #3b9eff);
    display: inline-flex; align-items: center; justify-content: center;
    color: #fff; font: 600 12px/1 inherit; flex-shrink: 0;
}
.avatar--sm { width: 28px; height: 28px; font-size: 11px; }

/* =============================================
   LAYOUT
   ============================================= */
.app-layout {
    display: flex;
    margin-top: var(--titlebar-h);
    height: calc(100vh - var(--titlebar-h));
}

.main {
    flex: 1;
    margin-right: var(--sidebar-w);
    overflow-y: auto;
    padding: 24px 28px;
    scroll-behavior: smooth;
}

/* =============================================
   SIDEBAR
   ============================================= */
.sidebar {
    width: var(--sidebar-w);
    height: calc(100vh - var(--titlebar-h));
    position: fixed; right: 0; top: var(--titlebar-h);
    background: var(--bg-1);
    border-left: 1px solid var(--border);
    display: flex; flex-direction: column;
    z-index: 100;
    user-select: none;
}

.sidebar-scroll {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: 8px 0;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(0,0,0,.1); border-radius: 2px; }

/* Nav Group */
.nav-group { margin-bottom: 2px; }

.nav-group-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 16px;
    cursor: pointer;
    transition: background var(--dur);
}
.nav-group-header:hover { background: rgba(0,0,0,.025); }

.nav-group-title {
    font: 600 11px/1 inherit;
    color: var(--fg-3);
    text-transform: uppercase;
    letter-spacing: .4px;
}

.nav-group-chevron {
    width: 16px; height: 16px;
    color: var(--fg-4);
    transition: transform .2s var(--ease);
    flex-shrink: 0;
}

.nav-group.collapsed .nav-group-chevron { transform: rotate(-90deg); }

.nav-group-items {
    overflow: hidden;
    transition: max-height .25s var(--ease);
}
.nav-group.collapsed .nav-group-items { max-height: 0 !important; }

/* Nav Item */
.nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 16px; margin: 0 8px;
    border-radius: var(--r);
    cursor: pointer;
    color: var(--fg-2);
    font-size: 12.5px;
    text-decoration: none;
    position: relative;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: background var(--dur), color var(--dur);
}
.nav-item:hover { background: rgba(0,0,0,.035); color: var(--fg-1); }

.nav-item.active {
    background: var(--accent-subtle);
    color: var(--accent);
    font-weight: 500;
}
.nav-item:focus { outline: none; }
.nav-item:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.nav-icon { width: 16px; height: 16px; flex-shrink: 0; opacity: .7; }
.nav-item.active .nav-icon { opacity: 1; }

.nav-badge {
    margin-left: auto;
    background: var(--danger); color: #fff;
    font: 600 10px/16px inherit;
    padding: 0 5px; min-width: 16px; height: 16px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
}

.nav-count { margin-left: auto; color: var(--fg-4); font-size: 11px; }

/* Footer */
.sidebar-footer { padding: 8px 12px; border-top: 1px solid var(--border); }

/* Режим «крупніший шрифт»: перемикач у підвалі сайдбара */
.comfort-ui-toggle {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0 4px 10px;
    padding: 10px 12px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--bg-2);
    cursor: pointer;
    font: 500 13px/1.4 inherit;
    color: var(--fg-1);
    user-select: none;
}
.comfort-ui-toggle:hover { background: var(--bg-3); }
.comfort-ui-toggle input {
    width: 18px;
    height: 18px;
    margin-top: 2px;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--accent);
}
.comfort-ui-toggle__text { display: block; }
.comfort-ui-toggle__hint {
    display: block;
    font-weight: 400;
    font-size: 11px;
    color: var(--fg-3);
    margin-top: 2px;
    line-height: 1.3;
}

.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 8px; border-radius: var(--r-md);
    cursor: pointer; transition: background var(--dur);
}
.sidebar-user:hover { background: rgba(0,0,0,.035); }
.sidebar-user-info h4 { font: 500 12px/1.3 inherit; }
.sidebar-user-info p  { font-size: 10px; color: var(--fg-3); line-height: 1.3; }

.status-dot {
    width: 7px; height: 7px; border-radius: 50%;
    margin-left: auto; flex-shrink: 0;
}
.status-dot--online { background: var(--success); }

.sidebar-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: transparent;
    color: var(--fg-2);
    font: 500 12px/1.3 inherit;
    cursor: pointer;
    transition: background var(--dur), color var(--dur), border-color var(--dur);
}
.sidebar-logout-btn:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--danger);
    border-color: rgba(220, 38, 38, 0.35);
}
.sidebar-logout-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.sidebar-logout-btn svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }

.tb-btn--logout {
    color: var(--fg-3);
}
.tb-btn--logout:hover {
    color: var(--danger);
    background: rgba(220, 38, 38, 0.08);
}

/* Плавна зміна розділу (SPA-навігація) */
#mainContent.main--nav-transition {
    opacity: 0.5;
    transition: opacity 0.14s ease;
    pointer-events: none;
}

/* =============================================
   PAGE
   ============================================= */
.page { display: none; }
.page.active { display: block; animation: pageIn .2s ease; }

@keyframes pageIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.page-header { margin-bottom: 20px; }
.page-title { font: 600 24px/1.3 inherit; }
.page-subtitle { font-size: 12px; color: var(--fg-3); margin-top: 2px; }
.page-actions {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 8px; margin-top: 14px;
}

/* Дзвінки: дата й кнопки в один ряд зліва, без розтягування по ширині */
.page-actions--client-calls {
    justify-content: flex-start;
    gap: 10px;
}
.page-actions--client-calls .client-calls-date-range {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.page-actions--client-calls .client-calls-range-caption {
    font-size: 13px;
    margin-right: 2px;
}
.page-actions--client-calls .client-calls-range-dash {
    font-size: 13px;
    user-select: none;
}
.page-actions--client-calls .client-calls-date-range .form-input {
    width: auto;
    min-width: 148px;
}
.page-actions--client-calls .client-calls-hint {
    font-size: 12px;
    margin-left: auto;
}

/* =============================================
   BUTTONS
   ============================================= */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    height: 30px; padding: 0 14px;
    border: 1px solid var(--border-s); border-radius: var(--r);
    font: 500 12px/1 inherit;
    background: var(--bg-1); color: var(--fg-1);
    cursor: pointer; white-space: nowrap;
    transition: background var(--dur), transform .08s;
}
.btn:hover { background: var(--bg-2); }
.btn:active { transform: scale(.97); }
.btn svg { width: 14px; height: 14px; }

.btn--accent { background: var(--accent); color: #fff; border-color: transparent; }
.btn--accent:hover { background: var(--accent-hover); }

.btn--order {
    background: var(--warning-bg);
    color: var(--warning);
    border-color: #f0d7a8;
}

.btn--order:hover {
    background: #f9e7c9;
    color: #7f4b00;
    border-color: #e7c184;
    filter: none;
}

.btn--ghost { border-color: transparent; background: none; color: var(--fg-2); }
.btn--ghost:hover { background: rgba(0,0,0,.04); color: var(--fg-1); }

.btn--sm { height: 26px; padding: 0 10px; font-size: 11px; }

.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* Icon/CRUD actions */
.btn--danger {
    background: var(--danger);
    color: #fff;
    border-color: transparent;
}
.btn--danger:hover { filter: brightness(.95); }

.btn-icon {
    width: 30px;
    height: 30px;
    padding: 0;
    border-radius: var(--r);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-icon svg { width: 14px; height: 14px; }

.clients-stat-card--map,
.orders-stat-card--map {
    position: relative;
    padding-right: 92px;
}

.clients-map-btn,
.orders-map-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    height: 75%;
    aspect-ratio: 1 / 1;
    width: auto;
    border: 0;
    background: transparent;
    color: var(--info);
    border-radius: 10px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform var(--dur), box-shadow var(--dur), filter var(--dur);
}

.clients-map-btn img,
.orders-map-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.clients-map-btn:hover,
.orders-map-btn:hover {
    transform: translateY(-50%) translateY(-1px);
    box-shadow: var(--shadow);
    filter: saturate(1.08);
}

#pg-clients .page-actions {
    justify-content: flex-start;
    align-items: center;
}

#pg-clients .page-header {
    margin-bottom: 10px;
}

body.clients-ui-mode-mvp #pg-clients .stats-row,
body.clients-ui-mode-mvp #pg-clients .client-orders-history-card {
    display: none;
}

body.clients-ui-mode-mvp #pg-clients .page-summary {
    margin-bottom: 6px;
}

body.clients-ui-mode-mvp #pg-clients .mobile-scroll-table {
    margin-bottom: 0;
}

body.clients-ui-mode-mvp #pg-clients .clients-table-wrap {
    height: clamp(420px, calc(100vh - 170px), 76vh);
    max-height: none;
    overflow-y: auto;
}

#pg-clients .page-summary,
#pg-orders .page-summary,
#pg-routes .page-summary {
    margin-top: -10px;
}

/* Клієнти: щільніші блоки (статистика → дії → таблиця → історія) */
#pg-clients .stats-row {
    gap: 6px;
    margin-bottom: 6px;
}
#pg-clients .stat-card {
    padding: 8px 12px;
}
#pg-clients .stat-top {
    margin-bottom: 4px;
}
#pg-clients .page-actions {
    margin-top: 6px;
    gap: 5px;
}
#pg-clients .clients-pagination {
    margin-top: 0;
}
#pg-clients .mobile-scroll-table + .card,
#pg-clients .client-orders-history-card {
    margin-top: 6px;
    margin-bottom: 6px;
}
#pg-clients .client-orders-history-card .card-header {
    padding: 8px 12px;
    align-items: flex-start;
    gap: 4px 12px;
}
#pg-clients .client-orders-history-card .card-header__title {
    font-size: 12px;
    font-weight: 600;
}
#pg-clients .client-orders-history-card .card-header .text--muted,
#pg-clients .client-orders-history-sub {
    font-size: 11px !important;
    margin: 0;
    line-height: 1.35;
}

/* Клієнти: більш гармонійні заголовки колонок */
#pg-clients .clients-table-wrap thead th,
#pg-clients .client-orders-history-wrap thead th {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.01em;
    text-transform: uppercase;
    color: var(--fg-1);
    padding: 7px 10px;
    line-height: 1.3;
    background: linear-gradient(180deg, #f2f5fa, #e9eef6);
    border-bottom: 1px solid #cfd7e3;
    box-shadow: inset 0 -1px 0 rgba(0,0,0,.04);
}
#pg-clients .clients-table-wrap tbody td,
#pg-clients .client-orders-history-wrap tbody td {
    padding: 5px 10px;
    font-size: 13px;
    line-height: 1.1;
}
#pg-clients .clients-table-wrap tbody td[colspan],
#pg-clients .client-orders-history-wrap tbody td[colspan] {
    padding: 12px 10px !important;
    font-size: 12px;
}

html.comfort-ui #pg-clients .clients-table-wrap thead th,
html.comfort-ui #pg-clients .client-orders-history-wrap thead th {
    font-size: 12px;
    padding: 8px 12px;
}
html.comfort-ui #pg-clients .clients-table-wrap tbody td,
html.comfort-ui #pg-clients .client-orders-history-wrap tbody td {
    padding: 7px 12px;
    font-size: 13px;
}
html.comfort-ui #pg-clients .cell-user-name {
    font-size: 13px;
}
html.comfort-ui #pg-clients .cell-user-sub {
    font-size: 11px;
}

html.comfort-ui #pg-clients .clients-table-wrap {
    max-height: min(500px, 54vh);
}

html.comfort-ui #pg-clients .client-orders-history-wrap {
    max-height: min(232px, 30vh);
}

/* Клієнти: менше полів у контенті сторінки */
#mainContent.main:has(#pg-clients.active) {
    padding: 16px 22px;
}
html.comfort-ui #mainContent.main:has(#pg-clients.active) {
    padding: 18px 24px;
}

#pg-clients .cell-user {
    gap: 6px;
}
#pg-clients .cell-user-name {
    font-size: 13px;
    line-height: 1.1;
}
#pg-clients .cell-user-sub {
    font-size: 10.5px;
    line-height: 1.1;
}

/* Клієнти: зробити дії виразнішими */
#pg-clients #clients-table thead th:last-child,
#pg-clients #clients-table tbody td:last-child {
    width: 238px;
    min-width: 238px;
}
#pg-clients #clients-table tbody .row-actions {
    gap: 4px;
    align-items: center;
}
#pg-clients #clients-table tbody .clients-order-create-btn {
    background: linear-gradient(180deg, #2f89ff, #1f6fe0);
    border: 1px solid #1d62c4;
    color: #fff;
    font-weight: 700;
    padding: 0 10px;
    height: 26px;
    line-height: 24px;
}
#pg-clients #clients-table tbody .clients-order-create-btn:hover {
    background: linear-gradient(180deg, #4a98ff, #2f7ce8);
    border-color: #1a58ae;
}
#pg-clients #clients-table tbody .clients-order-create-btn:focus-visible {
    outline: 2px solid rgba(31, 111, 224, 0.35);
    outline-offset: 1px;
}
#pg-clients #clients-table tbody .client-kebab {
    position: relative;
}
#pg-clients #clients-table tbody .client-kebab-toggle svg {
    width: 16px;
    height: 16px;
}
#pg-clients #clients-table tbody .client-kebab-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 40;
    min-width: 164px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.16);
    padding: 4px;
}
#pg-clients #clients-table tbody .client-kebab-item {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--fg-2);
    padding: 7px 8px;
    border-radius: var(--r-sm);
    display: inline-flex;
    gap: 8px;
    align-items: center;
    cursor: pointer;
    text-align: left;
    font-size: 12px;
}
#pg-clients #clients-table tbody .client-kebab-item:hover {
    background: var(--bg-2);
    color: var(--fg-1);
}
#pg-clients #clients-table tbody .client-kebab-item__icon {
    width: 16px;
    text-align: center;
}
#pg-clients #clients-table tbody .row-actions .btn-icon {
    width: 26px;
    height: 26px;
    border: 1px solid var(--border);
    background: var(--bg-2);
    color: var(--fg-2);
}
#pg-clients #clients-table tbody .row-actions .btn-icon:hover {
    background: var(--accent-subtle);
    border-color: rgba(0, 103, 192, 0.28);
    color: var(--accent);
}
#pg-clients #clients-table tbody .row-actions .btn-icon:focus-visible {
    outline: 2px solid rgba(0, 103, 192, 0.35);
    outline-offset: 1px;
}
#pg-clients #clients-table tbody .row-actions .btn-icon svg {
    width: 13px;
    height: 13px;
    stroke-width: 2.1;
}
#pg-clients th.th-sort-asc::after,
#pg-clients th.th-sort-desc::after {
    font-size: 8px;
    margin-left: 3px;
}

#pg-orders .page-header {
    margin-bottom: 10px;
}

#pg-orders .stats-row {
    gap: 8px;
    margin-bottom: 8px;
}

#pg-orders .page-actions {
    justify-content: flex-start;
    align-items: center;
    margin-top: 8px;
    gap: 10px 12px;
}

/* Пошук не забирає всю ширину між кнопкою та чіпами */
#pg-orders .orders-filter-wrap {
    flex: 0 1 300px;
    min-width: 200px;
    max-width: 340px;
}

#pg-orders .orders-date-filter-wrap {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

#pg-orders .orders-date-filter-wrap .form-input {
    min-width: 168px;
}

#pg-orders .page-actions .chips {
    flex: 0 1 auto;
}

#pg-routes .page-header {
    margin-bottom: 10px;
}

#pg-routes .page-actions {
    justify-content: flex-start;
    align-items: center;
}

.routes-date-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 1 auto;
    margin: 0;
}

.routes-date-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--fg-2);
    white-space: nowrap;
}

.routes-date-wrap .form-input {
    min-width: 140px;
}

#pg-routes .routes-gen-mode-chips {
    flex-shrink: 0;
}

.gen-manual-target-chips {
    margin: 4px 0 14px;
    flex-shrink: 0;
}

.gen-manual-bulk-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 10px 0 12px;
}

.gen-manual-existing-panel {
    margin-bottom: 4px;
}

.gen-manual-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px 16px;
    margin-bottom: 12px;
}

.gen-manual-toolbar__vehicle {
    margin: 0;
    flex: 1 1 220px;
    min-width: 200px;
}

.gen-manual-toolbar__hint {
    font-size: 12px;
    align-self: center;
    flex: 1 1 160px;
}

.gen-manual-toolbar__bulk {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.gen-manual-orders-wrap {
    max-height: min(380px, 52vh);
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}

.gen-manual-orders-table {
    width: 100%;
    font-size: 12px;
}

.gen-manual-orders-table th,
.gen-manual-orders-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.gen-manual-orders-table thead th {
    background: var(--bg-2);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.gen-manual-orders-table .th-check {
    width: 40px;
    text-align: center;
}

.gen-manual-orders-table .th-check input {
    vertical-align: middle;
}

.gen-manual-selected-summary {
    margin: 10px 0 0;
    font-size: 12px;
}

.gen-manual-selected-summary.gen-manual-selected-summary--warn {
    color: var(--warning);
    font-weight: 500;
}

.clients-filter-wrap,
.orders-filter-wrap {
    position: relative;
    width: min(420px, 100%);
    flex: 1 1 320px;
    min-width: 240px;
}

.clients-filter-wrap .tb-search,
.orders-filter-wrap .tb-search {
    width: 100%;
    padding-left: 36px;
    padding-right: 34px;
}

.clients-filter-icon,
.orders-filter-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 14px;
    height: 14px;
    color: var(--fg-3);
    pointer-events: none;
}

.clients-filter-clear,
.orders-filter-clear {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--fg-3);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.clients-filter-clear:hover,
.orders-filter-clear:hover {
    background: var(--bg-2);
    color: var(--fg-1);
}

.clients-filter-clear.is-hidden,
.orders-filter-clear.is-hidden {
    display: none;
}

#pg-clients .clients-company-filter,
#pg-clients .clients-no-geo-filter,
#pg-clients .clients-show-1c-name-filter {
    flex: 0 0 auto;
    align-self: center;
    margin: 0;
    white-space: nowrap;
    font-size: 13px;
    user-select: none;
}

#pg-clients #clients-table .clients-col-1c.is-hidden {
    display: none;
}

#pg-clients #clients-table td.clients-col-1c {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ~12 рядків даних + заголовок */
#pg-clients .clients-table-wrap {
    max-height: min(468px, 52vh);
    overflow-y: auto;
}

#pg-clients .clients-table-wrap .cell-address {
    white-space: pre-line;
    overflow-wrap: break-word;
}

#pg-clients #clients-table .cell-client-id {
    width: 52px;
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
    vertical-align: middle;
}

#pg-clients .clients-table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-1);
}

/* ~5 останніх замовлень + заголовок */
#pg-clients .client-orders-history-wrap {
    max-height: min(218px, 28vh);
    overflow-y: auto;
}

#pg-clients .client-orders-history-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-1);
}

.clients-pagination,
.orders-pagination,
.routes-pagination {
    margin-top: 2px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

#pg-clients .clients-pagination {
    justify-content: space-between;
}

#pg-clients .clients-pagination__range {
    font-size: 12px;
    line-height: 1.35;
    flex: 1 1 auto;
    min-width: 0;
}

#pg-clients .clients-pagination__nav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

#pg-orders .orders-table-wrap {
    max-height: min(560px, calc(100vh - 280px));
    overflow-y: auto;
}

#pg-orders .orders-table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-1);
    /* Лише щільніші рядки: вертикальні відступи; шрифт як у решти таблиць */
    padding-top: 5px;
    padding-bottom: 5px;
}

#pg-orders .orders-table-wrap tbody td {
    padding-top: 5px;
    padding-bottom: 5px;
}

#pg-orders .orders-table-card {
    margin-bottom: 0;
}

/* Шапка «Список замовлень»: заголовок і фільтри в одному логічному блоці, без роз’їзду */
#pg-orders .orders-table-card .card-header--toolbar {
    justify-content: flex-start;
    align-items: center;
    gap: 10px 14px;
    padding: 8px 12px;
}

#pg-orders .orders-table-card .card-header__lead {
    flex: 0 0 auto;
}

#pg-orders .orders-table-card .card-header__filters {
    flex: 0 1 auto;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
}

#pg-orders .orders-table-card .card-header__filters .form-group {
    flex: 0 0 auto;
    min-width: 0;
}

#pg-orders .orders-table-card .card-header__filters .form-input--sm {
    width: auto;
    min-width: 148px;
    max-width: 200px;
}

#pg-orders .orders-erp-sync-filter {
    flex: 0 0 auto;
}

#pg-orders .orders-erp-sync-filter__label {
    margin: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    font-size: 12px;
}

/* Таблиця: фіксовані пропорції колонок замість рівномірного розтягування */
#pg-orders .orders-table-wrap #orders-table {
    table-layout: fixed;
    width: 100%;
    font-size: 12px;
}

#pg-orders .orders-table-wrap #orders-table thead th,
#pg-orders .orders-table-wrap #orders-table tbody td {
    padding-left: 8px;
    padding-right: 8px;
}

#pg-orders #orders-table th:nth-child(1),
#pg-orders #orders-table td:nth-child(1) {
    width: 48px;
}

#pg-orders #orders-table th:nth-child(2),
#pg-orders #orders-table td:nth-child(2) {
    width: 11%;
}

#pg-orders #orders-table th:nth-child(3),
#pg-orders #orders-table td:nth-child(3) {
    width: 14%;
}

#pg-orders #orders-table th:nth-child(4),
#pg-orders #orders-table td:nth-child(4) {
    width: 22%;
}

#pg-orders #orders-table th:nth-child(5),
#pg-orders #orders-table td:nth-child(5) {
    width: 86px;
}

#pg-orders #orders-table th:nth-child(6),
#pg-orders #orders-table td:nth-child(6) {
    width: 96px;
}

#pg-orders #orders-table th:nth-child(7),
#pg-orders #orders-table td:nth-child(7) {
    width: 10%;
}

#pg-orders #orders-table th:nth-child(8),
#pg-orders #orders-table td:nth-child(8) {
    width: 108px;
}

#pg-orders #orders-table th:nth-child(9),
#pg-orders #orders-table td:nth-child(9) {
    width: 76px;
    white-space: nowrap;
}

#pg-orders #orders-table th:nth-child(10),
#pg-orders #orders-table td:nth-child(10) {
    width: 44px;
    text-align: center;
    vertical-align: middle;
}

#pg-orders #orders-table th.th-orders-1c,
#pg-orders #orders-table td.cell-orders-1c {
    padding-left: 4px;
    padding-right: 4px;
}

#pg-orders #orders-table td.cell-orders-1c .form-checkbox {
    justify-content: center;
    margin: 0;
}

#pg-orders #orders-table td.cell-orders-1c input[type="checkbox"] {
    cursor: default;
}

#pg-orders #orders-table td.cell-orders-1c input[type="checkbox"]:not(:disabled) {
    cursor: pointer;
}

#pg-orders #orders-table th:nth-child(11),
#pg-orders #orders-table td:nth-child(11) {
    width: 72px;
    text-align: right;
}

#pg-orders #orders-table td.cell-order-items {
    font-size: 11px;
    line-height: 1.35;
    word-break: break-word;
    overflow-wrap: anywhere;
}

#pg-clients .clients-table-card {
    margin-bottom: 0;
}

#pg-routes .routes-table-wrap {
    max-height: min(560px, calc(100vh - 280px));
    overflow-y: auto;
}

#pg-routes .routes-table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-1);
    padding-top: 5px;
    padding-bottom: 5px;
}

#pg-routes .routes-table-wrap tbody td {
    padding-top: 5px;
    padding-bottom: 5px;
}

#pg-routes .routes-table-card {
    margin-bottom: 0;
}

#pg-routes .route-orders-table-wrap {
    max-height: 320px;
    overflow-x: auto;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

#pg-routes #route-orders-card {
    min-width: 0;
    max-width: 100%;
}

#pg-routes .route-orders-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
    min-width: 0;
}

#pg-routes .route-orders-split__left,
#pg-routes .route-orders-split__right {
    min-width: 0;
    max-width: 100%;
}

@media (max-width: 1024px) {
    #pg-routes .route-orders-split {
        grid-template-columns: 1fr;
    }

    /* Таблиця «Замовлення маршруту» поза .mobile-scroll-table — потрібен явний max-content + скрол */
    #pg-routes .route-orders-table-wrap {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        display: block;
    }

    #pg-routes #route-orders-table {
        max-width: none;
    }
}

#pg-routes .route-orders-route-map-el {
    height: 400px;
    width: 100%;
    border-radius: 8px;
    border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
    background: var(--bg-2, #f3f3f3);
}

#pg-routes .route-orders-map-placeholder {
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
    border-radius: 8px;
    border: 1px dashed var(--border, rgba(0, 0, 0, 0.12));
    font-size: 13px;
    color: var(--fg-3, #666);
    line-height: 1.45;
}

#pg-routes .route-orders-table-wrap thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--bg-1);
    padding: 4px 8px;
    font-size: 10px;
    letter-spacing: 0.04em;
    line-height: 1.2;
}

#pg-routes .route-orders-table-wrap thead th.th-ro-resizable {
    position: sticky;
    padding-right: 10px !important;
    overflow: visible;
}

#pg-routes .route-orders-table-wrap .col-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 7px;
    margin-right: -2px;
    cursor: col-resize;
    z-index: 3;
    user-select: none;
    touch-action: none;
}

#pg-routes .route-orders-table-wrap .col-resize-handle:hover,
body.col-resize-active #pg-routes .route-orders-table-wrap .col-resize-handle {
    background: rgba(0, 120, 212, 0.28);
}

body.col-resize-active {
    cursor: col-resize !important;
    user-select: none;
}

/* Компактні рядки: замовлення на маршруті */
#pg-routes .route-orders-table-wrap tbody td {
    padding: 4px 8px;
    font-size: 11px;
    line-height: 1.25;
    vertical-align: top;
    word-break: break-word;
}

#pg-routes .route-orders-table-wrap .route-order-drag-handle {
    vertical-align: middle;
    padding-left: 4px;
    padding-right: 4px;
    font-size: 12px;
}

#pg-routes .route-orders-table-wrap .th-route-drag {
    padding-left: 4px !important;
    padding-right: 4px !important;
}

#pg-routes .route-orders-table-wrap .route-order-por {
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

#pg-routes .route-orders-table-wrap tbody td:nth-child(3) {
    white-space: nowrap;
    vertical-align: middle;
}


#pg-routes .route-orders-table-wrap .badge {
    padding: 1px 5px;
    gap: 3px;
    font-size: 10px;
    line-height: 1.2;
}

#pg-routes .route-orders-table-wrap .badge::before {
    width: 4px;
    height: 4px;
}

#pg-routes .route-orders-split__left .route-orders-table-wrap {
    max-height: min(520px, 55vh);
}

#pg-routes #route-orders-table {
    table-layout: fixed;
    width: auto;
    max-width: none;
}

/* Ширини колонок задаються з JS (localStorage) */

#pg-routes #route-orders-table .th-ro-actions,
#pg-routes #route-orders-table td.cell-ro-actions {
    text-align: right;
    padding-right: 6px !important;
}

#pg-routes #route-orders-table td.cell-ro-client,
#pg-routes #route-orders-table td.cell-ro-address {
    overflow: hidden;
    max-width: 0;
    vertical-align: top;
}

#pg-routes #route-orders-table .cell-ro-clamp {
    display: block;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    overflow: hidden;
    white-space: normal;
    word-break: break-word;
    line-height: 1.25;
    max-height: calc(2 * 1.25em + 1px);
}

#pg-routes #route-orders-table td.route-orders-empty {
    max-width: none;
}

#pg-routes #route-orders-table td.cell-ro-items {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    font-size: 10px;
    line-height: 1.3;
}

#pg-routes #route-orders-table td.cell-ro-sum {
    white-space: nowrap;
    vertical-align: middle;
    font-weight: 600;
    text-align: right;
}

#pg-routes #route-orders-table td.cell-ro-status {
    white-space: nowrap;
    vertical-align: middle;
}

#pg-routes #route-orders-table td.cell-ro-status .badge {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: inline-block;
    vertical-align: middle;
}

.row-actions {
    display: inline-flex;
    gap: 6px;
    justify-content: flex-end;
}

.crud-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.table-note {
    font-size: 11px;
    color: var(--fg-3);
}

/* =============================================
   BADGES (status)
   ============================================= */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 2px 8px; border-radius: 20px;
    font: 500 11px/1 inherit;
}
.badge::before {
    content: ''; width: 5px; height: 5px; border-radius: 50%;
}

.badge--info    { background: var(--info-bg);    color: var(--info); }
.badge--info::before    { background: var(--info); }
.badge--warning { background: var(--warning-bg); color: var(--warning); }
.badge--warning::before { background: var(--warning); }
.badge--success { background: var(--success-bg); color: var(--success); }
.badge--success::before { background: var(--success); }
.badge--danger  { background: var(--danger-bg);  color: var(--danger); }
.badge--danger::before  { background: var(--danger); }
.badge--purple  { background: var(--purple-bg);  color: var(--purple); }
.badge--purple::before  { background: var(--purple); }

/* =============================================
   STATS
   ============================================= */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 10px; margin-bottom: 20px;
}
.stats-row--3 { grid-template-columns: repeat(3, 1fr); }
.stats-row--4 { grid-template-columns: repeat(4, 1fr); }
.stats-row--5 { grid-template-columns: repeat(5, 1fr); }

.stat-card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 14px 16px;
    transition: box-shadow var(--dur);
}
.stat-card:hover { box-shadow: var(--shadow); }

.stat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }

.stat-icon {
    width: 30px; height: 30px;
    border-radius: var(--r);
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
}
.bg--info    { background: var(--info-bg); }
.bg--success { background: var(--success-bg); }
.bg--warning { background: var(--warning-bg); }
.bg--danger  { background: var(--danger-bg); }
.bg--purple  { background: var(--purple-bg); }

.trend { font: 600 10px/1 inherit; display: flex; align-items: center; gap: 2px; }
.trend--up   { color: var(--success); }
.trend--down { color: var(--danger); }

.stat-value { font: 600 22px/1.2 inherit; }
.stat-label { font-size: 11px; color: var(--fg-3); margin-top: 1px; }

/* Routes: панель статистики + логістика */
#pg-routes .routes-dashboard-row {
    display: grid;
    grid-template-columns: minmax(280px, 520px) minmax(0, 1fr);
    gap: 12px;
    align-items: stretch;
    margin-bottom: 16px;
    min-width: 0;
}

#pg-routes .routes-dashboard-row__stats.stats-row {
    margin-bottom: 0;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    align-content: stretch;
    min-width: 0;
}

#pg-routes .routes-dashboard-row .stat-card--routes-dash {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 100%;
    padding: 12px 14px;
    margin: 0;
}

#pg-routes .routes-dashboard-row .stat-card--routes-dash .stat-top {
    margin-bottom: 6px;
}

#pg-routes .routes-dashboard-row .stat-card--routes-dash .stat-value {
    font-size: 1.25rem;
}

#pg-routes .routes-dashboard-row .stat-card--routes-dash .stat-label {
    font-size: 11px;
}

/* Логістика в тон карткам (без «чужої» темної плити) */
#pg-routes .routes-logistics-kpi--integrated {
    margin-bottom: 0;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--bg-1);
    color: var(--fg-1);
    box-shadow: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 100%;
}

#pg-routes .routes-logistics-kpi--integrated .routes-logistics-kpi__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 6px 12px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-2, #f6f7f9);
}

#pg-routes .routes-logistics-kpi--integrated .routes-logistics-kpi__head-title {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--fg-3);
}

#pg-routes .routes-logistics-kpi--integrated .routes-logistics-kpi__head-sub {
    font-size: 11px;
    color: var(--fg-3);
    text-align: right;
    max-width: 100%;
}

#pg-routes .routes-logistics-kpi__grid--integrated {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
    flex: 1;
    align-items: stretch;
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-right: 1px solid var(--border);
    border-bottom: none;
    min-height: 0;
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi:nth-child(4n) {
    border-right: none;
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi__main {
    flex: 1;
    min-width: 0;
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi__label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--fg-3);
    margin-bottom: 2px;
    line-height: 1.2;
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi__value {
    font-family: ui-monospace, 'Cascadia Code', 'Segoe UI Mono', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--fg-1);
    line-height: 1.2;
    letter-spacing: -0.02em;
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi__hint {
    font-size: 10px;
    margin-top: 3px;
    color: var(--fg-3);
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi__icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi__icon svg {
    width: 18px;
    height: 18px;
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi--load .log-kpi__icon {
    color: var(--success);
    background: var(--success-bg);
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi--km .log-kpi__icon {
    color: var(--info);
    background: var(--info-bg);
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi--drive .log-kpi__icon {
    color: var(--warning);
    background: var(--warning-bg);
}

#pg-routes .routes-logistics-kpi__grid--integrated .log-kpi--svc .log-kpi__icon {
    color: var(--purple);
    background: var(--purple-bg);
}

@media (max-width: 1200px) {
    #pg-routes .routes-dashboard-row {
        grid-template-columns: 1fr;
    }

    #pg-routes .routes-dashboard-row__stats.stats-row {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    #pg-routes .routes-logistics-kpi__grid--integrated {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #pg-routes .routes-logistics-kpi__grid--integrated .log-kpi:nth-child(4n) {
        border-right: 1px solid var(--border);
    }

    #pg-routes .routes-logistics-kpi__grid--integrated .log-kpi:nth-child(2n) {
        border-right: none;
    }

    #pg-routes .routes-logistics-kpi__grid--integrated .log-kpi:nth-child(-n+2) {
        border-bottom: 1px solid var(--border);
    }
}

@media (max-width: 520px) {
    #pg-routes .routes-dashboard-row__stats.stats-row {
        grid-template-columns: 1fr;
    }

    #pg-routes .routes-logistics-kpi__grid--integrated {
        grid-template-columns: 1fr;
    }

    #pg-routes .routes-logistics-kpi__grid--integrated .log-kpi {
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    #pg-routes .routes-logistics-kpi__grid--integrated .log-kpi:last-child {
        border-bottom: none;
    }
}

/* =============================================
   CARDS
   ============================================= */
.card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
    margin-bottom: 12px;
}
.card--clickable { cursor: pointer; transition: box-shadow var(--dur); }
.card--clickable:hover { box-shadow: var(--shadow); }

.card-header {
    padding: 12px 16px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
}
.card-header h3 { font: 600 13px/1 inherit; }

/* Шапка картки з заголовком + полями пошуку (замовлення): без накладання */
.card-header--toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 12px;
}
.card-header--toolbar .card-header__lead {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    flex: 1 1 auto;
    min-width: 0;
}
.card-header--toolbar .card-header__lead .card-header__title {
    margin: 0;
    min-width: 0;
    flex: 0 1 auto;
}
.card-header--toolbar .card-header__filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    flex: 0 1 auto;
    min-width: 0;
}
.card-header--toolbar .card-header__filters .form-group {
    margin: 0;
    flex: 1 1 140px;
    min-width: 0;
    max-width: 100%;
}
.card-header--toolbar .card-header__filters .form-input {
    width: 100%;
}
@media (max-width: 640px) {
    .card-header--toolbar .card-header__lead {
        flex: 1 1 100%;
    }
    .card-header--toolbar .card-header__filters {
        flex: 1 1 100%;
    }
}

.card-body { padding: 14px 16px; }
.card-body--flush { padding: 0; }

/* =============================================
   GRIDS
   ============================================= */
.grid { display: grid; gap: 12px; }
.grid--2 { grid-template-columns: 1fr 1fr; }
.grid--3 { grid-template-columns: repeat(3, 1fr); }

/* =============================================
   TABLE
   ============================================= */
.tbl-wrap { overflow-x: auto; }

/* Оптимізація маршруту: таблиця ~половина екрана + карта */
.optimize-result-layout {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 16px;
    margin-top: 8px;
}
.optimize-result-panel {
    flex: 1 1 320px;
    min-width: 0;
}
.optimize-result-panel--table {
    flex: 1 1 min(50%, 520px);
    max-width: 100%;
}
.optimize-result-panel--map {
    flex: 1 1 min(50%, 520px);
    min-height: 360px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.optimize-route-map-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--fg-2);
}
.optimize-route-map {
    flex: 1;
    min-height: 360px;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: var(--bg-2);
    z-index: 0;
}
@media (max-width: 900px) {
    .optimize-result-panel--table,
    .optimize-result-panel--map {
        flex: 1 1 100%;
    }
    .optimize-route-map {
        min-height: 280px;
    }
}

/* Оптимізація: блок статистики */
.optimize-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 24px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--bg-2);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
}
.optimize-stats-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
}
.optimize-stats-icon { font-size: 16px; }
.optimize-stats-label { color: var(--fg-2); }
.optimize-stats-value { font-weight: 600; color: var(--fg-1); }

/* Таблиця маршрутів: кешована статистика оптимізації */
.route-opt-stats { font-size: 12px; line-height: 1.35; color: var(--fg-2); max-width: 200px; }
.route-opt-stats-icon { opacity: 0.85; }

/* Маршрути: клік по рядку — підсвітка обраного */
#routes-table-body tr.route-row--selectable { cursor: pointer; }
#routes-table-body tr.route-row--active { background: rgba(0, 120, 212, 0.09); }

#route-orders-table-body tr.route-order-row { cursor: pointer; }

.th-route-drag { width: 36px; padding-left: 8px !important; padding-right: 8px !important; }
.route-order-drag-handle[draggable='true'] {
    cursor: grab;
    user-select: none;
    color: var(--fg-3);
    text-align: center;
    font-size: 14px;
    letter-spacing: -2px;
    vertical-align: middle;
}
.route-order-drag-handle[draggable='true']:active { cursor: grabbing; }
.route-order-drag-handle--readonly {
    color: var(--fg-4, #ccc);
    text-align: center;
    cursor: default;
    user-select: none;
}
#route-orders-table-body tr.route-order-row--dragging { opacity: 0.45; }
#route-orders-table-body tr.route-order-row--drop-target { box-shadow: inset 0 0 0 2px var(--accent, #0078d4); }

table { width: 100%; border-collapse: collapse; }

thead th {
    text-align: left;
    padding: 8px 14px;
    font: 600 11px/1 inherit;
    color: var(--fg-3);
    text-transform: uppercase;
    letter-spacing: .3px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-3);
    white-space: nowrap;
}
th.th-sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
th.th-sortable:hover {
    color: var(--fg-1);
}
th.th-sort-asc::after,
th.th-sort-desc::after {
    margin-left: 4px;
    font-size: 10px;
    opacity: 0.8;
}
th.th-sort-asc::after {
    content: '▲';
}
th.th-sort-desc::after {
    content: '▼';
}

tbody td {
    padding: 9px 14px;
    font-size: 12.5px;
    border-bottom: 1px solid var(--border-xs);
    vertical-align: middle;
}
tbody tr { transition: background var(--dur); }
tbody tr:nth-child(even) { background: rgba(0, 0, 0, 0.02); }
tbody tr:hover { background: rgba(0,0,0,.015); }
tbody tr.clickable-row:hover { background: rgba(0,103,192,.06); }
tbody tr.row--selected { background: rgba(0,103,192,.10); }
tbody tr.row--selected:hover { background: rgba(0,103,192,.14); }
tbody tr:last-child td { border-bottom: none; }

/* Cell user */
.cell-user { display: flex; align-items: center; gap: 8px; }
.cell-user-name { font: 500 12.5px/1 inherit; }
.cell-user-sub  { font-size: 10px; color: var(--fg-4); }

/* =============================================
   TABS
   ============================================= */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 14px; }

.tab {
    padding: 8px 14px; border: none; background: none;
    font: 500 12px/1 inherit; color: var(--fg-3);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color var(--dur), border-color var(--dur);
}
.tab:hover { color: var(--fg-1); }
.tab--active, .tab.tab--active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel--active { display: block; }

/* =============================================
   CHIPS
   ============================================= */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px; border: 1px solid var(--border-s); border-radius: 16px;
    font: 500 11px/1 inherit;
    background: var(--bg-1); color: var(--fg-2);
    cursor: pointer;
    transition: all var(--dur);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip--active, .chip.chip--active {
    background: var(--accent); color: #fff; border-color: var(--accent);
}

/* Інтеграції: смуга вкладок + плитка вмісту */
.integrations-card-body {
    max-width: 960px;
}
.integrations-tabs-bar {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0;
    padding: 5px;
    margin: 0 0 20px;
    border-radius: var(--r-lg);
    background: var(--bg-2);
    border: 1px solid var(--border);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.integrations-tabs-bar__btn {
    font: 600 14px/1.3 inherit;
    letter-spacing: 0.02em;
    padding: 11px 26px;
    min-height: 44px;
    border: none;
    border-radius: calc(var(--r-lg) - 4px);
    background: transparent;
    color: var(--fg-2);
    cursor: pointer;
    transition: color var(--dur), background var(--dur), box-shadow var(--dur), transform var(--dur);
}
.integrations-tabs-bar__btn:hover {
    color: var(--fg-1);
    background: rgba(0, 0, 0, 0.05);
}
.integrations-tabs-bar__btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.integrations-tabs-bar__btn--active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.integrations-tabs-bar__btn--active:hover {
    color: #fff;
    background: var(--accent);
    filter: brightness(1.05);
}
.integrations-tab-panel--surface {
    margin: 0 0 4px;
    padding: 20px 22px 22px;
    border-radius: var(--r-lg);
    border: 1px solid var(--border);
    background: var(--bg-2);
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.07),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
/* Вміст картки відділений від загального фону сторінки */
#pg-integrations .card {
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.06);
}
#pg-integrations .card-body {
    background: var(--bg-1);
}

/* Інтеграції: вкладка Binotel — дві колонки (REST / WebSocket) */
.integrations-binotel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px 20px;
    align-items: start;
}
.integrations-binotel-col {
    min-width: 0;
    padding: 14px 16px;
    border-radius: var(--r-md);
    border: 1px solid var(--border-s);
    background: var(--bg-1);
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
}
@media (max-width: 820px) {
    .integrations-binotel-grid {
        grid-template-columns: 1fr;
    }
}

/* Майстер 1С: сегмент «Без коду» / «Усі» */
.segmented {
    display: inline-flex;
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    overflow: hidden;
    background: var(--bg-1);
}
.segmented__btn {
    border: none;
    background: transparent;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    color: var(--text-muted);
}
.segmented__btn:hover {
    background: rgba(0, 0, 0, 0.05);
}
.segmented__btn--active {
    background: var(--accent);
    color: #fff;
}
.integration-1c-master-card {
    border: 1px solid var(--border);
    background: var(--bg-1);
}
.integration-1c-master-card:hover:not(:disabled) {
    border-color: var(--accent);
}
.integration-1c-master-card:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
.integration-1c-master-card__badge {
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg-2);
    white-space: nowrap;
}

/* =============================================
   KANBAN
   ============================================= */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

.kanban-col {
    background: var(--bg-2);
    border-radius: var(--r-md);
    padding: 10px;
    min-height: 300px;
}

.kanban-col-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 10px; padding-bottom: 8px;
    border-bottom: 2px solid var(--border);
}
.kanban-col-head h4 { font-size: 12px; }

.kanban-cnt {
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--border);
    font: 600 10px/20px inherit; text-align: center;
    color: var(--fg-2);
}

.kanban-col--new     .kanban-col-head { border-bottom-color: var(--info); }
.kanban-col--process .kanban-col-head { border-bottom-color: var(--warning); }
.kanban-col--delivery .kanban-col-head { border-bottom-color: var(--purple); }
.kanban-col--done    .kanban-col-head { border-bottom-color: var(--success); }

.kcard {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 10px; margin-bottom: 6px;
    cursor: pointer;
    transition: box-shadow var(--dur);
}
.kcard:hover { box-shadow: var(--shadow); }
.kcard h5 { font: 500 12px/1.3 inherit; margin-bottom: 4px; }
.kcard p  { font-size: 11px; color: var(--fg-2); margin-bottom: 2px; }

.kcard-ft { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; }
.kcard-amt  { font: 600 12px/1 inherit; }
.kcard-time { font-size: 10px; color: var(--fg-4); }

/* =============================================
   TIMELINE
   ============================================= */
.timeline { padding-left: 20px; position: relative; }
.timeline::before {
    content: '';
    position: absolute; left: 5px; top: 6px; bottom: 6px;
    width: 2px; background: var(--border);
}

.tl-item { position: relative; padding-bottom: 16px; }
.tl-item:last-child { padding-bottom: 0; }

.tl-dot {
    position: absolute; left: -18px; top: 3px;
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-1);
}
.tl-dot--success { background: var(--success); }
.tl-dot--warning { background: var(--warning); }
.tl-dot--muted   { background: var(--fg-4); }

.tl-time { font-size: 10px; color: var(--fg-4); margin-bottom: 1px; }
.tl-text { font-size: 12px; }

/* =============================================
   PROGRESS
   ============================================= */
.progress {
    height: 5px; background: var(--bg-0);
    border-radius: 3px; overflow: hidden;
}
.progress-fill {
    height: 100%; border-radius: 3px;
    background: var(--accent);
    transition: width .5s var(--ease);
}
.progress-fill--success { background: var(--success); }
.progress-fill--warning { background: var(--warning); }
.progress-fill--danger  { background: var(--danger); }

/* =============================================
   DRIVER CARD
   ============================================= */
.drv-card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 14px;
    transition: box-shadow var(--dur);
}
.drv-card:hover { box-shadow: var(--shadow); }

.drv-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }

.drv-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font: 600 13px/1 inherit;
    position: relative;
}
.online-dot {
    position: absolute; bottom: 0; right: 0;
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--success);
    border: 2px solid var(--bg-1);
}

.drv-name  { font: 600 13px/1 inherit; }
.drv-phone { font-size: 11px; color: var(--fg-4); }

.drv-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }

.drv-stat {
    text-align: center; padding: 6px;
    background: var(--bg-2); border-radius: var(--r);
}
.drv-stat-val { display: block; font: 600 14px/1.2 inherit; }
.drv-stat-lbl { display: block; font-size: 9px; color: var(--fg-4); text-transform: uppercase; letter-spacing: .3px; }

.drv-progress { margin-top: 10px; }
.drv-progress-head {
    display: flex; justify-content: space-between;
    font-size: 11px; color: var(--fg-2); margin-bottom: 3px;
}
.drv-progress-head span:last-child { font-weight: 600; }

/* =============================================
   MAP
   ============================================= */
.map-box {
    width: 100%; height: 320px;
    background: linear-gradient(145deg, #eaf4fb, #d8edf5 50%, #e2f0f8);
    border-radius: var(--r-md);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    position: relative; overflow: hidden;
}
.map-label { font-size: 13px; color: var(--fg-3); opacity: .5; position: relative; }

.map-pin, .map-car {
    position: absolute;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.map-pin {
    width: 18px; height: 18px;
    background: var(--accent);
    border-radius: 50% 50% 50% 0;
    transform: rotate(-45deg);
}
.map-car {
    width: 14px; height: 14px;
    background: var(--success);
    border-radius: 50%;
}

.map-legend {
    display: flex; gap: 14px; margin-top: 10px;
    font-size: 11px; color: var(--fg-2);
}
.map-legend span { display: flex; align-items: center; gap: 4px; }

/* =============================================
   CHART
   ============================================= */
.chart-bars {
    display: flex; align-items: flex-end; gap: 6px;
    height: 200px; padding-top: 16px;
}
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chart-val { font: 600 9px/1 inherit; color: var(--fg-2); }
.chart-lbl { font-size: 9px; color: var(--fg-4); }
.chart-bar {
    width: 100%; max-width: 32px;
    background: linear-gradient(180deg, var(--accent), rgba(0,103,192,.5));
    border-radius: 3px 3px 0 0;
    transition: height .6s var(--ease);
}
.chart-bar--light { background: linear-gradient(180deg, var(--accent-light), rgba(96,205,255,.4)); }

/* Donut */
.donut {
    width: 120px; height: 120px; border-radius: 50%;
    background: conic-gradient(var(--accent) 0% 45%, var(--success) 45% 72%, var(--warning) 72% 88%, var(--danger) 88%);
    position: relative;
    margin: 0 auto 12px;
}
.donut::after {
    content: '';
    position: absolute; inset: 26px;
    background: var(--bg-1); border-radius: 50%;
}

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.legend-item { display: flex; align-items: center; gap: 4px; font-size: 10px; color: var(--fg-2); }

.legend-dot {
    display: inline-block;
    width: 8px; height: 8px; border-radius: 2px;
}
.legend-dot--accent  { background: var(--accent); }
.legend-dot--success { background: var(--success); }
.legend-dot--warning { background: var(--warning); }
.legend-dot--danger  { background: var(--danger); }

/* =============================================
   FORMS
   ============================================= */
.form-group { margin-bottom: 12px; }
.form-label { display: block; font: 500 11px/1 inherit; color: var(--fg-2); margin-bottom: 3px; }

.form-input {
    width: 100%; height: 32px;
    border: 1px solid var(--border-s); border-radius: var(--r);
    padding: 0 10px;
    font: 12px/32px inherit;
    background: var(--bg-1); color: var(--fg-1);
    outline: none;
    transition: border-color var(--dur), box-shadow var(--dur);
}
.form-input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

select.form-input {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' fill='%238A8A8A' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

/* Сторінка «Адреси»: select + пошук у загальному стилі .form-input */
#pg-addresses .addresses-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}
#pg-addresses label.addresses-toolbar__city.form-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}
#pg-addresses .addresses-select.form-input {
    min-width: 220px;
    width: auto;
}
#pg-addresses label.addresses-toolbar__source.form-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}
#pg-addresses .addresses-select-source.form-input {
    min-width: 240px;
    width: auto;
}
#pg-addresses .addresses-search-card {
    padding: 12px 16px;
    box-shadow: var(--shadow-sm);
}
#pg-addresses .addresses-search-label {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0;
}
#pg-addresses .addresses-search-label__text {
    flex-shrink: 0;
    white-space: nowrap;
    font-weight: 500;
}
#pg-addresses .addresses-search-input.form-input {
    flex: 1;
    min-width: 180px;
    max-width: 440px;
    width: auto;
}

textarea.form-input { height: auto; padding: 8px 10px; resize: vertical; min-height: 60px; line-height: 1.4; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* =============================================
   AUTH LOADING
   ============================================= */
.auth-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 2600;
    background: var(--bg-0);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: var(--fg-2);
}

/* =============================================
   MODAL
   ============================================= */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.32);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 36px 12px 12px;
    overflow-y: auto;
    opacity: 0; visibility: hidden;
    transition: opacity .2s, visibility .2s;
}
.modal-overlay.show { opacity: 1; visibility: visible; }

/* Вхід: не закривати кліком по фону (див. initModals) */
.modal-overlay--blocking { z-index: 2500; }
.modal-overlay--below-child { z-index: 1900; }

.modal {
    background: var(--bg-1);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-xl);
    width: min(92%, calc(100vw - 16px));
    max-width: min(540px, calc(100vw - 16px));
    max-height: 85vh;
    overflow: hidden;
    display: flex; flex-direction: column;
    transform: scale(.96) translateY(8px);
    transition: transform .25s var(--ease);
}
.modal-overlay.show .modal { transform: none; }

.modal-header {
    padding: 18px 20px 10px;
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { font: 600 16px/1 inherit; }

.modal-close {
    width: 28px; height: 28px;
    border: none; background: none; border-radius: var(--r);
    cursor: pointer;
    font-size: 16px; color: var(--fg-3);
    display: flex; align-items: center; justify-content: center;
    transition: background var(--dur);
}
.modal-close:hover { background: rgba(0,0,0,.05); }

.modal-body { padding: 10px 20px; overflow-y: auto; flex: 1; }

.modal-footer {
    padding: 12px 20px;
    display: flex; justify-content: flex-end; gap: 6px;
    border-top: 1px solid var(--border);
}

.modal--wide { max-width: min(720px, calc(100vw - 16px)); }
.modal--incoming-call.modal--wide { max-width: min(880px, calc(100vw - 16px)); }

.modal--map {
    max-width: min(1180px, calc(100vw - 20px));
    width: min(1180px, calc(100vw - 20px));
    max-height: calc(100vh - 24px);
}
.modal--map .modal-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.modal-map-container {
    flex: 1 1 auto;
    width: 100%;
    height: min(680px, 72vh);
    min-height: min(480px, 58vh);
    border-radius: 8px;
    overflow: hidden;
}
@media (max-width: 640px) {
    .modal--map {
        width: calc(100vw - 12px);
        max-width: calc(100vw - 12px);
    }
    .modal-map-container {
        height: min(56vh, 520px);
        min-height: 280px;
    }
}
.modal-header--incoming-call {
    align-items: flex-start;
    gap: 8px;
    padding: 14px 18px 10px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(46, 125, 50, 0.06), transparent 70%);
}
.modal-header--incoming-call .modal-header h2,
.modal-header--incoming-call h2 {
    margin: 0;
    font-size: 15px;
}
.incoming-call-client-card--compact {
    padding: 8px 10px;
    border-radius: var(--r);
    border: 1px solid var(--border);
    background: var(--bg-2);
    margin-bottom: 12px;
}
.incoming-call-client-card__head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 10px;
    margin-bottom: 2px;
}
.incoming-call-client-card__name {
    font-weight: 600;
    font-size: 15px;
    line-height: 1.25;
    color: var(--fg-1);
}
.incoming-call-client-card__meta-inline {
    font-size: 12px;
    color: var(--fg-3);
    display: inline-flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 6px;
}
.incoming-call-client-card__dot {
    opacity: 0.45;
    user-select: none;
}
.incoming-call-client-card__phone {
    font-size: 12px;
    line-height: 1.35;
    margin-bottom: 2px;
}
.incoming-call-addresses-block--compact {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}
.incoming-call-addresses-block__title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--fg-3);
    margin: 0 0 4px;
}
.incoming-call-addresses-empty {
    font-size: 12px;
    margin: 0;
    line-height: 1.3;
}
.incoming-call-addresses-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.incoming-call-addresses-list--compact .incoming-call-addresses-list__item {
    display: block;
    padding: 2px 0;
    font-size: 12px;
    line-height: 1.4;
    border: none;
}
.incoming-call-addr-type {
    font-weight: 600;
    color: var(--fg-2);
}
.incoming-call-addr-text {
    color: var(--fg-1);
}
.incoming-call-section-title {
    font: 600 13px/1.3 inherit;
    margin: 0 0 8px;
    color: var(--fg-2);
}
.incoming-call-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--r);
    max-height: 42vh;
    overflow-y: auto;
}
.incoming-call-orders-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.incoming-call-orders-table th,
.incoming-call-orders-table td {
    padding: 5px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.incoming-call-orders-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-1);
    z-index: 1;
    font-weight: 600;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--fg-3);
}
.incoming-call-td-address { max-width: 160px; word-break: break-word; }
.incoming-call-td-items { max-width: 200px; font-size: 12px; color: var(--fg-3); }
.incoming-call-empty__title { font: 600 16px/1.3 inherit; margin: 0; }
.modal-footer--incoming-call { flex-wrap: wrap; }

.modal-body--scroll { max-height: 65vh; overflow-y: auto; }

.client-form { --cf-gap: 4px; --cf-mb: 6px; }
.client-form .form-group { margin-bottom: var(--cf-gap); }
.client-form .form-row { gap: var(--cf-gap); margin-bottom: var(--cf-gap); }
.client-form .form-row:last-child { margin-bottom: 0; }
.client-form .form-input { height: 28px; font-size: 11px; padding: 0 8px; }
.client-form .form-input[rows] { height: auto; min-height: 48px; padding: 6px 8px; }
.client-form .form-label { font-size: 10px; margin-bottom: 1px; }
.client-form-section { margin-bottom: var(--cf-mb); }
.client-form-section:last-child { margin-bottom: 0; }
.client-form-section-title {
    font: 600 10px/1.3 inherit;
    color: var(--fg-3);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin: 0 0 4px;
    padding-bottom: 3px;
    border-bottom: 1px solid var(--border);
}
.client-form .form-row--3 { grid-template-columns: repeat(3, 1fr); }
.client-form .form-row--4 { grid-template-columns: repeat(4, 1fr); }
.client-form .form-row--5 { grid-template-columns: repeat(5, 1fr); }
.client-form .form-row--6 { grid-template-columns: repeat(6, 1fr); }
.client-form .addr-street-wide { grid-column: span 2; }

/* GPS: широта/довгота + «Визначити на карті» і GoogleMaps в одному рядку (клієнт, склад) */
.modal-body .addr-gps-row.form-row--4 {
    grid-template-columns: repeat(4, 1fr);
}
.modal-body .addr-gps-row .addr-gps-actions {
    grid-column: span 2;
    align-self: end;
}
.modal-body .addr-gps-actions-label {
    display: block;
    visibility: hidden;
    min-height: 1em;
    margin-bottom: 1px;
    pointer-events: none;
}
.client-form .addr-gps-actions-label {
    font-size: 10px;
    margin-bottom: 1px;
}
.modal-body .addr-gps-actions-inner {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
}
.modal-body .addr-gps-actions-inner .btn {
    flex: 0 0 auto;
    white-space: nowrap;
}

.addresses-container { display: flex; flex-direction: column; gap: 8px; margin-bottom: 6px; }
.address-block {
    padding: 8px; border: 1px solid var(--border); border-radius: var(--r-sm);
    background: var(--bg-subtle, rgba(0,0,0,.02));
}
.address-block-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 5px; padding-bottom: 4px; border-bottom: 1px solid var(--border);
}
.address-block-title { font: 600 11px/1.3 inherit; color: var(--fg-2); }
.address-block-remove { font-size: 10px; color: var(--fg-3); padding: 2px 6px; }
.address-block-remove:hover { color: var(--danger); }
#btn-nc-add-address, #btn-ec-add-address { margin-top: 4px; }

.modal--client-form { max-width: min(960px, calc(100vw - 16px)); }
#modal-newClient .modal,
#modal-editClient .modal { max-height: 92vh; }
#modal-newClient .modal-header,
#modal-editClient .modal-header { padding: 10px 16px 4px; }
#modal-newClient .modal-header h2,
#modal-editClient .modal-header h2 { font-size: 15px; }
#modal-newClient .modal-body--scroll,
#modal-editClient .modal-body--scroll {
    max-height: none;
    padding: 4px 16px 8px;
}
#modal-newClient .modal-footer,
#modal-editClient .modal-footer { padding: 8px 16px; }

.client-form--compact { --cf-gap: 2px; --cf-mb: 4px; }
.client-form--compact .form-input { height: 26px; font-size: 11px; padding: 0 6px; }
.client-form--compact .form-label { font-size: 9px; margin-bottom: 0; }
.client-form--compact .client-form-section-title {
    margin: 0 0 2px;
    padding-bottom: 2px;
    font-size: 9px;
}
.client-form--compact .form-group.cf-span-2 { grid-column: span 2; }
.client-form--compact .addresses-container { gap: 4px; margin-bottom: 2px; }
.client-form--compact .address-block {
    padding: 4px 6px;
    border-radius: var(--r-sm);
}
.client-form--compact .address-block-header {
    margin-bottom: 2px;
    padding-bottom: 2px;
}
.client-form--compact .address-block-title { font-size: 10px; }
.client-form--compact .address-block-remove { padding: 0 4px; font-size: 9px; }
.client-form--compact .addr-gps-actions-inner .btn {
    font-size: 10px;
    padding: 1px 6px;
    min-height: 24px;
}
.client-form--compact .addr-gps-row .addr-gps-actions { grid-column: span 2; }
#modal-newClient #btn-nc-add-address,
#modal-editClient #btn-ec-add-address {
    margin-top: 2px;
    padding: 2px 8px;
    font-size: 10px;
}

.form-input--invalid {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 1px var(--danger);
}
.form-input--invalid:focus {
    box-shadow: 0 0 0 1px var(--danger), 0 0 0 3px rgba(196, 43, 28, 0.2);
}

@media (max-width: 640px) {
    .client-form .form-row--4,
    .client-form .form-row--5,
    .client-form .form-row--6 { grid-template-columns: repeat(2, 1fr); }
    .client-form .form-row--3 { grid-template-columns: 1fr 1fr; }
    .modal-body .addr-gps-row.form-row--4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* =============================================
   TOAST
   ============================================= */
.toast-box {
    position: fixed;
    bottom: max(20px, env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: max-content;
    max-width: calc(100vw - 24px);
    pointer-events: none;
}

.toast {
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-xl);
    padding: 10px 16px;
    display: flex; align-items: center; gap: 10px;
    min-width: 260px;
    max-width: 100%;
    font-size: 14px;
    line-height: 1.35;
    pointer-events: auto;
    animation: toastIn .25s var(--ease);
}
.toast--success { border-left: 3px solid var(--success); }
.toast--error   { border-left: 3px solid var(--danger); }
.toast--info    { border-left: 3px solid var(--accent); }
.toast--warning { border-left: 3px solid var(--warning); }

@keyframes toastIn {
    from { transform: translateY(12px); opacity: 0; }
    to   { transform: none; opacity: 1; }
}

/* =============================================
   PLACEHOLDER PAGE
   ============================================= */
.placeholder-page {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    min-height: 400px; text-align: center;
    color: var(--fg-3);
}
.placeholder-page > svg { width: 56px; height: 56px; opacity: .2; margin-bottom: 12px; }
.placeholder-page h2  { font: 600 18px/1.3 inherit; color: var(--fg-2); margin-bottom: 6px; }
.placeholder-page p   { font-size: 13px; max-width: 360px; margin-bottom: 16px; }

/* Welcome page: centered text and larger CTA */
#pg-welcome .welcome-header {
    text-align: center;
}

#pg-welcome .welcome-header .page-subtitle {
    margin-top: 6px;
    font-size: 14px;
}

#pg-welcome .placeholder-page p {
    text-align: center;
}

#pg-welcome .welcome-cta {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 8px;
}

#pg-welcome .welcome-cta .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 44px;
    padding: 0 28px;
    font-size: 14px;
    border-radius: var(--r-md);
}

#pg-welcome .welcome-cta .btn svg {
    display: block;
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    opacity: 1;
    margin-bottom: 0;
}

/* =============================================
   RESPONSIVE
   ============================================= */
@media (max-width: 1200px) {
    .kanban { grid-template-columns: repeat(2, 1fr); }
    .grid--3, .stats-row--3, .stats-row--4, .stats-row--5 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
        transition: transform .3s var(--ease);
        top: 0;
        height: 100vh;
        z-index: 2001; /* выше шапки */
    }
    .sidebar.open { transform: none; }
    .tb-btn--burger { display: inline-flex; }
    .main { margin-right: 0; }
    .grid--2, .grid--3, .stats-row--3, .stats-row--4, .stats-row--5 { grid-template-columns: 1fr; }
    .kanban { grid-template-columns: 1fr; }
    .stats-row { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .modal-body .addr-gps-row.form-row--4 {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Titlebar: не даємо правому блоку виїхати за екран */
    .titlebar {
        gap: 6px;
        min-width: 0;
        overflow: hidden;
    }
    .tb-left {
        min-width: 0;
        flex: 1 1 auto;
        gap: 6px;
    }
    .tb-right {
        min-width: 0;
        flex: 0 1 auto;
        gap: 4px;
        max-width: 100%;
    }
    .tb-breadcrumb {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .tb-user-info,
    .tb-divider,
    .tb-search-hint {
        display: none;
    }
    .tb-user {
        padding: 2px;
        flex-shrink: 0;
    }
    .tb-btn-order {
        width: 34px;
        height: 32px;
        padding: 0;
        justify-content: center;
        flex-shrink: 0;
    }
    .tb-btn-order__label {
        display: none;
    }
    .tb-ws-status {
        padding: 4px 7px;
        gap: 4px;
    }
    .tb-ws-status-text {
        display: none;
    }
    .tb-incoming-call-btn__label {
        display: none;
    }

    .tb-btn--notify,
    .tb-btn--messages,
    .tb-btn--settings {
        display: none;
    }

    #pg-clients .clients-company-filter,
    #pg-clients .clients-no-geo-filter,
    #pg-clients .clients-show-1c-name-filter {
        display: none;
    }
}

@media (max-width: 600px) {
    body {
        overflow-y: auto;
        overflow-x: hidden;
    }

    .titlebar {
        position: sticky;
        inset: auto;
        top: 0;
        left: 0;
        right: 0;
        flex-wrap: wrap;
        height: auto;
        padding: 6px 8px 8px;
        row-gap: 6px;
        overflow: visible;
    }
    .tb-left, .tb-right {
        width: 100%;
        justify-content: space-between;
        flex: 0 0 auto;
        max-width: 100%;
    }
    .tb-right {
        flex-wrap: nowrap;
        justify-content: flex-start;
        gap: 4px;
    }
    .tb-btn-order {
        margin-right: auto;
    }
    .tb-center {
        order: 3;
        flex: 1 0 100%;
        max-width: 100%;
    }
    .tb-search {
        height: 30px;
        font-size: 11px;
    }
    .app-layout {
        margin-top: 0;
        height: auto;
        min-height: calc(100vh - var(--titlebar-h));
        min-width: 0;
        max-width: 100%;
    }
    .main {
        padding: 16px 12px;
        overflow-y: visible;
        overflow-x: clip;
        min-width: 0;
        max-width: 100%;
    }
    #mainContent.main:has(#pg-clients.active) {
        padding: 14px 10px;
    }
    .page.active {
        min-width: 0;
        max-width: 100%;
        overflow-x: clip;
    }
    .page-summary {
        min-width: 0;
        max-width: 100%;
    }
    .page-header {
        margin-bottom: 14px;
    }
    .page-title {
        font-size: 20px;
    }
    .page-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .page-actions .btn-group {
        width: 100%;
    }
    .page-actions .btn-group .btn,
    .page-actions > .btn {
        flex: 1 0 auto;
        justify-content: center;
        width: 100%;
    }
    thead th,
    tbody td {
        padding: 6px 10px;
        font-size: 11.5px;
    }
    .row-actions {
        gap: 4px;
    }
    .btn-icon {
        width: 28px;
        height: 28px;
    }

    .stats-row > .stat-card {
        min-width: 0;
    }

    /* Таблиці: скрол всередині .tbl-wrap, батьки не розтягуються за контентом (min-width:0) */
    .mobile-scroll-table {
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: visible;
    }
    .mobile-scroll-table .card {
        min-width: 0;
        max-width: 100%;
        overflow-x: hidden;
    }
    .mobile-scroll-table .tbl-wrap {
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }
    .mobile-scroll-table table {
        font-size: 11px;
        white-space: nowrap;
    }

    /* Замовлення: на вузькому екрані — горизонтальний скрол, товари переносяться */
    #pg-orders .mobile-scroll-table #orders-table {
        table-layout: auto;
        min-width: 900px;
    }
    #pg-orders .mobile-scroll-table #orders-table td.cell-order-items {
        white-space: normal;
    }

    .tbl-wrap {
        display: block;
        width: 100%;
        max-width: 100%;
        min-width: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }
    .tbl-wrap table {
        width: max-content;
        white-space: nowrap;
    }

    /* Фільтр у колонці page-actions: flex-grow:1 розтягував блок по висоті → «дірка» та зміщена іконка */
    #pg-clients .clients-filter-wrap,
    #pg-orders .orders-filter-wrap {
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
        max-width: none;
    }

    /* Картка з кнопкою карти: не виходити за сітку статистики */
    .clients-stat-card--map,
    .orders-stat-card--map {
        overflow: hidden;
        isolation: isolate;
        padding-right: 52px;
    }

    .clients-map-btn,
    .orders-map-btn {
        height: auto;
        width: 40px;
        max-height: 40px;
        right: 8px;
    }

    .clients-map-btn:hover,
    .orders-map-btn:hover {
        transform: translateY(-50%) translateY(-1px);
    }

    /* Клієнти: таблиця не стискається під екран — скрол у .clients-table-wrap */
    #pg-clients .mobile-scroll-table {
        max-width: 100%;
    }

    #pg-clients .clients-table-card {
        min-width: 0;
        max-width: 100%;
    }

    #pg-clients .clients-table-wrap {
        max-height: min(468px, 52vh);
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    #pg-clients .clients-table-wrap table {
        width: max-content;
        min-width: 640px;
        white-space: normal;
        table-layout: auto;
    }

    #pg-clients .clients-table-wrap thead th {
        white-space: nowrap;
    }

    #pg-clients .clients-table-wrap tbody td {
        white-space: normal;
        vertical-align: top;
        overflow-wrap: break-word;
        word-break: normal;
    }

    #pg-clients .clients-table-wrap td.cell-address {
        white-space: normal;
        min-width: 9rem;
        max-width: 14rem;
    }

    #pg-clients .clients-table-wrap tbody td:nth-child(1),
    #pg-clients .clients-table-wrap tbody td:nth-child(3),
    #pg-clients .clients-table-wrap tbody td:nth-child(5),
    #pg-clients .clients-table-wrap tbody td:nth-child(6),
    #pg-clients .clients-table-wrap tbody td:nth-child(7),
    #pg-clients .clients-table-wrap tbody td:nth-child(8) {
        white-space: nowrap;
        vertical-align: middle;
    }

    #pg-clients .clients-table-wrap .cell-user .cell-user-name {
        white-space: normal;
    }

    /*
     * iOS Safari: position:sticky на td не працює з border-collapse:collapse
     * (заголовок може «залипнути», а рядки — ні). Потрібен separate + sticky на td.
     */
    #pg-clients .mobile-scroll-table .card.clients-table-card {
        overflow: visible;
    }
    #pg-clients .clients-table-wrap {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    #pg-clients #clients-table {
        border-collapse: separate;
        border-spacing: 0;
    }
    #pg-clients #clients-table .clients-col-id {
        display: none;
    }
    #pg-clients #clients-table thead th.clients-col-name,
    #pg-clients #clients-table tbody td.clients-col-name {
        position: -webkit-sticky;
        position: sticky;
        left: 0;
        min-width: 9.5rem;
        max-width: 11.5rem;
        box-shadow: 4px 0 8px -4px rgba(0, 0, 0, 0.12);
        background-clip: padding-box;
    }
    #pg-clients #clients-table thead th.clients-col-name {
        z-index: 4;
        background: linear-gradient(180deg, #f2f5fa, #e9eef6);
    }
    #pg-clients #clients-table tbody td.clients-col-name {
        z-index: 2;
        background: #ffffff;
        background-color: var(--bg-1);
    }
    #pg-clients #clients-table tbody tr:hover td.clients-col-name {
        background-color: var(--bg-2);
    }
    #pg-clients #clients-table tbody tr.row--selected td.clients-col-name {
        background-color: #dceaf8;
    }
    #pg-clients #clients-table tbody tr.row--selected:hover td.clients-col-name {
        background-color: #d0e3f5;
    }

    #pg-clients .mobile-scroll-table + .card {
        min-width: 0;
        max-width: 100%;
    }

    #pg-clients .client-orders-history-wrap {
        max-height: min(218px, 30vh);
        width: 100%;
        max-width: 100%;
        min-width: 0;
    }

    #pg-clients .client-orders-history-wrap table {
        white-space: normal;
        min-width: 480px;
    }

    #pg-clients .client-orders-history-wrap tbody td {
        white-space: normal;
        vertical-align: top;
        word-break: break-word;
    }

    #pg-clients .client-orders-history-wrap tbody td:nth-child(1),
    #pg-clients .client-orders-history-wrap tbody td:nth-child(2),
    #pg-clients .client-orders-history-wrap tbody td:nth-child(5),
    #pg-clients .client-orders-history-wrap tbody td:nth-child(6) {
        white-space: nowrap;
        vertical-align: middle;
    }

    #pg-clients .stats-row {
        margin-bottom: 6px;
    }

    #pg-clients .page-actions {
        margin-top: 5px;
        gap: 5px;
    }

    #pg-clients #clients-chips {
        justify-content: flex-start;
    }
}

/* Search results dropdown */
.search-results-dropdown{position:absolute;top:100%;left:0;right:0;z-index:120;background:var(--bg-1);border:1px solid var(--border);border-radius:8px;max-height:220px;overflow-y:auto;box-shadow:0 8px 24px rgba(0,0,0,.12)}
/* Модалка «Початкові залишки»: не обрізати нативний select; список клієнта — fixed (див. app.js) */
#modal-tara-initial-balance .modal {
    overflow: visible;
    max-height: min(92vh, 760px);
}
#modal-tara-initial-balance .modal-body {
    overflow-x: visible;
    overflow-y: auto;
    max-height: min(56vh, 440px);
}
.tib-client-search-wrap {
    position: relative;
    z-index: 2;
}
.search-results-dropdown--tib-fixed {
    position: fixed;
    left: 0;
    top: 0;
    right: auto;
    width: min(100vw - 24px, 360px);
    max-height: min(220px, 40vh);
    z-index: 5000;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
}
.search-result-item{padding:8px 12px;cursor:pointer;font-size:13px;border-bottom:1px solid var(--border);transition:background .15s}
.search-result-item:hover{background:var(--bg-3)}
.search-result-item:last-child{border-bottom:none}
.search-result-item__name{font-weight:600;line-height:1.2}
.search-result-item__sub{font-size:11px;line-height:1.3;color:var(--fg-3);margin-top:2px}
.search-result-item__addr{white-space:normal;word-break:break-word;padding-left:2px;border-left:2px solid var(--border);margin-top:3px}

/* Pagination row */
.pagination-row{display:flex;gap:4px;justify-content:center;padding:12px 0;flex-wrap:wrap}

/* Form input small variant */
.form-input--sm{padding:6px 10px;font-size:12px;height:32px}

/* Badge secondary */
.badge--secondary{background:var(--bg-3);color:var(--fg-2)}

/* Order address cards */
.ord-address-card{transition:border-color .2s,box-shadow .2s;min-width:0}
.ord-address-card:has(.ord-addr-toggle:checked){border-color:var(--accent);box-shadow:0 0 0 1px var(--accent)}
.ord-address-card .ord-addr-body{transition:opacity .2s}
.ord-address-card:has(.ord-addr-toggle:not(:checked)) .ord-addr-body{opacity:.4;pointer-events:none}

.ord-addr-card-head{
    display:flex;align-items:flex-start;justify-content:space-between;gap:8px;margin-bottom:8px
}
.ord-addr-card-head-label{
    display:flex;align-items:flex-start;gap:8px;font-weight:600;font-size:14px;cursor:pointer;
    min-width:0;flex:1
}
.ord-addr-card-head-label .ord-addr-label{word-break:break-word}
.ord-addr-card-slot{font-size:12px;flex-shrink:0;max-width:42%}

/* Дата + слоти: без minmax(180px) — щоб не виходило за екран на мобільних */
.ord-addr-delivery-slot-grid{
    display:grid;
    grid-template-columns:minmax(0,1.2fr) minmax(0,1fr) minmax(0,1fr);
    gap:8px;
    align-items:end
}

/* Рядок товару в замовленні */
.ord-order-item-row{
    display:flex;flex-wrap:wrap;gap:8px;align-items:flex-end;margin-bottom:8px
}
.ord-order-item-row .form-group{margin:0;min-width:0}
.ord-order-item-product-wrap{flex:3 1 140px;min-width:0}
.ord-order-item-qty-wrap{flex:1 1 72px; min-width:0; max-width:100%}
.ord-order-item-price-wrap{flex:1 1 88px; min-width:0; max-width:100%}
.ord-order-item-remove-btn{flex:0 0 auto;margin-bottom:4px}

/* Модалки замовлення: не розтягувати сторінку по горизонталі */
#modal-newOrder .modal,
#modal-orderDetail .modal {
    min-width:0;
}
#modal-newOrder .modal-body,
#modal-orderDetail .modal-body {
    overflow-x:hidden;
    min-width:0;
}

/* Перегляд замовлення: сітка полів */
.order-detail-meta-grid{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:12px;
    margin-bottom:16px;
    min-width:0
}
.order-detail-meta-grid > div{min-width:0;word-break:break-word}
.order-detail-meta-grid__full{grid-column:1 / -1}

@media (max-width:520px){
    .order-detail-meta-grid{grid-template-columns:1fr}
}

@media (max-width:520px){
    .ord-addr-delivery-slot-grid{
        grid-template-columns:1fr
    }
    .ord-addr-card-slot{max-width:100%}
    .ord-order-item-row .ord-order-item-product-wrap{flex:1 1 100%}
    .ord-order-item-row .ord-order-item-qty-wrap,
    .ord-order-item-row .ord-order-item-price-wrap {
        flex:1 1 calc(50% - 6px);
    }
}

@media (max-width:600px){
    #modal-orderDetail .modal-footer{
        flex-wrap:wrap;
        justify-content:stretch;
        gap:8px
    }
    #modal-orderDetail .modal-footer .btn{
        flex:1 1 auto;
        min-width:0
    }
    #modal-orderDetail #order-detail-status-select{
        width:100%;
        min-width:0
    }
    #modal-newOrder .modal-footer{
        flex-wrap:wrap;
        gap:8px
    }
    #modal-newOrder .modal-footer .btn{
        flex:1 1 calc(50% - 4px);
        min-width:0
    }
}

/* =============================================
   ЗРУЧНЕ ЧИТАННЯ (html.comfort-ui) — операторам / слабкому зору
   Увімкнення: чекбокс у сайдбарі або на сторінці входу; ключ localStorage aquaComfortUi
   ============================================= */
html.comfort-ui {
    --titlebar-h: 52px;
    --sidebar-w: 308px;
    --fg-3: #525252;
    --fg-4: #8F8F8F;
}

html.comfort-ui body {
    font-size: 16px;
    line-height: 1.55;
}

html.comfort-ui .comfort-ui-toggle {
    font-size: 14px;
    padding: 12px 14px;
}
html.comfort-ui .comfort-ui-toggle__hint { font-size: 12px; }

html.comfort-ui .tb-breadcrumb { font-size: 15px; }
html.comfort-ui .tb-breadcrumb .sep { font-size: 14px; }
html.comfort-ui .tb-breadcrumb span:last-child { font-size: 17px; }

html.comfort-ui .tb-search {
    height: 40px;
    font-size: 15px;
    line-height: 40px;
    padding-left: 40px;
}
html.comfort-ui .tb-search-icon { left: 12px; width: 16px; height: 16px; }
html.comfort-ui .tb-search-hint { font-size: 12px; padding: 2px 8px; }

html.comfort-ui .tb-search-dropdown__item { padding: 12px 14px; }
html.comfort-ui .tb-search-dropdown__item--sub { font-size: 13px; }
html.comfort-ui .tb-search-dropdown__empty,
html.comfort-ui .tb-search-dropdown__loading { font-size: 14px; }

html.comfort-ui .tb-ws-status {
    font-size: 13px;
    padding: 6px 12px;
}
html.comfort-ui .tb-incoming-call-btn { font-size: 14px; padding: 6px 12px; }
html.comfort-ui .tb-incoming-call-btn svg { width: 17px; height: 17px; }

html.comfort-ui .tb-btn {
    width: 40px;
    height: 36px;
}
html.comfort-ui .tb-btn svg { width: 18px; height: 18px; }

html.comfort-ui .tb-user-name { font-size: 14px; }
html.comfort-ui .tb-user-role { font-size: 12px; }
html.comfort-ui .avatar { width: 36px; height: 36px; font-size: 13px; }

html.comfort-ui .nav-group-title { font-size: 12px; }
html.comfort-ui .nav-item { font-size: 14px; padding: 8px 16px; margin: 0 6px; }
html.comfort-ui .nav-count { font-size: 13px; }
html.comfort-ui .nav-badge { font-size: 11px; min-height: 18px; padding: 0 6px; }

html.comfort-ui .sidebar-user-info h4 { font-size: 14px; }
html.comfort-ui .sidebar-user-info p { font-size: 12px; }
html.comfort-ui .sidebar-logout-btn { font-size: 14px; padding: 10px 12px; }

html.comfort-ui .page-title { font-size: 28px; }
html.comfort-ui .page-subtitle { font-size: 14px; }

html.comfort-ui .btn {
    height: 36px;
    font-size: 14px;
    padding: 0 16px;
    gap: 8px;
}
html.comfort-ui .btn svg { width: 16px; height: 16px; }
html.comfort-ui .btn--sm { height: 32px; font-size: 13px; padding: 0 12px; }
html.comfort-ui .btn-icon { width: 36px; height: 36px; }

html.comfort-ui .form-label { font-size: 13px; margin-bottom: 5px; }
html.comfort-ui .form-input {
    height: 40px;
    font-size: 15px;
    line-height: 40px;
    padding: 0 12px;
}
html.comfort-ui textarea.form-input {
    min-height: 72px;
    padding: 10px 12px;
    line-height: 1.45;
}

html.comfort-ui .modal-header h2 { font-size: 19px; }
html.comfort-ui .modal-close { width: 36px; height: 36px; font-size: 20px; }
html.comfort-ui .modal-body { font-size: 15px; }

html.comfort-ui .badge { font-size: 13px; padding: 4px 10px; }
html.comfort-ui .stat-label { font-size: 13px; }
html.comfort-ui .stat-value { font-size: 24px; }

html.comfort-ui .table-note { font-size: 13px; }
html.comfort-ui .cell-user-name { font-size: 14px; }
html.comfort-ui .cell-user-sub { font-size: 12px; }

html.comfort-ui .auth-loading-overlay { font-size: 16px; }

html.comfort-ui .incoming-call-client-card__name { font-size: 17px; }
html.comfort-ui .incoming-call-client-card__meta-inline { font-size: 14px; }
html.comfort-ui .modal-header--incoming-call .modal-header h2,
html.comfort-ui .modal-header--incoming-call h2 { font-size: 17px; }

html.comfort-ui ::-webkit-scrollbar { width: 12px; height: 12px; }
html.comfort-ui .sidebar-scroll::-webkit-scrollbar { width: 8px; }

html.comfort-ui .btn:focus-visible,
html.comfort-ui .form-input:focus-visible,
html.comfort-ui .nav-item:focus-visible,
html.comfort-ui .comfort-ui-toggle:focus-within {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* =============================================
   Імпорт клієнтів (сторінка)
   ============================================= */
.client-import-page__header {
    margin-bottom: 8px;
}
.client-import-page__lead {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}
.client-import-page__icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: var(--r-lg);
    background: var(--accent-subtle);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
}
.client-import-page__icon svg {
    width: 26px;
    height: 26px;
}
.client-import-page__titles .page-title {
    margin-bottom: 4px;
}
.client-import-page__titles .page-subtitle {
    max-width: 52rem;
    line-height: 1.5;
}

.cii-workbench-card {
    margin-top: 16px;
}
.cii-workbench-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.cii-crumb {
    font-size: 13px;
    font-weight: 600;
    color: var(--fg-1);
    line-height: 1.45;
    flex: 1;
    min-width: 200px;
}
.cii-workbench-body {
    padding-top: 8px;
}
.cii-grid {
    display: grid;
    grid-template-columns: minmax(200px, 280px) 1fr;
    gap: 20px;
    align-items: start;
}
@media (max-width: 900px) {
    .cii-grid {
        grid-template-columns: 1fr;
    }
}
.cii-queue-aside__title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--fg-3);
    margin-bottom: 10px;
}
.cii-queue-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 480px;
    overflow: auto;
    padding-right: 4px;
}
.cii-queue-item {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 8px;
    align-items: center;
    width: 100%;
    padding: 10px 12px;
    text-align: left;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--bg-1);
    font-size: 13px;
    cursor: pointer;
    transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.cii-queue-item:hover {
    border-color: var(--accent-light);
    background: var(--bg-2);
}
.cii-queue-item--active {
    border-color: var(--accent);
    background: var(--accent-subtle);
}
.cii-queue-item__line {
    font-family: ui-monospace, monospace;
    font-size: 11px;
    color: var(--fg-3);
    white-space: nowrap;
}
.cii-queue-item__name {
    color: var(--fg-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cii-queue-item__st {
    font-size: 11px;
    font-weight: 600;
    color: var(--fg-2);
    white-space: nowrap;
}
.cii-editor .cii-progress {
    margin: 0 0 12px;
}
.cii-editor-nav,
.cii-editor-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 16px;
    align-items: center;
}
.cii-done-card {
    margin-top: 16px;
}

.client-import-card .card-header {
    align-items: flex-start;
    padding-bottom: 12px;
}
.client-import-card__hint {
    font-size: 12px;
    margin-top: 6px;
    margin-bottom: 0;
}

.client-import-file-input {
    max-width: min(100%, 32rem);
    padding: 8px 12px;
    cursor: pointer;
}
.client-import-filename-line {
    min-height: 1.25em;
    margin: 6px 0 0;
    font-size: 13px;
}
.client-import-mini-hint {
    font-size: 12px;
    margin: 0 0 12px;
    line-height: 1.45;
}

.client-import-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}
.client-import-actions .btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.client-import-result-panel {
    margin-top: 24px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
    background: var(--bg-1);
    box-shadow: var(--shadow-sm);
}
.client-import-result-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
}
.client-import-result-panel__title {
    font-size: 13px;
    font-weight: 600;
    color: var(--fg-1);
}
.client-import-result-panel__badge {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--fg-3);
    padding: 3px 8px;
    border-radius: 4px;
    background: var(--bg-0);
    border: 1px solid var(--border);
}
.client-import-result {
    margin: 0;
    padding: 14px 16px;
    max-height: 420px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 12px;
    line-height: 1.45;
    font-family: ui-monospace, 'Cascadia Code', 'Consolas', monospace;
    color: var(--fg-1);
    background: var(--bg-3);
    display: block;
}

/* Імпорт клієнтів: спільні стилі банерів / details (сторінка) */
.ciw-banner {
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: var(--r-md);
    font-size: 13px;
    line-height: 1.45;
}
.ciw-banner__title {
    display: block;
    margin-bottom: 4px;
    color: var(--fg-1);
}
.ciw-banner__text {
    color: var(--fg-2);
}
.ciw-banner--danger {
    background: var(--danger-bg);
    border: 1px solid rgba(196, 43, 28, 0.35);
}
.ciw-banner--danger .ciw-banner__title {
    color: var(--danger);
}
.ciw-banner--neutral {
    background: var(--bg-2);
    border: 1px solid var(--border);
}
.ciw-raw-group {
    margin-bottom: 16px;
}
.ciw-export-text {
    font-size: 13px;
    line-height: 1.45;
    resize: vertical;
    min-height: 88px;
    background: var(--surface-muted, #f6f7f9);
}

.ciw-raw-snippet {
    margin: 0;
    padding: 12px 14px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: 12px;
    line-height: 1.4;
    white-space: pre-wrap;
    max-height: 120px;
    overflow: auto;
    font-family: ui-monospace, 'Consolas', monospace;
    color: var(--fg-2);
}
.ciw-details {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 4px 12px 12px;
    background: var(--bg-2);
}
.ciw-details__summary {
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
    padding: 8px 4px;
    list-style: none;
}
.ciw-details__summary::-webkit-details-marker {
    display: none;
}
.ciw-details__inner {
    padding-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* В MVP режимі таблиця клієнтів має займати робочу висоту екрана */
body.clients-ui-mode-mvp #pg-clients .clients-table-wrap {
    /* Залишаємо місце для верхніх панелей, кнопок і пагінації */
    height: clamp(360px, calc(100dvh - 205px), 82dvh) !important;
    max-height: clamp(360px, calc(100dvh - 205px), 82dvh) !important;
    overflow-y: auto;
}

/* Єдине вікно оператора (без постійного бокового меню) */
body.operator-unified .main {
    margin-right: 0;
}
body.operator-unified #sidebar {
    display: flex;
    transform: translateX(100%);
    transition: transform 0.28s ease;
    top: calc(var(--titlebar-h) + 44px);
    height: calc(100vh - var(--titlebar-h) - 44px);
}
body.operator-unified #sidebar.open {
    transform: translateX(0);
    box-shadow: -12px 0 32px rgba(0, 0, 0, 0.12);
}
body.operator-unified .tb-btn--burger {
    display: inline-flex !important;
}
body.operator-unified .app-layout {
    margin-top: calc(var(--titlebar-h) + 44px);
    height: calc(100vh - var(--titlebar-h) - 44px);
}
.operator-workspace-chrome {
    display: none;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px 12px;
    position: fixed;
    z-index: 95;
    left: 0;
    right: 0;
    top: var(--titlebar-h);
    min-height: 44px;
    padding: 6px 12px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
    box-sizing: border-box;
}
body.operator-unified .operator-workspace-chrome:not([hidden]) {
    display: flex;
}
.op-ws-tabs {
    display: inline-flex;
    gap: 4px;
    flex-wrap: wrap;
}
.op-ws-tab {
    border: 1px solid #4b6bff;
    background: #eef2ff;
    border-radius: var(--r-md);
    padding: 7px 14px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    color: #1f3bb3;
    box-shadow: 0 0 0 1px rgba(75, 107, 255, 0.18);
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.op-ws-tab:hover {
    background: #dfe7ff;
    border-color: #3f5fff;
}
.op-ws-tab:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(75, 107, 255, 0.28);
}
.op-ws-tab.is-active,
.op-ws-widget[data-operator-go].is-active {
    background: #4b6bff;
    border-color: #3552d9;
    color: #fff;
    box-shadow: 0 3px 10px rgba(53, 82, 217, 0.35);
}
.op-ws-widget[data-operator-go] {
    border-color: #4b6bff;
    color: #1f3bb3;
    font-weight: 700;
}
.op-ws-widget[data-operator-go]:hover {
    background: #e4ebff;
}
.op-ws-tab--sm {
    padding: 4px 10px;
    font-size: 11px;
}
.op-ws-hint {
    font-size: 11px;
    color: var(--fg-4);
    margin: 0;
}
.op-ws-palette {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.op-ws-palette-label {
    font-size: 11px;
    color: var(--fg-3);
}
.op-ws-widgets {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.op-ws-master-hint,
.op-ws-dual-hint {
    margin: 0;
    font-size: 11px;
    color: var(--fg-3);
    flex: 1 1 200px;
}
.op-ws-more {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}
.op-ws-more-label {
    font-size: 11px;
    white-space: nowrap;
}
.operator-dual {
    display: grid;
    gap: 0;
    min-height: calc(100vh - var(--titlebar-h) - 44px - 48px);
    align-items: stretch;
}
.operator-dual--split {
    grid-template-columns: 1fr 1fr;
}
.operator-dual--sidebar {
    grid-template-columns: 1fr minmax(260px, 320px);
}
.operator-dual__pane {
    min-width: 0;
    overflow: auto;
    border-right: 1px solid var(--border);
    padding: 12px 14px 24px;
}
.operator-dual__pane:last-child {
    border-right: none;
}
.operator-dual__err {
    padding: 24px 12px;
    text-align: center;
}
@media (max-width: 960px) {
    .operator-dual--split {
        grid-template-columns: 1fr;
    }
    .operator-dual--sidebar {
        grid-template-columns: 1fr;
    }
    .operator-dual__pane {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 50vh;
    }
    .operator-dual__pane:last-child {
        border-bottom: none;
    }
}

@media (max-width: 768px) {
    body.operator-unified #sidebar {
        top: calc(var(--titlebar-h) + 44px);
        height: calc(100vh - var(--titlebar-h) - 44px);
    }
}

/* Мобільний titlebar у потоці (sticky) — не резервуємо місце під fixed chrome */
@media (max-width: 600px) {
    body.operator-unified .app-layout {
        margin-top: 0;
        height: auto;
        min-height: 0;
    }
    body.operator-unified .operator-workspace-chrome,
    body.operator-unified .operator-workspace-chrome:not([hidden]) {
        position: static;
        display: none;
    }
    body.operator-unified #sidebar {
        top: 0;
        height: 100vh;
    }
}
