:root {
  --bg: #0f0f0f; --surface: #1a1a1a; --surface-2: #222; --border: #2a2a2a;
  --text: #f0f0f0; --muted: #888;
  --green: #22c55e; --green-bright: #4ade80; --red: #ef4444; --yellow: #eab308; --accent: #3b82f6;
  --header-h: 52px; --tabs-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%; overflow-x: hidden;
  padding-bottom: calc(var(--tabs-h) + var(--safe-bottom));
}
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.app-header {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  height: calc(var(--header-h) + var(--safe-top)); padding: var(--safe-top) 16px 0;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.app-title { font-weight: 700; font-size: 17px; }
.header-right { display: flex; align-items: center; gap: 8px; }
.badge { padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.badge--loading { background: var(--surface-2); color: var(--muted); }
.badge--bullish { background: rgba(34, 197, 94, .18); color: var(--green); }
.badge--caution { background: rgba(234, 179, 8, .18); color: var(--yellow); }
.badge--bear { background: rgba(239, 68, 68, .18); color: var(--red); }

.btn {
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); font-weight: 600; }
.btn-secondary { background: var(--surface-2); }
.icon-btn {
  min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--muted);
  font-size: 18px; cursor: pointer; border-radius: 10px;
}
.link-btn { border: 0; background: none; color: var(--yellow); cursor: pointer; min-height: 36px; padding: 0 4px; }

.tab-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex;
  height: calc(var(--tabs-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tab-btn {
  position: relative; flex: 1; border: 0; background: none; color: var(--muted);
  font-size: 14px; font-weight: 600; cursor: pointer;
}
.tab-btn.active { color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
.count-badge {
  position: absolute; top: 6px; margin-left: 4px; min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--green); color: #000; font-size: 11px; line-height: 18px;
}

main { padding: 12px 16px; }
.tab { display: none; }
.tab.active { display: block; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.field { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.field select { min-height: 44px; padding: 0 8px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); }
.note {
  margin-bottom: 12px; padding: 10px 12px; border-radius: 10px;
  background: rgba(234, 179, 8, .12); color: var(--yellow); font-size: 14px;
}
.empty { color: var(--muted); text-align: center; padding: 32px 8px; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--surface); position: sticky; top: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr:focus { background: var(--surface); outline: none; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.sub { color: var(--muted); font-size: 12px; }
.stars { color: var(--yellow); letter-spacing: -1px; }
.rr-high { color: var(--green-bright); font-weight: 700; }
.rr-ok { color: var(--green); }
.halal-ok { color: var(--green); font-weight: 700; }

.state { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.state--ready { background: rgba(34, 197, 94, .2); color: var(--green); }
.state--entry_not_ready { background: rgba(234, 179, 8, .18); color: var(--yellow); }
.state--stop_hit { background: rgba(239, 68, 68, .2); color: var(--red); }
.state--target_hit { background: rgba(59, 130, 246, .2); color: #93c5fd; }

.alert-banner { position: sticky; top: calc(var(--header-h) + var(--safe-top)); z-index: 15; padding: 8px 16px 0; background: var(--bg); }
.alert { display: flex; align-items: center; margin-bottom: 8px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.alert--ready { border-color: var(--green); }
.alert--stop_hit { border-color: var(--red); }
.alert--target_hit { border-color: var(--accent); }
.alert--entry_not_ready { border-color: var(--yellow); }
.alert-main { flex: 1; text-align: left; border: 0; background: none; padding: 10px 12px; cursor: pointer; }
.alert-main .small { display: block; color: var(--muted); }
.install-hint {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 8px 16px 0; padding: 6px 6px 6px 12px; border-radius: 12px; background: var(--surface); font-size: 14px;
}

#tab-chart.active {
  display: flex; flex-direction: column;
  height: calc(100dvh - var(--header-h) - var(--safe-top) - var(--tabs-h) - var(--safe-bottom) - 24px);
  min-height: 420px;
}
.chart-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ticker-form { display: flex; gap: 6px; }
.ticker-form input {
  width: 96px; min-height: 44px; padding: 0 10px; border-radius: 10px; text-transform: uppercase;
  background: var(--surface); border: 1px solid var(--border);
}
.chart-title { flex: 1; min-width: 120px; }
.chips {
  display: flex; gap: 6px; margin: 10px 0 6px; overflow-x: auto; scrollbar-width: none;
  -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-width: 48px; min-height: 40px; padding: 0 12px; border-radius: 999px; scroll-snap-align: start;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chart-sub { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 6px; min-height: 28px; }
.toggle { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.toggle input { width: 18px; height: 18px; }
.pill { font-size: 12px; padding: 3px 8px; border-radius: 999px; }
.pill--up { background: rgba(34, 197, 94, .2); color: var(--green); }
.pill--flat { background: rgba(234, 179, 8, .18); color: var(--yellow); }
.chart-wrap { position: relative; flex: 1; min-height: 300px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.chart { position: absolute; inset: 0; }
.chart-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; text-align: center; }

.login {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center;
  padding: 16px; background: var(--bg);
}
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0 0 8px; font-size: 24px; text-align: center; }
.login-card label { color: var(--muted); font-size: 14px; }
.login-card input {
  min-height: 48px; padding: 0 12px; border-radius: 10px; font-size: 17px;
  background: var(--surface); border: 1px solid var(--border);
}
.error { min-height: 20px; margin: 0; color: var(--red); font-size: 14px; text-align: center; }

@media (max-width: 440px) {
  main { padding: 10px 12px; }
  th, td { padding: 9px 4px; }
  th:first-child, td:first-child { padding-left: 8px; }
  th:last-child, td:last-child { padding-right: 8px; }
  table { font-size: 12.5px; }
  .sub { font-size: 11px; }
  .stars { font-size: 11px; }
  .link-btn { font-size: 12px; }
  .check-label { display: none; }
}

@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .tab-bar {
    position: sticky; top: calc(var(--header-h) + var(--safe-top)); bottom: auto;
    height: 48px; padding: 0 8px; border-top: 0; border-bottom: 1px solid var(--border);
  }
  .tab-btn { flex: 0 0 auto; padding: 0 20px; }
  .tab-btn.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .tab-btn--chart { display: none; }
  .alert-banner { top: calc(var(--header-h) + 48px); }
  main {
    display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 16px; align-items: start;
  }
  .tab.active { grid-column: 1; }
  #tab-chart, #tab-chart.active {
    display: flex; flex-direction: column; grid-column: 2; grid-row: 1;
    position: sticky; top: calc(var(--header-h) + 60px); height: calc(100vh - var(--header-h) - 84px);
  }
}
