/* Subscription Dashboard — light/dark, no external dependencies. */

:root {
  color-scheme: light;
  --plane:          #f9f9f7;
  --surface:        #fcfcfb;
  --surface-2:      #f3f3f0;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --border-strong:  rgba(11,11,11,0.18);

  --series-1: #2a78d6;   /* blue   */
  --series-2: #eb6834;   /* orange */
  --series-3: #1baf7a;   /* aqua   */
  --series-4: #eda100;   /* yellow */

  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;

  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --shadow: 0 1px 2px rgba(11,11,11,0.05), 0 1px 3px rgba(11,11,11,0.04);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:          #0d0d0d;
    --surface:        #1a1a19;
    --surface-2:      #232322;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255,255,255,0.10);
    --border-strong:  rgba(255,255,255,0.20);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --good-ink: #0ca30c;
    --accent:   #3987e5;
    --shadow: 0 1px 2px rgba(0,0,0,0.4);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:          #0d0d0d;
  --surface:        #1a1a19;
  --surface-2:      #232322;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #898781;
  --grid:           #2c2c2a;
  --axis:           #383835;
  --border:         rgba(255,255,255,0.10);
  --border-strong:  rgba(255,255,255,0.20);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --good-ink: #0ca30c;
  --accent:   #3987e5;
  --shadow: 0 1px 2px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--plane);
  color: var(--text-primary);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }

