/* ============================================================================
   Nugglets Dashboard - design system
   - Strict 4px spacing grid · one emerald accent · light + dark via [data-theme]
   - Dark is the default. Light overrides live in [data-theme="light"].
   All colors/spacing are CSS variables so theming stays centralized.
   ========================================================================== */

:root {
    /* Spacing scale (4px grid) */
    --s-1: 4px;  --s-2: 8px;  --s-3: 12px;  --s-4: 16px;  --s-6: 24px;  --s-8: 32px;

    /* Radius */
    --radius-sm: 6px;  --radius: 8px;  --radius-lg: 12px;  --radius-pill: 999px;

    /* Shell metrics */
    --sb-w: 236px;  --sb-w-collapsed: 60px;  --tb-h: 52px;  --content-max: 1200px;

    /* Single accent - refined emerald */
    --accent: #10b981;
    --accent-hover: #0ea372;
    --accent-fg: #ffffff;
    --accent-soft: rgba(16, 185, 129, .14);
    --accent-ring: rgba(16, 185, 129, .40);

    /* Status */
    --danger: #f0616d;  --danger-soft: rgba(240, 97, 109, .14);
    --warning: #e0a30a; --warning-soft: rgba(224, 163, 10, .14);
    --info: #5b9dff;    --info-soft: rgba(91, 157, 255, .14);
    --success: var(--accent); --success-soft: var(--accent-soft);

    /* Typography */
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

    /* ---- Dark theme (default) ---- */
    --bg: #0b0d0f;
    --bg-elev: #121518;
    --bg-elev-2: #171b1f;
    --bg-hover: #1b2024;
    --border: #23282d;
    --border-strong: #2e353c;
    --text: #e6e8ea;
    --text-muted: #99a0a8;
    --text-faint: #6b727a;
    --shadow-elev: 0 8px 24px rgba(0, 0, 0, .45);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --skeleton: linear-gradient(90deg, #16191d 25%, #1e2227 37%, #16191d 63%);
}

[data-theme="light"] {
    --bg: #f6f7f8;
    --bg-elev: #ffffff;
    --bg-elev-2: #f1f3f5;
    --bg-hover: #eef0f2;
    --border: #e6e8eb;
    --border-strong: #d6dadf;
    --text: #1a1d21;
    --text-muted: #5b626a;
    --text-faint: #8b929a;
    --shadow-elev: 0 8px 24px rgba(15, 23, 42, .10);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --skeleton: linear-gradient(90deg, #eceef0 25%, #f4f6f7 37%, #eceef0 63%);
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; line-height: 1.2; letter-spacing: -.01em; }
button { font-family: inherit; }
svg { display: block; }
.tnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.pos { color: var(--accent); font-variant-numeric: tabular-nums; }
.neg { color: var(--danger); font-variant-numeric: tabular-nums; }

/* Accessible focus ring everywhere */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--accent-ring);
    outline-offset: 2px;
}

/* ============================================================================
   Shell
   ========================================================================== */
.app-sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sb-w); z-index: 40;
    display: flex; flex-direction: column;
    background: var(--bg-elev); border-right: 1px solid var(--border);
    transition: width .15s ease, transform .15s ease;
}
.app-main {
    margin-left: var(--sb-w); min-height: 100vh;
    display: flex; flex-direction: column;
    transition: margin-left .15s ease;
}
body.sidebar-collapsed .app-sidebar { width: var(--sb-w-collapsed); }
body.sidebar-collapsed .app-main { margin-left: var(--sb-w-collapsed); }

/* Sidebar header (logo) */
.sb-head {
    display: flex; align-items: center; gap: var(--s-2);
    height: var(--tb-h); padding: 0 var(--s-3); flex-shrink: 0;
    border-bottom: 1px solid var(--border);
}
.sb-logo { width: 34px; height: 34px; border-radius: var(--radius-sm); flex-shrink: 0; }
.sb-wordmark { font-weight: 700; font-size: 15px; letter-spacing: -.02em; }
.sb-collapse {
    margin-left: auto; display: grid; place-items: center;
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    background: transparent; border: 1px solid transparent; color: var(--text-muted);
    cursor: pointer; transition: .15s ease;
}
.sb-collapse:hover { background: var(--bg-hover); color: var(--text); }
/* Collapsed: hide the logo + wordmark but KEEP the toggle so it can expand again.
   The chevron flips to point right (= expand). */
body.sidebar-collapsed .sb-wordmark, body.sidebar-collapsed .sb-logo { display: none; }
body.sidebar-collapsed .sb-head { justify-content: center; padding: 0; }
body.sidebar-collapsed .sb-collapse { margin-left: 0; }
body.sidebar-collapsed .sb-collapse svg { transform: rotate(180deg); }

