@font-face {
    font-family: "RF Dewi";
    src: url("../fonts/RFDewi-Regular.woff2") format("woff2"),
         url("../fonts/RFDewi-Regular.ttf") format("truetype");
    font-display: swap;
}

@font-face {
    font-family: "RF Dewi Expanded";
    src: url("../fonts/RFDewiExpanded-Bold.woff2") format("woff2"),
         url("../fonts/RFDewiExpanded-Bold.ttf") format("truetype");
    font-display: swap;
}

:root {
    color-scheme: light;

    --accent: #704896;
    --accent-hover: #5a3a7a;
    --accent-tint: rgba(112,72,150,.08);
    --text-on-accent: #fff;
    /* Header-only decorative gradient (slated for rework in P-1.2) */
    --primary: #E71D73;
    --primary-gradient: #B93483;

    /* Interactive = brand accent. One accent family owns actions, links and focus.
       Blue is reserved for the informational badge palette only. */
    --interactive: var(--accent);
    --interactive-hover: var(--accent-hover);
    --interactive-tint: var(--accent-tint);
    --focus-ring: rgba(112,72,150,.20);
    --highlight-bg: rgba(112,72,150,.18);
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --danger-border: rgba(220,38,38,.15);
    --danger-tint: rgba(220,38,38,.08);
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --success-bg: #f0fdf4;
    --warning: #d97706;
    --warning-bg: #fffbeb;

    /* Inverted light ladder — mirror of the dark theme.
       Dark:  cards > header > sidebar > bg   (light → dark)
       Light: bg > sidebar > header > cards   (light → dark, roles flipped)
       Pigment is the brand violet (desaturated), not neutral grey: dark
       surfaces are blue-violet (#0A0E17/#141925), light mirrors that hue.
       Fields and floats stay white so they pop out of tinted cards. */
    --bg: #f8f7fc;
    --surface: #e6e1f2;            /* content panels — darkest chrome layer */
    --surface-secondary: #ded8ee;  /* sunken: table heads, toolbars, chips */
    --surface-elevated: #ffffff;   /* floats: modals, popovers, dropdowns */
    --surface-hover: #e2dcf1;
    --field-bg: #ffffff;           /* inputs — white holes in tinted cards */
    --field-canvas-bg: #eeeaf6;    /* search fields on the canvas — must differ from bg (mirrors dark elevated-on-bg) */
    --float-bg: #ffffff;           /* overlays floating above cards */
    --header-bg: #e9e5f4;
    --btn-secondary-bg: #ffffff;
    /* No-grey policy: secondary/tertiary are full-contrast aliases of the
       primary text color. Hierarchy is built with size/weight, not greyness.
       Tertiary is tuned for tinted lavender cards (≥4.5:1), not for white. */
    --text-primary: #171226;
    --text-secondary: var(--text-primary);
    /* Placeholder tier: input hints, empty-value markers, muted meta. */
    --text-tertiary: #615a7c;
    --text-placeholder: #615a7c;
    --text-muted: var(--text-tertiary);
    --border: #d6cfe9;
    --border-strong: #beb5d8;
    /* Inputs read as fields on tinted cards: white fill + crisp border. */
    --input-border: var(--border-strong);

    /* Light mirrors of the dark-theme brand washes (felt, not seen).
       KPI strip = the magenta second accent, matching the header strip. */
    --header-brand: linear-gradient(105deg, rgba(112,72,150,.04) 0%, rgba(124,131,219,.02) 48%, rgba(112,72,150,.03) 100%);
    --kpi-strip: linear-gradient(90deg, var(--primary) 0%, var(--primary-gradient) 100%);

    --sidebar-bg-from: #f1eef9;
    --sidebar-bg-to: #ebe7f5;
    --hover-subtle: rgba(0,0,0,.04);
    --overlay: rgba(0,0,0,.4);
    --overlay-light: rgba(0,0,0,.3);

    --badge-blue-bg: #dbeafe;   --badge-blue-fg: #1d4ed8;
    --badge-indigo-bg: #e0e7ff; --badge-indigo-fg: #4338ca;
    --badge-amber-bg: #fef3c7;  --badge-amber-fg: #92400e;
    --badge-orange-bg: #fed7aa; --badge-orange-fg: #9a3412;
    --badge-green-bg: #d1fae5;  --badge-green-fg: #065f46;
    --badge-violet-bg: #ede9fe; --badge-violet-fg: #5b21b6;
    --badge-pink-bg: #fce7f3;   --badge-pink-fg: #9d174d;
    --badge-gray-bg: #edeaf5;   --badge-gray-fg: #171226;
    --badge-red-bg: #fef2f2;    --badge-red-fg: #dc2626;
    --badge-teal-bg: #ccfbf1;   --badge-teal-fg: #0f766e;

    --radius-xs: 3px;
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-pill: 999px;

    --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow-md: 0 2px 6px rgba(0,0,0,.06);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.08);
    --shadow-xl: 0 8px 24px rgba(0,0,0,.1);

    --font-sans: "RF Dewi", -apple-system, BlinkMacSystemFont, sans-serif;
    --font-heading: "RF Dewi Expanded", -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: "SF Mono", "Fira Code", monospace;

    /* Type scale — fixed px, floor 12px. Nothing in the UI may go below --text-xs.
       Display sizes (≥28px: dashboard hero numbers, 404) stay literal by design. */
    --text-xs: 12px;    /* captions, table headers, badges */
    --text-sm: 13px;    /* secondary text, meta, dates */
    --text-base: 14px;  /* controls, table body, buttons */
    --text-md: 15px;    /* body text */
    --text-lg: 16px;    /* emphasized body, sub-titles */
    --text-xl: 20px;    /* card / section titles */
    --text-2xl: 24px;   /* KPI values, page-level numbers */
    --text-3xl: 28px;   /* display */

    --sidebar-width: 250px;
    --header-height: 80px;
}

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

    --accent: #A888E8;
    --accent-hover: #BCA2F0;
    --accent-tint: rgba(168,136,232,.13);
    --text-on-accent: #171226;

    --interactive: var(--accent);
    --interactive-hover: var(--accent-hover);
    --interactive-tint: var(--accent-tint);
    --focus-ring: rgba(168,136,232,.30);
    --highlight-bg: rgba(168,136,232,.24);
    --danger: #EF4444;
    --danger-bg: #2a1417;
    --danger-border: rgba(239,68,68,.30);
    --danger-tint: rgba(239,68,68,.14);
    --danger-hover: #F87171;
    --success: #22C55E;
    --success-bg: #0e2418;
    --warning: #F59E0B;
    --warning-bg: #2a2008;

    --bg: #0A0E17;
    --surface: #141925;
    --surface-secondary: #10141F;
    --surface-elevated: #1B2230;
    --surface-hover: #1B2230;
    --text-primary: #F1F4F9;
    --text-secondary: var(--text-primary);
    --text-tertiary: #9AA3B2;
    --text-placeholder: #9AA3B2;
    --text-muted: var(--text-tertiary);
    --border: rgba(255,255,255,.07);
    --border-strong: rgba(255,255,255,.12);
    /* Dark inputs keep the hairline border (no fill step) — mirrors the
       pre-token rendering exactly. */
    --input-border: var(--border);
    /* Mappings for the light ladder tokens: dark rendering is unchanged. */
    --field-bg: var(--surface);
    --field-canvas-bg: var(--surface);
    --float-bg: var(--surface);
    --header-bg: var(--surface);
    --btn-secondary-bg: var(--surface);

    --header-brand: linear-gradient(105deg, rgba(168,136,232,.09) 0%, rgba(124,131,219,.05) 48%, rgba(168,136,232,.07) 100%);
    --kpi-strip: linear-gradient(90deg, #A888E8 0%, #7C83DB 100%);

    --sidebar-bg-from: #0E1320;
    --sidebar-bg-to: #0A0E17;
    --hover-subtle: rgba(255,255,255,.04);
    --overlay: rgba(5,8,15,.68);
    --overlay-light: rgba(5,8,15,.55);

    --badge-blue-bg: #16294a;   --badge-blue-fg: #93c5fd;
    --badge-indigo-bg: #24264f; --badge-indigo-fg: #c7d2fe;
    --badge-amber-bg: #3a2c0a;  --badge-amber-fg: #fcd34d;
    --badge-orange-bg: #3d220d; --badge-orange-fg: #fdba74;
    --badge-green-bg: #0e3326;  --badge-green-fg: #6ee7b7;
    --badge-violet-bg: #271a45; --badge-violet-fg: #c4b5fd;
    --badge-pink-bg: #3d1229;   --badge-pink-fg: #f9a8d4;
    --badge-gray-bg: #1c2333;   --badge-gray-fg: #F1F4F9;
    --badge-red-bg: #2a1417;    --badge-red-fg: #f87171;
    --badge-teal-bg: #134e4a;   --badge-teal-fg: #5eead4;

    --shadow-xs: 0 1px 2px rgba(0,0,0,.30);
    --shadow-sm: 0 1px 2px rgba(0,0,0,.35), 0 2px 4px rgba(0,0,0,.25);
    --shadow-md: 0 4px 12px rgba(0,0,0,.38);
    --shadow-lg: 0 10px 28px rgba(0,0,0,.45);
    --shadow-xl: 0 18px 50px rgba(0,0,0,.55);
}

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

