/* ============================================================
   SkladPro.Nod — design system
   Stone-processing ERP for Uzbekistan.
   Palette: Apple-inspired monochrome (light #f5f5f7 default,
   dark #000000). Restrained blue accent, Inter typography.
   ============================================================ */
:root {
    /* ── Palette (Light) ──
       Apple HIG: neutral grays, restrained blue accent,
       functional green/red/orange for statuses.
    ── */
    --primary: #0071e3;
    --primary-hover: #0077ed;
    --primary-soft: rgba(0, 113, 227, 0.10);
    --primary-rgb: 0, 113, 227;

    --accent: #0071e3;
    --accent-soft: rgba(0, 113, 227, 0.10);

    --surface-page: #f5f5f7;
    --surface-card: #ffffff;
    --surface-muted: #f2f2f4;
    --surface-row-hover: #e8e8ed;
    --border: #e5e5ea;
    --border-strong: #d2d2d7;

    --text: #1d1d1f;
    --text-secondary: #56565c;
    --text-muted: #6e6e73;

    --success: #34c759;
    --success-soft: rgba(52, 199, 89, 0.12);
    --danger: #ff3b30;
    --danger-soft: rgba(255, 59, 48, 0.12);
    --warning: #ff9500;
    --warning-soft: rgba(255, 149, 0, 0.14);
    --info: #0071e3;
    --info-soft: rgba(0, 113, 227, 0.10);
    --secondary: #6e6e73;
    --secondary-soft: #f2f2f4;
    --danger-color: #ff3b30;
    --success-color: #34c759;
    --text-inverse: #ffffff;

    /* ── Typography ── */
    --font-display: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', Monaco, 'Cascadia Code', monospace;

    /* ── Metrics ── */
    --radius: 20px;
    --radius-sm: 12px;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.06);
    --bottom-nav-height: 64px;
    --top-bar-height: 60px;
    --app-max-width: 480px;
}

/* ── Dark Theme (Apple: black surfaces, inverted text) ── */
body.theme-dark {
    --primary: #0a84ff;
    --primary-hover: #3a9bff;
    --primary-soft: rgba(10, 132, 255, 0.18);
    --primary-rgb: 10, 132, 255;
    --accent: #0a84ff;
    --accent-soft: rgba(10, 132, 255, 0.18);

    --surface-page: #000000;
    --surface-card: #1c1c1e;
    --surface-muted: #242426;
    --surface-row-hover: #2c2c2e;
    --border: #333336;
    --border-strong: #48484a;

    --text: #f5f5f7;
    --text-secondary: #b0b0b8;
    --text-muted: #98989f;

    --success: #30d158;
    --success-soft: rgba(48, 209, 88, 0.16);
    --danger: #ff453a;
    --danger-soft: rgba(255, 69, 58, 0.16);
    --warning: #ff9f0a;
    --warning-soft: rgba(255, 159, 10, 0.16);
    --info: #0a84ff;
    --info-soft: rgba(10, 132, 255, 0.18);
    --secondary: #98989f;
    --secondary-soft: #2c2c2e;
    --danger-color: #ff453a;
    --success-color: #30d158;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.5);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 8px rgba(0, 0, 0, 0.5);
}

/* ── Glass surfaces (light) ── */
body.theme-dark .bottom-nav,
body.theme-dark .top-bar {
    background-color: rgba(0, 0, 0, 0.72);
    border-color: rgba(255, 255, 255, 0.10);
}
html body.theme-dark .app-sidebar {
    background: rgba(0, 0, 0, 0.72);
    border-right-color: rgba(255, 255, 255, 0.10);
}

html body.theme-dark .sidebar-link.active {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
}

body.theme-dark .form-control {
    background-color: rgba(118, 118, 128, 0.24);
}
body.theme-dark .form-control:focus {
    background-color: var(--surface-card);
}
body.theme-dark .search-box .form-control:focus {
    background-color: var(--surface-card);
}

body.theme-dark .notif-badge {
    border-color: var(--surface-card);
}

body.theme-dark select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236e6e73' d='M6 8 0 2 1.4.6 6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E");
}

