/* Itecpay EVs dashboard. Tokens and rules: DESIGN.md. Components use var(--token) only. */
:root {
  --bg:#F6F7F9; --surface:#FFFFFF; --surface-2:#EEF0F3; --border:#D9DDE3; --border-strong:#858C99;
  --text:#14171C; --text-2:#525866; --text-3:#646B78;
  --brand:#1F4FD1; --brand-hover:#1A43B3; --brand-soft:#E8EEFC; --on-brand:#FFFFFF;
  --success:#15803D; --success-soft:#F0F8F3;
  --warning:#B45309; --warning-soft:#FDF1E3;
  --danger:#B91C1C;  --danger-soft:#FBEAEA;
  --neutral:#5F6672; --neutral-soft:#ECEEF1;
  --focus:#1F4FD1;
  --shadow-float: 0 4px 16px rgba(0,0,0,.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0F1115; --surface:#171A20; --surface-2:#1F232B; --border:#2C313A; --border-strong:#646B7A;
    --text:#E6E8EC; --text-2:#A7ADB8; --text-3:#7E8592;
    --brand:#6E95FF; --brand-hover:#8AA9FF; --brand-soft:#1B2747; --on-brand:#0F1115;
    --success:#4ADE80; --success-soft:#12291B;
    --warning:#FBBF24; --warning-soft:#2E2410;
    --danger:#F87171;  --danger-soft:#331616;
    --neutral:#9AA1AD; --neutral-soft:#22262E;
    --focus:#8AA9FF;
    --shadow-float: 0 4px 16px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:#0F1115; --surface:#171A20; --surface-2:#1F232B; --border:#2C313A; --border-strong:#646B7A;
  --text:#E6E8EC; --text-2:#A7ADB8; --text-3:#7E8592;
  --brand:#6E95FF; --brand-hover:#8AA9FF; --brand-soft:#1B2747; --on-brand:#0F1115;
  --success:#4ADE80; --success-soft:#12291B;
  --warning:#FBBF24; --warning-soft:#2E2410;
  --danger:#F87171;  --danger-soft:#331616;
  --neutral:#9AA1AD; --neutral-soft:#22262E;
  --focus:#8AA9FF;
  --shadow-float: 0 4px 16px rgba(0,0,0,.5);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { line-height: 1.25; font-weight: 600; margin: 0; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 12px; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.hint { color: var(--text-3); font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------------ Layout */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px;
  display: flex; flex-direction: column; gap: 16px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: block; font-size: 16px; font-weight: 600; color: var(--text); padding: 4px 8px; }
.brand:hover { text-decoration: none; }
.brand span { color: var(--brand); }
.nav { display: flex; flex-direction: column; gap: 16px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 12px; font-weight: 500; color: var(--text-3); padding: 0 8px 4px; }
.nav a { color: var(--text-2); padding: 8px; border-radius: 6px; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
.sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.sidebar-foot .who { font-weight: 500; overflow-wrap: anywhere; }
.sidebar-foot .links { display: flex; gap: 16px; align-items: center; }
.sidebar-foot form { display: inline; }
.main { padding: 24px 32px 48px; max-width: 1264px; width: 100%; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; }
.page-head .row { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: 24px; }
.stack > *, .stations > *, .grid-2 > * { min-width: 0; }
.stack--16 { gap: 16px; }
.stack--8 { gap: 8px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row--between { justify-content: space-between; }
.narrow { max-width: 560px; }
.narrow-lg { max-width: 720px; }

/* ------------------------------------------------------------------ Panels, tables */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.panel-body { padding: 16px; }
.panel > .table-wrap { border-radius: 0 0 8px 8px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 24px; margin: 0; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--surface-2); color: var(--text-2); font-weight: 500; font-size: 12px; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.empty { padding: 24px 16px; color: var(--text-2); }
.empty strong { color: var(--text); }
.link-strong { font-weight: 600; }

/* ------------------------------------------------------------------ Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge--success { color: var(--success); background: var(--success-soft); }
.badge--brand   { color: var(--brand);   background: var(--brand-soft); }
.badge--warning { color: var(--warning); background: var(--warning-soft); }
.badge--danger  { color: var(--danger);  background: var(--danger-soft); }
.badge--neutral { color: var(--neutral); background: var(--neutral-soft); }
.badge--outline { color: var(--text-2); background: transparent; border: 1px solid var(--border-strong); }

/* ------------------------------------------------------------------ Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: 6px; border: 1px solid transparent;
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background-color 120ms, border-color 120ms, color 120ms;
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--brand); color: var(--on-brand); }
.btn--primary:hover { background: var(--brand-hover); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn--secondary:hover { background: var(--surface-2); }
.btn--danger { background: var(--danger); color: var(--on-brand); }
.btn--text { background: none; color: var(--brand); padding: 0 4px; height: auto; }
.btn--sm { height: 32px; padding: 0 12px; }
.btn--lg { height: 48px; padding: 0 24px; font-size: 16px; }
.btn--block { width: 100%; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .4; cursor: not-allowed; }
.inline-form { display: inline; }

/* ------------------------------------------------------------------ Forms */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label, .field > .label { font-weight: 500; font-size: 12px; color: var(--text-2); }
input[type="text"], input[type="password"], input[type="email"], input[type="number"], input[type="tel"],
input[type="date"], input[type="datetime-local"], select, textarea {
  height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px; min-width: 0; width: 100%;
}
textarea { height: auto; padding: 8px 12px; min-height: 72px; }
input[type="number"] { font-variant-numeric: tabular-nums; }
.field--error input, .field--error select { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 12px; }
.field-warning { color: var(--warning); font-size: 12px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.check input { width: 18px; height: 18px; flex: none; }
.check-list { display: flex; flex-direction: column; gap: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.action { border: 1px solid var(--border); border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.action h3 { font-size: 14px; }
.action p { margin: 0; color: var(--text-2); font-size: 12px; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.filters .field--wide { grid-column: span 2; }

/* ------------------------------------------------------------------ Alerts */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 24px; border: 1px solid transparent; }
.alert--success { background: var(--success-soft); color: var(--success); }
.alert--danger { background: var(--danger-soft); color: var(--danger); }
.alert--warning { background: var(--warning-soft); color: var(--warning); }
.alert--info { background: var(--brand-soft); color: var(--text); border-color: var(--border); }
.alert--inline { margin-bottom: 0; }
.alert code { color: var(--text); }
.secret { display: block; margin-top: 8px; padding: 8px 12px; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 6px; font-size: 14px; user-select: all; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ Summary strip, attention list */
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.summary > div { padding: 16px; border-right: 1px solid var(--border); }
.summary > div:last-child { border-right: 0; }
.summary .label { color: var(--text-2); font-size: 12px; font-weight: 500; }
.summary .value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.25; }
.attention { list-style: none; margin: 0; padding: 0; }
.attention li { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.attention li:last-child { border-bottom: 0; }
.attention .what { display: flex; flex-direction: column; }

/* ------------------------------------------------------------------ Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; margin-bottom: 24px; }
.tab { padding: 10px 12px; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; margin-bottom: -1px; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-current="page"] { color: var(--brand); border-bottom-color: var(--brand); }

/* ------------------------------------------------------------------ Stations */
.stations { display: flex; flex-direction: column; gap: 24px; }
.station-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.station-head .name { font-size: 16px; font-weight: 600; }
.connector { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.connector:last-child { border-bottom: 0; }
.connector .no { width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border-strong); display: grid; place-items: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.connector .info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.connector .info .line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.connector .act { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }

/* ------------------------------------------------------------------ New charge */
.charge-form .section { padding: 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 16px; }
.charge-form .section:last-child { border-bottom: 0; }
.charge-form .section-title { font-weight: 600; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segment {
  display: flex; flex-direction: column; gap: 4px; padding: 12px 16px; min-height: 48px;
  border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); cursor: pointer;
}
.segment-title { font-weight: 600; }
.segment-desc { font-size: 12px; color: var(--text-2); }
.segmented input:checked + .segment { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.segmented input:focus-visible + .segment { outline: 2px solid var(--focus); outline-offset: 2px; }
.chips { display: none; flex-wrap: wrap; gap: 8px; }
.js .chips { display: flex; }
.chip { height: 40px; padding: 0 16px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; font-variant-numeric: tabular-nums; cursor: pointer; }
.chip:hover { background: var(--surface-2); }
.chip.is-selected { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.info-box { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; background: var(--surface-2); display: flex; flex-direction: column; gap: 4px; }
.info-box .big { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.estimate { color: var(--text-2); font-variant-numeric: tabular-nums; min-height: 21px; }
.charge-form:has(input[name="mode"][value="prepaid"]:checked) [data-mode-only="postpaid"],
.charge-form:has(input[name="mode"][value="postpaid"]:checked) [data-mode-only="prepaid"] { display: none; }

/* ------------------------------------------------------------------ Order detail */
.stepper { display: flex; list-style: none; margin: 0; padding: 0; align-items: center; }
.step { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.step:last-child { flex: 0 0 auto; }
.step:not(:last-child)::after { content: ""; flex: 1; height: 2px; background: var(--border); margin: 0 8px; min-width: 12px; }
.step.is-done:not(:last-child)::after { background: var(--success); }
.step-dot {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--border-strong); background: var(--surface);
  display: grid; place-items: center; font-size: 12px; font-weight: 600; color: var(--text-2); flex: none; position: relative;
}
.step.is-current .step-dot { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.step.is-done .step-dot { background: var(--success); border-color: var(--success); color: var(--on-brand); }
.step.is-done .step-dot span { visibility: hidden; }
.step.is-done .step-dot::after { content: ""; position: absolute; width: 5px; height: 10px; border: solid var(--on-brand); border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }
.step.is-failed .step-dot { background: var(--danger); border-color: var(--danger); color: var(--on-brand); }
.step.is-stopped .step-dot { border-color: var(--neutral); color: var(--neutral); }
.step-label { font-weight: 500; white-space: nowrap; }
.step.is-todo .step-label, .step.is-stopped .step-label { color: var(--text-2); }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.metric { padding: 16px; border-right: 1px solid var(--border); min-width: 0; }
.metric:last-child { border-right: 0; }
.metric .label { color: var(--text-2); font-size: 12px; font-weight: 500; }
.metric .value { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; overflow-wrap: anywhere; }
.metric .note { color: var(--text-2); font-size: 12px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 12px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--text-2); font-variant-numeric: tabular-nums; }
.order-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.order-actions form { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.order-actions .field { min-width: 180px; }
.refund-box { border: 1px solid var(--border); border-radius: 8px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }

/* ------------------------------------------------------------------ Misc lists */
details summary { cursor: pointer; color: var(--brand); }
pre.raw { margin: 8px 0 0; white-space: pre-wrap; word-break: break-all; background: var(--surface-2); padding: 8px; border-radius: 4px; max-width: 640px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth .panel { width: 100%; max-width: 380px; }
.auth form { display: flex; flex-direction: column; gap: 16px; }
.auth .brand-large { font-size: 22px; font-weight: 600; }
.auth .brand-large span { color: var(--brand); }

/* Receipt */
.receipt-page { max-width: 480px; margin: 24px auto; padding: 0 16px; }
.receipt { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.receipt h1 { font-size: 20px; }
.receipt table td { padding: 6px 0; border-bottom: 1px solid var(--border); }
.receipt table td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.receipt .total td { font-weight: 600; font-size: 16px; }

/* ------------------------------------------------------------------ Responsive */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn--sm { min-height: 40px; }
  .btn--text { min-height: 0; }
  .check { min-height: 44px; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--border); padding: 12px 16px; gap: 8px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  .nav-group { flex-direction: row; gap: 4px; }
  .nav-label { display: none; }
  .nav a { white-space: nowrap; padding: 8px 12px; }
  .sidebar-foot { flex-direction: row; justify-content: space-between; align-items: center; margin-top: 0; padding-top: 8px; flex-wrap: wrap; }
  .main { padding: 16px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric:nth-child(2) { border-right: 0; }
  .metric:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .summary > div:nth-child(2n) { border-right: 0; }
  .summary > div { border-bottom: 1px solid var(--border); }
  .filters .field--wide { grid-column: auto; }
  .timeline li { grid-template-columns: 1fr; gap: 0; }
  .connector { grid-template-columns: 32px minmax(0, 1fr); }
  .connector .act { grid-column: 1 / -1; justify-content: stretch; }
  .connector .act .btn, .connector .act form { flex: 1; }
  .connector .act form .btn { width: 100%; }
  .order-actions form, .order-actions .field { width: 100%; }
  .order-actions .btn { width: 100%; }
}
@media (max-width: 480px) {
  h1 { font-size: 20px; }
  .segmented { grid-template-columns: 1fr; }
  .step-label { font-size: 13px; }
  .metric .value { font-size: 24px; }
}
@media print {
  .sidebar, .no-print { display: none !important; }
  .app { display: block; }
  body { background: #fff; color: #000; }
  .main { padding: 0; max-width: none; }
  .receipt, .panel { border-color: #999; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; }

.page-title { font-variant-numeric: tabular-nums; }
.compact-note { padding: 12px 16px; color: var(--text-2); }

.pay-list { list-style: none; margin: 0; padding: 0; }
.pay-list li { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.pay-list li:last-child { border-bottom: 0; }
.pay-main { display: flex; justify-content: space-between; gap: 12px; }
.pay-sub { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.info-box .hint, th .hint, .summary .hint { color: var(--text-2); }