body {
    background: var(--bg);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--text-md);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

a { color: var(--interactive); text-decoration: none; }
a:hover { color: var(--interactive-hover); }

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: linear-gradient(180deg, var(--sidebar-bg-from) 0%, var(--sidebar-bg-to) 100%);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    padding: 16px 12px;
    overflow: hidden;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    overflow-y: auto;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: var(--text-md);
    color: var(--text-primary); /* full-contrast labels: black in light, white in dark */
    text-decoration: none;
    transition: background .12s, color .12s;
    font-weight: 500;
}

.sidebar-link:hover {
    background: var(--hover-subtle);
    color: var(--text-primary);
}

.sidebar-link.active {
    background: var(--accent-tint);
    color: var(--accent);
    font-weight: 600;
    /* The one place the brand accent earns its keep (same language as dark) */
    box-shadow: inset 2px 0 0 var(--accent);
}

button.sidebar-link {
    background: none;
    border: none;
    width: 100%;
    cursor: pointer;
    font: inherit;
    text-align: left;
}

.sidebar-link svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.sidebar-bottom {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}

.main {
    margin-left: var(--sidebar-width);
    padding-top: var(--header-height);
    flex: 1;
    min-width: 0; /* flex item must not be sized by wide content (tables/matrices) */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.page-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1100;
    background: var(--header-brand), var(--header-bg);
    border-bottom: 1px solid var(--border);
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 28px;
    gap: 16px;
    flex-shrink: 0;
}