/* Sidebar nav */
.sb-nav { flex: 1; overflow-y: auto; padding: var(--s-3) var(--s-2); display: flex; flex-direction: column; gap: 2px; }
.sb-group-label {
    font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-faint); padding: var(--s-4) var(--s-3) var(--s-2);
}
.sb-item {
    display: flex; align-items: center; gap: var(--s-3);
    padding: var(--s-2) var(--s-3); border-radius: var(--radius-sm);
    color: var(--text-muted); font-size: 13px; font-weight: 500;
    transition: background .15s ease, color .15s ease; white-space: nowrap;
}
.sb-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.sb-item:hover { background: var(--bg-hover); color: var(--text); }
.sb-item.is-active { background: var(--accent-soft); color: var(--accent); }
.sb-item.is-active svg { color: var(--accent); }
body.sidebar-collapsed .sb-label, body.sidebar-collapsed .sb-group-label { display: none; }
body.sidebar-collapsed .sb-item { justify-content: center; padding: var(--s-2); }

/* Sidebar footer: user menu */
.sb-foot { border-top: 1px solid var(--border); padding: var(--s-2); position: relative; }
.sb-user {
    width: 100%; display: flex; align-items: center; gap: var(--s-2);
    padding: var(--s-2); border-radius: var(--radius-sm);
    background: transparent; border: none; cursor: pointer; color: var(--text); text-align: left;
    transition: background .15s ease;
}
.sb-user:hover { background: var(--bg-hover); }
.sb-user-meta { min-width: 0; flex: 1; }
.sb-user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user-sub { font-size: 11px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-user-caret { color: var(--text-faint); flex-shrink: 0; }
body.sidebar-collapsed .sb-user-meta, body.sidebar-collapsed .sb-user-caret { display: none; }
body.sidebar-collapsed .sb-user { justify-content: center; }

/* Dropdown menu (elevated) */
.menu {
    position: absolute; bottom: calc(100% + var(--s-1)); left: var(--s-2); right: var(--s-2);
    background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: var(--radius);
    box-shadow: var(--shadow-elev); padding: var(--s-1); z-index: 50;
    opacity: 0; transform: translateY(4px); pointer-events: none; transition: .15s ease;
}
.menu.open { opacity: 1; transform: none; pointer-events: auto; }
.menu a, .menu button {
    display: flex; align-items: center; gap: var(--s-2); width: 100%;
    padding: var(--s-2) var(--s-3); border-radius: var(--radius-sm);
    font-size: 13px; color: var(--text); background: none; border: none; cursor: pointer; text-align: left;
}
.menu a:hover, .menu button:hover { background: var(--bg-hover); }
.menu .menu-sep { height: 1px; background: var(--border); margin: var(--s-1) 0; }
.menu .menu-danger { color: var(--danger); }

/* Topbar */
.app-topbar {
    position: sticky; top: 0; z-index: 30;
    height: var(--tb-h); flex-shrink: 0;
    display: flex; align-items: center; gap: var(--s-3);
    padding: 0 var(--s-6); background: color-mix(in srgb, var(--bg) 80%, transparent);
    backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.tb-burger { display: none; }
.tb-title { font-size: 15px; font-weight: 600; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: var(--s-2); }
.tb-search {
    display: flex; align-items: center; gap: var(--s-2);
    background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 0 var(--s-3); height: 32px; width: 220px; color: var(--text-muted);
}
.tb-search input { border: none; background: none; color: var(--text); font-size: 13px; width: 100%; outline: none; }
.tb-search input::placeholder { color: var(--text-faint); }
.icon-btn {
    position: relative; display: grid; place-items: center; width: 32px; height: 32px;
    border-radius: var(--radius-sm); background: transparent; border: 1px solid transparent;
    color: var(--text-muted); cursor: pointer; transition: .15s ease;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
/* "Back to website" pill — leaves the dashboard for the public marketing site */
.tb-back {
    display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
    border-radius: var(--radius-sm); border: 1px solid var(--border); background: transparent;
    color: var(--text-muted); font-weight: 600; font-size: 13px; text-decoration: none;
    white-space: nowrap; transition: .15s ease;
}
.tb-back:hover { background: var(--bg-hover); color: var(--text); text-decoration: none; }
@media (max-width: 640px) {
    .tb-back { width: 32px; padding: 0; justify-content: center; }
    .tb-back .tb-back-label { display: none; }
}
.icon-btn .dot {
    position: absolute; top: 5px; right: 6px; width: 7px; height: 7px;
    border-radius: 50%; background: var(--accent); border: 2px solid var(--bg);
}

/* Content */
.app-content { padding: var(--s-6); width: 100%; max-width: var(--content-max); margin: 0 auto; }
.page-head { margin-bottom: var(--s-6); }
.page-title { font-size: 22px; font-weight: 600; letter-spacing: -.02em; }
.page-sub { color: var(--text-muted); font-size: 13px; margin-top: var(--s-1); }

/* ============================================================================
   Avatar
   ========================================================================== */
.avatar {
    border-radius: 50%; object-fit: cover; flex-shrink: 0;
    background: var(--accent-soft); color: var(--accent);
    display: grid; place-items: center; font-weight: 600; overflow: hidden;
}
.avatar-img { object-fit: cover; width: 100%; height: 100%; display: block; }
.avatar-24 { width: 24px; height: 24px; font-size: 10px; }
.avatar-28 { width: 28px; height: 28px; font-size: 11px; }
.avatar-96 { width: 96px; height: 96px; font-size: 30px; }

/* ============================================================================
   Cards / panels
   ========================================================================== */
.card, .panel {
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
    padding: var(--s-4);
}
.panel { margin-bottom: var(--s-6); }
.card-head, .panel-head {
    display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
    margin-bottom: var(--s-4);
}
.card-title, .panel-head h2 { font-size: 14px; font-weight: 600; }

/* KPI cards */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-4); margin-bottom: var(--s-6); }
.kpi {
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
    padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-2);
}
.kpi-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.kpi-value { font-size: 24px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-foot { display: flex; align-items: center; gap: var(--s-2); font-size: 12px; }
.trend { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; font-variant-numeric: tabular-nums; }
.trend.up { color: var(--accent); }
.trend.down { color: var(--danger); }

/* ============================================================================
   Tables
   ========================================================================== */
.table-wrap { overflow-x: auto; }
table.dt { width: 100%; border-collapse: collapse; font-size: 13px; }
table.dt th {
    text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em;
    color: var(--text-faint); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border);
    white-space: nowrap; user-select: none;
}
table.dt th.sortable { cursor: pointer; }
table.dt th.sortable:hover { color: var(--text-muted); }
table.dt th .arrow { opacity: .5; font-size: 9px; }
table.dt td {
    padding: 0 var(--s-3); height: 40px; border-bottom: 1px solid var(--border);
    color: var(--text); white-space: nowrap; vertical-align: middle;
}
table.dt td.num { font-variant-numeric: tabular-nums; text-align: right; }
table.dt tbody tr { transition: background .15s ease; }
table.dt tbody tr:hover { background: var(--bg-hover); }
table.dt tbody tr:last-child td { border-bottom: none; }
.cell-strong { font-weight: 600; }

