:root {
  --bg: #f4f6f6;
  --surface: #ffffff;
  --surface-2: #eef2f2;
  --text: #0f1a1c;
  --muted: #5c6b6e;
  --line: #dde4e4;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --buy: #0e8a4f;
  --buy-bg: #e3f5ec;
  --sell: #c2410c;
  --sell-bg: #fdeee5;
  --danger: #b91c1c;
  --danger-bg: #fdecec;
  --warn: #a16207;
  --warn-bg: #fdf6e3;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 26, 28, .06), 0 2px 8px rgba(15, 26, 28, .04);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1416;
    --surface: #121e21;
    --surface-2: #19282b;
    --text: #e6eeee;
    --muted: #8fa0a3;
    --line: #233437;
    --accent: #2dd4bf;
    --accent-ink: #062a26;
    --buy: #34d399;
    --buy-bg: #0f2c22;
    --sell: #fb923c;
    --sell-bg: #331d10;
    --danger: #f87171;
    --danger-bg: #351616;
    --warn: #facc15;
    --warn-bg: #2e2810;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
b { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); min-height: 1.4em; margin: 8px 0 0; }

/* Giriş */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 28px 22px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 10px 0 0; font-size: 24px; }
.login-card p { margin: 2px 0 18px; }
.login-logo { border-radius: 14px; }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
input {
  display: block; width: 100%; margin-top: 4px; padding: 11px 12px; font: inherit; color: var(--text);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; outline: none;
}
input:focus { border-color: var(--accent); }

/* Düğmeler */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger-bg); border-color: transparent; color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; margin-top: 6px; }
.small-btn { padding: 4px 10px; font-size: 13px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.btn-row.end { justify-content: flex-end; }

/* Yerleşim */
.app { max-width: 1100px; margin: 0 auto; padding: 0 16px calc(84px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 0 10px; background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; margin-right: auto; }
.brand img { border-radius: 8px; }
.badge { font-size: 11px; font-weight: 700; letter-spacing: .04em; padding: 3px 8px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.badge.live { background: var(--danger); color: #fff; }
.pill { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.running { background: var(--buy-bg); color: var(--buy); }
.pill.paused, .pill.paused_fee { background: var(--warn-bg); color: var(--warn); }
.pill.error { background: var(--danger-bg); color: var(--danger); }
.conn { display: flex; gap: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.dot.on { background: var(--buy); }

.banner { border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }
.banner.danger { background: var(--danger-bg); color: var(--danger); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }

.grid-cards { display: grid; gap: 12px; grid-template-columns: 1fr; margin-bottom: 12px; }
@media (min-width: 640px) { .grid-cards { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1000px) { .grid-cards { grid-template-columns: repeat(4, 1fr); } }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 12px; min-width: 0;
}
.grid-cards .card { margin-bottom: 0; }
.label { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.label.row { display: flex; align-items: center; justify-content: space-between; }
.price { font: 600 34px/1.1 var(--mono); letter-spacing: -.02em; margin: 2px 0 6px; }
.sub { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.sub b { font-family: var(--mono); color: var(--text); }
.chip { display: inline-block; margin-top: 10px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--buy-bg); color: var(--buy); }
.chip.out { background: var(--warn-bg); color: var(--warn); }
.chip:empty { display: none; }

.range { display: grid; gap: 6px; }
.range > div { display: flex; justify-content: space-between; align-items: baseline; padding: 6px 10px; border-radius: 8px; background: var(--surface-2); }
.range > div:first-child b { color: var(--sell); }
.range > div:last-child b { color: var(--buy); }
.range .center { background: transparent; border: 1px dashed var(--line); }
.range b { font-family: var(--mono); font-size: 16px; }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv b { font-family: var(--mono); text-align: right; }
.pos { color: var(--buy); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.list .empty { color: var(--muted); justify-content: center; }
.list .grow { flex: 1; min-width: 0; }
.list .mono { font-family: var(--mono); }
.tag { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; white-space: nowrap; }
.tag.buy { background: var(--buy-bg); color: var(--buy); }
.tag.sell { background: var(--sell-bg); color: var(--sell); }
.tag.role { background: var(--surface-2); color: var(--muted); }
.events li { align-items: flex-start; }
.events time { font-family: var(--mono); font-size: 12px; color: var(--muted); white-space: nowrap; padding-top: 1px; }
.events .lvl-warn .grow { color: var(--warn); }
.events .lvl-error .grow { color: var(--danger); }
.events .who { display: block; font-size: 12px; color: var(--muted); }

/* Merdiven */
.ladder { display: grid; font-family: var(--mono); font-size: 13px; }
.rung { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 8px; min-height: 30px; border-bottom: 1px solid var(--line); padding: 2px 0; }
.rung:last-child { border-bottom: 0; }
.rung .p { color: var(--muted); }
.rung .slots { display: flex; flex-wrap: wrap; gap: 4px; }
.rung.center { background: var(--surface-2); border-radius: 6px; }
.rung.center .p { color: var(--text); font-weight: 700; }
.rung.edge-buy .p { color: var(--buy); font-weight: 700; }
.rung.edge-sell .p { color: var(--sell); font-weight: 700; }
.rung.one { border-bottom-color: var(--muted); }
.gap { color: var(--muted); font-size: 12px; padding: 4px 0 4px 8px; border-bottom: 1px dashed var(--line); }
.warn-text { color: var(--warn); font-weight: 700; }
.now { display: flex; align-items: center; gap: 8px; color: var(--accent); font-weight: 700; font-size: 12px; padding: 2px 0; }
.now::after { content: ""; flex: 1; height: 2px; background: var(--accent); border-radius: 2px; }

.prefs { margin-top: 8px; }
.pref { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.pref:last-child { border-bottom: 0; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: background .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Sekme çubuğu */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; max-width: 140px; appearance: none; border: 0; background: none; color: var(--muted); font: inherit;
  font-size: 11px; font-weight: 600; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: pointer;
}
.tabbar svg { width: 22px; height: 22px; fill: currentColor; }
.tabbar button.active { color: var(--accent); }

.dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--text); padding: 18px; max-width: 340px; width: calc(100% - 32px); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100% - 32px);
}

.grid-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 10px; }
.grid-form > :not(label:nth-child(-n+3)) { grid-column: 1 / -1; }
.grid-form label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); font-size: 14px; }
.grid-form label.check input { width: auto; margin-top: 3px; }
@media (max-width: 420px) { .grid-form { grid-template-columns: 1fr 1fr; } .grid-form label:nth-child(3) { grid-column: 1 / -1; } }
