/* ------------------------------------------------------------------ *
   styles.css — a trading dashboard that has to be readable at 09:15 on a
   phone and at 15:25 on a laptop.

   Dark by default because that is where this thing lives; the light theme is
   a real theme, not an inversion, for anyone reading it outdoors.
 * ------------------------------------------------------------------ */

:root {
  --bg:        #0a0d13;
  --bg-2:      #10151f;
  --panel:     #121826;
  --panel-2:   #171e2e;
  --line:      #1f2839;
  --line-2:    #2a3547;
  --text:      #e8edf7;
  --muted:     #8494ad;
  --faint:     #5b6980;

  --up:        #25d07d;
  --up-dim:    #25d07d22;
  --down:      #ff5f6d;
  --down-dim:  #ff5f6d22;
  --warn:      #ffb020;
  --warn-dim:  #ffb02022;
  --accent:    #4c8dff;
  --accent-dim:#4c8dff22;

  --radius:    14px;
  --radius-sm: 9px;
  --shadow:    0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.28);
  --mono:      ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans:      -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

html[data-theme="light"] {
  --bg:        #f2f4f8;
  --bg-2:      #e9edf4;
  --panel:     #ffffff;
  --panel-2:   #f6f8fc;
  --line:      #dfe5ee;
  --line-2:    #ccd5e2;
  --text:      #101725;
  --muted:     #5d6b83;
  --faint:     #8b98ad;
  --up:        #04955a;
  --up-dim:    #04955a1a;
  --down:      #d92b3f;
  --down-dim:  #d92b3f1a;
  --warn:      #b57400;
  --warn-dim:  #b574001a;
  --accent:    #1f63d6;
  --accent-dim:#1f63d61a;
  --shadow:    0 1px 2px rgba(16,23,37,.06), 0 8px 24px rgba(16,23,37,.07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }
.warnc { color: var(--warn); }

/* ------------------------------------------------------------- login --- */
.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1000px 600px at 50% -10%, var(--accent-dim), transparent 70%), var(--bg);
}
.gate-card {
  width: min(380px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}
.gate-mark { font-size: 34px; }
.gate-card h1 { font-size: 20px; margin: 10px 0 4px; letter-spacing: -.02em; }
.gate-card p { margin: 0 0 22px; font-size: 13px; }
.gate-card input {
  width: 100%; margin-bottom: 12px;
}
.gate-form { display: block; }

/* the one moment a password is on screen — big, selectable, hard to skim past */
.cred-box {
  background: var(--bg-2); border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); padding: 14px 16px; margin: 14px 0;
  display: flex; flex-direction: column; gap: 10px;
}
.cred-box > div { display: flex; align-items: baseline; gap: 14px; }
.cred-k {
  flex: 0 0 78px; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .07em; color: var(--faint); font-weight: 600;
}
.cred-v { font-size: 17px; font-weight: 600; user-select: all; word-break: break-all; }

/* ------------------------------------------------------------- team --- */
.invite-row { display: flex; gap: 8px; flex-wrap: wrap; }
.invite-row input { flex: 1 1 160px; }
.invite-row select { flex: 0 0 130px; }
@media (max-width: 620px) {
  .invite-row input, .invite-row select, .invite-row .btn { flex: 1 1 100%; }
}
.role-pill {
  font-size: 10.5px; font-weight: 650; letter-spacing: .05em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px;
}
.role-admin    { background: var(--down-dim); color: var(--down); }
.role-operator { background: var(--warn-dim); color: var(--warn); }
.role-viewer   { background: var(--accent-dim); color: var(--accent); }
.you-tag { font-size: 10.5px; color: var(--faint); margin-left: 6px; }