/* Badges / pills */
.badge {
    display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 var(--s-2);
    border-radius: var(--radius-pill); font-size: 12px; font-weight: 600;
    background: var(--bg-elev-2); color: var(--text-muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-pending  { background: var(--warning-soft); color: var(--warning); }
.badge-fulfilled{ background: var(--info-soft);    color: var(--info); }
.badge-shipped  { background: var(--accent-soft);  color: var(--accent); }
.badge-refunded { background: var(--danger-soft);  color: var(--danger); }
.badge-instock  { background: var(--accent-soft);  color: var(--accent); }
.badge-low      { background: var(--warning-soft); color: var(--warning); }
.badge-out      { background: var(--danger-soft);  color: var(--danger); }
.badge-plain::before { display: none; }

/* ============================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
    height: 34px; padding: 0 var(--s-4); border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
    border: 1px solid var(--border-strong); background: var(--bg-elev-2); color: var(--text);
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-sm { height: 28px; padding: 0 var(--s-3); font-size: 12px; }
.btn-lg { height: 40px; padding: 0 var(--s-6); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ============================================================================
   Forms
   ========================================================================== */
.form-row { margin-bottom: var(--s-4); }
.form-row > label { display: block; font-size: 13px; font-weight: 500; margin-bottom: var(--s-2); }
.form-input, .form-select, .form-textarea, input[type="text"].form-input, select.form-input, textarea.form-input {
    width: 100%; height: 36px; padding: 0 var(--s-3);
    background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text); font-size: 13px; font-family: inherit; transition: border-color .15s ease, box-shadow .15s ease;
}
.form-textarea, textarea.form-input { height: auto; padding: var(--s-2) var(--s-3); min-height: 84px; resize: vertical; line-height: 1.5; }
.form-input::placeholder { color: var(--text-faint); }
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%2399a0a8' d='M5 6 0 0h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right var(--s-3) center; padding-right: var(--s-8); }
.form-help { display: block; color: var(--text-muted); font-size: 12px; margin-top: var(--s-1); }
.form-error { display: block; color: var(--danger); font-size: 12px; margin-top: var(--s-1); }
.has-error .form-input, .has-error .form-select, .has-error .form-textarea { border-color: var(--danger); }
ul.errorlist { list-style: none; margin: 0 0 var(--s-3); padding: 0; color: var(--danger); font-size: 12px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4); }

