/* RetailPlus ERP design system: tokens, layout, components. No framework; one file. */

:root {
    --brand: #4f46e5;
    --brand-strong: #4338ca;
    --brand-soft: #eef2ff;
    --brand-ring: rgba(79, 70, 229, .22);
    --accent: #0ea5e9;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --text: #0f172a;
    --text-2: #334155;
    --muted: #64748b;
    --subtle: #94a3b8;
    --border: #e5e9f2;
    --border-strong: #cbd5e1;

    --success: #059669; --success-soft: #ecfdf5;
    --warning: #b45309; --warning-soft: #fffbeb;
    --danger: #dc2626;  --danger-soft: #fef2f2;
    --info: #2563eb;    --info-soft: #eff6ff;
    --violet: #7c3aed;  --violet-soft: #f5f3ff;
    --teal: #0d9488;    --teal-soft: #f0fdfa;

    --sidebar: #0b1120;
    --sidebar-2: #111a2e;
    --sidebar-text: #a5b0c6;
    --sidebar-active: rgba(99, 102, 241, .18);

    --radius: 14px;
    --radius-sm: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 6px 16px rgba(15, 23, 42, .05);
    --shadow-lg: 0 20px 50px rgba(15, 23, 42, .18);
    --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    --sidebar-width: 264px;
    --topbar-height: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-strong); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
small { font-size: 12.5px; }
img { max-width: 100%; }
button { font: inherit; }
.icon { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: 13px; }
.nowrap { white-space: nowrap; }
.block { display: block; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
:focus-visible { outline: 3px solid var(--brand-ring); outline-offset: 2px; }

/* ===== App layout ===== */
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: 100vh; }
.main { display: flex; flex-direction: column; min-width: 0; }
.content { flex: 1; padding: 28px 32px 48px; max-width: 1440px; width: 100%; margin: 0 auto; }