/* Thin brand strip under the header — the accent lives here, not in a full-fill gradient */
.page-header::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -3px;
    height: 3px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--primary-gradient) 45%, var(--accent) 100%);
    pointer-events: none;
}

/* Logo swap: the white-letter variant is unreadable on light surfaces */
.header-logo {
    height: 35px;
    width: auto;
    flex-shrink: 0;
    content: url("../assets/metrica_logo_dark.svg");
}
[data-theme="dark"] .header-logo { content: url("../assets/metrica_logo.svg"); }

/* Login pages sit on the plain page background — same theme-dependent swap.
   (Kept here so both portal and archive login markup get it from one place.) */
.login-logo { content: url("../assets/metrica_logo_dark.svg"); }
[data-theme="dark"] .login-logo { content: url("../assets/metrica_logo.svg"); }

.header-text h1 {
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    color: var(--text-primary);
    line-height: 1.2;
}

.header-text span {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    display: block;
    margin-top: 1px;
}

.page-content {
    flex: 1;
    padding: 24px;
    max-width: 1440px;
    margin: 0 auto;
    overflow-x: hidden;
    width: 100%;
}

.burger-btn {
    display: none;
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    margin-right: 8px;
    border-radius: var(--radius-sm);
}

.burger-btn:hover { background: var(--hover-subtle); color: var(--text-primary); }

.burger-btn svg {
    width: 22px;
    height: 22px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--overlay-light);
    z-index: 999;
}

.sidebar-overlay.active { display: block; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: var(--radius-md);
    min-height: 36px;
    padding: 7px 16px;
    cursor: pointer;
    text-decoration: none;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: 500;
    transition: background .15s, box-shadow .15s, transform .1s;
    line-height: 1.4;
}

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