body.theme-dark .modal-header {
    background: var(--surface-card);
}

body.theme-dark .donut-center-num {
    fill: var(--text);
}
body.theme-dark .donut-center-lbl {
    fill: var(--text-muted);
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
    font-family: var(--font-body);
    background: var(--surface-page);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    min-height: 100vh;
}

.skip-link {
    position: absolute;
    left: 0;
    top: 0;
    transform: translateY(-100%);
    background: var(--surface-card);
    color: var(--primary);
    padding: 10px 14px;
    z-index: 2000;
    border-bottom-right-radius: 12px;
    border-top-right-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    text-decoration: none;
    font-weight: 600;
}
.skip-link:focus-visible {
    transform: translateY(0);
    outline: 3px solid var(--primary);
}

/* Scrollbars — thin, warm */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
::-webkit-scrollbar-track { background: transparent; }

/* Selection colour */
::selection { background: var(--primary-soft); color: var(--primary); }

/* ---------- App shell ---------- */
.app-container {
    background-color: transparent;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
    display: flex;
    flex-direction: column;
}
.app-body { display: flex; flex-direction: column; flex: 1; min-width: 0; }

.app-sidebar { display: none; }
.top-bar { display: none; }
.bottom-nav { display: none; }
body.authenticated .top-bar { display: flex; }
body.authenticated .bottom-nav { display: flex; }
body.authenticated .app-sidebar { display: none; }

/* ---------- Top bar ---------- */
.top-bar {
    height: var(--top-bar-height);
    background-color: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 20;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.top-bar-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.top-bar h1 {
    font-family: var(--font-display);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variation-settings: normal;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.page-badge {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.16em;
    color: var(--text-muted);
    font-weight: 700;
}
.top-bar .actions { display: flex; gap: 12px; align-items: center; flex-shrink: 0; }

/* ---------- Page hero ---------- */
.page-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
    padding: 24px;
    border-radius: var(--radius);
    background: var(--surface-card);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.page-hero h2 {
    font-size: clamp(24px, 2.4vw, 30px);
    line-height: 1.1;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0;
}
.page-hero .eyebrow {
    color: var(--primary);
    font-size: 12px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    margin-bottom: 6px;
}
.card-minimal {
    border: 1px solid transparent;
    background: var(--surface-card);
    box-shadow: var(--shadow-sm);
}
.list-group-compact .list-row {
    padding: 10px 12px;
    gap: 10px;
}
.list-group-compact .list-row + .list-row {
    border-top: 1px solid var(--border);
}

/* ---------- Main content ---------- */
/* Прокручивается ДОКУМЕНТ, а не этот блок.
   Раньше здесь стояли overflow-y: auto + -webkit-overflow-scrolling: touch —
   это создаёт отдельный слой прокрутки внутри страницы. На телефоне он
   перехватывает касание, хотя прокручивать ему нечего (высота блока равна
   высоте содержимого), и палец «не двигает» экран: приходится тянуть вторым
   пальцем или попадать точно по прокручиваемой области. Документ и так
   прокручивается — вложенный скроллер лишний. */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 18px clamp(14px, 4vw, 18px);
    /* env() работает только при viewport-fit=cover (см. base.html) —
       иначе отступ под нижней навигацией не учитывает вырез экрана. */
    padding-bottom: calc(var(--bottom-nav-height) + 18px + env(safe-area-inset-bottom, 0px));
}
#app-content { flex: 1; }

.card-grid {
    display: grid;
    gap: 16px;
}

/* ---------- Bottom navigation ---------- */
.bottom-nav {
    height: var(--bottom-nav-height);
    background-color: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    z-index: 30;
    padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    gap: 3px;
    transition: color 0.2s;
    flex: 1;
    min-width: 0;
    padding: 6px 2px;
}
.nav-item span:not(.nav-icon) {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nav-item.active { color: var(--primary); }
.nav-item:active { transform: scale(0.94); }
.nav-item:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.18);
    border-radius: 14px;
}
.nav-icon { font-size: 22px; line-height: 1; }

