/* ============ Alvarez Team App — premium admin design system ============ */

:root {
    color-scheme: dark;
    --bg: #0d1220;
    --bg-2: #0a0f1a;
    --surface: #151d2e;
    --surface-2: #1b2436;
    --surface-hi: #202b40;
    --border: rgba(255, 255, 255, 0.07);
    --border-hi: rgba(255, 255, 255, 0.12);
    --text: #e9edf5;
    --text-2: #aab4c5;
    --text-3: #6b7688;
    --accent: #4d7cfe;
    --accent-2: #6a5cff;
    --accent-soft: rgba(77, 124, 254, 0.14);
    --grad-blue: linear-gradient(135deg, #4d7cfe, #6a5cff);
    --grad-green: linear-gradient(135deg, #22c55e, #14b8a6);
    --grad-amber: linear-gradient(135deg, #f59e0b, #f97316);
    --grad-rose: linear-gradient(135deg, #f43f5e, #e11d48);
    --grad-violet: linear-gradient(135deg, #8b5cf6, #6366f1);
    --grad-cyan: linear-gradient(135deg, #06b6d4, #3b82f6);
    --ok: #34d399; --ok-bg: rgba(52, 211, 153, 0.14);
    --warn: #fbbf24; --warn-bg: rgba(251, 191, 36, 0.15);
    --danger: #fb7185; --danger-bg: rgba(251, 113, 133, 0.14);
    --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px -12px rgba(0,0,0,0.5);
    --shadow-lg: 0 20px 48px -16px rgba(0,0,0,0.6);
    --r-xl: 20px; --r-lg: 16px; --r-md: 12px; --r-sm: 9px;
    --sidebar-w: 250px;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Inter, sans-serif;
}
:root[data-theme="light"], html[data-light] {
    color-scheme: light;
}
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        color-scheme: light;
        --bg: #eef1f7;
        --bg-2: #ffffff;
        --surface: #ffffff;
        --surface-2: #f4f6fb;
        --surface-hi: #eef2f8;
        --border: rgba(15, 23, 42, 0.08);
        --border-hi: rgba(15, 23, 42, 0.14);
        --text: #0f1a2e;
        --text-2: #55627a;
        --text-3: #8a96ab;
        --accent-soft: rgba(77, 124, 254, 0.1);
        --shadow: 0 1px 2px rgba(15,23,42,0.06), 0 10px 30px -16px rgba(15,23,42,0.18);
        --shadow-lg: 0 24px 60px -20px rgba(15,23,42,0.22);
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14.5px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border-hi); border-radius: 8px; }

/* ---------------- shell ---------------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; min-height: 100dvh; }

.sidebar {
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    padding: 18px 14px;
    position: sticky; top: 0; height: 100vh; height: 100dvh;
    overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 11px; padding: 6px 8px 20px; }
.brand-logo {
    width: 38px; height: 38px; border-radius: 11px; flex: none;
    background: var(--grad-blue); display: grid; place-items: center;
    box-shadow: 0 6px 18px -6px rgba(77,124,254,0.7);
}
.brand-logo svg { width: 21px; height: 21px; color: #fff; }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.brand-sub { font-size: 11px; color: var(--text-3); margin-top: -2px; }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); padding: 14px 10px 6px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border-radius: 11px; cursor: pointer;
    color: var(--text-2); font-size: 14.5px; font-weight: 500;
    border: none; background: none; width: 100%; text-align: left;
    transition: background 0.15s, color 0.15s;
    position: relative;
}
.nav-item svg { width: 19px; height: 19px; flex: none; }
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active::before { content: ""; position: absolute; left: -14px; top: 50%; transform: translateY(-50%); width: 3px; height: 20px; background: var(--accent); border-radius: 0 3px 3px 0; }
.nav-badge { margin-left: auto; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--grad-rose); color: #fff; display: grid; place-items: center; }
.nav-badge[hidden] { display: none; }
.sidebar-foot { padding: 12px 10px 4px; border-top: 1px solid var(--border); margin-top: 8px; font-size: 11.5px; color: var(--text-3); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20;
    height: 62px; display: flex; align-items: center; gap: 12px;
    padding: 0 24px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(160%) blur(14px);
    -webkit-backdrop-filter: saturate(160%) blur(14px);
    border-bottom: 1px solid var(--border);
}
.menu-btn, .back-btn {
    display: none; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 10px; border: none;
    background: var(--surface); color: var(--text); cursor: pointer;
}
.menu-btn svg, .back-btn svg { width: 20px; height: 20px; }
.back-btn.show { display: inline-flex; }
.breadcrumb { display: flex; align-items: center; gap: 7px; font-size: 14px; min-width: 0; overflow: hidden; }
.crumb { color: var(--text-3); white-space: nowrap; cursor: pointer; }
.crumb:hover { color: var(--text-2); }
.crumb.current { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.crumb-sep { color: var(--text-3); display: inline-flex; }
.crumb-sep svg { width: 15px; height: 15px; }
.topbar-spacer { flex: 1; }
.topbar-pill { display: flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: 13px; color: var(--text-2); }
.topbar-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.topbar-pill.offline { color: var(--danger); }
.topbar-pill.offline .dot { background: var(--danger); box-shadow: 0 0 8px var(--danger); }

/* keyboard focus visibility */
.nav-item:focus-visible, .btn:focus-visible, .seg-item:focus-visible, .nav-card:focus-visible,
.icon-btn:focus-visible, .menu-btn:focus-visible, .back-btn:focus-visible, .crumb:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, .add-row input:focus-visible { outline: none; }

.content { padding: 24px; max-width: 1120px; width: 100%; margin: 0 auto; }

/* ---------------- stat cards ---------------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 12px;
    transition: transform 0.15s, border-color 0.15s;
}
.stat-card.tappable { cursor: pointer; }
.stat-card.tappable:hover { transform: translateY(-2px); border-color: var(--border-hi); }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-ico { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; color: #fff; box-shadow: 0 8px 20px -8px rgba(0,0,0,0.5); }
.stat-ico svg { width: 22px; height: 22px; }
.ic-blue { background: var(--grad-blue); } .ic-green { background: var(--grad-green); }
.ic-amber { background: var(--grad-amber); } .ic-rose { background: var(--grad-rose); }
.ic-violet { background: var(--grad-violet); } .ic-cyan { background: var(--grad-cyan); }
.stat-num { font-size: 30px; font-weight: 750; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-2); }
.delta { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 8px; display: inline-flex; align-items: center; gap: 3px; }
.delta.up { background: var(--ok-bg); color: var(--ok); }
.delta.down { background: var(--danger-bg); color: var(--danger); }
.delta.flat { background: var(--surface-2); color: var(--text-3); }

/* ---------------- section title ---------------- */
.sec-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); margin: 22px 2px 10px; }
.sec-title:first-child { margin-top: 2px; }

/* ---------------- panel / chart ---------------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; flex-wrap: wrap; }
.panel-title { font-size: 16px; font-weight: 650; letter-spacing: -0.01em; }
.panel-sub { font-size: 12.5px; color: var(--text-3); }
.chart { width: 100%; height: 200px; display: block; }
.chart-axis { fill: var(--text-3); font-size: 10px; }
.legend { display: flex; gap: 16px; }
.legend span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

/* ---------------- nav cards (quick links) ---------------- */
.qgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.nav-card { display: flex; align-items: center; gap: 13px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px; cursor: pointer; box-shadow: var(--shadow); transition: transform 0.15s, border-color 0.15s; text-align: left; width: 100%; }
.nav-card:hover { transform: translateY(-2px); border-color: var(--border-hi); }
.nav-ico { flex: none; width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.nav-ico svg { width: 20px; height: 20px; }
.nav-ico.danger { background: var(--danger-bg); color: var(--danger); }
.nav-ico.shield { background: var(--warn-bg); color: var(--warn); }
.nav-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.nav-title { display: block; font-weight: 600; font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-sub { display: block; font-size: 12.5px; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-chev { flex: none; color: var(--text-3); display: grid; place-items: center; }
.nav-chev svg { width: 18px; height: 18px; }

/* ---------------- grouped list ---------------- */
.group { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; box-shadow: var(--shadow); }
.group-item { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border-top: 1px solid var(--border); cursor: pointer; transition: background 0.13s; }
.group-item:first-child { border-top: none; }
.group-item:hover { background: var(--surface-2); }
.gi-body { flex: 1; min-width: 0; }
.gi-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gi-sub { font-size: 12.5px; color: var(--text-3); margin-top: 1px; }
.gi-code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; word-break: break-all; }

/* ---------------- pills ---------------- */
.pill { flex: none; display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 650; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }
.pill svg { width: 12px; height: 12px; }

/* ---------------- segmented ---------------- */
.seg { display: inline-flex; gap: 3px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; margin-bottom: 18px; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg-item { min-width: max-content; padding: 8px 15px; border: none; background: none; color: var(--text-2); font-size: 13.5px; font-weight: 550; border-radius: 9px; cursor: pointer; white-space: nowrap; transition: background 0.15s, color 0.15s; }
.seg-item:hover { color: var(--text); }
.seg-item.active { background: var(--surface-hi); color: var(--text); box-shadow: var(--shadow); }

/* ---------------- forms ---------------- */
.section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 4px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.field { padding: 14px 0; border-top: 1px solid var(--border); }
.field:first-child { border-top: none; }
.field label { display: block; font-size: 12.5px; color: var(--text-2); margin-bottom: 7px; font-weight: 500; }
.field input, .field select, .add-row input {
    width: 100%; height: 44px; padding: 0 14px; font-size: 14.5px; color: var(--text);
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
    appearance: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .add-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7688' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 13px center; padding-right: 38px;
}
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 0; border-top: 1px solid var(--border); }
.row:first-child { border-top: none; }
.row-label { font-size: 14.5px; }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; cursor: pointer; background: var(--surface-hi); border: 1px solid var(--border-hi); border-radius: 999px; transition: background 0.2s; }
.slider::before { content: ""; position: absolute; height: 22px; width: 22px; left: 3px; top: 2px; background: #fff; border-radius: 50%; transition: transform 0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.3); }
.switch input:checked + .slider { background: var(--grad-green); border-color: transparent; }
.switch input:checked + .slider::before { transform: translateX(20px); }

/* ---------------- buttons ---------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 46px; padding: 0 18px; width: 100%; font-size: 15px; font-weight: 650; border: none; border-radius: 11px; cursor: pointer; transition: filter 0.15s, transform 0.12s, opacity 0.15s; }
.btn:active { transform: scale(0.99); }
.btn.primary { background: var(--grad-blue); color: #fff; box-shadow: 0 10px 24px -10px rgba(77,124,254,0.8); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.ok { background: var(--ok-bg); color: var(--ok); }
.btn.subtle { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.subtle:hover { border-color: var(--border-hi); }
.btn.sm { height: 36px; width: auto; padding: 0 15px; font-size: 13.5px; }
.btn svg { width: 17px; height: 17px; }
.btn:disabled { opacity: 0.55; cursor: default; }

.icon-btn { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 9px; background: none; border: none; color: var(--text-3); cursor: pointer; transition: background 0.13s, color 0.13s; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }
.icon-btn svg { width: 19px; height: 19px; }

.add-row { display: flex; gap: 9px; margin-bottom: 16px; align-items: stretch; }
.add-row input { flex: 1; }
.chk { display: inline-flex; align-items: center; gap: 6px; flex: none; font-size: 13px; color: var(--text-2); padding: 0 4px; }
.field textarea {
    width: 100%; min-height: 96px; padding: 12px 14px; font-size: 14.5px; color: var(--text); font-family: inherit;
    background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; resize: vertical;
}
.field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chk-list { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.chk-list input[type="checkbox"] { width: auto; height: auto; appearance: auto; }

/* ---------------- list items ---------------- */
.list { display: flex; flex-direction: column; gap: 11px; }
.item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; box-shadow: var(--shadow); }
.item-row { display: flex; align-items: center; gap: 11px; }
.item-main { flex: 1; min-width: 0; }
.item-title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.item-sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; word-break: break-word; }
.item-meta { display: flex; flex-wrap: wrap; gap: 8px; font-size: 12px; color: var(--text-3); margin-bottom: 6px; align-items: center; }
.item-meta .tag { background: var(--surface-2); padding: 2px 9px; border-radius: 7px; font-variant-numeric: tabular-nums; }

/* ---------------- bars / heatmap ---------------- */
.bar { height: 8px; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--grad-blue); border-radius: 6px; }
.heatmap-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
.heatmap { display: inline-flex; flex-direction: column; gap: 4px; }
.hm-row { display: flex; align-items: center; gap: 4px; }
.hm-label { width: 28px; flex: none; font-size: 11px; color: var(--text-3); }
.hm-cell { width: 13px; height: 13px; flex: none; border-radius: 3px; background: var(--surface-2); }

/* ---------------- empty / loading / toast ---------------- */
.empty, .error { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; color: var(--text-3); padding: 48px 20px; }
.empty svg, .error svg { width: 42px; height: 42px; opacity: 0.5; flex: none; }
.empty-title { color: var(--text); font-weight: 600; font-size: 15px; }
.error { color: var(--danger); }
.loading { display: grid; place-items: center; padding: 56px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 2.5px solid var(--border-hi); border-top-color: var(--accent); animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.note { font-size: 12.5px; color: var(--text-3); margin: 12px 2px 0; line-height: 1.55; }

.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(10px); display: flex; align-items: center; gap: 9px; background: var(--surface-hi); color: var(--text); border: 1px solid var(--border-hi); padding: 12px 18px; border-radius: 13px; font-size: 14px; font-weight: 550; box-shadow: var(--shadow-lg); z-index: 200; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast svg { width: 17px; height: 17px; }
.toast.err { color: var(--danger); }
.toast svg { color: var(--ok); }
.toast.err svg { color: var(--danger); }

/* ---------------- login ---------------- */
.login-wrap { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: var(--bg); z-index: 60; }
.login-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); padding: 30px 26px; text-align: center; }
.login-logo { width: 52px; height: 52px; border-radius: 15px; background: var(--grad-blue); display: grid; place-items: center; margin: 0 auto 16px; box-shadow: 0 10px 26px -8px rgba(77,124,254,0.7); }
.login-logo svg { width: 28px; height: 28px; color: #fff; }
.login-title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.login-sub { font-size: 13.5px; color: var(--text-3); margin: 4px 0 20px; }
.login-card .btn { margin-top: 14px; }
.login-err { color: var(--danger); font-size: 13px; margin-top: 6px; }

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 30; opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.scrim.show { opacity: 1; pointer-events: auto; }

/* ---------------- responsive ---------------- */
@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: 0; top: 0; z-index: 40; width: 264px; transform: translateX(-100%); transition: transform 0.25s cubic-bezier(0.4,0,0.2,1); box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: translateX(0); }
    .menu-btn { display: inline-flex; }
    .topbar { padding: 0 16px; }
    .content { padding: 16px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
    .stat-num { font-size: 25px; }
    .stat-ico { width: 40px; height: 40px; }
}
@media (max-width: 460px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .breadcrumb .crumb:not(.current) { display: none; }
    .breadcrumb .crumb-sep { display: none; }
}