.btn-primary {
    background: var(--interactive);
    color: var(--text-on-accent);
}
.btn-primary:hover { background: var(--interactive-hover); color: var(--text-on-accent); }

.btn-secondary {
    background: var(--btn-secondary-bg);
    color: var(--text-primary);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-secondary); border-color: var(--border-strong); }

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid var(--danger-border);
}
.btn-danger:hover { background: var(--danger-tint); }

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--surface-secondary); color: var(--text-primary); }

/* Ghost button that keeps destructive semantics without the filled danger chip */
.btn-text-danger { color: var(--danger); }
.btn-text-danger:hover { background: var(--danger-tint); color: var(--danger); }

.btn-sm {
    min-height: 30px;
    padding: 4px 12px;
    font-size: var(--text-xs);
}

.btn-lg {
    min-height: 44px;
    padding: 10px 20px;
    font-size: var(--text-md);
    font-weight: 600;
}

.btn-accent {
    background: var(--accent);
    color: var(--text-on-accent);
}
.btn-accent:hover { background: var(--accent-hover); color: var(--text-on-accent); }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
}

/* Horizontal scroll wrapper for wide tables (portal pages render
   .table-scroll too, but only the archive CSS defined it — F-01) */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Base chips (filter tabs): active state is a tint, not a solid fill (§1.6) */
.chip { flex: 0 0 auto; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--input-border); background: var(--surface-secondary); color: var(--text-primary); font-size: var(--text-sm); cursor: pointer; white-space: nowrap; }
.chip-active { background: var(--interactive-tint); color: var(--interactive); border-color: var(--interactive); }

.badge-danger { background: var(--badge-red-bg); color: var(--badge-red-fg); }
.badge-new { background: var(--badge-blue-bg); color: var(--badge-blue-fg); }
.badge-accepted { background: var(--badge-indigo-bg); color: var(--badge-indigo-fg); }
.badge-in_design { background: var(--badge-amber-bg); color: var(--badge-amber-fg); }
.badge-in_calculation { background: var(--badge-teal-bg); color: var(--badge-teal-fg); }
.badge-sent_approval { background: var(--badge-orange-bg); color: var(--badge-orange-fg); }
.badge-approved { background: var(--badge-green-bg); color: var(--badge-green-fg); }
.badge-in_print { background: var(--badge-violet-bg); color: var(--badge-violet-fg); }
.badge-in_postprint { background: var(--badge-pink-bg); color: var(--badge-pink-fg); }
.badge-ready { background: var(--badge-green-bg); color: var(--badge-green-fg); }
.badge-ready_to_print { background: var(--badge-violet-bg); color: var(--badge-violet-fg); }
.badge-issued { background: var(--badge-gray-bg); color: var(--badge-gray-fg); }
.badge-cancelled { background: var(--badge-gray-bg); color: var(--badge-gray-fg); }
.badge-completed { background: var(--badge-teal-bg); color: var(--badge-teal-fg); }

/* ── Материальное обеспечение заказа (provisioning) ── */
.badge-materials-full { background: var(--badge-green-bg); color: var(--badge-green-fg); }
.badge-materials-partial { background: var(--badge-orange-bg); color: var(--badge-orange-fg); }
.badge-materials-none { background: var(--badge-pink-bg); color: var(--badge-pink-fg); font-weight: 700; }
.badge-materials-unmapped,
.badge-materials-cancelled { background: var(--badge-gray-bg); color: var(--badge-gray-fg); }

.mat-line-shortage td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.mat-line-shortage .num:last-child,
.mat-line-shortage td:nth-child(6) { color: var(--danger); font-weight: 600; }
.prov-unit, .wh-unit { color: var(--text-tertiary); }
.prov-meta, .wh-inv-meta--card { color: var(--text-secondary); font-size: var(--text-xs); margin-top: 2px; }

.badge-role-admin { background: var(--badge-amber-bg); color: var(--badge-amber-fg); }
.badge-role-manager { background: var(--badge-blue-bg); color: var(--badge-blue-fg); }
.badge-role-designer { background: var(--badge-violet-bg); color: var(--badge-violet-fg); }
.badge-role-printer { background: var(--badge-green-bg); color: var(--badge-green-fg); }
.badge-role-postprint { background: var(--badge-pink-bg); color: var(--badge-pink-fg); }