.sidebar-link:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.12);
    background: var(--surface-row-hover);
}

/* ---------- Cards ---------- */
.card {
    background: var(--surface-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 18px;
    margin-bottom: 16px;
}
a.card, .card[data-id], .card[style*="cursor:pointer"] { transition: box-shadow 0.3s ease, transform 0.3s ease; }
.card.card-interactive { cursor: pointer; }
.card.card-interactive:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.18); }
.card[data-id]:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.card[data-id]:active { transform: scale(0.995); }
.card-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

/* Hero card — premium monochrome surface with subtle top highlight */
.hero-card {
    background: linear-gradient(135deg, #1d1d1f 0%, #3a3a3c 100%);
    color: #fff;
    border: none;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    position: relative;
    overflow: hidden;
}
.hero-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.04));
}
.hero-card .metric-title { color: rgba(255, 255, 255, 0.72); font-weight: 500; }
.hero-card .metric-value {
    color: #fff;
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: -0.02em;
}
body.theme-dark .hero-card {
    background: linear-gradient(135deg, #3a3a3c 0%, #2c2c2e 100%);
}

/* ---------- Badges ---------- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}
.badge-new { background: var(--primary-soft); color: var(--primary); }
.badge-progress { background: var(--warning-soft); color: #8a4d00; }
.badge-ready { background: var(--success-soft); color: var(--success); }
.badge-cancel { background: var(--danger-soft); color: var(--danger); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 22px;
    height: 40px;
    border: 1px solid transparent;
    border-radius: 980px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    line-height: 1;
    transition: background 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s, transform 0.15s ease, opacity 0.25s;
    text-decoration: none;
    width: 100%;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.45); }
.btn:active { transform: scale(0.97); }
.btn-primary { background-color: var(--primary); color: #fff; }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-primary:active { background-color: var(--primary-hover); }
.btn-secondary { background: var(--surface-muted); color: var(--text); border-color: transparent; }
.btn-secondary:hover { background: var(--surface-row-hover); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(0.95); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(0.92); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn-sm { height: 34px; padding: 0 16px; font-size: 13px; width: auto; border-radius: 980px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}
.form-control {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid transparent;
    border-radius: 10px;
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background-color: rgba(118, 118, 128, 0.12);
    transition: background-color 0.18s, border-color 0.18s, box-shadow 0.18s;
    -webkit-appearance: none;
    appearance: none;
}
select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2386868b' d='M6 8 0 2 1.4.6 6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
}
.form-control::placeholder { color: var(--text-muted); }
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--surface-card);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.18);
}
textarea.form-control { resize: vertical; min-height: 60px; }

/* ---------- Metric grid ---------- */
.metrics-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}
.metric-card {
    background: var(--surface-card);
    border-radius: var(--radius);
    padding: 15px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    overflow: hidden;
}
/* Signature: soft status rule on metric cards */
.metric-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
    opacity: .45;
}
.metric-card.blue::before { background: var(--primary); }
.metric-card.yellow::before { background: var(--warning); }
.metric-card.green::before { background: var(--success); }
.metric-card.purple::before { background: var(--text-muted); }
.metric-card.red::before { background: var(--danger); }

