/* ViewCtrader — design tokens (dark default, light via data-theme) */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2a2a28;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --grid: #2c2c2a;
  --axis: #383835;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #898781;
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.14);
  --pos: #0ca30c;
  --neg: #e66767;
  --pos-fill: #0ca30c;
  --neg-fill: #e66767;
  --mid: #383835;
  --warn: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --warn-soft: rgba(250, 178, 25, 0.12);
  --critical-soft: rgba(208, 59, 59, 0.14);
  --good-soft: rgba(12, 163, 12, 0.13);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --surface-2: #f3f3f0;
  --surface-3: #ebebe7;
  --border: rgba(11, 11, 11, 0.09);
  --border-strong: rgba(11, 11, 11, 0.16);
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7873;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.1);
  --pos: #006300;
  --neg: #c62f2f;
  --pos-fill: #008300;
  --neg-fill: #e34948;
  --mid: #e6e5e0;
  --warn-soft: rgba(250, 178, 25, 0.16);
  --critical-soft: rgba(208, 59, 59, 0.1);
  --good-soft: rgba(0, 131, 0, 0.1);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
svg { display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.num, table.data td, table.data th { font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.nowrap { white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- layout */
.app { display: grid; grid-template-columns: 224px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 8px;
  padding: 16px 12px; border-right: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 12px; color: var(--text); font-weight: 650; font-size: 16px; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; }
.brand-bg { fill: var(--accent); }
.brand-line { fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.brand-dot { fill: #fff; }
.brand-lg { justify-content: center; font-size: 22px; }
.brand-lg svg { width: 40px; height: 40px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--text); }
.nav a.active svg { stroke: var(--accent); }
.nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav-badge { margin-left: auto; font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--text-2); border-radius: 999px; padding: 1px 7px; }
.nav-badge:empty { display: none; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding: 8px; }
.conn { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); }
.foot-actions { display: flex; gap: 6px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent; cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--pos-fill); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.wait { background: var(--warn); }
.dot.bad { background: var(--critical); }
.dot.off { background: var(--muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar h1 { font-size: 18px; font-weight: 650; margin: 0; letter-spacing: -0.01em; }
.mode-badge { font-size: 11px; font-weight: 600; color: var(--warn); background: var(--warn-soft); border-radius: 999px; padding: 2px 8px; }
.scope { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.updated { font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }

.page { padding: 20px 24px 48px; display: flex; flex-direction: column; gap: 16px; outline: none; max-width: 1600px; width: 100%; }
.banner { margin: 16px 24px 0; padding: 10px 14px; border-radius: 10px; font-size: 13px; border: 1px solid var(--border); background: var(--surface); }
.banner.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.banner.error { background: var(--critical-soft); border-color: color-mix(in srgb, var(--critical) 40%, transparent); }
.banner a { font-weight: 600; }

/* ---------------------------------------------------------------- controls */
.field select, .select select, .input, input[type="text"], input[type="number"], input[type="password"], input[type="date"] {
  height: 34px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); min-width: 0;
}
.select select { padding-right: 28px; max-width: 320px; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }
.btn-danger { color: var(--neg); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn-block { width: 100%; }
.seg { display: inline-flex; padding: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--border); flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 5px 11px; border-radius: 7px; cursor: pointer; color: var(--text-2); font-size: 13px; font-weight: 500; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow), 0 0 0 1px var(--border); }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--text-2); user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { width: 32px; height: 18px; border-radius: 999px; background: var(--surface-3); position: relative; transition: background .15s; flex: none; }
.switch-track::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(14px); }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }
.toolbar .search { width: 220px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); }
.field input, .field select { width: 100%; }
.form-error { color: var(--neg); font-size: 13px; min-height: 1.2em; margin: 8px 0; }