/* ---------- shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 216px; flex: 0 0 216px;
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 9px; padding: 0 8px 18px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px; flex: 0 0 28px;
  background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.brand-name { font-weight: 600; font-size: 14px; line-height: 1.2; }
.brand-sub { font-size: 11px; color: var(--text-muted); }
.brand-link { display: inline-flex; align-items: center; }
.brand-logo { height: 26px; width: auto; max-width: 100%; object-fit: contain; display: block; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.nav-group { margin-bottom: 14px; }
.nav-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--text-muted); padding: 0 8px 6px; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 7px; color: var(--text-secondary);
  font-size: 13px; margin-bottom: 1px;
}
.nav a:hover { background: var(--surface-2); color: var(--text-primary); text-decoration: none; }
.nav a.active { background: var(--surface-2); color: var(--text-primary); font-weight: 600; }
.nav a .ico { width: 16px; text-align: center; opacity: 0.75; flex: 0 0 16px; }
.nav a .pill {
  margin-left: auto; font-size: 10px; font-weight: 700; padding: 1px 6px;
  border-radius: 99px; background: var(--critical); color: #fff;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 22px;
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 12px; color: var(--text-secondary); text-align: right; line-height: 1.3; }
.topbar .who b { color: var(--text-primary); display: block; font-weight: 600; }
.content { padding: 22px; max-width: 1320px; width: 100%; }
.page-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--text-secondary); font-size: 13px; margin-top: 3px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border);
}
.card-head .sub { font-size: 12px; color: var(--text-muted); font-weight: 400; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }
.card-body.tight { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.split-7-5 { grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); }

/* ---------- stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 15px; box-shadow: var(--shadow);
}
.stat .k {
  font-size: 11px; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.05em; font-weight: 600; margin-bottom: 7px;
}
.stat .v { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.stat .m { font-size: 12px; color: var(--text-secondary); margin-top: 5px; }
.stat .m .up   { color: var(--good-ink); font-weight: 600; }
.stat .m .down { color: var(--critical); font-weight: 600; }
.stat.alert { border-color: var(--critical); }
.stat.alert .v { color: var(--critical); }

/* ---------- tables ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); font-weight: 600; padding: 9px 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface);
}
table.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr:hover { background: var(--surface-2); }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl .muted { color: var(--text-muted); }
table.tbl .strong { font-weight: 600; }
.table-wrap { overflow-x: auto; }
tfoot td { font-weight: 600; border-top: 2px solid var(--axis); background: var(--surface-2); }

/* ---------- badges & buttons ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-good     { color: var(--good-ink);  background: rgba(12,163,12,0.10);  border-color: rgba(12,163,12,0.25); }
.badge-info     { color: var(--accent);    background: rgba(42,120,214,0.10); border-color: rgba(42,120,214,0.25); }
.badge-warning  { color: #8a5b00;          background: rgba(250,178,25,0.14); border-color: rgba(250,178,25,0.35); }
.badge-critical { color: var(--critical);  background: rgba(208,59,59,0.10);  border-color: rgba(208,59,59,0.25); }
.badge-neutral  { color: var(--text-secondary); background: var(--surface-2); border-color: var(--border); }
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .badge-warning { color: var(--warning); }
}
:root[data-theme="dark"] .badge-warning { color: var(--warning); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 7px 13px; border-radius: 8px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-primary); cursor: pointer; font-family: inherit; line-height: 1.4;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-danger { color: var(--critical); border-color: rgba(208,59,59,0.4); }
.btn-danger:hover { background: rgba(208,59,59,0.08); }
.btn-sm { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.field .hint { font-size: 11px; color: var(--text-muted); }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=file], select, textarea {
  font: inherit; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-primary); width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent);
}
textarea { min-height: 76px; resize: vertical; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.inline-form { display: inline; }
.filters {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.filters .field { min-width: 140px; }

/* ---------- flash / callouts ---------- */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; border: 1px solid; display: flex; gap: 8px; }
.flash-ok    { background: rgba(12,163,12,0.08);  border-color: rgba(12,163,12,0.3);  color: var(--good-ink); }
.flash-err   { background: rgba(208,59,59,0.08);  border-color: rgba(208,59,59,0.3);  color: var(--critical); }
.flash-warn  { background: rgba(250,178,25,0.10); border-color: rgba(250,178,25,0.35); color: var(--text-primary); }
.flash-info  { background: rgba(42,120,214,0.08); border-color: rgba(42,120,214,0.3); color: var(--text-primary); }
.note { font-size: 12px; color: var(--text-secondary); }
.empty { padding: 34px 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* ---------- charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axisline { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 11px; }
.chart .bar { transition: opacity 0.12s; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart .bar.hl { opacity: 0.78; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-secondary); padding: 0 16px 12px; }
.chart-legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: -1px; }
.tip {
  position: absolute; pointer-events: none; opacity: 0; transition: opacity 0.1s;
  background: var(--text-primary); color: var(--plane); font-size: 12px; line-height: 1.45;
  padding: 6px 9px; border-radius: 7px; white-space: nowrap; z-index: 30;
  transform: translate(-50%, -100%); box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}
.tip b { font-variant-numeric: tabular-nums; }

/* horizontal labelled bars — direct labels satisfy the contrast relief rule */
.hbar { display: flex; flex-direction: column; gap: 13px; }
.hbar .row .lab { display: flex; font-size: 13px; margin-bottom: 5px; align-items: baseline; }
.hbar .row .lab .n { font-weight: 500; }
.hbar .row .lab .v { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.hbar .row .lab .s { color: var(--text-muted); font-size: 12px; margin-left: 8px; }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 5px; }

.toolbar-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); padding: 0 16px; }
.toolbar-tabs a {
  padding: 10px 13px; font-size: 13px; color: var(--text-secondary);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.toolbar-tabs a:hover { color: var(--text-primary); text-decoration: none; }
.toolbar-tabs a.active { color: var(--text-primary); font-weight: 600; border-bottom-color: var(--accent); }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 7px 18px; font-size: 13px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .card-body { padding: 26px; }

/* ---------- print (invoices) ---------- */
@media print {
  .sidebar, .topbar, .page-head .actions, .no-print { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #ccc; }
  .content { padding: 0; }
}

@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid.cols-3, .grid.cols-4, .grid.split-7-5 { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; border-right: none; border-bottom: 1px solid var(--border); }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .nav-group { margin-bottom: 8px; }
  .grid.cols-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 14px; }
}