/* Toggle switch */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); padding: var(--s-3) 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle-row .t-label { font-size: 13px; font-weight: 500; }
.toggle-row .t-desc { font-size: 12px; color: var(--text-muted); }
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider {
    position: absolute; inset: 0; background: var(--bg-elev-2); border: 1px solid var(--border-strong);
    border-radius: var(--radius-pill); transition: .15s ease; cursor: pointer;
}
.switch .slider::before {
    content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px;
    background: var(--text-faint); border-radius: 50%; transition: .15s ease;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent-ring); outline-offset: 2px; }

/* Segmented control (theme picker) */
.segmented { display: inline-flex; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; }
.segmented label { padding: var(--s-2) var(--s-4); font-size: 13px; border-radius: 5px; cursor: pointer; color: var(--text-muted); }
.segmented input { position: absolute; opacity: 0; }
.segmented input:checked + label { background: var(--bg-elev); color: var(--text); box-shadow: var(--shadow-sm); }

/* ============================================================================
   Empty states & skeletons
   ========================================================================== */
.empty {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: var(--s-8) var(--s-4); color: var(--text-muted); gap: var(--s-2);
}
.empty .empty-icon {
    width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--radius);
    background: var(--bg-elev-2); color: var(--text-faint); margin-bottom: var(--s-2);
}
.empty .empty-title { font-size: 14px; font-weight: 600; color: var(--text); }
.empty .empty-msg { font-size: 13px; max-width: 320px; }

.skeleton { background: var(--skeleton); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.sk-line { height: 12px; margin: var(--s-2) 0; }
.sk-line.lg { height: 22px; width: 60%; }
.sk-line.sm { height: 10px; width: 40%; }
/* Loading swap: show skeletons until body.loaded; then reveal real content. */
[data-skel] { display: none; }
body:not(.loaded) [data-skel] { display: block; }
body:not(.loaded) [data-real] { display: none; }

/* ============================================================================
   Toasts
   ========================================================================== */
.toast-stack { position: fixed; top: var(--s-4); right: var(--s-4); z-index: 200; display: flex; flex-direction: column; gap: var(--s-2); }
.toast {
    display: flex; align-items: center; gap: var(--s-2);
    min-width: 240px; max-width: 360px; padding: var(--s-3) var(--s-4);
    background: var(--bg-elev); border: 1px solid var(--border-strong); border-left: 3px solid var(--text-muted);
    border-radius: var(--radius); box-shadow: var(--shadow-elev); font-size: 13px;
    animation: toast-in .18s ease;
}
.toast-success { border-left-color: var(--accent); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
@keyframes toast-in { from { opacity: 0; transform: translateX(8px); } to { opacity: 1; transform: none; } }

/* ============================================================================
   Modal
   ========================================================================== */
.modal-overlay {
    position: fixed; inset: 0; z-index: 150; background: rgba(0, 0, 0, .55);
    display: grid; place-items: center; padding: var(--s-4);
    opacity: 0; pointer-events: none; transition: opacity .15s ease;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
    width: 100%; max-width: 420px; background: var(--bg-elev);
    border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
    box-shadow: var(--shadow-elev); padding: var(--s-6);
    transform: translateY(8px); transition: transform .15s ease;
}
.modal-overlay.open .modal { transform: none; }
.modal h3 { font-size: 16px; margin-bottom: var(--s-2); }
.modal p { color: var(--text-muted); font-size: 13px; margin: 0 0 var(--s-6); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s-2); }

/* ============================================================================
   Dashboard-home specific
   ========================================================================== */
.dash-cols { display: grid; grid-template-columns: 2fr 1fr; gap: var(--s-6); align-items: start; }
.attn-item { display: flex; gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--border); }
.attn-item:last-child { border-bottom: none; }
.attn-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.attn-dot.warn { background: var(--warning); }
.attn-dot.info { background: var(--info); }
.attn-title { font-size: 13px; font-weight: 600; }
.attn-sub { font-size: 12px; color: var(--text-muted); }

