:root {
  color-scheme: light;
  --bg: #edf1f4;
  --shell: #f8fafb;
  --panel: #ffffff;
  --ink: #121a22;
  --muted: #667382;
  --line: #d8e0e8;
  --line-strong: #c6d0db;
  --accent: #08795f;
  --accent-2: #245a9a;
  --red: #aa3442;
  --amber: #9a6413;
  --green: #0c7652;
  --shadow: 0 14px 34px rgba(20, 31, 43, 0.08);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #f7f9fb 0, rgba(247, 249, 251, 0) 260px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #f7fafc, #e6edf3 54%, #f2f5f0);
}
.login-panel {
  width: min(460px, 100%);
  display: grid;
  gap: 20px;
  border: 1px solid rgba(198, 208, 219, 0.9);
  border-radius: 10px;
  padding: 28px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 26px 70px rgba(20, 31, 43, 0.16);
}
.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #10212b;
  color: #f5fbf9;
  font-size: 13px;
  font-weight: 900;
}
.compact-brand { padding: 18px 16px 14px; color: #f8fbfd; }
.compact-brand .brand-mark { width: 36px; height: 36px; background: #f8fbfd; color: #10212b; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
}
.side-rail {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: #101c25;
  border-right: 1px solid #253644;
}
.rail-nav { display: grid; align-content: start; gap: 4px; padding: 10px; }
.rail-nav a {
  border-radius: 7px;
  padding: 11px 12px;
  color: #b7c6d1;
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}
.rail-nav a:hover, .rail-nav a.active { background: #1d303d; color: #fff; }
.rail-footer {
  margin: 10px;
  border: 1px solid #2a3d4c;
  border-radius: 8px;
  padding: 12px;
  color: #dce6ee;
  background: #152632;
}
.rail-footer span { display: block; color: #91a5b4; font-size: 12px; font-weight: 800; }
.rail-footer strong { display: block; margin-top: 4px; }

.main-shell { min-width: 0; padding: 18px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1580px;
  margin: 0 auto 14px;
}
.top-actions, .button-row, .dual-buttons, .segmented { display: flex; align-items: center; gap: 8px; }
.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 30px; line-height: 1.1; }
h2 { margin-bottom: 0; font-size: 17px; line-height: 1.2; }
.muted { color: var(--muted); line-height: 1.5; }

.account-strip {
  max-width: 1580px;
  margin: 0 auto 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.metric-tile {
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  background: linear-gradient(180deg, #fff, #f8fafb);
  box-shadow: 0 8px 22px rgba(20, 31, 43, 0.05);
}
.metric-tile span, .metric-tile small { display: block; color: var(--muted); font-size: 12px; font-weight: 800; }
.metric-tile strong { display: block; margin: 9px 0 4px; font-size: 24px; line-height: 1; }
.accent-tile { border-color: #abcfc5; background: linear-gradient(180deg, #f9fffc, #eff8f4); }

.terminal-grid {
  max-width: 1580px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 250px minmax(520px, 1fr) 290px;
  gap: 12px;
  align-items: start;
}
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  padding: 14px;
}
.wide { grid-column: 1 / -1; }
.panel-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 13px;
}
.status-pill, .live-dot, .badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  background: #f8fafb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.live-dot { color: var(--green); border-color: #b9d8cf; background: #edf8f4; }
.badge.ok { color: var(--green); background: #edf8f4; border-color: #b9d8cf; }
.badge.warn { color: var(--amber); background: #fff7ea; border-color: #ebd1a5; }
.badge.bad { color: var(--red); background: #fff0f2; border-color: #ecc0c6; }

button {
  border: 1px solid #066a52;
  border-radius: 7px;
  padding: 9px 12px;
  background: linear-gradient(180deg, #0b8a6d, #08765e);
  color: #fff;
  font-weight: 900;
  min-height: 38px;
}
button:hover { filter: brightness(0.98); }
button:disabled { opacity: 0.6; cursor: wait; }
button.secondary, button.ghost, .segmented button, .link-button {
  border-color: var(--line-strong);
  background: linear-gradient(180deg, #fff, #f3f6f8);
  color: var(--ink);
}
button.ghost { color: #516171; }
.link-button { min-height: 30px; padding: 6px 8px; color: var(--accent-2); }
.icon-button { width: 34px; height: 34px; padding: 0; font-size: 18px; line-height: 1; }
.segmented button { min-width: 42px; padding: 7px 9px; min-height: 34px; }
.segmented button.active { background: #eaf6f2; border-color: #acd9ca; color: var(--accent); }
.buy { background: linear-gradient(180deg, #138862, #0d7453); border-color: #0a6046; flex: 1; }
.sell { background: linear-gradient(180deg, #b94a56, #a43743); border-color: #8b2d37; flex: 1; }

.stack-form, .deposit-grid, .rule-grid { display: grid; gap: 11px; }
.stack-form.compact { gap: 10px; }
.deposit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.deposit-grid button { grid-column: 1 / -1; }
label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}
input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 9px 10px;
  background: #fbfcfd;
  color: var(--ink);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(8, 121, 95, 0.13);
}
.form-error { margin: 0; min-height: 20px; color: var(--red); font-size: 13px; font-weight: 800; }

.market-list, .depth-book, .activity-feed { display: grid; gap: 8px; }
.market-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  border-color: var(--line);
  background: #fbfcfd;
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}
.market-row small { font-weight: 900; }
.positive { color: var(--green); }
.negative { color: var(--red); }

.chart-panel { min-height: 454px; }
.chart-surface {
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #f7fafc;
  aspect-ratio: 2.55 / 1;
}
canvas { display: block; width: 100%; height: 100%; }
.trade-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}
.trade-strip div, .quote-band {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 9px 10px;
  background: #fbfcfd;
}
.trade-strip span, .quote-band span { display: block; color: var(--muted); font-size: 12px; font-weight: 900; }
.trade-strip strong, .quote-band strong { display: block; margin-top: 3px; }
.quote-band { display: flex; justify-content: space-between; align-items: center; }
.quote-band strong { margin: 0; }

.depth-row {
  position: relative;
  display: flex;
  justify-content: space-between;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fbfcfd;
  font-size: 13px;
}
.depth-row.ask { color: var(--red); }
.depth-row.bid { color: var(--green); }
.depth-row strong { color: var(--ink); }
.activity-item {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  align-items: start;
  border-bottom: 1px solid var(--line);
  padding: 0 0 10px;
}
.activity-item:last-child { border-bottom: 0; padding-bottom: 0; }
.activity-item > span {
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--accent);
}
.activity-item strong, .activity-item small { display: block; overflow-wrap: anywhere; }
.activity-item small { margin-top: 2px; color: var(--muted); font-size: 12px; font-weight: 700; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
.compact-table table { min-width: 520px; }
th, td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  font-size: 13px;
  vertical-align: middle;
}
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0; }
tbody tr:hover { background: #f8fafb; }
.empty-table { text-align: center; color: var(--muted); padding: 24px; }
.address-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: 12px; }

.rules-editor { display: grid; gap: 12px; }
.rule-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}
.rule-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.rule-grid { grid-template-columns: repeat(6, minmax(132px, 1fr)); }
.checkline { display: flex; flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
.checkline input { width: auto; min-height: auto; }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 28, 37, 0.48);
  z-index: 20;
}
.modal-panel {
  width: min(660px, 100%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  padding: 16px;
  box-shadow: 0 30px 90px rgba(16, 28, 37, 0.34);
}
.deposit-result {
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}
.qr-box { display: grid; grid-template-columns: 142px minmax(0, 1fr); gap: 14px; align-items: center; }
.qr-box img { width: 142px; height: 142px; border: 1px solid var(--line); border-radius: 7px; background: #fff; }
.qr-box strong { overflow-wrap: anywhere; }

@media (max-width: 1280px) {
  .app-shell { grid-template-columns: 190px minmax(0, 1fr); }
  .terminal-grid { grid-template-columns: 240px minmax(420px, 1fr); }
  .ticket-panel, .depth-panel, .activity-panel { grid-column: auto; }
  .rule-grid { grid-template-columns: repeat(3, minmax(150px, 1fr)); }
}
@media (max-width: 940px) {
  .app-shell { display: block; }
  .side-rail { position: static; height: auto; display: block; }
  .rail-nav { grid-template-columns: repeat(3, 1fr); }
  .rail-footer { display: none; }
  .account-strip, .terminal-grid { grid-template-columns: 1fr; }
  .wide, .ticket-panel, .depth-panel, .activity-panel { grid-column: auto; }
  .trade-strip, .deposit-grid, .qr-box { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .main-shell { padding: 12px; }
  .topbar { display: grid; }
  .top-actions { flex-wrap: wrap; justify-content: flex-start; }
  .rail-nav { grid-template-columns: 1fr; }
  .rule-grid { grid-template-columns: 1fr; }
  .chart-surface { aspect-ratio: 1.45 / 1; }
}