#toast-container {
    position: fixed;
    top: 80px;
    right: 16px;
    z-index: 1000000; /* above preview overlays (999999) so errors are never hidden */
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
    max-width: 360px;
}

.toast {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    line-height: 1.4;
    color: #fff;
    opacity: 0;
    transform: translateX(30px);
    transition: opacity .2s, transform .2s;
    pointer-events: auto;
    box-shadow: var(--shadow-lg);
    word-break: break-word;
}

.toast-visible { opacity: 1; transform: translateX(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--accent); }
.toast-warning { background: var(--warning, #d97706); }

.toast-progress { background: var(--accent); }

.toast-progress-bar {
    margin-top: 8px;
    height: 3px;
    background: rgba(255,255,255,.3);
    border-radius: var(--radius-xs);
    overflow: hidden;
}

.toast-progress-fill {
    height: 100%;
    background: #fff;
    transition: width .3s;
    width: 0;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xs);
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-base);
}

table.data-table th {
    background: var(--surface-secondary);
    font-weight: 600;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

table.data-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    vertical-align: middle;
    font-variant-numeric: tabular-nums;
}

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--surface-secondary); }

.input,
input[type="text"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="email"],
select,
textarea {
    font-family: var(--font-sans);
    font-size: var(--text-md);
    padding: 7px 12px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius-md);
    background: var(--field-bg);
    color: var(--text-primary);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    line-height: 1.4;
}

.input:focus,
input[type="text"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
select:focus,
textarea:focus {
    border-color: var(--interactive);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-placeholder);
}

select { cursor: pointer; }

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: var(--overlay);
    backdrop-filter: blur(2px);
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn .12s;
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--float-bg);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 660px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 24px;
    box-shadow: var(--shadow-xl);
    animation: modalIn .12s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(.97) translateY(4px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
    font-size: var(--text-md);
}

/* ── Base form / modal-footer / pagination primitives ──
   Shared foundation for every page. Modules may extend or override
   these after common.css (e.g. dashboard.css, order.css). */
.form-group {
    margin-bottom: 14px;
}
.form-label {
    display: block;
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .3px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.form-group .input {
    width: 100%;
}
.form-group textarea.input {
    resize: vertical;
    min-height: 80px;
}
.modal-title {
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
}
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}
.modal-actions .push-left { margin-right: auto; }
.pagination { display: flex; align-items: center; gap: 12px; padding: 12px 2px; }
.pagination-info { font-size: var(--text-sm); color: var(--text-secondary); }

@media (max-width: 1024px) {
    :root { --sidebar-width: 0px; --header-height: 68px; }
    .sidebar {
        left: auto;
        right: 0;
        transform: translateX(100%);
        transition: transform .2s ease;
        width: 260px;
        border-right: none;
        border-left: 1px solid var(--border);
    }
    .sidebar.open { transform: translateX(0); }
    .main { margin-left: 0; }
    .burger-btn { display: flex; margin-left: auto; order: 99; }
    .sidebar-overlay.active { display: block; backdrop-filter: blur(3px); }
    .card {
        padding: 18px 20px;
    }
    table.data-table th,
    table.data-table td {
        padding: 6px 10px;
    }
}

@media (max-width: 768px) {
    :root { --header-height: 60px; }
    .page-header { padding: 0 16px; gap: 12px; }
    .header-logo { height: 28px; }
    .header-text h1 { font-size: var(--text-xl); }
    .header-text span { font-size: var(--text-xs); }
    .page-content { padding: 16px; }
    .btn { min-height: 36px; padding: 8px 14px; }
    .btn-sm { min-height: 32px; padding: 6px 12px; }
    .card {
        padding: 16px;
    }
    table.data-table th,
    table.data-table td {
        padding: 6px 8px;
        font-size: var(--text-sm);
    }
    .modal { max-width: 100%; margin: 8px; padding: 16px; max-height: 90vh; }
    #toast-container { top: auto; bottom: 16px; right: 12px; left: 12px; max-width: none; }
    .toast { transform: translateY(20px); }
    .toast-visible { transform: translateY(0); }
}

