:root,
[data-theme="light"] {
    --bg: #f4f4f5;
    --bg-card: #ffffff;
    --bg-hover: #f4f4f5;
    --border: #e4e4e7;
    --border-strong: #d4d4d8;
    --text: #09090b;
    --text-muted: #71717a;
    --accent: #0284c7;
    --accent-hover: #0369a1;
    --accent-soft: rgba(2, 132, 199, 0.1);
    --success: #059669;
    --success-soft: rgba(5, 150, 105, 0.12);
    --danger: #e11d48;
    --danger-soft: rgba(225, 29, 72, 0.12);
    --warning: #d97706;
    --shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 16px 36px rgba(15, 23, 42, 0.14);
}

[data-theme="dark"] {
    --bg: #09090b;
    --bg-card: #141417;
    --bg-hover: #27272a;
    --border: #27272a;
    --border-strong: #3f3f46;
    --text: #fafafa;
    --text-muted: #a1a1aa;
    --accent: #0ea5e9;
    --accent-hover: #0284c7;
    --accent-soft: rgba(14, 165, 233, 0.14);
    --success: #10b981;
    --success-soft: rgba(16, 185, 129, 0.14);
    --danger: #f43f5e;
    --danger-soft: rgba(244, 63, 94, 0.14);
    --warning: #f59e0b;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 18px 44px rgba(0, 0, 0, 0.55);
}

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

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 12.5px;
    line-height: 1.35;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; background: var(--bg-hover); padding: 2px 5px; border-radius: 4px; }
input[type="checkbox"] { margin: 0; width: 14px; height: 14px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }

/* Auth */
.auth-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 12px; }
.auth-card { width: 100%; max-width: 320px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; letter-spacing: -0.02em; margin-bottom: 10px; }
.brand-icon { width: 20px; height: 20px; object-fit: contain; display: block; flex-shrink: 0; }
.auth-title { margin: 0 0 12px; font-size: 17px; font-weight: 700; }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-back { display: inline-block; margin-top: 12px; font-size: 11.5px; color: var(--text-muted); }

/* Centered Compact Shell */
.shell { max-width: 1080px; margin: 0 auto; padding: 8px 12px 24px; display: flex; flex-direction: column; gap: 8px; }

/* Compact Header: 2 clean non-wrapping rows */
.hdr { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.hdr-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: nowrap; }
.hdr-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.hdr-actions { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.brand { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; font-size: 14px; letter-spacing: -0.02em; color: var(--text); height: 28px; white-space: nowrap; }
.user-tag { display: inline-flex; align-items: center; height: 22px; font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 0 7px; border-radius: 5px; line-height: 1; white-space: nowrap; }

.hdr-sub { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: nowrap; }
.tabs { display: flex; align-items: center; gap: 2px; background: var(--bg); padding: 2px; border-radius: 7px; border: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; min-width: 0; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: none; background: transparent; color: var(--text-muted); height: 24px; padding: 0 9px; border-radius: 5px; font-size: 12px; font-weight: 500; cursor: pointer; white-space: nowrap; flex-shrink: 0; display: inline-flex; align-items: center; line-height: 1; }
.tab:hover { color: var(--text); }
.tab.active { background: var(--bg-card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

.date-pills { display: inline-flex; align-items: center; height: 28px; background: var(--bg); border: 1px solid var(--border); border-radius: 7px; padding: 2px; gap: 1px; flex-shrink: 0; }
.pill { border: none; background: transparent; color: var(--text-muted); height: 22px; padding: 0 7px; border-radius: 5px; font-size: 11px; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; line-height: 1; white-space: nowrap; }
.pill.active { background: var(--bg-card); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.07); }

.popover-wrap { position: relative; }
.date-popover {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 60;
    background: var(--bg-card); border: 1px solid var(--border-strong); border-radius: 9px;
    padding: 10px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 8px; width: 170px;
}
.date-popover[hidden] { display: none; }

.main { display: flex; flex-direction: column; gap: 8px; }

/* Uniform Controls */
.input { background: var(--bg); border: 1px solid var(--border-strong); color: var(--text); border-radius: 7px; padding: 0 9px; height: 30px; font-size: 12.5px; outline: none; }
.input:focus { border-color: var(--accent); }
.input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.input[type="number"]::-webkit-inner-spin-button,
.input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.input-xs { height: 28px; padding: 0 7px; font-size: 11.5px; border-radius: 6px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; height: 30px; padding: 0 12px; border-radius: 7px; font-size: 12px; font-weight: 600; border: 1px solid transparent; cursor: pointer; white-space: nowrap; line-height: 1; }
.btn-xs { height: 28px; padding: 0 9px; font-size: 11.5px; border-radius: 6px; }
.btn-full { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-hover); color: var(--text); border-color: var(--border-strong); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.icon-btn { width: 28px; height: 28px; padding: 0; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text-muted); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; line-height: 1; }
.icon-btn svg { width: 14px; height: 14px; display: block; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-strong); }

