/* Layout: sticky top bar (timeframes, global notifications, legend) over a grid of chart cards, two columns from 1024px. */
:root {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --fg: #141821;
  --muted: #646b7c;
  --border: #dfe2e8;
  --grid: #eff1f4;
  --up: #089981;
  --down: #f23645;
  --support: #2962ff;
  --resistance: #f57c00;
  --safety: #9c27b0;
  --notify: #e0a800;
  --crossed: #0891b2;
  --safety-crossed: #db2777;
  --crossed-soft: #e0f4f9;
  --safety-crossed-soft: #fde7f1;
  --accent: #2962ff;
  --accent-soft: #e8eeff;
  --frozen-soft: #fff6dc;
  --trade: #10a35a;
  --trade-soft: #e3f6ea;
  --loss: #e0313d;
  --loss-soft: #fde8ea;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1016;
    --surface: #151922;
    --fg: #e4e7ee;
    --muted: #8d94a5;
    --border: #262c38;
    --grid: #1b202a;
    --up: #26a69a;
    --down: #ef5350;
    --support: #5c8dff;
    --resistance: #ffa040;
    --safety: #c77dff;
    --notify: #ffd23f;
    --crossed: #22c3e6;
    --safety-crossed: #f472b6;
    --crossed-soft: #0e2a31;
    --safety-crossed-soft: #2f1222;
    --accent: #5c8dff;
    --accent-soft: #1a2440;
    --frozen-soft: #2b2512;
    --trade: #2fbf71;
    --trade-soft: #10281a;
    --loss: #ff5a5f;
    --loss-soft: #2e1416;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1016;
  --surface: #151922;
  --fg: #e4e7ee;
  --muted: #8d94a5;
  --border: #262c38;
  --grid: #1b202a;
  --up: #26a69a;
  --down: #ef5350;
  --support: #5c8dff;
  --resistance: #ffa040;
  --safety: #c77dff;
  --notify: #ffd23f;
  --crossed: #22c3e6;
  --safety-crossed: #f472b6;
  --crossed-soft: #0e2a31;
  --safety-crossed-soft: #2f1222;
  --accent: #5c8dff;
  --accent-soft: #1a2440;
  --frozen-soft: #2b2512;
  --trade: #2fbf71;
  --trade-soft: #10281a;
  --loss: #ff5a5f;
  --loss-soft: #2e1416;
  color-scheme: dark;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  z-index: 10;
  background: var(--surface);
}

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner,
.legend-inner,
.grid {
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding-block: 10px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-right: auto;
}
.brand-name {
  font-weight: 650;
  font-size: 15px;
}
.chip {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 2px 7px;
  border-radius: 999px;
  white-space: nowrap;
}
.chip-sample {
  color: var(--muted);
  border: 1px solid var(--border);
}
.chip-push {
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid transparent;
}
.chip-push[data-state='blocked'],
.chip-push[data-state='install'] {
  color: var(--muted);
  background: none;
  border-color: var(--border);
}

.tfs {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}
.tfs button {
  font: 600 13px/1 var(--sans);
  min-width: 36px;
  padding: 7px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.tfs button {
  position: relative;
}
/* A dot on timeframes where an instrument is frozen (amber) or in a trade (green). */
.tfs button[data-state]::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--notify);
}
.tfs button[data-state="trade"]::after {
  background: var(--trade);
}
.tfs button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--fg);
  box-shadow: 0 0 0 1px var(--border);
}