@media (max-width: 480px) {
    .page-header { padding: 0 12px; gap: 10px; }
    .header-logo { height: 24px; }
    .header-text h1 { font-size: var(--text-lg); }
    .header-text span { display: none; }
    .page-content { padding: 12px; }
    .card {
        padding: 14px;
        border-radius: var(--radius-md);
    }
    table.data-table th,
    table.data-table td {
        padding: 5px 6px;
        font-size: var(--text-sm);
    }
}

/* ═══════════════════════════════════════════════
   MOBILE UX · touch targets, iOS zoom, focus, scroll lock
   ═══════════════════════════════════════════════ */

@media (max-width: 768px) {
    /* 16px prevents iOS Safari from auto-zooming on focus */
    input, select, textarea, .input { font-size: 16px; }
    /* Comfortable touch targets (Apple HIG ≈44px) */
    .btn { min-height: 44px; padding: 10px 16px; }
    .btn-sm { min-height: 40px; padding: 8px 14px; }
    .burger-btn, .ntf-bell { min-width: 44px; min-height: 44px; align-items: center; justify-content: center; }
}

@media (hover: none) {
    .sidebar-link { min-height: 44px; }
}

/* Keyboard focus must be visible (mouse clicks stay clean) */
:focus-visible {
    outline: 2px solid var(--interactive);
    outline-offset: 2px;
}

/* Background scroll lock while an overlay is open (toggled by sidebar.js) */
body.overlay-locked { overflow: hidden; }

/* ═══════════════════════════════════════════════
   DARK THEME · B2B refinements (scoped)
   Neutral layered surfaces; accent is rare & deliberate.
   ═══════════════════════════════════════════════ */

/* Sidebar — quiet panel, part of the surface */
[data-theme="dark"] .sidebar {
    background: rgba(14,19,32,.78);
    -webkit-backdrop-filter: blur(16px) saturate(115%);
    backdrop-filter: blur(16px) saturate(115%);
    border-right: 1px solid rgba(255,255,255,.07);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    [data-theme="dark"] .sidebar { background: #0E1320; }
}
/* Active nav — the one place the brand accent earns its keep */
[data-theme="dark"] .sidebar-link.active {
    background: var(--accent-tint);
    color: var(--text-primary);
    box-shadow: inset 2px 0 0 var(--accent);
}
[data-theme="dark"] .sidebar-link.active svg { stroke: var(--accent); }

/* Header — neutral base + barely-there brand wash (felt, not seen) */
[data-theme="dark"] .page-header {
    background: var(--header-brand), var(--surface);
    border-bottom: 1px solid rgba(255,255,255,.07);
    box-shadow: none;
}
[data-theme="dark"] .header-text h1 {
    font-weight: 600;
    color: var(--text-primary);
}
[data-theme="dark"] .header-text span { color: var(--text-secondary); }
[data-theme="dark"] .header-logo { opacity: .92; }
[data-theme="dark"] .burger-btn:hover { background: rgba(255,255,255,.08); }

/* Cards — clear layering and quiet depth */
[data-theme="dark"] .card {
    box-shadow: 0 1px 2px rgba(0,0,0,.35), inset 0 1px 0 rgba(255,255,255,.05);
}

/* Buttons — solid, neutral, no glow */
[data-theme="dark"] .btn-primary {
    box-shadow: 0 1px 2px rgba(0,0,0,.35);
}
[data-theme="dark"] .btn-primary:hover {
    box-shadow: 0 1px 2px rgba(0,0,0,.4), 0 0 0 1px rgba(168,136,232,.28);
}

/* Dark accent is light: text on filled accent surfaces must be dark */
[data-theme="dark"] .toast-info,
[data-theme="dark"] .toast-progress { color: var(--text-on-accent); }
[data-theme="dark"] .sidebar-user-avatar { color: var(--text-on-accent); }

/* Inputs — restrained focus ring (no neon) */
[data-theme="dark"] .input:focus,
[data-theme="dark"] input[type="text"]:focus,
[data-theme="dark"] input[type="password"]:focus,
[data-theme="dark"] input[type="date"]:focus,
[data-theme="dark"] input[type="number"]:focus,
[data-theme="dark"] input[type="email"]:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
    border-color: rgba(168,136,232,.6);
    box-shadow: 0 0 0 3px rgba(168,136,232,.20);
}