/* Sidebar */
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: linear-gradient(180deg, var(--sidebar) 0%, var(--sidebar-2) 100%); color: var(--sidebar-text); display: flex; flex-direction: column; z-index: 40; scrollbar-width: thin; scrollbar-color: #26324d transparent; }
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 22px; color: #fff; }
.brand:hover { color: #fff; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(135deg, #6366f1, #0ea5e9); box-shadow: 0 8px 20px rgba(79, 70, 229, .45); font-weight: 800; font-size: 17px; color: #fff; }
.brand-name { font-weight: 800; font-size: 17px; letter-spacing: -.02em; }
.brand-name span { color: #818cf8; }
.brand-sub { display: block; font-size: 11px; font-weight: 500; color: #7c89a6; letter-spacing: .04em; text-transform: uppercase; }
.nav { padding: 6px 12px 24px; display: flex; flex-direction: column; gap: 2px; }
.nav-label { padding: 18px 12px 6px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #5d6a87; }
.nav-link, .nav-group-toggle { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border: 0; border-radius: 10px; background: none; color: var(--sidebar-text); font-size: 14px; font-weight: 500; text-align: left; cursor: pointer; transition: background .15s, color .15s; }
.nav-link:hover, .nav-group-toggle:hover { background: rgba(255, 255, 255, .05); color: #e2e8f0; }
.nav-link.is-active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #818cf8; }
.nav-link .icon, .nav-group-toggle .icon { width: 19px; height: 19px; opacity: .9; }
.nav-group-toggle .chev { margin-left: auto; width: 16px; height: 16px; transition: transform .2s; }
.nav-group.is-open .nav-group-toggle .chev { transform: rotate(180deg); }
.nav-group.is-open > .nav-group-toggle { color: #e2e8f0; }
.nav-sub { display: none; flex-direction: column; gap: 1px; margin: 2px 0 6px 21px; padding-left: 12px; border-left: 1px solid #1f2a44; }
.nav-group.is-open .nav-sub { display: flex; }
.nav-sub .nav-link { padding: 7px 10px; font-size: 13.5px; }
.nav-sub-heading { padding: 8px 10px 2px; font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: #4f5c7a; }
.nav-soon { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; font-size: 13.5px; color: #56627e; cursor: default; }
.pill-soon { padding: 1px 7px; border-radius: 999px; background: rgba(148, 163, 184, .12); color: #7c89a6; font-size: 10.5px; font-weight: 600; }
.sidebar-footer { margin-top: auto; padding: 16px 22px 20px; font-size: 12px; color: #56627e; border-top: 1px solid #18223a; }

/* Topbar */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px; height: var(--topbar-height); padding: 0 32px; background: rgba(255, 255, 255, .86); backdrop-filter: saturate(180%) blur(12px); border-bottom: 1px solid var(--border); }
.topbar-menu { display: none; }
.topbar-title { font-size: 15px; font-weight: 600; color: var(--text-2); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.company-switch { display: inline-flex; align-items: center; gap: 10px; padding: 6px 12px 6px 6px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); font-size: 13.5px; font-weight: 600; max-width: 320px; }
.company-switch:hover { border-color: var(--border-strong); color: var(--text); }
.company-switch .avatar { width: 30px; height: 30px; font-size: 12px; border-radius: 9px; }
.company-switch .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-switch.is-empty { color: var(--muted); padding-left: 12px; }
.user-menu { position: relative; }
.user-button { display: inline-flex; align-items: center; gap: 10px; padding: 4px 8px 4px 4px; border: 0; border-radius: 12px; background: none; cursor: pointer; color: var(--text); }
.user-button:hover { background: var(--surface-2); }
.user-button .who { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.2; }
.user-button .who strong { font-size: 13.5px; }
.user-button .who small { color: var(--muted); font-size: 11.5px; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: linear-gradient(135deg, #6366f1, #8b5cf6); color: #fff; font-size: 13px; font-weight: 700; flex: none; }
.avatar.tone-teal { background: linear-gradient(135deg, #0ea5e9, #14b8a6); }
.menu { position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; padding: 6px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-lg); display: none; z-index: 50; }
.menu.is-open { display: block; }
.menu-head { padding: 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-head strong { display: block; font-size: 14px; }
.menu-head small { color: var(--muted); }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border: 0; border-radius: 8px; background: none; color: var(--text-2); font-size: 14px; text-align: left; cursor: pointer; }
.menu-item:hover { background: var(--surface-2); color: var(--text); }
.menu-item.danger { color: var(--danger); }

/* ===== Page header ===== */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.eyebrow { font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand); margin-bottom: 6px; }
.page-title { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.page-subtitle { margin-top: 6px; color: var(--muted); max-width: 720px; }
.page-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ===== Grid & cards ===== */
.grid { display: grid; gap: 18px; }
.grid-kpi { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.stack { display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 16px; font-weight: 700; }
.card-subtitle { margin-top: 2px; color: var(--muted); font-size: 13px; }
.card-body { padding: 22px; }
.card-footer { padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius) var(--radius); }

/* KPI */
.kpi { position: relative; display: flex; flex-direction: column; gap: 14px; padding: 20px; overflow: hidden; transition: transform .15s, box-shadow .15s; }
a.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi-icon { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; }
.kpi-icon .icon { width: 20px; height: 20px; }
.kpi-value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-value small { font-size: 14px; font-weight: 600; color: var(--muted); margin-right: 4px; }
.kpi-foot { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.trend { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 999px; font-weight: 700; font-size: 12px; }
.trend.up { background: var(--success-soft); color: var(--success); }
.trend.down { background: var(--danger-soft); color: var(--danger); }
.trend.flat { background: var(--surface-2); color: var(--muted); }
.tone-brand { background: var(--brand-soft); color: var(--brand); }
.tone-green { background: var(--success-soft); color: var(--success); }
.tone-amber { background: var(--warning-soft); color: var(--warning); }
.tone-red { background: var(--danger-soft); color: var(--danger); }
.tone-blue { background: var(--info-soft); color: var(--info); }
.tone-violet { background: var(--violet-soft); color: var(--violet); }
.tone-teal { background: var(--teal-soft); color: var(--teal); }
.kpi-section-title { display: flex; align-items: center; gap: 10px; margin: 8px 0 12px; font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.kpi-section-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* Hero */
.hero { position: relative; overflow: hidden; padding: 28px 30px; border-radius: 18px; color: #fff; background: radial-gradient(1200px 400px at 90% -20%, rgba(14, 165, 233, .55), transparent 60%), linear-gradient(135deg, #312e81 0%, #4f46e5 55%, #6366f1 100%); box-shadow: 0 18px 40px rgba(79, 70, 229, .28); margin-bottom: 24px; }
.hero h1 { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.hero p { margin-top: 6px; color: rgba(255, 255, 255, .82); max-width: 640px; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.hero-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; background: rgba(255, 255, 255, .14); font-size: 13px; font-weight: 600; }
.hero-chip .icon { width: 15px; height: 15px; }

/* ===== Buttons ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px; border: 1px solid transparent; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; line-height: 1; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, box-shadow .15s, color .15s; text-decoration: none; }
.btn .icon { width: 17px; height: 17px; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: 0 1px 2px rgba(79, 70, 229, .3), inset 0 1px 0 rgba(255, 255, 255, .12); }
.btn-primary:hover { background: var(--brand-strong); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text-2); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { border-color: var(--border-strong); color: var(--text); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #047857; color: #fff; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 9px; }
.btn[disabled], .btn.is-busy { opacity: .6; pointer-events: none; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 9px; background: none; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.inline-form { display: inline; margin: 0; }

/* ===== Forms ===== */
.form-grid { display: grid; gap: 18px; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.field-label .req { color: var(--danger); margin-left: 2px; }
.field-hint { font-size: 12.5px; color: var(--muted); }
.field-error { font-size: 12.5px; color: var(--danger); font-weight: 500; }
.input, .select, textarea.input { width: 100%; height: 42px; padding: 0 13px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; font-size: 14.5px; transition: border-color .15s, box-shadow .15s; }
textarea.input { height: auto; min-height: 92px; padding: 10px 13px; resize: vertical; }
.select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; }
.input:hover, .select:hover { border-color: #94a3b8; }
.input:focus, .select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); }
.input[disabled], .select[disabled], .input[readonly] { background: var(--surface-2); color: var(--muted); }
.input-sm, .select-sm { height: 36px; font-size: 13.5px; }
.input-validation-error { border-color: var(--danger) !important; }
.input-group { position: relative; }
.input-group .input { padding-left: 40px; }
.input-group > .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--subtle); pointer-events: none; }
.input-group .input-action { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.check { display: inline-flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-2); cursor: pointer; user-select: none; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; margin: 0; }
.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.switch input { appearance: none; flex: none; width: 40px; height: 23px; margin: 0; border-radius: 999px; background: var(--border-strong); position: relative; cursor: pointer; transition: background .2s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 17px; height: 17px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .2); transition: transform .2s; }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(17px); }
.switch strong { display: block; font-size: 14px; }
.switch small { color: var(--muted); }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding-top: 6px; }
.form-section { padding: 22px; border-bottom: 1px solid var(--border); }
.form-section:last-child { border-bottom: 0; }
.form-section-title { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
.form-section-hint { color: var(--muted); font-size: 13px; margin-bottom: 16px; }

/* ===== Alerts ===== */
.alert { display: flex; gap: 12px; padding: 14px 16px; border-radius: 12px; border: 1px solid; font-size: 14px; margin-bottom: 18px; }
.alert .icon { width: 20px; height: 20px; margin-top: 1px; }
.alert strong { display: block; margin-bottom: 2px; }
.alert-danger { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.alert-success { background: var(--success-soft); border-color: #a7f3d0; color: #065f46; }
.alert-info { background: var(--info-soft); border-color: #bfdbfe; color: #1e40af; }
.alert-warning { background: var(--warning-soft); border-color: #fde68a; color: #92400e; }
.validation-summary-valid { display: none; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-muted { background: #eef1f6; color: var(--muted); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }
.badge-violet { background: var(--violet-soft); color: var(--violet); }

/* ===== Tables ===== */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.toolbar .search { position: relative; flex: 1 1 260px; max-width: 420px; }
.toolbar .search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--subtle); width: 17px; height: 17px; }
.toolbar .search .input { padding-left: 38px; height: 38px; }
.toolbar .select { width: auto; min-width: 160px; height: 38px; }
.toolbar-meta { margin-left: auto; color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 600; cursor: pointer; }
.chip:hover { border-color: var(--border-strong); color: var(--text); }
.chip.is-active { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip .count { padding: 0 6px; border-radius: 999px; background: rgba(15, 23, 42, .07); font-size: 11.5px; }
.chip.is-active .count { background: rgba(255, 255, 255, .22); }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.table th { position: sticky; top: 0; padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; text-align: left; white-space: nowrap; }
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]::after { content: "↕"; margin-left: 6px; opacity: .35; font-size: 11px; }
.table th[data-sort].asc::after { content: "↑"; opacity: .9; }
.table th[data-sort].desc::after { content: "↓"; opacity: .9; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbff; }
.table .col-actions { width: 1%; text-align: right; white-space: nowrap; }
.table .cell-main { display: flex; align-items: center; gap: 12px; }
.table .cell-main strong { display: block; font-weight: 600; }
.table .cell-main small { color: var(--muted); }
.table tr.is-muted td { color: var(--muted); }
.table-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.pager { display: flex; gap: 6px; }
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 48px 24px; color: var(--muted); }
.empty .kpi-icon { width: 52px; height: 52px; border-radius: 16px; }
.empty .kpi-icon .icon { width: 24px; height: 24px; }
.empty h3 { color: var(--text); font-size: 16px; }
.empty p { max-width: 420px; }
.row-actions { display: inline-flex; align-items: center; gap: 2px; }

/* ===== Toasts ===== */
.toast-stack { position: fixed; top: 18px; right: 18px; z-index: 100; display: flex; flex-direction: column; gap: 10px; width: min(400px, calc(100vw - 32px)); }
.toast { display: flex; align-items: flex-start; gap: 12px; padding: 14px 14px 14px 16px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); animation: toast-in .25s ease-out; border-left: 4px solid; }
.toast.is-leaving { animation: toast-out .2s ease-in forwards; }
.toast-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; flex: none; }
.toast-body { flex: 1; min-width: 0; font-size: 14px; }
.toast-body strong { display: block; margin-bottom: 2px; }
.toast-body p { color: var(--text-2); }
.toast-success { border-left-color: var(--success); } .toast-success .toast-icon { background: var(--success-soft); color: var(--success); }
.toast-error { border-left-color: var(--danger); } .toast-error .toast-icon { background: var(--danger-soft); color: var(--danger); }
.toast-info { border-left-color: var(--info); } .toast-info .toast-icon { background: var(--info-soft); color: var(--info); }
.toast-warning { border-left-color: var(--warning); } .toast-warning .toast-icon { background: var(--warning-soft); color: var(--warning); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ===== Dialogs ===== */
dialog.modal { width: min(520px, calc(100vw - 32px)); padding: 0; border: 0; border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.modal.wide { width: min(720px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(3px); }
dialog.modal[open] { animation: modal-in .18s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-header { display: flex; align-items: flex-start; gap: 14px; padding: 22px 22px 6px; }
.modal-header h2 { font-size: 18px; }
.modal-header p { margin-top: 4px; color: var(--muted); font-size: 14px; }
.modal-body { padding: 16px 22px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px 20px; }
.secret-box { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border: 1px dashed var(--border-strong); border-radius: 12px; background: var(--surface-2); font-family: var(--mono); font-size: 18px; font-weight: 700; letter-spacing: .04em; }

/* ===== Auth pages ===== */
.auth { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); min-height: 100vh; background: var(--surface); }
.auth-showcase { position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between; padding: 44px 52px; color: #fff; background: radial-gradient(900px 500px at 100% 0%, rgba(14, 165, 233, .45), transparent 60%), radial-gradient(700px 500px at 0% 100%, rgba(139, 92, 246, .45), transparent 60%), linear-gradient(160deg, #1e1b4b 0%, #312e81 50%, #4338ca 100%); }
.auth-showcase::after { content: ""; position: absolute; inset: 0; background-image: linear-gradient(rgba(255, 255, 255, .05) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .05) 1px, transparent 1px); background-size: 44px 44px; mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent); pointer-events: none; }
.auth-showcase > * { position: relative; z-index: 1; }
.auth-showcase .brand { padding: 0; }
.auth-pitch h2 { font-size: 38px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; max-width: 520px; }
.auth-pitch h2 span { background: linear-gradient(90deg, #a5b4fc, #67e8f9); -webkit-background-clip: text; background-clip: text; color: transparent; }
.auth-pitch p { margin-top: 16px; color: rgba(255, 255, 255, .78); font-size: 16px; max-width: 480px; }
.auth-features { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 32px; max-width: 540px; }
.auth-feature { display: flex; gap: 12px; padding: 14px; border-radius: 14px; background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .12); backdrop-filter: blur(6px); }
.auth-feature .kpi-icon { width: 36px; height: 36px; border-radius: 10px; background: rgba(255, 255, 255, .14); color: #fff; }
.auth-feature strong { display: block; font-size: 14px; }
.auth-feature small { color: rgba(255, 255, 255, .7); }
.auth-legal { color: rgba(255, 255, 255, .55); font-size: 12.5px; }
.auth-main { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--surface); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { display: none; padding: 0 0 28px; color: var(--text); }
.auth-title { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.auth-subtitle { margin: 8px 0 28px; color: var(--muted); }
.auth-form { display: flex; flex-direction: column; gap: 18px; }
.auth-form .input { height: 48px; font-size: 15px; }
.auth-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.auth-foot { margin-top: 28px; padding-top: 20px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.auth-foot .icon { color: var(--success); }
.company-list { display: flex; flex-direction: column; gap: 10px; }
.company-option { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); text-align: left; cursor: pointer; transition: border-color .15s, box-shadow .15s, transform .15s; }
.company-option:hover { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-ring); transform: translateY(-1px); }
.company-option .avatar { border-radius: 12px; width: 44px; height: 44px; font-size: 15px; }
.company-option strong { display: block; font-size: 15px; }
.company-option small { color: var(--muted); }
.company-option .chev { margin-left: auto; color: var(--subtle); }
.company-option.is-current { border-color: var(--brand); background: var(--brand-soft); }

/* ===== Permission matrix ===== */
.perm-table td, .perm-table th { text-align: center; }
.perm-table td:first-child, .perm-table th:first-child { text-align: left; }
.perm-table input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); cursor: pointer; }
.perm-group td { background: var(--surface-2) !important; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding-top: 9px; padding-bottom: 9px; }
.perm-na { color: var(--subtle); }
.role-list { display: flex; flex-direction: column; padding: 8px; gap: 2px; }
.role-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--text-2); font-weight: 500; }
.role-item:hover { background: var(--surface-2); color: var(--text); }
.role-item.is-active { background: var(--brand-soft); color: var(--brand); font-weight: 700; }

/* Access grid (user form) */
.access-row { display: grid; grid-template-columns: minmax(0, 1fr) 240px; align-items: center; gap: 14px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px; }
.access-row + .access-row { margin-top: 8px; }
.access-row.is-selected { border-color: #c7d2fe; background: #fafaff; }
.access-row .check strong { display: block; color: var(--text); }

/* Setup list */
.setup-list { display: flex; flex-direction: column; }
.setup-item { display: flex; align-items: center; gap: 14px; padding: 14px 22px; border-bottom: 1px solid var(--border); }
.setup-item:last-child { border-bottom: 0; }
.setup-item .kpi-icon { width: 36px; height: 36px; border-radius: 10px; }
.setup-item div { flex: 1; min-width: 0; }
.setup-item strong { display: block; font-size: 14px; }
.setup-item small { color: var(--muted); }
.chart-placeholder { display: grid; place-items: center; height: 240px; margin: 22px; border: 1px dashed var(--border-strong); border-radius: 12px; background: repeating-linear-gradient(135deg, var(--surface-2), var(--surface-2) 10px, #fff 10px, #fff 20px); color: var(--muted); text-align: center; padding: 20px; }
.status-page { display: grid; place-items: center; min-height: 60vh; text-align: center; }
.status-code { font-size: 72px; font-weight: 800; letter-spacing: -.04em; background: linear-gradient(135deg, #4f46e5, #0ea5e9); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ===== Responsive ===== */
@media (max-width: 1100px) {
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .auth { grid-template-columns: 1fr; }
    .auth-showcase { display: none; }
    .auth-card .brand { display: flex; }
}
@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-width); transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow-lg); }
    body.nav-open .sidebar { transform: none; }
    body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 35; }
    .topbar { padding: 0 16px; }
    .topbar-menu { display: inline-grid; }
    .topbar-title { display: none; }
    .content { padding: 20px 16px 40px; }
    .grid-2, .grid-3, .form-grid.cols-2, .form-grid.cols-3 { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .user-button .who { display: none; }
    .company-switch { max-width: 180px; }
    .access-row { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .page-title { font-size: 22px; }
    .hero { padding: 22px; }
    .hero h1 { font-size: 21px; }
    .kpi-value { font-size: 24px; }
    .toolbar .search { max-width: none; }
    .toolbar .select { flex: 1 1 140px; }
    .page-actions, .page-actions .btn { width: 100%; }
    /* Smart tables become cards on phones. */
    .table.responsive thead { display: none; }
    .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
    .table.responsive tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
    .table.responsive td { padding: 4px 0; border: 0; text-align: left !important; }
    .table.responsive td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--subtle); }
    .table.responsive .col-actions { text-align: left; padding-top: 8px; }
}
@media print {
    .sidebar, .topbar, .toast-stack, .page-actions, .toolbar { display: none !important; }
    .app { display: block; }
    .content { padding: 0; }
}

/* ===== Refinements ===== */
.app { background: linear-gradient(90deg, var(--sidebar) 0, var(--sidebar) var(--sidebar-width), var(--bg) var(--sidebar-width)); }
.topbar .topbar-menu { display: none; }
.avatar.tone-teal { color: #fff; }
.toast-stack { top: calc(var(--topbar-height) + 12px); }
.perm-table td { padding-top: 9px; padding-bottom: 9px; }
.grid-kpi-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-kpi-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi.compact { flex-direction: row; align-items: center; gap: 14px; padding: 16px 18px; }
.kpi.compact .kpi-value { font-size: 21px; line-height: 1.15; }
.kpi.compact .kpi-value small { font-size: 12px; }
.kpi.compact .kpi-label { display: block; font-size: 12.5px; }
.kpi.compact > div { min-width: 0; }
@media (max-width: 1280px) { .grid-kpi-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .grid-kpi-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
    .app { background: var(--bg); }
    .topbar .topbar-menu { display: inline-grid; }
    .grid-kpi-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .grid-kpi, .grid-kpi-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
    .grid-kpi-5 { gap: 12px; }
    .kpi { padding: 14px; gap: 10px; }
    .kpi-icon { width: 34px; height: 34px; border-radius: 10px; }
    .kpi-value { font-size: 20px; }
    .kpi-value small { display: block; font-size: 11px; }
    .kpi-foot { font-size: 11.5px; }
    .kpi-foot .trend { display: none; }
    .kpi.compact { padding: 12px; gap: 10px; }
    .kpi.compact .kpi-value { font-size: 18px; }
    .hero-meta .hero-chip:last-child { display: none; }
}

/* ===== Phase 1: master screens ===== */
.combo { position: relative; }
.combo-native { position: absolute !important; opacity: 0; pointer-events: none; width: 1px !important; height: 1px !important; bottom: 0; left: 12px; }
.combo-input { padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 15px; }
.combo-list { display: none; position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 60; max-height: 260px; overflow-y: auto; margin: 0; padding: 6px; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); }
.combo.is-open .combo-list { display: block; }
.combo-list li { padding: 8px 10px; border-radius: 8px; font-size: 14px; cursor: pointer; }
.combo-list li:hover, .combo-list li.is-active { background: var(--brand-soft); color: var(--brand-strong); }
.combo-list li.is-selected { font-weight: 700; }
.combo-list li.combo-empty { color: var(--muted); cursor: default; background: none; }
dialog.modal .modal-body { overflow: visible; }
tr.is-filtered { display: none; }
.margin { display: block; margin-top: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.margin.is-good { color: var(--success); }
.margin.is-low { color: var(--warning); }
.margin.is-bad { color: var(--danger); }
.form-error { margin: 0 22px; }
.code-cell { font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--text-2); }
.tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 18px; border-radius: 12px; background: #e9edf5; width: fit-content; max-width: 100%; overflow-x: auto; }
.tab { display: inline-flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 9px; color: var(--text-2); font-size: 14px; font-weight: 600; white-space: nowrap; }
.tab:hover { color: var(--text); }
.tab.is-active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }
.mapping-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.series-preview { font-family: var(--mono); font-weight: 700; color: var(--brand); }
.type-pill { display: inline-block; min-width: 74px; text-align: center; }
@media (max-width: 900px) { .mapping-grid { grid-template-columns: 1fr; } }
.input[style*="uppercase"]::placeholder { text-transform: none; }
@media (max-width: 640px) {
    /* Compact phone cards: two columns of label/value, the first cell and the actions full width. */
    .table.responsive tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 14px; }
    .table.responsive tbody td:first-child, .table.responsive tbody td.col-actions, .table.responsive tbody td[colspan] { grid-column: 1 / -1; }
    .table.responsive tbody tr[hidden], .table.responsive tbody tr.is-filtered { display: none; }
    .table.responsive td.num { text-align: left; }
}

/* ===== Phase 2: documents ===== */
.doc-head { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.doc-head .wide { grid-column: span 2; }
.line-table td { vertical-align: top; }
.line-table .input, .line-table .combo-input { height: 38px; font-size: 14px; }
.line-table .col-item { min-width: 280px; }
.line-table .col-qty { width: 130px; }
.line-table .col-rate { width: 150px; }
.line-table .col-amount { width: 140px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; padding-top: 22px; }
.line-table .col-remove { width: 44px; padding-top: 16px; }
.line-table td.readonly { padding-top: 22px; }
.line-meta { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }
.line-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); }
.totals { display: grid; grid-template-columns: auto auto; justify-content: end; gap: 6px 28px; padding: 16px 22px; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.totals dt { color: var(--muted); text-align: right; }
.totals dd { margin: 0; text-align: right; font-weight: 600; min-width: 120px; }
.totals .grand { font-size: 18px; font-weight: 800; color: var(--text); }
.doc-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.doc-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; padding: 20px 22px; }
.doc-meta dt { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--subtle); }
.doc-meta dd { margin: 4px 0 0; font-weight: 600; }
.progress { position: relative; height: 8px; border-radius: 999px; background: #e9edf5; overflow: hidden; min-width: 80px; }
.progress > span { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: linear-gradient(90deg, #6366f1, #0ea5e9); }
.progress.done > span { background: var(--success); }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
.qty-input { max-width: 140px; margin-left: auto; text-align: right; }
.doc-number { font-family: var(--mono); font-weight: 700; color: var(--brand); }
tr[data-href] { cursor: pointer; }
.timeline { list-style: none; margin: 0; padding: 18px 22px; display: flex; flex-direction: column; gap: 14px; }
.timeline li { display: flex; gap: 12px; font-size: 14px; }
.timeline .dot { flex: none; width: 10px; height: 10px; margin-top: 6px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.timeline .dot.red { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.timeline .dot.green { background: var(--success); box-shadow: 0 0 0 4px var(--success-soft); }
.timeline small { display: block; color: var(--muted); }
.print-only { display: none; }
.picker-list { display: flex; flex-direction: column; }
.picker-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 14px 22px; border-bottom: 1px solid var(--border); color: inherit; }
.picker-item:hover { background: #fafbff; color: inherit; }
.picker-item:last-child { border-bottom: 0; }
.qty-pos { color: var(--success); font-weight: 600; }
.qty-neg { color: var(--danger); font-weight: 600; }
@media (max-width: 900px) {
    .doc-head, .doc-meta { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .doc-head .wide { grid-column: 1 / -1; }
    .line-table .col-item { min-width: 220px; }
}
@media (max-width: 640px) {
    .doc-head, .doc-meta { grid-template-columns: 1fr; }
    .line-table.responsive tbody tr { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .line-table .col-amount, .line-table td.readonly, .line-table .col-remove { padding-top: 4px; }
    .line-table .qty-input { max-width: none; margin-left: 0; }
    .totals { justify-content: stretch; }
}
@media print {
    @page { margin: 14mm; }
    body { background: #fff; font-size: 12px; }
    .print-only { display: block; }
    .no-print, .page-header .page-actions, .doc-actions, .tabs, dialog { display: none !important; }
    .card { border: 0; box-shadow: none; }
    .page-header { margin-bottom: 10px; }
    .badge { border: 1px solid currentColor; }
    .print-head { display: flex; justify-content: space-between; gap: 20px; padding-bottom: 12px; margin-bottom: 14px; border-bottom: 2px solid #0f172a; }
    .print-head h2 { font-size: 20px; }
    .table th { position: static; background: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .table td, .table th { padding: 6px 8px; }
    .signatures { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 30px; margin-top: 40px; }
    .signatures div { border-top: 1px solid #0f172a; padding-top: 6px; font-size: 11px; }
}
.signatures { display: none; }
.table th.num { text-align: right; }
.table th.col-amount { text-align: right; }
@media print {
    html, body, .app, .main { background: #fff !important; }
    .app { display: block; }
    .grid, .grid-2, .grid-3 { display: block !important; }
    .span-2 { grid-column: auto; }
    .content { max-width: none; }
    .print-head, .page-title, .page-subtitle, .table td, .totals { color: #0f172a; }
}

/* ===== Phase 3: sales ===== */
.segmented { display: inline-flex; padding: 4px; gap: 4px; border-radius: 12px; background: #e9edf5; }
.segment { position: relative; display: inline-flex; align-items: center; gap: 8px; padding: 8px 18px; border-radius: 9px; font-weight: 700; font-size: 14px; color: var(--text-2); cursor: pointer; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment.is-active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }
.segment:focus-within { outline: 3px solid var(--brand-ring); }
tr.is-over td { background: #fff7f7; }
.sale-total-box { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.sale-total-box .amount { font-size: 30px; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.invoice-parties { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.invoice-parties h3 { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--subtle); margin-bottom: 6px; }
.vat-summary { margin: 0 22px 18px; }
@media (max-width: 640px) { .invoice-parties { grid-template-columns: 1fr; } .sale-total-box { align-items: flex-start; } }
@media print { .invoice-parties { border-color: #cbd5e1; } }
.sales-chart { width: 100%; height: auto; display: block; }
.sales-chart .grid-line { stroke: var(--border); stroke-width: 1; }
.sales-chart .axis { fill: var(--subtle); font-size: 11px; font-family: var(--font); }
.sales-chart .bar { fill: #a5b4fc; transition: fill .15s; }
.sales-chart .bar:hover { fill: var(--brand); }
.sales-chart .bar.today { fill: var(--brand); }