/* ============================================================================
   Settings layout
   ========================================================================== */
.settings-layout { display: grid; grid-template-columns: 200px 1fr; gap: var(--s-6); align-items: start; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--tb-h) + var(--s-6)); }
.settings-nav a {
    padding: var(--s-2) var(--s-3); border-radius: var(--radius-sm); font-size: 13px; font-weight: 500;
    color: var(--text-muted); transition: .15s ease;
}
.settings-nav a:hover { background: var(--bg-hover); color: var(--text); }
.settings-nav a.is-active { background: var(--accent-soft); color: var(--accent); }
.settings-section { max-width: 620px; }
.settings-block { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s-6); margin-bottom: var(--s-6); }
.settings-block h2 { font-size: 15px; margin-bottom: var(--s-1); }
.settings-block .block-sub { color: var(--text-muted); font-size: 13px; margin-bottom: var(--s-4); }
.block-danger { border-color: var(--danger-soft); }
.block-danger h2 { color: var(--danger); }

/* Avatar uploader */
.avatar-upload { display: flex; align-items: center; gap: var(--s-4); margin-bottom: var(--s-4); }
.avatar-drop { position: relative; cursor: pointer; border-radius: 50%; }
.avatar-drop input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.avatar-overlay {
    position: absolute; inset: 0; border-radius: 50%; display: grid; place-items: center;
    background: rgba(0, 0, 0, .5); color: #fff; opacity: 0; transition: opacity .15s ease; pointer-events: none;
    font-size: 11px; text-align: center; gap: 2px;
}
.avatar-drop:hover .avatar-overlay { opacity: 1; }
.avatar-hint { font-size: 12px; color: var(--text-muted); }

/* Integration / plan stub cards */
.stub-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-4); }
.stub-card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); }
.stub-card .stub-name { font-weight: 600; font-size: 13px; }
.stub-card .stub-desc { font-size: 12px; color: var(--text-muted); flex: 1; }
.plan-current { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.plan-name { font-size: 20px; font-weight: 600; }

/* ============================================================================
   Ported legacy classes - keep existing CRUD/tool pages styled in the new system
   ========================================================================== */
.crud-layout { display: grid; grid-template-columns: 340px 1fr; gap: var(--s-6); align-items: start; }
.crud-form { position: sticky; top: calc(var(--tb-h) + var(--s-6)); }
.crud-form-wide { max-width: 620px; }
.crud-list { min-width: 0; }
.btn-block.btn { width: 100%; }
.table-scroll { overflow-x: auto; }
/* Map old .data-table to the new table look */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: var(--s-2) var(--s-3); border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tr:last-child td { border-bottom: none; }
.row-done td { opacity: .5; }
.row-actions { display: flex; gap: var(--s-3); align-items: center; white-space: nowrap; }
.row-actions form { margin: 0; display: inline; }
.link-danger { background: none; border: none; color: var(--danger); font: inherit; cursor: pointer; padding: 0; font-weight: 500; }
.link-danger:hover { text-decoration: underline; }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 var(--s-2); border-radius: var(--radius-pill); font-size: 12px; font-weight: 600; background: var(--bg-elev-2); color: var(--text-muted); }
.pill-status { background: var(--accent-soft); color: var(--accent); }
.pill-low { background: var(--bg-elev-2); color: var(--text-muted); }
.pill-normal { background: var(--info-soft); color: var(--info); }
.pill-high { background: var(--warning-soft); color: var(--warning); }
.pill-urgent { background: var(--danger-soft); color: var(--danger); }
.calc-result { border-radius: var(--radius); padding: var(--s-6); text-align: center; margin-bottom: var(--s-4); display: flex; flex-direction: column; gap: var(--s-1); }
.calc-result.is-good { background: var(--accent-soft); border: 1px solid var(--accent); }
.calc-result.is-bad { background: var(--danger-soft); border: 1px solid var(--danger); }
.calc-result-label { color: var(--text-muted); font-size: 13px; }
.calc-result-value { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; }
.calc-result.is-good .calc-result-value { color: var(--accent); }
.calc-result-tag { font-weight: 600; font-size: 13px; }
.calc-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-3); }
.calc-metric { background: var(--bg-elev-2); border-radius: var(--radius-sm); padding: var(--s-3); text-align: center; }
.calc-metric span { display: block; color: var(--text-muted); font-size: 12px; margin-bottom: var(--s-1); }
.calc-metric strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.calc-hint { color: var(--text-muted); font-size: 12px; margin-top: var(--s-3); }
.content-library { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-4); }
.content-item { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s-4); background: var(--bg-elev-2); }
.content-item header { display: flex; align-items: center; gap: var(--s-2); margin-bottom: var(--s-3); }
.content-body { white-space: pre-wrap; word-break: break-word; font-size: 13px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--s-3); max-height: 220px; overflow: auto; margin: 0 0 var(--s-3); }
.content-item footer { display: flex; gap: var(--s-3); }

