/* The IMOP phone app's look: built for reading figures at a glance with one hand.
   Follows the phone's dark or light setting. Gains and losses carry a sign as well as a colour;
   states carry a word and a mark, never a colour alone. Tap targets are at least 44 px. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --line: #dde1e6;
  --text: #11151a;
  --muted: #5b6470;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --up: #0f7a3d;
  --down: #c0262d;
  --warn: #9a5b00;
  --warn-bg: #fff4e0;
  --stop: #b3141b;
  --stop-bg: #fde8e8;
  --ok: #0f7a3d;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 14px;
  --gap: 12px;
  --tabs-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1d232c;
    --line: #2a313b;
    --text: #e8ebef;
    --muted: #9aa4b0;
    --accent: #4d8eea;
    --accent-text: #0b0f14;
    --up: #3fb873;
    --down: #f0605d;
    --warn: #e6a23c;
    --warn-bg: #2a2214;
    --stop: #ff5a55;
    --stop-bg: #2c1516;
    --ok: #3fb873;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
body.gate { padding-bottom: 24px; }

h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-decoration: none; }

/* ---- header ---- */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.top h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); flex: none; }
.back { min-height: 44px; display: inline-flex; align-items: center; padding: 0 4px; font-weight: 550; }

main { padding: 16px; display: flex; flex-direction: column; gap: var(--gap);
  max-width: 640px; margin: 0 auto; }

/* ---- cards and panels ---- */
.card, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  color: var(--text);
  display: block;
}
.panel { display: flex; flex-direction: column; gap: 10px; }
.center { text-align: center; align-items: center; }
.card.account:active { background: var(--surface-2); }
.card.line { display: flex; align-items: center; gap: 10px; padding: 12px 16px; min-height: 52px; }

.row { display: flex; align-items: center; gap: 8px; }
.right { margin-left: auto; }
.name { font-weight: 600; font-size: 17px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 13px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; margin-left: auto; }

.figure { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; margin-top: 10px;
  font-variant-numeric: tabular-nums; }
.label { font-size: 14px; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.up { color: var(--up); }
.down { color: var(--down); }

dl { margin: 0; }
dl.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 10px 14px; margin-top: 14px; }
dl.grid dt { font-size: 13px; color: var(--muted); }
dl.grid dd { margin: 2px 0 0; font-size: 16px; font-weight: 550; }
dl.list > div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
dl.list > div:last-child { border-bottom: 0; }
dl.list dt { color: var(--muted); }
dl.list dd { margin: 0; font-weight: 550; text-align: right; }

.state { margin-top: 14px; }
.section { font-size: 15px; font-weight: 650; color: var(--muted); text-transform: none; margin: 8px 4px 0;
  display: flex; align-items: center; gap: 8px; }
.count { font-size: 13px; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 0 8px; }

.small { font-size: 14px; }
.muted { color: var(--muted); }
.empty { padding: 4px 4px 8px; }
.stamp { text-align: center; margin-top: 4px; }
.error { color: var(--down); font-weight: 550; }
.ok { color: var(--ok); font-weight: 550; }
ul.plain { margin: 6px 0; padding-left: 18px; }

/* ---- states ---- */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 550;
  border-radius: 999px; padding: 3px 10px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill.small { font-size: 12px; padding: 1px 8px; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.connected, .pill.running { color: var(--ok); }
.pill.lost, .pill.failed { color: var(--down); }
.pill.waiting_phone { color: var(--warn); }
.pill.stop { color: var(--stop); background: var(--stop-bg); }
.pill.stopped .dot { background: transparent; border: 2px solid currentColor; width: 9px; height: 9px; }

.side { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.side.long::before { content: "▲ "; color: var(--up); }
.side.short::before { content: "▼ "; color: var(--down); }

.notice { border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.warn strong { color: var(--text); }
.notice.stop { background: var(--stop-bg); color: var(--stop); flex-direction: row; align-items: center; gap: 8px; font-weight: 600; }

.alert { border-left: 4px solid var(--line); }
.alert.warn { border-left-color: var(--warn); }
.alert.error { border-left-color: var(--down); }

/* ---- buttons and fields ---- */
.btn {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.wide { width: 100%; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: var(--stop); border-color: var(--stop); color: #fff; margin-top: 20px; }
.btn.link { border: 0; background: none; color: var(--accent); min-height: 44px; }
.btn.busy { opacity: 0.6; }
.btn:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; width: 100%; text-align: left; font-size: 14px; color: var(--muted); }
.field input { min-height: 48px; font: inherit; font-size: 16px; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; }

details.panel summary { min-height: 44px; display: flex; align-items: center; font-weight: 600; cursor: pointer; }
.kinds { display: flex; flex-direction: column; gap: 2px; }
.switch { display: flex; align-items: center; gap: 12px; min-height: 44px; border-bottom: 1px solid var(--line); }
.switch input { width: 22px; height: 22px; accent-color: var(--accent); }

.install .how { display: none; }
.install.ios-safari .ios-safari, .install.ios-other .ios-other, .install.android-firefox .android-firefox,
.install.android-chrome .android-chrome, .install.android-other .android-other { display: block; }
.install.can-prompt .how { display: none; }

/* ---- tab bar ---- */
.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab { min-height: var(--tabs-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; font-size: 12px; font-weight: 550; color: var(--muted); }
.tab.on { color: var(--accent); }

.ico { display: inline-block; width: 24px; height: 24px; background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
.ico-accounts { --icon: url("/static/icons/accounts.svg"); }
.ico-strategies { --icon: url("/static/icons/strategies.svg"); }
.ico-alerts { --icon: url("/static/icons/alerts.svg"); }
.ico-more { --icon: url("/static/icons/more.svg"); }
.ico-stop { --icon: url("/static/icons/stop.svg"); width: 18px; height: 18px; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 12px);
  z-index: 20;
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 550;
}
.toast[hidden] { display: none; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .card { transition: background-color 120ms ease; }
}

[data-refresh] { display: flex; flex-direction: column; gap: var(--gap); }
[hidden] { display: none !important; }
.panel h2 { font-size: 18px; font-weight: 650; }
.panel h3 { font-size: 16px; font-weight: 650; }