[data-theme="dark"] select option,
[data-theme="dark"] select optgroup {
    background-color: var(--surface);
    color: var(--text-primary);
}

/* Tables — neutral, readable, calm dividers */
[data-theme="dark"] table.data-table th {
    background: var(--surface-secondary);
    border-bottom: 1px solid rgba(255,255,255,.08);
    color: var(--text-secondary);
}
[data-theme="dark"] table.data-table td {
    border-bottom: 1px solid rgba(255,255,255,.06);
}
[data-theme="dark"] table.data-table tr:hover td {
    background: rgba(255,255,255,.035);
}

/* Modals & elevated surfaces */
[data-theme="dark"] .modal {
    background: var(--surface-elevated);
    border: 1px solid rgba(255,255,255,.08);
}
[data-theme="dark"] .modal-overlay {
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

/* Toast — subtle separation on dark */
[data-theme="dark"] .toast {
    box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255,255,255,.06);
}

/* ═══════════════════════════
   Custom checkboxes
   ═══════════════════════════ */
.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    font-size: var(--text-sm);
    cursor: pointer;
}
.check-row input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--field-bg);
    cursor: pointer;
    position: relative;
    flex-shrink: 0;
    transition: all .12s;
}
.check-row input[type="checkbox"]:hover {
    border-color: var(--interactive);
}
.check-row input[type="checkbox"]:checked {
    background: var(--interactive);
    border-color: var(--interactive);
}
.check-row input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 1px;
    width: 6px;
    height: 10px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.check-row label {
    cursor: pointer;
    color: var(--text-primary);
    font-size: var(--text-sm);
    user-select: none;
}

/* ═══════════════════════════
   Admin create block
   ═══════════════════════════ */
.admin-create { padding: 4px 0; }
.admin-create-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 14px;
}
.admin-create-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
    min-width: 140px;
}
.admin-create-field label {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
}
.admin-create-field input,
.admin-create-field select {
    padding: 8px 12px;
    border: 1px solid var(--input-border);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: var(--text-base);
    background: var(--field-bg);
    color: var(--text-primary);
    outline: none;
    height: 40px;
    transition: border-color .15s;
}
.admin-create-field input:focus,
.admin-create-field select:focus {
    border-color: var(--interactive);
    box-shadow: 0 0 0 2px var(--focus-ring);
}
.admin-perm-section { margin-top: 4px; }
.admin-perm-section > label {
    display: block;
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}
.admin-perm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 2px 16px;
    background: var(--surface-secondary);
    padding: 12px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

/* ═══════════════════════════
   Accordion global
   ═══════════════════════════ */
.accordion-toggle {
    cursor: pointer;
    user-select: none;
    transition: color .12s;
}
.accordion-toggle:hover { color: var(--interactive); }
.accordion-arrow {
    display: inline-block;
    font-size: var(--text-xs);
    width: 18px;
    color: var(--text-tertiary);
    transition: color .12s;
}
.accordion-toggle:hover .accordion-arrow { color: var(--interactive); }

/* ═══════════════════════════
   Notification bell + panel (rendered by /js/sidebar.js on every authenticated page)
   ═══════════════════════════ */