/* ============================================================================
   Command-center dashboard (screenshot layout)
   ========================================================================== */
/* Colored icon tiles */
.ic-green  { background: rgba(22,163,74,.12);  color: #16a34a; }
.ic-blue   { background: rgba(37,99,235,.12);  color: #2563eb; }
.ic-purple { background: rgba(124,58,237,.12); color: #7c3aed; }
.ic-orange { background: rgba(245,158,11,.14); color: #f59e0b; }
.ic-red    { background: rgba(239,68,68,.12);  color: #ef4444; }
.spark-green { color: #16a34a; } .spark-blue { color: #2563eb; }
.spark-purple { color: #7c3aed; } .spark-orange { color: #f59e0b; }
.spark-red { color: #ef4444; }

/* Header */
.dash-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-4); margin-bottom: var(--s-6); flex-wrap: wrap; }
.dash-greeting { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.dash-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.date-pill { display: inline-flex; align-items: center; gap: var(--s-2); padding: var(--s-2) var(--s-3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-elev); font-size: 13px; font-weight: 500; color: var(--text-muted); }

/* KPI grid */
.kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--s-3); margin-bottom: var(--s-4); }
.kpi-card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s-4); display: flex; flex-direction: column; gap: var(--s-2); position: relative; overflow: hidden; }
.kpi-top { display: flex; align-items: center; gap: var(--s-2); }
.kpi-ic { width: 30px; height: 30px; border-radius: var(--radius-sm); display: grid; place-items: center; flex-shrink: 0; }
.kpi-name { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.kpi-num { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.kpi-trend { font-size: 11px; display: flex; align-items: center; gap: 5px; }
.kpi-spark { width: 100%; height: 30px; margin-top: auto; }
.trend.up { color: #16a34a; font-weight: 600; } .trend.down { color: #ef4444; font-weight: 600; }
.kpi-insights { background: linear-gradient(180deg, rgba(124,58,237,.06), transparent); }
.kpi-new { margin-left: auto; font-size: 10px; font-weight: 700; color: #7c3aed; background: rgba(124,58,237,.12); padding: 2px 7px; border-radius: var(--radius-pill); text-transform: uppercase; }
.kpi-insight-text { font-size: 12px; color: var(--text-muted); margin: 0; flex: 1; }

/* Bento rows */
.bento { display: grid; gap: var(--s-4); margin-bottom: var(--s-4); align-items: start; }
.bento-8-4 { grid-template-columns: 2fr 1fr; }
.bento-7-5 { grid-template-columns: 1.4fr 1fr; }
.bento-3 { grid-template-columns: repeat(3, 1fr); }
.rail { display: flex; flex-direction: column; gap: var(--s-4); }
.rail .panel { margin: 0; }
.mini-select, .mini-link { font-size: 12px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 4px; }
.mini-select { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 4px var(--s-2); }

/* Profit overview */
.profit-body { display: grid; grid-template-columns: 1.6fr 1fr; gap: var(--s-4); }
.profit-total { margin-bottom: var(--s-2); }
.profit-total strong { font-size: 20px; font-weight: 700; }
.linechart { width: 100%; height: 180px; }
.chart-x { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.profit-donut { display: flex; flex-direction: column; align-items: center; gap: var(--s-2); }

/* Donuts */
.donut { width: 130px; height: 130px; border-radius: 50%; display: grid; place-items: center; position: relative; flex-shrink: 0; }
.donut-sm { width: 120px; height: 120px; }
.donut-hole { width: 66%; height: 66%; background: var(--bg-elev); border-radius: 50%; display: grid; place-items: center; text-align: center; }
.donut-hole strong { font-size: 18px; font-weight: 700; display: block; }
.donut-hole span { font-size: 10px; color: var(--text-muted); }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 12px; }
.legend li { display: flex; align-items: center; gap: var(--s-2); color: var(--text-muted); }
.legend li b { margin-left: auto; color: var(--text); font-variant-numeric: tabular-nums; }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* Expense cards */
.expense-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-2); margin-top: var(--s-4); }
.expense-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--s-3); display: flex; flex-direction: column; gap: 2px; }
.expense-card strong { font-size: 15px; }
.expense-card .trend { font-size: 11px; }

/* Alerts */
.alert-list { list-style: none; margin: 0; padding: 0; }
.alert-item { display: flex; align-items: flex-start; gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--border); }
.alert-item:last-child { border-bottom: none; }
.alert-ic { width: 26px; height: 26px; border-radius: var(--radius-sm); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.alert-danger { background: rgba(239,68,68,.12); color: #ef4444; }
.alert-warning { background: rgba(245,158,11,.14); color: #f59e0b; }
.alert-info { background: rgba(37,99,235,.12); color: #2563eb; }
.alert-success { background: rgba(22,163,74,.12); color: #16a34a; }
.alert-title { font-size: 13px; font-weight: 600; }
.alert-sub { font-size: 12px; color: var(--text-muted); }
.alert-time { margin-left: auto; font-size: 11px; color: var(--text-faint); white-space: nowrap; }

/* Quick actions + upsell */
.qa-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s-2); }
.qa { display: flex; flex-direction: column; align-items: center; gap: var(--s-2); padding: var(--s-3) var(--s-1); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 11px; text-align: center; color: var(--text-muted); }
.qa:hover { background: var(--bg-hover); color: var(--text); }
.qa-ic { width: 32px; height: 32px; border-radius: var(--radius-sm); display: grid; place-items: center; }
.upsell { text-align: center; }
.upsell-rocket { font-size: 26px; }
.upsell h3 { font-size: 14px; margin: var(--s-2) 0; }
.upsell p { font-size: 12px; color: var(--text-muted); margin-bottom: var(--s-4); }

/* Winning products list */
.win-list { list-style: none; margin: 0; padding: 0; }
.win-item { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) 0; border-bottom: 1px solid var(--border); }
.win-item:last-child { border-bottom: none; }
.win-thumb { width: 34px; height: 34px; border-radius: var(--radius-sm); flex-shrink: 0; }
.win-meta { flex: 1; min-width: 0; }
.win-name { font-size: 13px; font-weight: 600; }
.win-sub { font-size: 11px; color: var(--text-muted); }
.win-spark { width: 70px; height: 28px; flex-shrink: 0; }
.win-score { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--accent); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.win-all { display: inline-block; margin-top: var(--s-3); font-size: 12px; color: var(--accent); font-weight: 600; }

/* Research insights */
.research-banner { font-size: 12px; font-weight: 600; color: #f59e0b; margin-bottom: var(--s-2); }
.research-list { list-style: none; margin: 0; padding: 0; }
.research-list li { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-2) 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.research-list li:last-child { border-bottom: none; }
.r-rank { width: 18px; color: var(--text-faint); font-weight: 600; }
.r-name { flex: 1; font-weight: 500; }
.r-score { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--accent); color: var(--accent); display: grid; place-items: center; font-size: 11px; font-weight: 700; }

/* Store health + orders-by-status shared row */
.health-row { display: flex; align-items: center; gap: var(--s-6); }
.ring { position: relative; width: 130px; height: 130px; flex-shrink: 0; }
.ring svg { width: 100%; height: 100%; }
.ring-center { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.ring-center strong { font-size: 26px; font-weight: 700; display: block; }
.ring-center span { font-size: 11px; color: var(--accent); font-weight: 600; }
.health-items { list-style: none; margin: 0; padding: 0; flex: 1; }
.health-items li { display: flex; align-items: center; gap: var(--s-2); padding: 5px 0; font-size: 13px; }
.health-items li b { margin-left: auto; color: var(--text-muted); font-weight: 500; font-size: 12px; }

/* Daily action feed */
.action-feed { list-style: none; margin: 0; padding: 0; }
.action-feed li { display: flex; gap: var(--s-3); padding: var(--s-2) 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.action-feed li:last-child { border-bottom: none; }
.af-ic { width: 24px; height: 24px; border-radius: var(--radius-sm); display: grid; place-items: center; flex-shrink: 0; font-size: 11px; }
.af-text { line-height: 1.45; }

/* Suppliers row */
.supplier-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--s-3); }
.supplier-card { display: flex; align-items: center; gap: var(--s-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--s-3); }
.supplier-ic { width: 32px; height: 32px; border-radius: var(--radius-sm); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.supplier-name { font-size: 13px; font-weight: 600; }
.supplier-rating { color: #f59e0b; font-size: 12px; }
.supplier-sub { font-size: 11px; color: var(--text-muted); }

/* Roadmap (module pages) */
.roadmap-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s-6); }
.roadmap-col h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); margin-bottom: var(--s-2); }
.roadmap-col ul { list-style: none; margin: 0; padding: 0; }
.roadmap-col li { font-size: 13px; padding: 5px 0 5px 20px; position: relative; color: var(--text-muted); }
.roadmap-col li::before { content: "○"; position: absolute; left: 0; color: var(--accent); }

/* Order status pills */
.badge-paid { background: var(--info-soft); color: var(--info); }
.badge-sent { background: var(--warning-soft); color: var(--warning); }
.badge-fulfilled { background: rgba(124,58,237,.14); color: #7c3aed; }
.badge-shipped { background: rgba(37,99,235,.14); color: #2563eb; }
.badge-delivered { background: var(--accent-soft); color: var(--accent); }
.badge-cancelled { background: var(--bg-elev-2); color: var(--text-muted); }
.badge-refunded { background: var(--danger-soft); color: var(--danger); }

/* Order form */
.order-form .panel { margin-bottom: var(--s-4); }
.form-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s-4); }
.form-2col .form-row:last-child { grid-column: 1 / -1; }  /* notes spans full width */
.items-table td { padding: var(--s-2) var(--s-1); height: auto; }
.items-table .form-input, .items-table .form-select { height: 32px; }
.item-del { text-align: center; }
.del-check { display: inline-flex; align-items: center; gap: 3px; color: var(--danger); font-size: 12px; cursor: pointer; }

/* Profit cost strip */
.cost-strip { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3); }
.cost-strip > div { display: flex; flex-direction: column; }
.cost-strip strong { font-size: 16px; }
.cost-op { color: var(--text-faint); font-size: 18px; }

/* Sidebar additions */
.sb-brand { display: flex; flex-direction: column; line-height: 1.1; }
.sb-subtitle { font-size: 11px; color: var(--accent); font-weight: 600; }
.sb-badge { margin-left: auto; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: var(--radius-pill); }
body.sidebar-collapsed .sb-badge { display: none; }
.pro-card { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s-3); margin-bottom: var(--s-2); }
.pro-head { display: flex; align-items: center; gap: var(--s-2); font-size: 13px; font-weight: 600; color: var(--accent); }
.pro-sub { font-size: 11px; color: var(--text-muted); margin: 2px 0 var(--s-2); }
.pro-meter { height: 6px; background: var(--bg-elev-2); border-radius: var(--radius-pill); overflow: hidden; }
.pro-meter span { display: block; height: 100%; background: var(--accent); }
.pro-credits { font-size: 11px; color: var(--text-muted); margin: 6px 0 var(--s-2); }
.pro-btn { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pro-btn:hover { background: var(--accent); color: var(--accent-fg); }
body.sidebar-collapsed .pro-card { display: none; }

@media (max-width: 1200px) {
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
    .bento-8-4, .bento-7-5 { grid-template-columns: 1fr; }
    .bento-3 { grid-template-columns: 1fr; }
    .supplier-row { grid-template-columns: repeat(2, 1fr); }
    .roadmap-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .kpi-grid { grid-template-columns: 1fr 1fr; }
    .profit-body { grid-template-columns: 1fr; }
    .qa-grid, .expense-cards { grid-template-columns: 1fr 1fr; }
    .supplier-row { grid-template-columns: 1fr; }
}

/* ============================================================================
   Responsive
   ========================================================================== */
.scrim { display: none; }
@media (max-width: 1024px) {
    .kpi-row { grid-template-columns: repeat(2, 1fr); }
    .dash-cols { grid-template-columns: 1fr; }
    .crud-layout { grid-template-columns: 1fr; }
    .crud-form { position: static; }
    .content-library { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
    .app-sidebar { transform: translateX(-100%); width: var(--sb-w); }
    body.drawer-open .app-sidebar { transform: none; box-shadow: var(--shadow-elev); }
    body.sidebar-collapsed .app-sidebar { width: var(--sb-w); }      /* drawer is full on mobile */
    body.sidebar-collapsed .sb-label, body.sidebar-collapsed .sb-group-label,
    body.sidebar-collapsed .sb-wordmark, body.sidebar-collapsed .sb-user-meta { display: block; }
    .app-main { margin-left: 0; }
    body.sidebar-collapsed .app-main { margin-left: 0; }
    .tb-burger { display: grid; }
    .sb-collapse { display: none; }
    .tb-search { display: none; }
    body.drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.5); }
    .settings-layout { grid-template-columns: 1fr; }
    .settings-nav { position: static; flex-direction: row; overflow-x: auto; }
    .kpi-row { grid-template-columns: 1fr 1fr; }
    .field-grid, .calc-metrics, .stub-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
    .kpi-row { grid-template-columns: 1fr; }
    .app-content { padding: var(--s-4); }
}