/* ------------------------------------------------------------ topbar --- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; white-space: nowrap; }
.brand .mark { font-size: 17px; }
.brand-text { letter-spacing: -.01em; color: var(--muted); }
.brand-text b { color: var(--text); font-weight: 650; }
.topbar-pills { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
.topbar-right { display: flex; gap: 4px; }
.clock { font-size: 13px; color: var(--muted); }

.pill {
  font-size: 11px; font-weight: 650; letter-spacing: .06em; text-transform: uppercase;
  padding: 4px 10px; border-radius: 999px;
  background: var(--up-dim); color: var(--up); border: 1px solid transparent;
  white-space: nowrap;
}
.pill.live { background: var(--down-dim); color: var(--down); }
.pill.dry  { background: var(--accent-dim); color: var(--accent); }
.pill.ghost { background: transparent; color: var(--muted); border-color: var(--line-2); }
.pill.warn { background: var(--warn-dim); color: var(--warn); }
.pill.dot::before {
  content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; margin-right: 6px; vertical-align: 1px;
  animation: beat 2s ease-in-out infinite;
}
@keyframes beat { 0%,100% { opacity: 1 } 50% { opacity: .25 } }

.icon-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: transparent; border: 1px solid var(--line);
  color: var(--muted); font-size: 15px; cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-2); background: var(--panel); }

/* ----------------------------------------------------------- banners --- */
.banner {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 16px 0; padding: 10px 14px;
  border-radius: var(--radius-sm); font-size: 13px;
  border: 1px solid;
}
.banner.danger { background: var(--down-dim); border-color: var(--down); color: var(--down); }
.banner.warn   { background: var(--warn-dim); border-color: var(--warn); color: var(--warn); }
.banner.info   { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }
.banner b { font-weight: 650; }
.banner .btn { margin-left: auto; }

/* -------------------------------------------------------------- tabs --- */
.tabs {
  display: flex; gap: 2px; padding: 10px 16px 0;
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  background: transparent; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); font-size: 13.5px; font-weight: 550;
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 16px; display: flex; flex-direction: column; gap: 14px; max-width: 1500px; }
.tab-panel { display: flex; flex-direction: column; gap: 14px; }