/* ---------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 14px; font-weight: 650; margin: 0; }
.card-head .sub { font-size: 12px; color: var(--muted); }
.card.flush { padding: 0; }
.card.flush .card-head { padding: 14px 16px 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }

.hero-row { display: grid; grid-template-columns: minmax(280px, 1.1fr) minmax(0, 2fr); gap: 16px; }
.hero .label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.hero .value { font-size: 48px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; margin: 8px 0 12px; }
.hero .breakdown { display: flex; gap: 20px; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.hero .breakdown b { display: block; font-size: 15px; color: var(--text); font-weight: 600; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.kpi .label { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 21px; font-weight: 620; margin-top: 4px; letter-spacing: -0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.alert { border-color: color-mix(in srgb, var(--warn) 45%, transparent); background: linear-gradient(var(--warn-soft), var(--warn-soft)), var(--surface); }
.kpis-inner { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

.stale { opacity: 0.62; }
.age { font-size: 12px; color: var(--muted); white-space: nowrap; }
.age.old { color: var(--warn); }

/* ---------------------------------------------------------------- tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-weight: 550; font-size: 12px; color: var(--muted); padding: 8px 10px;
  border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; background: var(--surface);
}
table.data th.r, table.data td.r { text-align: right; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text); }
table.data th .arrow { font-size: 10px; margin-left: 3px; color: var(--accent); }
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--surface-2); }
table.data tr.clickable { cursor: pointer; }
table.data td.strong { font-weight: 600; }
table.data .acc-cell { display: flex; flex-direction: column; line-height: 1.25; }
table.data .acc-cell small { color: var(--muted); font-size: 11px; }
table.data tfoot td { font-weight: 600; border-top: 1px solid var(--border-strong); border-bottom: 0; }
.card.flush .table-wrap { padding: 4px 6px 8px; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 13px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); flex-wrap: wrap; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 650; padding: 2px 7px; border-radius: 5px; letter-spacing: 0.02em; white-space: nowrap; }
.badge.buy { color: var(--accent); background: var(--accent-soft); }
.badge.sell { color: var(--serious); background: color-mix(in srgb, var(--serious) 14%, transparent); }
.badge.live { color: var(--pos); background: var(--good-soft); }
.badge.demo { color: var(--text-2); background: var(--surface-3); }
.badge.warn { color: var(--warn); background: var(--warn-soft); }
.badge.bad { color: var(--neg); background: var(--critical-soft); }
.badge.muted { color: var(--muted); background: var(--surface-2); }
.badge.label { color: var(--text-2); background: var(--surface-2); font-weight: 550; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; white-space: nowrap; }

/* ---------------------------------------------------------------- meters (prop limits) */
.limits { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.limit-card { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--surface); display: flex; flex-direction: column; gap: 12px; }
.limit-card h3 { margin: 0; font-size: 13px; font-weight: 650; display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.meter-row .top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }
.meter-row .top b { color: var(--text); font-weight: 600; }
.meter { height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--accent) 16%, var(--surface-2)); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); min-width: 0; }
.meter.warn { background: color-mix(in srgb, var(--warn) 18%, var(--surface-2)); }
.meter.warn > span { background: var(--warn); }
.meter.bad { background: color-mix(in srgb, var(--critical) 18%, var(--surface-2)); }
.meter.bad > span { background: var(--critical); }
.meter.good > span { background: var(--pos-fill); }
.meter-row .foot { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* exposure list */
.expo { display: flex; flex-direction: column; }
.expo-row { display: grid; grid-template-columns: 90px 1fr 90px; gap: 10px; align-items: center; padding: 7px 2px; border-bottom: 1px solid var(--border); font-size: 13px; }
.expo-row:last-child { border-bottom: 0; }
.expo-bar { position: relative; height: 10px; }
.expo-bar::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--axis); }
.expo-bar span { position: absolute; top: 0; height: 100%; border-radius: 4px; }
.expo-bar .long { left: 50%; background: var(--accent); border-radius: 0 4px 4px 0; }
.expo-bar .short { right: 50%; background: var(--serious); border-radius: 4px 0 0 4px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------------------------------------------------------------- charts */
.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 200px; }
.chart-box.xs { height: 160px; }
.chart-box canvas { position: absolute; inset: 0; }

/* calendar */
.cal-head { display: flex; align-items: center; gap: 8px; }
.cal-head b { min-width: 120px; text-align: center; font-size: 13px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)) minmax(70px, 0.9fr); gap: 4px; }
.cal .dow { font-size: 11px; color: var(--muted); text-align: center; padding: 2px 0 4px; }
.cal .cell {
  min-height: 64px; border-radius: 8px; padding: 6px 7px; background: var(--surface-2); display: flex; flex-direction: column; justify-content: space-between;
  font-size: 12px; border: 1px solid transparent; min-width: 0;
}
.cal .cell.out { background: transparent; }
.cal .cell .d { color: var(--muted); font-size: 11px; }
.cal .cell .v { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal .cell .n { font-size: 10px; color: var(--muted); }
.cal .cell.today { border-color: var(--accent); }
.cal .week { background: transparent; border: 1px dashed var(--border-strong); }

/* tooltip */
.tooltip {
  position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  max-width: 260px;
}
.tooltip .t-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 14px; }

/* accounts editor */
.acct-edit { display: grid; grid-template-columns: minmax(200px, 1.1fr) minmax(0, 3fr); gap: 16px; padding: 16px; border-bottom: 1px solid var(--border); }
.acct-edit:last-child { border-bottom: 0; }
.acct-edit .who { display: flex; flex-direction: column; gap: 6px; }
.acct-edit .who .login { font-size: 16px; font-weight: 650; }
.acct-edit .who .meta { font-size: 12px; color: var(--muted); }
.acct-edit .fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 12px; align-items: end; }
.acct-edit .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; grid-column: 1 / -1; }
.acct-edit .err { color: var(--neg); font-size: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.note { font-size: 12px; color: var(--muted); }
.progress { height: 4px; border-radius: 999px; background: var(--surface-3); overflow: hidden; width: 120px; display: inline-block; vertical-align: middle; }
.progress span { display: block; height: 100%; background: var(--accent); }

/* login */
.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px; text-align: center; }
.auth-card form { text-align: left; margin-top: 20px; }
.auth-card h1 { font-size: 18px; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .hero-row { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; z-index: 20; bottom: 0; left: 0; right: 0; top: auto; height: auto;
    flex-direction: row; padding: 4px 6px calc(4px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--border);
  }
  .sidebar .brand, .sidebar-foot { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; font-size: 10px; padding: 6px 4px; flex: 1; position: relative; }
  .nav-badge { position: absolute; top: 2px; right: 18%; margin: 0; font-size: 9px; padding: 0 5px; }
  .main { padding-bottom: 64px; }
  .topbar { padding: 10px 16px; }
  .page { padding: 16px 16px 32px; }
  .banner { margin: 12px 16px 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hero .value { font-size: 40px; }
  .acct-edit { grid-template-columns: 1fr; }
  .toolbar .search { width: 100%; }
  .cal { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .cal .week, .cal .dow.wk { display: none; }
  .cal .cell { min-height: 48px; padding: 4px; }
  .cal .cell .v { font-size: 10px; }
  .cal .cell .n { display: none; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi .value { font-size: 18px; }
  .scope { width: 100%; }
  .select, .select select { width: 100%; max-width: none; }
  .expo-row { grid-template-columns: 70px 1fr 76px; }
}
