/* DRFX Control Center — customer + admin UI.
   Palette per PROJECT-SPEC (navy base, emerald = running/OK, red = risk/close, gold = brand).
   One loud element per page: the state plate. Everything else stays quiet. */

:root {
  color-scheme: dark;
  --bg: #070d1a;
  --surface: #0e1729;
  --surface-2: #162238;
  --surface-3: #1c2b45;
  --line: #263650;
  --line-strong: #3a4d6d;
  --ink: #f3efe6;
  --ink-soft: #c9cfda;
  --muted: #8e9bb3;
  --gold: #d9b66a;
  --gold-deep: #b8923f;
  --green: #2ed38d;
  --green-ink: #0a2a1d;
  --green-dim: #123426;
  --red: #ff6b7a;
  --red-dim: #3a1c25;
  --amber: #f0b64a;
  --amber-dim: #3a2e14;
  --blue: #6fa8ff;
  --blue-dim: #16284a;
  --r-s: 8px;
  --r-m: 14px;
  --r-l: 22px;
  --font: "Leelawadee UI", "Segoe UI", "Noto Sans Thai", "Sukhumvit Set", "Thonburi", Tahoma, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Noto Sans Mono", monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 var(--font);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, p, ul, ol { margin: 0; }
h1 { font-size: 30px; line-height: 1.25; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 19px; line-height: 1.35; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
a { color: var(--gold); }
button, input, select, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 13px; }
.strong { font-weight: 700; }
.gold { color: var(--gold); }
.positive { color: var(--green); }
.negative { color: var(--red); }
.warn { color: var(--amber); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }
.mt { margin-top: 14px; }
.mt-l { margin-top: 24px; }
.mono { font-family: var(--mono); }
.desktop-only { display: initial; }
.mobile-only { display: none; }

/* ---------- buttons ---------- */
button {
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  border-radius: var(--r-s);
  padding: 10px 16px;
  font-size: 15px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  transition: background .12s, border-color .12s;
}
button:hover { background: var(--surface-3); }
button:disabled { opacity: .45; cursor: not-allowed; }
button[aria-busy="true"] { cursor: progress; }
button.primary { background: var(--gold); border-color: var(--gold); color: #1a150a; }
button.primary:hover { background: #e6c57c; }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.outline { background: transparent; }
button.danger { background: var(--red-dim); border-color: #6b3441; color: var(--red); }
button.danger:hover { background: #4a2430; }
button.text { background: none; border: 0; padding: 0; min-height: 0; color: var(--gold); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }
button.icon-btn { padding: 9px; min-height: 0; }
svg.icon { width: 20px; height: 20px; flex-shrink: 0; stroke: currentColor; stroke-width: 1.7; fill: none; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; margin-top: 14px; }
.field label { font-size: 14px; color: var(--ink-soft); font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-s);
  padding: 11px 13px;
  min-height: 46px;
}
.field input:focus, .field select:focus { border-color: var(--gold); outline: none; }
.field input[readonly] { color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); line-height: 1.5; }
.form-error { color: var(--red); font-size: 14px; min-height: 22px; margin-top: 8px; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; font-size: 15px; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 3px 0 0; accent-color: var(--gold); flex-shrink: 0; }
.radio-group { display: grid; gap: 10px; margin-top: 10px; }
.radio-card { display: grid; grid-template-columns: 22px 1fr; gap: 12px; align-items: start; padding: 14px; border: 1px solid var(--line); border-radius: var(--r-m); cursor: pointer; background: var(--surface-2); }
.radio-card:has(input:checked) { border-color: var(--gold); background: #1f2638; }
.radio-card input { margin: 3px 0 0; width: 20px; height: 20px; accent-color: var(--gold); }
.radio-card strong { display: block; }
.radio-card span { font-size: 14px; color: var(--muted); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); padding: 24px 18px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; min-width: 0; overflow: hidden; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(145deg, #f0d089, var(--gold-deep)); color: #1a150a; display: grid; place-items: center; font-weight: 800; font-size: 20px; }
.brand-name { font-weight: 800; letter-spacing: .04em; font-size: 17px; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--muted); letter-spacing: .12em; }
.nav { display: grid; gap: 4px; }
.nav button { justify-content: flex-start; background: transparent; border-color: transparent; color: var(--ink-soft); font-weight: 600; padding: 11px 12px; }
.nav button:hover { background: var(--surface-2); }
.nav button.active { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.side-bottom { margin-top: auto; display: grid; gap: 14px; }
.side-card { border: 1px solid var(--line); border-radius: var(--r-m); padding: 12px 14px; font-size: 14px; min-width: 0; }
.side-card p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--surface-3); display: grid; place-items: center; font-weight: 700; font-size: 14px; color: var(--gold); flex-shrink: 0; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.content { padding: 28px; max-width: 1080px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head p { color: var(--muted); margin-top: 6px; max-width: 60ch; }
.page-footer { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.mobile-nav { display: none; }

/* ---------- surfaces ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: 22px; }
.panel.tight { padding: 16px 18px; }
.panel h2 + p, .panel h2 + .list { margin-top: 10px; }
.note { border-radius: var(--r-m); padding: 12px 14px; font-size: 14px; line-height: 1.55; border: 1px solid var(--line); background: var(--surface-2); }
.note.warn { border-color: #5a4420; background: var(--amber-dim); color: #f6d69a; }
.note.danger { border-color: #6b3441; background: var(--red-dim); color: #ffc3ca; }
.note.ok { border-color: #1f5a41; background: var(--green-dim); color: #b6f0d4; }
.note.info { border-color: #2b4a80; background: var(--blue-dim); color: #c6daff; }
.badge { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); border-radius: 999px; padding: 3px 10px; font-size: 13px; font-weight: 600; color: var(--ink-soft); white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--green); border-color: #1f5a41; background: var(--green-dim); }
.badge.pending { color: var(--amber); border-color: #5a4420; background: var(--amber-dim); }
.badge.bad { color: var(--red); border-color: #6b3441; background: var(--red-dim); }
.badge.info { color: var(--blue); border-color: #2b4a80; background: var(--blue-dim); }
.badge.quiet { color: var(--muted); }
.secret { white-space: pre-wrap; font: 15px/1.5 var(--mono); padding: 12px 14px; border: 1px dashed var(--gold-deep); border-radius: var(--r-s); background: #0b1220; overflow-wrap: anywhere; user-select: all; margin-top: 10px; color: var(--gold); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.list { display: grid; }
.list > * { padding: 14px 0; border-top: 1px solid var(--line); }
.list > :first-child { border-top: 0; padding-top: 0; }
.list > :last-child { padding-bottom: 0; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.empty { text-align: center; padding: 44px 20px; }
.empty h2 { margin-bottom: 8px; }
.empty p { color: var(--muted); margin-bottom: 20px; max-width: 46ch; margin-inline: auto; }

/* ---------- state plate (the one loud element) ---------- */
.plate {
  position: relative;
  border-radius: var(--r-l);
  padding: 26px 28px;
  border: 1px solid var(--line);
  background: var(--surface);
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px 28px;
  align-items: end;
}
.plate::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--muted); }
.plate.running::before { background: var(--green); box-shadow: 0 0 28px 2px rgba(46, 211, 141, .35); }
.plate.stopped::before { background: var(--gold); }
.plate.installing::before { background: var(--blue); }
.plate.checking::before { background: var(--amber); }
.plate.offline::before { background: var(--red); }
.plate.blocked::before { background: var(--red); }
.plate-state { font-size: 42px; line-height: 1.1; font-weight: 800; letter-spacing: -0.015em; }
.plate.running .plate-state { color: var(--green); }
.plate.stopped .plate-state { color: var(--gold); }
.plate.installing .plate-state { color: var(--blue); }
.plate.checking .plate-state { color: var(--amber); }
.plate.offline .plate-state, .plate.blocked .plate-state { color: var(--red); }
.plate-sub { color: var(--ink-soft); margin-top: 8px; font-size: 15px; max-width: 52ch; }
.plate-money { text-align: right; }
.plate-money .amount { font-size: 34px; font-weight: 800; letter-spacing: -0.01em; line-height: 1.1; }
.plate-money .label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.plate-money .pnl { margin-top: 6px; font-weight: 700; }
.plate-money.stale .amount { color: var(--muted); }

/* ---------- controls: three keys ---------- */
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 18px; }
.key {
  display: grid; justify-items: center; gap: 6px; padding: 18px 12px 14px;
  border-radius: var(--r-m); border: 1px solid var(--line-strong); background: var(--surface-2);
  min-height: 104px; font-weight: 700; font-size: 17px; line-height: 1.2;
}
.key .icon { width: 26px; height: 26px; }
.key small { font-size: 13px; font-weight: 500; color: var(--muted); text-align: center; line-height: 1.35; }
.key.start { color: var(--green); border-color: #1f5a41; background: var(--green-dim); }
.key.start:hover:not(:disabled) { background: #17442f; }
.key.stop { color: var(--ink); }
.key.close { color: var(--red); border-color: #6b3441; background: var(--red-dim); }
.key.close:hover:not(:disabled) { background: #4a2430; }
.key:disabled { opacity: .4; }
.keys-note { font-size: 13px; color: var(--muted); margin-top: 10px; line-height: 1.6; }

/* ---------- exposure ---------- */
.exposure { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 16px; }
.exposure > div { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-m); padding: 12px 14px; }
.exposure .n { font-size: 26px; font-weight: 800; line-height: 1.1; }
.exposure .l { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ---------- stepper (a real sequence) ---------- */
.stepper { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0; margin-top: 16px; counter-reset: step; }
.step { position: relative; padding: 0 8px 0 0; display: grid; gap: 8px; }
.step .bar { height: 4px; border-radius: 2px; background: var(--line); }
.step.done .bar { background: var(--green); }
.step.now .bar { background: var(--amber); }
.step.now.installing .bar { background: var(--blue); }
.step strong { font-size: 15px; }
.step span { font-size: 13px; color: var(--muted); line-height: 1.45; }
.step.now strong { color: var(--ink); }
.step:not(.done):not(.now) strong { color: var(--muted); }

/* ---------- portfolio cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: 20px; display: grid; gap: 12px; text-align: left; cursor: pointer; }
.card:hover { border-color: var(--line-strong); background: #111b30; }
.card .lamp { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.card.running .lamp { background: var(--green); box-shadow: 0 0 10px var(--green); }
.card.stopped .lamp { background: var(--gold); }
.card.installing .lamp { background: var(--blue); }
.card.checking .lamp { background: var(--amber); }
.card.offline .lamp, .card.blocked .lamp { background: var(--red); }
.card .amount { font-size: 26px; font-weight: 800; letter-spacing: -0.01em; }
.card .state-line { font-weight: 700; }
.card.running .state-line { color: var(--green); }
.card.stopped .state-line { color: var(--gold); }
.card.installing .state-line { color: var(--blue); }
.card.checking .state-line { color: var(--amber); }
.card.offline .state-line, .card.blocked .state-line { color: var(--red); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-story { padding: 48px; display: flex; flex-direction: column; gap: 36px; background: radial-gradient(1200px 600px at -10% -10%, #1a2a4a 0%, var(--bg) 60%); border-right: 1px solid var(--line); }
.login-story h1 { font-size: 40px; max-width: 18ch; }
.login-story .lede { color: var(--ink-soft); max-width: 44ch; margin-top: 14px; font-size: 17px; }
.flow { display: grid; gap: 14px; margin-top: 8px; max-width: 48ch; }
.flow div { display: grid; grid-template-columns: 30px 1fr; gap: 12px; align-items: start; color: var(--ink-soft); font-size: 15px; }
.flow b { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--gold-deep); color: var(--gold); display: grid; place-items: center; font-size: 14px; }
.login-form-wrap { display: grid; place-items: center; padding: 40px 24px; }
.login-form { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-l); padding: 30px; }
.login-form h2 { font-size: 24px; }
.login-form .primary { width: 100%; margin-top: 18px; min-height: 48px; }
.login-form .alt { margin-top: 14px; text-align: center; font-size: 14px; color: var(--muted); display: grid; gap: 8px; }

/* ---------- modal ---------- */
dialog.modal { border: 1px solid var(--line-strong); border-radius: var(--r-l); background: var(--surface); color: var(--ink); padding: 0; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog.modal::backdrop { background: rgba(3, 7, 16, .75); backdrop-filter: blur(2px); }
dialog.modal form { padding: 24px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.modal-body { display: grid; gap: 4px; }
.modal-body p { line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.modal-actions button { min-width: 120px; }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1f2a40; border: 1px solid var(--line-strong); color: var(--ink); padding: 12px 18px; border-radius: 12px; font-size: 14px; max-width: min(92vw, 560px); z-index: 50; box-shadow: 0 10px 30px rgba(0, 0, 0, .45); }

/* ---------- misc ---------- */
.back { margin-bottom: 14px; }
.mb { margin-bottom: 14px; }
.mt-xs { margin-top: 6px; }
.push-right { margin-left: auto; }
.who { min-width: 0; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.totals-line { margin: -8px 0 16px; }
.steps { padding-left: 20px; display: grid; gap: 6px; margin-top: 8px; }
code { font-family: var(--mono); font-size: 14px; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }
.result-row { display: grid; gap: 6px; }
.failure-list { padding-left: 18px; color: var(--red); font-size: 14px; }
.history-side { display: grid; justify-items: end; gap: 4px; flex-shrink: 0; font-size: 13px; color: var(--muted); }
.queue-row { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; }
.queue-row .meta { font-size: 14px; color: var(--muted); margin-top: 2px; }
details.panel summary { cursor: pointer; font-weight: 700; }
details.panel[open] summary { margin-bottom: 14px; }
.inline-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; }
.inline-form .field { margin-top: 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

@media (max-width: 920px) {
  .desktop-only { display: none; }
  .mobile-only { display: initial; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 12px 16px; }
  .content { padding: 18px 16px 96px; }
  .mobile-nav { display: grid; grid-auto-flow: column; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); z-index: 10; }
  .mobile-nav button { flex-direction: column; gap: 2px; font-size: 12px; background: transparent; border-color: transparent; color: var(--muted); padding: 8px 4px; min-height: 0; }
  .mobile-nav button.active { color: var(--gold); }
  .plate { grid-template-columns: 1fr; padding: 20px; }
  .plate-state { font-size: 32px; }
  .plate-money { text-align: left; }
  .keys { grid-template-columns: 1fr; }
  .key { grid-template-columns: 28px 1fr; justify-items: start; text-align: left; min-height: 0; padding: 14px 16px; gap: 2px 12px; }
  .key .icon { grid-row: 1 / span 2; }
  .key small { text-align: left; }
  .exposure { grid-template-columns: 1fr 1fr; }
  .stepper { grid-template-columns: 1fr; gap: 10px; }
  .step { grid-template-columns: 6px 1fr; gap: 4px 12px; }
  .step .bar { width: 6px; height: auto; grid-row: 1 / span 2; }
  .login { grid-template-columns: 1fr; }
  .login-story { padding: 28px 22px; gap: 22px; border-right: 0; }
  .login-story h1 { font-size: 30px; }
  .login-form-wrap { padding: 8px 16px 40px; }
  .login-form { padding: 22px; }
  h1 { font-size: 26px; }
  .queue-row { grid-template-columns: 1fr; }
}