.ntf-bell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-md);
    transition: background .15s, color .15s;
    flex-shrink: 0;
    margin-left: auto;
}
.ntf-bell:hover { background: var(--hover-subtle); color: var(--text-primary); }
.ntf-bell svg {
    width: 20px; height: 20px;
    stroke: currentColor; fill: none;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.ntf-count {
    position: absolute;
    top: -4px; right: -4px;
    min-width: 16px; height: 16px;
    padding: 0 4px;
    border-radius: var(--radius-pill);
    background: var(--danger-bg);
    color: var(--danger);
    font-size: var(--text-xs);
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

.ntf-panel {
    position: fixed;
    top: calc(var(--header-height) + 6px);
    right: 12px;
    width: min(380px, calc(100vw - 24px));
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    background: var(--surface-elevated, var(--surface));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 1200;
    overflow: hidden;
}
/* display:flex above would override the UA's [hidden] { display:none } —
   without this rule the panel could never be closed. */
.ntf-panel[hidden] { display: none; }
.ntf-head {
    padding: 12px 14px;
    font-weight: 700;
    font-size: var(--text-sm);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.ntf-read-all {
    border: none;
    background: transparent;
    color: var(--interactive);
    font-size: var(--text-xs);
    font-weight: 600;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm, 6px);
}
.ntf-read-all:hover { background: var(--interactive-tint); }
.ntf-bell.open { background: var(--hover-subtle); color: var(--text-primary); }
.ntf-list { overflow-y: auto; }
.ntf-item {
    display: flex;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font: inherit;
    color: var(--text-primary);
    transition: background .12s;
}
.ntf-item:last-child { border-bottom: none; }
.ntf-item:hover { background: var(--surface-hover); }
.ntf-dot {
    flex-shrink: 0;
    width: 8px; height: 8px;
    margin-top: 5px;
    border-radius: 50%;
    background: var(--text-tertiary);
}
.ntf-dot-design   { background: var(--interactive); }
.ntf-dot-approval { background: var(--warning); }
.ntf-dot-reject   { background: var(--danger); }
.ntf-dot-print    { background: var(--accent); }
.ntf-dot-ready    { background: var(--success); }
.ntf-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ntf-text { font-size: var(--text-sm); line-height: 1.35; word-break: break-word; }
.ntf-meta { font-size: var(--text-xs); color: var(--text-tertiary); }
.ntf-empty { padding: 18px 14px; text-align: center; color: var(--text-tertiary); font-size: var(--text-sm); }
/* ═══════════════════════════════════════════════════════════════════
   Mobile redesign 2026-11-05 (slice 2.7) — unified mobile scale.
   Kurban's verdict on the 2.6 patch pass: proportions were broken —
   everything either huge or tiny, lots of empty air. This layer is
   ONE scale for every UI that loads common.css (all four of them):
   page inset 12px · block gaps 8–12px · card padding 12px · page
   title <= --text-xl · labels --text-xs/--text-sm · primary tap
   targets stay >=44px (MOBILE UX block above). Desktop untouched.
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    :root { --header-height: 56px; }
    .page-header { padding: 0 12px; gap: 8px; }
    .page-content { padding: 12px; }
    .card { padding: 12px; }
    .modal { padding: 16px 12px; }
    .modal-title { font-size: var(--text-lg); }
    .modal-actions { margin-top: 12px; gap: 8px; flex-wrap: wrap; }
    .form-group { margin-bottom: 10px; }
    .empty-state { padding: 24px 12px; }
    .pagination { padding: 8px 0; gap: 8px; }
    .admin-perm-grid { padding: 10px; }
    .admin-create-row { margin-bottom: 10px; gap: 8px; }
}

/* ═══════════════════════════════════════════════════════════════════
   Lightness 2026-11-05 (slice 2.8) — filter pills stop eating the
   first screen; the sidebar drawer gets a user chip and a tight
   rhythm instead of stretched-out links over an empty middle.
   Audit: goals/metrica-crm/hidden_files/AUDIT-LIGHTNESS.md §2–3.
   ═══════════════════════════════════════════════════════════════════ */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--accent-tint);
    border-radius: var(--radius-md);
    min-width: 0;
}
.sidebar-user-avatar {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: var(--text-sm);
}
.sidebar-user-meta { min-width: 0; display: flex; flex-direction: column; }
.sidebar-user-name {
    font-weight: 600;
    font-size: var(--text-base);
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-user-role {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (max-width: 1024px) {
    .sidebar { padding: 12px 10px; }
    .sidebar-nav { flex: none; }
    .sidebar-link { padding: 8px 12px; font-size: var(--text-base); }
    .sidebar-bottom { margin-top: 14px; padding-top: 10px; }
}

@media (max-width: 768px) {
    /* One horizontally scrolling chip row instead of 2–4 wrapped rows:
       the list starts right under the toolbar (orders/clients). */
    .cl-filter-pills {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 -12px 12px;
        padding: 2px 12px;
    }
    .cl-filter-pills::-webkit-scrollbar { display: none; }
    .cl-filter-pill { flex: none; }
}