.muted { color: var(--text-muted); }

.icon-btn.is-syncing svg { animation: spin .7s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* Cards & Strip KPIs */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); }
.card-hdr { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 13px; font-weight: 700; line-height: 1.2; }
.card-sub { margin: 2px 0 0; font-size: 11px; color: var(--text-muted); }

.kpi-strip { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }
.kpi-chip { background: var(--bg-card); border: 1px solid var(--border); border-radius: 9px; padding: 7px 10px; display: flex; flex-direction: column; justify-content: flex-start; min-width: 0; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi-lbl { font-size: 10.5px; color: var(--text-muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.kpi-val { font-size: 17px; font-weight: 800; letter-spacing: -0.02em; margin-top: 4px; display: flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.1; min-height: 20px; }
.kpi-delta { display: inline-flex; align-items: center; justify-content: center; height: 16px; font-size: 10px; font-weight: 600; padding: 0 5px; border-radius: 4px; line-height: 1; }
.delta-up { background: var(--success-soft); color: var(--success); }
.delta-down { background: var(--danger-soft); color: var(--danger); }
.goal-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 2.5px; background: var(--bg-hover); overflow: hidden; }
.goal-fill { height: 100%; background: var(--success); }

.chart-wrap { position: relative; height: 150px; width: 100%; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }

/* Generator */
.gen-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.gen-box { display: flex; align-items: center; height: 28px; flex: 1 1 220px; background: var(--bg); border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; transition: border-color .15s; }
.gen-box:focus-within { border-color: var(--accent); }
.gen-pref { display: inline-flex; align-items: center; height: 100%; padding: 0 8px; background: var(--bg-hover); color: var(--text-muted); font-size: 11.5px; font-weight: 600; border-right: 1px solid var(--border); white-space: nowrap; user-select: none; }
.gen-inp { border: none; background: transparent; color: var(--text); height: 100%; padding: 0 8px; font-size: 12.5px; font-weight: 600; flex: 1; min-width: 70px; outline: none; }
.gen-suf { display: inline-flex; align-items: center; height: 100%; padding: 0 8px; background: var(--accent-soft); color: var(--accent); font-size: 11.5px; font-weight: 700; border-left: 1px solid var(--border); user-select: none; }
.gen-suf[hidden] { display: none; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 8px; }
.table { width: 100%; border-collapse: collapse; font-size: 12px; text-align: left; font-variant-numeric: tabular-nums; }
.table th { padding: 6px 8px; font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--bg); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; line-height: 1.3; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--bg-hover); }

.badge { display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: 999px; font-size: 10.5px; font-weight: 600; line-height: 1; vertical-align: middle; }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-muted { background: var(--bg-hover); color: var(--text-muted); }

.breakdown-list { display: flex; flex-direction: column; gap: 3px; }
.breakdown-row { display: flex; align-items: center; justify-content: space-between; font-size: 11.5px; padding: 4px 7px; background: var(--bg); border-radius: 5px; font-variant-numeric: tabular-nums; }