.metric-title { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.metric-value {
    font-size: 22px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--text);
    letter-spacing: -0.01em;
}
/* Primary metric — copper accent version */
.metric-card.accent {
    background: linear-gradient(135deg, #1d1d1f 0%, #3a3a3c 100%);
    border: none;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}
.metric-card.accent::before { display: none; }
.metric-card.accent .metric-title { color: rgba(255, 255, 255, 0.8); }
.metric-card.accent .metric-value { color: #fff; }

.dash-2col { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 1024px) { .dash-2col { grid-template-columns: 1fr 1fr; align-items: start; } .dash-2col > * { margin-bottom: 0; } }

/* ---------- Stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr; gap: 12px; margin-bottom: 16px; }
@media (min-width: 560px) { .stat-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .stat-grid { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; } }
.stat-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 14px;
    transition: box-shadow 0.18s, transform 0.12s;
}
.stat-card.clickable { cursor: pointer; }
.stat-card.clickable:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.stat-card.clickable:active { transform: scale(0.985); }
.stat-icon {
    width: 42px; height: 42px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
}
.stat-icon.green { background: var(--success-soft); }
.stat-icon.blue { background: var(--primary-soft); }
.stat-icon.purple { background: var(--secondary-soft); }
.stat-icon.orange { background: var(--accent-soft); }
.stat-icon.red { background: var(--danger-soft); }
.stat-body { flex: 1; min-width: 0; }
.stat-title { font-size: 12.5px; color: var(--text-muted); font-weight: 500; margin-bottom: 3px; }
.stat-value {
    font-size: 21px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stat-delta { font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; gap: 2px; padding: 4px 8px; border-radius: 999px; flex-shrink: 0; white-space: nowrap; }
.stat-delta.up { color: var(--success); background: var(--success-soft); }
.stat-delta.down { color: var(--danger); background: var(--danger-soft); }
.stat-delta.flat { color: var(--text-muted); background: var(--surface-page); }

/* ---------- Donut chart ---------- */
.donut-wrap { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; padding: 6px 4px; }
.donut-svg { flex-shrink: 0; }
.donut-center-num { font-family: var(--font-display); font-size: 26px; font-weight: 700; fill: var(--text); }
.donut-center-lbl { font-size: 10px; fill: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.donut-legend { flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 8px; }
.donut-legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.donut-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.donut-label { flex: 1; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donut-pct { font-weight: 700; color: var(--text); }

/* ---------- Skeleton loader ---------- */
.skeleton-list { display: flex; flex-direction: column; gap: 10px; }
.skeleton-row { height: 64px; border-radius: var(--radius); background: linear-gradient(100deg, #ececf0 30%, #e2e2e6 50%, #ececf0 70%); background-size: 200% 100%; animation: skeleton 1.2s ease-in-out infinite; }
body.theme-dark .skeleton-row { background: linear-gradient(100deg, #2c2c2e 30%, #3a3a3c 50%, #2c2c2e 70%); background-size: 200% 100%; }
@keyframes skeleton { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Typography utilities ---------- */
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-muted { color: var(--text-muted); }
.font-bold { font-weight: 600; }
.text-sm { font-size: 12px; }

/* ---------- Alert blocks ---------- */
.alert-box {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
}
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-box-info { background: var(--info-soft, rgba(30, 111, 255, .12)); color: var(--info, #1e6fff); }
.alert-box-warning { background: var(--warning-soft, rgba(255, 152, 0, .12)); color: var(--warning, #b26a00); }

/* ---------- Chip tabs (segmented control) ---------- */
.tabs {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 6px;
    margin-bottom: 16px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
    flex-shrink: 0;
    padding: 9px 16px;
    font-size: 13px;
    font-weight: 600;
    width: auto;
    border-radius: 999px;
    border: 1px solid transparent;
    background: var(--surface-muted);
    color: var(--text-secondary);
    cursor: pointer;
    font-family: inherit;
    transition: all 0.3s ease;
    white-space: nowrap;
}
.tab-btn:hover { background: var(--surface-row-hover); color: var(--text); }
.tab-btn.active {
    background: var(--text);
    border-color: var(--text);
    color: var(--surface-card);
}

/* ---------- Modal ---------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 1000;
    animation: fade-in 0.15s ease-out;
    padding: 0;
}
.modal-content {
    background: var(--surface-card);
    width: 100%;
    max-width: var(--app-max-width);
    max-height: 90vh;
    max-height: 90dvh;
    overflow-y: auto;
    border-radius: 24px 24px 0 0;
    animation: slide-up 0.24s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: var(--shadow-lg);
}
@media (min-width: 520px) {
    .modal { align-items: center; padding: 20px; }
    .modal-content { border-radius: 22px; }
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px 8px;
    position: sticky;
    top: 0;
    background: var(--surface-card);
}
.modal-header h3 {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: 600;
    font-variation-settings: 'SOFT' 60;
}
.modal-header .close {
    border: none;
    background: var(--surface-page);
    color: var(--text-secondary);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 0.15s;
}
.modal-header .close:hover { background: var(--border-strong); }
.modal-body { padding: 12px 20px 22px; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up { from { transform: translateY(28px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }

/* ---------- List rows / groups ---------- */
.list-group {
    background: var(--surface-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
    margin-bottom: 16px;
}
.list-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    gap: 10px;
    background: var(--surface-card);
    transition: background 0.14s;
    min-width: 0;
}
.list-row:last-child { border-bottom: none; }
.list-row:hover { background: var(--surface-row-hover); }
.list-row:active { background: #e6e0d9; transform: scale(1.002); }
.list-row[role="button"] { cursor: pointer; }
.list-row[role="button"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.18);
    border-radius: 16px;
}
.list-row > div { min-width: 0; }

.chat-tab:focus-visible,
.tab-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.18);
}

.section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 18px 4px 8px;
}

/* ---------- Thumbnail ---------- */
.thumb {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, #f0f0f3, #e5e5ea);
    border-radius: 12px;
    flex-shrink: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Search box ---------- */
.search-box {
    position: relative;
    margin-bottom: 16px;
    display: flex;
    gap: 10px;
    align-items: stretch;
}
.search-box .form-control {
    padding-left: 42px;
    border-radius: 999px;
    background: var(--surface-muted);
    border-color: transparent;
    flex: 1;
}
.search-box .form-control:focus {
    background: var(--surface-card);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.14);
}
.search-box .search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-box .btn {
    min-width: 108px;
    width: auto;
    padding-left: 14px;
    padding-right: 14px;
}

/* ---------- Notification bell ---------- */
.icon-btn {
    position: relative;
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 19px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    border-radius: 50%;
    color: var(--text-secondary);
    transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-row-hover); color: var(--text); }
.notif-badge {
    position: absolute;
    top: -1px;
    right: -2px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--surface-card);
}

/* ---------- Data table ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
.data-table th {
    padding: 10px 8px;
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 12px;
    white-space: nowrap;
}
.data-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }

/* ---------- Kanban board ---------- */
.kanban-board {
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding: 4px 0 16px;
    min-height: 60vh;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x mandatory;
}
.kanban-column {
    min-width: 280px;
    max-width: 320px;
    flex-shrink: 0;
    background: var(--surface-muted);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 140px);
    scroll-snap-align: start;
}
.kanban-header {
    padding: 12px 14px 10px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.kanban-count {
    font-size: 11px;
    background: var(--border);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 999px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: normal;
}
.kanban-body {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 60px;
}
.kanban-body.drag-over {
    background: var(--primary-soft);
    border-radius: var(--radius-sm);
}

/* Kanban card */
.kanban-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    cursor: grab;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
    position: relative;
}
.kanban-card:active { cursor: grabbing; }
.kanban-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}
.kanban-card.dragging {
    opacity: 0.4;
    transform: scale(0.97);
    box-shadow: var(--shadow);
}
.kanban-card.danger {
    border-left: 4px solid var(--danger);
}
.kanban-card.overdue {
    border-left: 4px solid var(--warning);
}
.kanban-card-id {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.kanban-card-client {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kanban-card-product {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kanban-card-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: var(--text-muted);
    gap: 6px;
    flex-wrap: wrap;
}
.kanban-card-warning {
    font-size: 11px;
    color: var(--danger);
    font-weight: 500;
    margin-top: 4px;
}

/* Анимация появления карточки */
@keyframes card-enter {
    from { opacity: 0; transform: translateY(-8px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.kanban-card { animation: card-enter 0.2s ease-out; }

/* Анимация drop */
@keyframes card-drop {
    0% { transform: scale(1.05); }
    50% { transform: scale(0.96); }
    100% { transform: scale(1); }
}
.kanban-card.dropped {
    animation: card-drop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- Toggle switch ---------- */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    cursor: pointer;
}
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border-strong);
    border-radius: 24px;
    transition: background 0.2s;
    cursor: pointer;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    left: 3px;
    top: 3px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ---------- List states ---------- */
.list-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 120px;
    padding: 28px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    background: var(--surface-card);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
}.list-state-empty { flex-direction: column; }
.list-state-empty::before { content: '📭'; font-size: 30px; opacity: 0.7; }
.list-state-error { flex-direction: column; color: var(--danger); border-color: var(--danger-soft); }
.spinner {
    width: 22px;
    height: 22px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Route / error pages ---------- */
.route-error { max-width: 420px; margin: 12vh auto; text-align: center; }
.route-error h1 {
    font-family: var(--font-display);
    font-size: 24px;
    font-weight: 700;
    font-variation-settings: 'SOFT' 50;
    margin: 8px 0 10px;
}
.route-error p { color: var(--text-secondary); margin-bottom: 14px; }
.eyebrow { color: var(--primary); font-weight: 700; letter-spacing: 0.12em; font-size: 13px; }

/* ---------- Footer ---------- */
.app-footer {
    margin-top: 48px;
    padding: 20px 0;
    border-top: 1px solid var(--border);
    text-align: center;
    background: transparent;
}
.footer-top {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.footer-top span { font-weight: 400; color: var(--text-muted); }
.footer-bottom {
    margin-top: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}
.footer-bottom a { color: inherit; text-decoration: none; font-weight: 600; transition: color .2s ease; }
.footer-bottom a:hover { color: var(--accent); }
.footer-bottom span:last-child { font-style: italic; opacity: .75; }
@media (max-width:640px){ .app-footer{ display:none; } }

/* ============================================================
   DESKTOP (≥1024px)
   ============================================================ */
@media (min-width: 1024px) {
    .app-container { flex-direction: row; align-items: stretch; }
    .app-body { min-height: 100vh; min-width: 0; }

    /* Sidebar */
    body.authenticated .app-sidebar {
        display: flex;
        flex-direction: column;
        width: 260px;
        flex-shrink: 0;
        position: sticky;
        top: 0;
        height: 100vh;
        background: rgba(255, 255, 255, 0.72);
        -webkit-backdrop-filter: saturate(180%) blur(20px);
        backdrop-filter: saturate(180%) blur(20px);
        border-right: 1px solid rgba(0, 0, 0, 0.08);
        padding: 14px 12px;
    }
    body.authenticated .bottom-nav { display: none; }

    .sidebar-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        font-family: var(--font-display);
        font-weight: 700;
        font-size: 19px;
        font-variation-settings: 'SOFT' 60;
        letter-spacing: -0.01em;
        padding: 8px 10px 18px;
        color: var(--text);
        text-decoration: none;
    }
    .sidebar-brand-mark { color: var(--accent); flex-shrink: 0; }
    .sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
    .sidebar-link {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 10px 12px;
        border-radius: 10px;
        color: var(--text-secondary);
        text-decoration: none;
        font-size: 14px;
        font-weight: 500;
        white-space: nowrap;
        transition: background 0.15s, color 0.15s;
    }
    .sidebar-link .nav-icon { font-size: 18px; width: 22px; text-align: center; }
    .sidebar-link:hover { background: var(--surface-row-hover); color: var(--text); }
    .sidebar-link.active { background: rgba(0, 0, 0, 0.07); color: var(--text); font-weight: 600; }
    .sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 8px; }
    .sidebar-user { font-size: 13px; font-weight: 600; color: var(--text-secondary); padding: 4px 10px 10px; }
    .sidebar-logout { width: 100%; }

    body.authenticated .top-bar { padding: 0 40px; height: 64px; }
    .top-bar h1 { font-size: 22px; }

    .page-hero { padding: 32px 36px; margin-bottom: 24px; }
    .page-hero h2 { font-size: 32px; }

    .main-content { padding: 32px 48px 48px; }
    #app-content { width: 100%; max-width: 1760px; margin: 0 auto; }

    .metrics-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
    .card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
    .card-grid > .card { margin-bottom: 0; }

    .modal { align-items: center; padding: 24px; }
    .modal-content { max-width: 680px; border-radius: 22px; }
    .modal-body { padding: 16px 28px 28px; }

    .app-footer { text-align: center; padding: 20px 40px 12px; }
}