/* ------------------------------------------------------------- cards --- */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}
.card-head h2 { font-size: 13px; font-weight: 650; margin: 0; letter-spacing: .01em; }
.card-head > .muted, .card-head > .filters { margin-left: auto; }
.card-body { padding: 16px; }
.scroll-x { overflow-x: auto; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ------------------------------------------------------------- tiles --- */
.tiles {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
}
.tile {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 15px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.tile .label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--faint); font-weight: 600; margin-bottom: 5px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile .value {
  font-family: var(--mono); font-size: 21px; font-weight: 600;
  letter-spacing: -.02em; line-height: 1.15;
}
.tile .sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.tile.hero { grid-column: span 2; }
.tile.hero .value { font-size: 30px; }
@media (max-width: 560px) { .tile.hero { grid-column: span 2; } }

/* ------------------------------------------------------------ tables --- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--faint); font-weight: 600;
  padding: 0 12px 8px; white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
td {
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.empty { padding: 26px 12px; text-align: center; color: var(--muted); font-size: 13px; }

/* -------------------------------------------------------- straddle ----- */
.legs { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
@media (max-width: 560px) { .legs { grid-template-columns: 1fr; } }
.leg {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 11px 13px;
}
.leg .sym { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.leg .px  { display: flex; align-items: baseline; gap: 8px; margin-top: 5px; }
.leg .now { font-family: var(--mono); font-size: 19px; font-weight: 600; }
.leg .en  { font-size: 12px; color: var(--faint); }
/* the % move needs its own colour and would otherwise lose to .leg .en */
.leg .en.up   { color: var(--up); }
.leg .en.down { color: var(--down); }

.meter { margin-bottom: 13px; }
.meter-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12px; margin-bottom: 5px;
}
.meter-head .k { color: var(--muted); }
.meter-head .v { font-family: var(--mono); }
.meter-track {
  height: 7px; border-radius: 4px; background: var(--bg-2);
  overflow: hidden; border: 1px solid var(--line);
}
.meter-fill { height: 100%; border-radius: 3px; transition: width .5s ease, background .3s; }

/* ------------------------------------------------------------ charts --- */
.chart { width: 100%; height: 200px; }
.chart.tall { height: 280px; }
.chart svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .empty { height: 100%; display: grid; place-items: center; }

/* ----------------------------------------------------------- buttons --- */
.btn {
  background: var(--panel-2); border: 1px solid var(--line-2);
  color: var(--text); font-size: 13px; font-weight: 550; font-family: inherit;
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); background: var(--panel); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn.danger  { background: var(--down); border-color: var(--down); color: #fff; }
.btn.danger:hover:not(:disabled) { filter: brightness(1.08); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.wide { width: 100%; }

.action-row { display: flex; flex-wrap: wrap; gap: 8px; }
.kill-row {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; margin-bottom: 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--panel-2);
}
.kill-row .kill-text { flex: 1 1 240px; font-size: 13px; }
.job-output {
  margin-top: 14px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px;
  font-family: var(--mono); font-size: 12px; line-height: 1.55;
  max-height: 300px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}

/* ------------------------------------------------------------ inputs --- */
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=search], select {
  background: var(--bg-2); border: 1px solid var(--line-2);
  color: var(--text); font-family: inherit; font-size: 13.5px;
  padding: 8px 11px; border-radius: var(--radius-sm);
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; }

.seg-row { display: flex; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 3px; }
.seg-btn {
  background: transparent; border: none; color: var(--muted);
  font-size: 12.5px; font-family: inherit; font-weight: 550;
  padding: 5px 14px; border-radius: 6px; cursor: pointer;
}
.seg-btn.active { background: var(--panel-2); color: var(--text); box-shadow: var(--shadow); }

/* ------------------------------------------------------------ config --- */
.config-groups { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 12px; margin-bottom: 4px; }
.config-groups::-webkit-scrollbar { display: none; }
.group-btn {
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--muted); font-size: 12.5px; font-family: inherit; font-weight: 550;
  padding: 6px 13px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.group-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.field {
  display: grid; grid-template-columns: 1fr 190px; gap: 8px 20px;
  align-items: start; padding: 14px 0; border-bottom: 1px solid var(--line);
}
.field:last-child { border-bottom: none; }
@media (max-width: 700px) { .field { grid-template-columns: 1fr; } }
.field .f-label { font-size: 13.5px; font-weight: 550; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.field .f-help { font-size: 12px; color: var(--muted); margin-top: 3px; grid-column: 1; }
.field .f-input { grid-row: 1 / span 2; grid-column: 2; }
@media (max-width: 700px) { .field .f-input { grid-row: auto; grid-column: 1; } }
.field .f-input input, .field .f-input select { width: 100%; }
.field.changed { background: var(--accent-dim); margin: 0 -16px; padding-left: 16px; padding-right: 16px; }
.field.risky .f-label::after {
  content: "risk"; font-size: 9.5px; letter-spacing: .07em; text-transform: uppercase;
  background: var(--warn-dim); color: var(--warn); padding: 2px 6px; border-radius: 4px; font-weight: 650;
}
.badge-ov {
  font-size: 9.5px; letter-spacing: .06em; text-transform: uppercase; font-weight: 650;
  background: var(--accent-dim); color: var(--accent); padding: 2px 6px; border-radius: 4px;
}
.days { display: flex; gap: 4px; }
.day-btn {
  flex: 1 1 0; min-width: 0; background: var(--bg-2); border: 1px solid var(--line-2);
  color: var(--muted); font-size: 11px; font-family: inherit; font-weight: 600;
  padding: 7px 2px; border-radius: var(--radius-sm); cursor: pointer; text-transform: uppercase;
}
.day-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.toggle {
  position: relative; width: 46px; height: 26px; border-radius: 999px;
  background: var(--line-2); border: none; cursor: pointer; padding: 0;
  transition: background .2s;
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform .2s;
}
.toggle.on { background: var(--accent); }
.toggle.on::after { transform: translateX(20px); }
.toggle.on.danger-on { background: var(--down); }

.sticky-bar {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin: 0 -16px -16px; padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line-2);
}
.dirty-summary { flex: 1 1 200px; font-size: 13px; }
.sticky-actions { display: flex; gap: 8px; margin-left: auto; }

/* ------------------------------------------------------------ health --- */
.check-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.check-row:last-child { border-bottom: none; }
.check-dot {
  width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: none;
  background: var(--up);
}
.check-dot.bad { background: var(--down); }
.check-dot.warn { background: var(--warn); }
.check-body { min-width: 0; }
.check-body .k { font-size: 13.5px; font-weight: 550; }
.check-body .v { font-family: var(--mono); font-size: 12.5px; color: var(--text); word-break: break-word; }
.check-body .d { font-size: 12px; color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.kv:last-child { border-bottom: none; }
.kv .v { font-family: var(--mono); color: var(--muted); text-align: right; word-break: break-word; }

/* -------------------------------------------------------------- logs --- */
.logbox {
  margin: 0; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px;
  font-family: var(--mono); font-size: 12px; line-height: 1.6;
  height: 62vh; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.logbox .l-err  { color: var(--down); }
.logbox .l-warn { color: var(--warn); }
.logbox .l-ok   { color: var(--up); }

/* ------------------------------------------------------------- modal --- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4,7,12,.72); backdrop-filter: blur(4px);
  display: grid; place-items: center; padding: 20px;
}
.modal-card {
  width: min(520px, 100%); max-height: 86dvh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line-2);
  border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 12px; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
#modalConfirmWrap { margin-top: 14px; }
#modalConfirm { width: 100%; margin-top: 6px; font-family: var(--mono); }
.change-list { margin: 0; padding: 0; list-style: none; font-size: 13px; }
.change-list li {
  display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap;
  padding: 7px 0; border-bottom: 1px solid var(--line);
}
.change-list li:last-child { border-bottom: none; }
.change-list .k { flex: 1 1 140px; }
.change-list .from { font-family: var(--mono); color: var(--muted); text-decoration: line-through; }
.change-list .to { font-family: var(--mono); color: var(--accent); font-weight: 600; }

.error {
  background: var(--down-dim); border: 1px solid var(--down); color: var(--down);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 12.5px; margin-top: 12px;
}

/* ------------------------------------------------------------ toasts --- */
.toasts {
  position: fixed; z-index: 200; right: 16px; bottom: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  background: var(--panel); border: 1px solid var(--line-2);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); padding: 11px 15px;
  font-size: 13px; box-shadow: var(--shadow); max-width: min(400px, 88vw);
  animation: slide .22s ease;
}
.toast.ok  { border-left-color: var(--up); }
.toast.bad { border-left-color: var(--down); }
@keyframes slide { from { opacity: 0; transform: translateY(8px); } }

.footer { padding: 10px 16px 26px; }

/* On a phone the topbar cannot hold brand + pills + clock + buttons on one
   line, and squeezing them wraps into three ragged rows. Give the pills their
   own full-width row underneath instead. */
@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; padding: 10px 12px; }
  .brand { order: 1; }
  .topbar-right { order: 2; margin-left: auto; }
  .topbar-pills { order: 3; width: 100%; margin-left: 0; justify-content: flex-start;
                  flex-wrap: nowrap; }
  .wide-only { display: none; }
  .pill { padding: 4px 8px; font-size: 10.5px; }
  .clock { font-size: 12px; margin-left: auto; }
}

@media (max-width: 560px) {
  main { padding: 12px; }
  .card-body { padding: 13px; }
  .card-head { padding: 12px 13px; }
  .tile .value { font-size: 19px; }
  .tile.hero .value { font-size: 25px; }
  .banner { margin: 10px 12px 0; }
}