.checks-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(115px, 1fr)); gap: 4px; }
.check-item { display: flex; align-items: center; gap: 6px; height: 26px; padding: 0 7px; border: 1px solid var(--border); border-radius: 6px; font-size: 11.5px; cursor: pointer; background: var(--bg); }
.split-row { display: flex; gap: 5px; align-items: center; margin-bottom: 5px; }
.split-pct-wrap {
    display: inline-flex; align-items: center; height: 28px; width: 64px; padding: 0 7px; gap: 3px;
    background: var(--bg); border: 1px solid var(--border-strong); border-radius: 6px; flex-shrink: 0;
}
.split-pct-wrap:focus-within { border-color: var(--accent); }
.split-pct-inp {
    width: 100%; min-width: 0; border: none; background: transparent; color: var(--text);
    font-size: 11.5px; font-weight: 600; text-align: right; outline: none; padding: 0;
    font-variant-numeric: tabular-nums; -moz-appearance: textfield; appearance: textfield;
}
.split-pct-inp::-webkit-inner-spin-button,
.split-pct-inp::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.split-pct-suf { font-size: 11px; font-weight: 600; color: var(--text-muted); user-select: none; line-height: 1; }
.split-row .act-btn { width: 28px; height: 28px; }
.toggle-row { display: flex; align-items: center; gap: 8px; min-height: 28px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 7px; cursor: pointer; background: var(--bg); font-size: 12px; }
.field-label { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--text-muted); }

/* Action Icon Buttons */
.row-actions { display: flex; gap: 3px; align-items: center; justify-content: flex-end; }
.act-btn {
    width: 24px; height: 24px; padding: 0; border-radius: 6px;
    border: 1px solid var(--border); background: var(--bg); color: var(--text-muted);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 9.5px; font-weight: 700; flex-shrink: 0; line-height: 1;
}
.act-btn svg { width: 13px; height: 13px; display: block; }
.act-btn:hover { background: var(--bg-hover); color: var(--text); border-color: var(--border-strong); }
.act-btn.is-on { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.act-btn.is-del:hover { background: var(--danger); color: #fff; border-color: transparent; }
.act-btn-28 { width: 28px; height: 28px; }

.links-more-btn {
    margin-top: 6px; width: 100%; height: 28px; border-radius: 7px;
    border: 1px dashed var(--border-strong); background: var(--bg); color: var(--text-muted);
    font-size: 11.5px; font-weight: 600; cursor: pointer;
}
.links-more-btn:hover { background: var(--bg-hover); color: var(--text); }

/* Custom Modals */
.modal-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(9, 9, 11, 0.5); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal-box {
    width: 100%; max-width: 380px; background: var(--bg-card); border: 1px solid var(--border-strong);
    border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column; gap: 12px;
}
.modal-hdr { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modal-title { margin: 0; font-size: 14px; font-weight: 700; }
.modal-body { display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--text-muted); }
.modal-ftr { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }

.alert-error { background: var(--danger-soft); color: var(--danger); padding: 6px 8px; border-radius: 6px; font-size: 12px; margin-bottom: 8px; }
.toast-container { position: fixed; bottom: 12px; right: 12px; z-index: 300; display: flex; flex-direction: column; gap: 4px; }
.toast { background: var(--bg-card); border: 1px solid var(--border-strong); color: var(--text); padding: 7px 12px; border-radius: 8px; box-shadow: var(--shadow-lg); font-size: 12px; font-weight: 500; }
.toast-ok { border-left: 3px solid var(--success); }
.toast-err { border-left: 3px solid var(--danger); }

.loading-state { padding: 24px; text-align: center; color: var(--text-muted); }
.truncate { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: middle; }
.mobile-sub { display: none; font-size: 10.5px; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 860px) {
    .kpi-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
    .shell { padding: 6px 8px 18px; gap: 6px; }
    .hdr { padding: 7px 8px; gap: 6px; }
    .hdr-sub { flex-direction: column; align-items: stretch; gap: 5px; }
    .date-pills { width: 100%; justify-content: space-between; }
    .pill { flex: 1; justify-content: center; }
    .card { padding: 8px 10px; }
    .kpi-strip { gap: 5px; }
    .kpi-chip { padding: 6px 8px; }
    .kpi-val { font-size: 15px; }
    .chart-wrap { height: 135px; }
    .col-hide-sm { display: none; }
    .mobile-sub { display: block; }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
    .table th, .table td { padding: 5px 5px; font-size: 11px; }
}