button {
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg);
  cursor: pointer;
}
.icon-btn svg {
  width: 17px;
  height: 17px;
}
.btn-start {
  color: var(--accent);
}
.btn-locked {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.btn-stop {
  border-color: var(--down);
  color: var(--down);
}
.bell {
  color: var(--muted);
}
.bell[aria-pressed="true"] {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.bell.muted {
  opacity: 0.45;
}
.top-actions {
  display: flex;
  gap: 8px;
}
.layout-btn {
  width: 38px;
  height: 34px;
  color: var(--muted);
}
.layout-btn.is-forced {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}
.bell-global {
  width: 38px;
  height: 34px;
}

.legend-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  padding-block: 12px 0;
  font-size: 12px;
  color: var(--muted);
}
.legend-inner span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.sw {
  width: 16px;
  height: 2px;
  border-radius: 1px;
}
.sw-support { background: var(--support); }
.sw-resistance { background: var(--resistance); }
.sw-safety { background: var(--safety); }
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.dot-notify { background: var(--notify); }
.dot-crossed { background: var(--crossed); }
.dot-safety-crossed { background: var(--safety-crossed); }
.dot-start { background: var(--accent); }
.dot-stop { background: var(--muted); }

.grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 12px;
  padding-block: 10px 32px;
}
@media (max-width: 639px) {
  .top-actions {
    gap: 6px;
  }
  .top-actions .icon-btn {
    width: 34px;
    height: 32px;
  }
  .tfs {
    order: 3;
    flex-basis: 100%;
  }
  .tfs button {
    flex: 1;
  }
}
/* Automatic: two columns from iPad portrait width (744px), three from iPad landscape width (1100px). The layout switch can force any. */
@media (min-width: 744px) {
  .grid[data-layout="auto"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (min-width: 1100px) {
  .grid[data-layout="auto"] {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
.grid[data-layout="3"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.grid[data-layout="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid[data-layout="1"] {
  grid-template-columns: minmax(0, 1fr);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  min-width: 0;
}
/* Frozen cards take the colour of their latest notification: touch, line crossed or safety line crossed. */
.card.is-frozen {
  --tone: var(--notify);
  --tone-soft: var(--frozen-soft);
  border-color: var(--tone);
}
.card.is-frozen[data-notify="line"] {
  --tone: var(--crossed);
  --tone-soft: var(--crossed-soft);
}
.card.is-frozen[data-notify="safety"] {
  --tone: var(--safety-crossed);
  --tone-soft: var(--safety-crossed-soft);
}
.card.is-trade {
  border-color: var(--trade);
  box-shadow: 0 0 0 1px var(--trade);
}
.card.is-trade .card-head {
  background: var(--trade-soft);
}
/* A trade that's currently losing. */
.card.is-trade.is-loss {
  border-color: var(--loss);
  box-shadow: 0 0 0 1px var(--loss);
}
.card.is-trade.is-loss .card-head {
  background: var(--loss-soft);
}
.card.is-frozen .card-head {
  background: var(--tone-soft);
}
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 12px;
  /* Extra room at the bottom for the candle countdown text. */
  padding: 10px 12px 22px;
  border-bottom: 1px solid var(--border);
}
.title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  min-width: 0;
}
.title h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}
.sym {
  color: var(--muted);
  font-size: 12px;
}
.price {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.price.up { color: var(--up); }
.price.down { color: var(--down); }
.trade {
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.trade.pos { color: var(--up); }
.trade.neg { color: var(--down); }
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-soft);
}
.badge.badge-frozen {
  color: var(--fg);
  background: var(--frozen-soft);
}
.status {
  font-size: 12px;
  color: var(--muted);
}
.actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
/* Candle countdown: a line along the header's bottom edge filling up as the candle runs, with the time left at its end. */
.timer {
  position: relative;
  height: 0;
  z-index: 1;
}
.timer-fill {
  position: absolute;
  left: 0;
  top: -2px;
  height: 2px;
  min-width: 2px;
  background: var(--up);
  border-radius: 0 2px 2px 0;
}
.timer-fill.down {
  background: var(--down);
}
.timer-text {
  position: absolute;
  left: 0;
  bottom: 5px;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}
/* Briefly highlights a card opened from a notification. */
@media (prefers-reduced-motion: no-preference) {
  .card.flash {
    animation: card-flash 1.2s ease-out;
  }
  @keyframes card-flash {
    0%, 30% { box-shadow: 0 0 0 4px var(--accent); }
    100% { box-shadow: 0 0 0 0 transparent; }
  }
}
.empty {
  grid-column: 1 / -1;
  margin: 24px 0;
  text-align: center;
  color: var(--muted);
}
.chart {
  position: relative;
  height: 300px;
  touch-action: pan-y;
}
/* The crosshair's time, shown at the top of the chart. */
.time-label {
  position: absolute;
  top: 6px;
  left: 0;
  transform: translateX(-50%);
  z-index: 3;
  padding: 3px 7px;
  border-radius: 4px;
  background: var(--muted);
  color: var(--surface);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

.toasts {
  position: fixed;
  right: max(16px, env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: max(16px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  z-index: 20;
  pointer-events: none;
}
.toast {
  box-sizing: border-box;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  max-width: 420px;
  width: 100%;
  background: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-left: 3px solid var(--notify);
  border-radius: 10px;
  padding: 10px 6px 10px 12px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.18);
  pointer-events: auto;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.toast-line {
  border-left-color: var(--crossed);
}
.toast-safety {
  border-left-color: var(--safety-crossed);
}
.toast {
  cursor: pointer;
}
.toast-body {
  flex: 1;
  min-width: 0;
}
.toast p {
  margin: 0;
  overflow-wrap: anywhere;
}
.toast small {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 3px;
}
.toast-close {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: -4px 0;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.toast-close svg {
  width: 16px;
  height: 16px;
}
@media (prefers-reduced-motion: no-preference) {
  .toast {
    animation: toast-in 0.2s ease-out;
  }
  @keyframes toast-in {
    from { transform: translateY(8px); opacity: 0.4; }
  }
}
