:root {
  --bg: #131722;
  --panel: #1e222d;
  --panel-2: #2a2e39;
  --border: #2a2e39;
  --text: #d1d4dc;
  --muted: #787b86;
  --accent: #2962ff;
  --accent-soft: rgba(41, 98, 255, .18);
  --up: #089981;
  --down: #f23645;
  --hover: rgba(255, 255, 255, .06);
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
  --top-h: 48px;
  --foot-h: 40px;
  --side-w: 300px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #ffffff;
  --panel: #f8f9fd;
  --panel-2: #f0f3fa;
  --border: #e0e3eb;
  --text: #131722;
  --muted: #6a6d78;
  --accent-soft: rgba(41, 98, 255, .12);
  --hover: rgba(0, 0, 0, .05);
  --shadow: 0 8px 28px rgba(0, 0, 0, .15);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
body { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; }
svg .soft { opacity: .25; stroke: none; }
[hidden] { display: none !important; }

#app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

/* ---------------------------------------------------------------- ust bar */
#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  min-height: calc(var(--top-h) + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
#symInfo {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
  flex: 0 1 auto;
  white-space: nowrap;
  overflow: hidden;
}
#symCode { font-weight: 700; font-size: 16px; }
#symPrice { font-weight: 600; font-variant-numeric: tabular-nums; }
#symChange { font-variant-numeric: tabular-nums; font-size: 13px; }
#symName { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
#toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 6px 0;
}
#toolbar::-webkit-scrollbar { display: none; }
#topRight { display: flex; gap: 2px; margin-left: auto; }

.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 2px; flex: none; }
.seg button, .icon-btn, .txt-btn {
  border: 0;
  background: transparent;
  border-radius: 6px;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text);
  flex: none;
}
.seg button { min-width: 30px; height: 28px; padding: 0 7px; font-size: 13px; font-weight: 600; }
.seg button:hover, .icon-btn:hover, .txt-btn:hover { background: var(--hover); }
.seg button.on, .txt-btn.on { background: var(--accent-soft); color: var(--accent); }
.txt-btn { border: 1px solid var(--border); background: var(--panel); font-size: 13px; }
.txt-btn.small { height: 30px; padding: 0 10px; }
.icon-btn { min-width: 38px; height: 38px; }
#btnRefresh.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- ana alan */
#app > * { min-width: 0; }
#main {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  min-height: 0;
}
#app.list-closed #main { grid-template-columns: minmax(0, 1fr) 0; }
#app.list-closed #sidebar { display: none; }
#chartWrap { position: relative; min-width: 0; min-height: 0; }
#chart { position: absolute; inset: 0; }
#legend {
  position: absolute;
  top: 6px;
  left: max(8px, env(safe-area-inset-left));
  z-index: 3;
  pointer-events: none;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1.55;
  max-width: calc(100% - 90px);
  text-shadow: 0 0 3px var(--bg), 0 0 3px var(--bg);
}
#legend .row { display: flex; flex-wrap: wrap; column-gap: 10px; }
#legend .k { color: var(--muted); margin-right: 3px; }
#legend .title { font-weight: 600; }
.up { color: var(--up); }
.down { color: var(--down); }
#drawHint {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  z-index: 4;
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--accent);
  color: #fff;
  padding: 6px 6px 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
#drawHint button { border: 0; background: rgba(255,255,255,.2); color: #fff; border-radius: 999px; padding: 4px 10px; cursor: pointer; }
#emptyState {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
  z-index: 2;
  background: var(--bg);
}

/* ---------------------------------------------------------------- izleme listesi */
#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--bg);
}
.side-head { display: flex; gap: 6px; padding: 8px; border-bottom: 1px solid var(--border); }
#addForm { display: flex; flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
#addForm:focus-within { border-color: var(--accent); }
#search {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 0 10px;
  font-size: 16px; /* iOS yakinlastirmasin */
  outline: none;
  text-transform: uppercase;
}
#search::placeholder { text-transform: none; color: var(--muted); }
#addForm .icon-btn { height: 34px; min-width: 34px; }
.side-head { align-items: center; }
.side-head .seg button { min-width: 0; padding: 0 7px; font-size: 12px; height: 28px; }
.side-head > .icon-btn { min-width: 34px; height: 34px; }
.mk {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  vertical-align: 2px;
  background: var(--accent-soft);
  color: var(--accent);
}
.cur { color: var(--muted); font-size: 11px; font-weight: 500; }
.list-head, #watchlist li {
  display: grid;
  grid-template-columns: 1fr auto 64px;
  gap: 8px;
  align-items: center;
  padding: 0 12px;
}
.list-head { color: var(--muted); font-size: 11px; height: 26px; border-bottom: 1px solid var(--border); }
.list-head span:not(:first-child) { text-align: right; }
#watchlist { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
#watchlist li { min-height: 48px; cursor: pointer; border-bottom: 1px solid var(--border); position: relative; }
#watchlist li:hover { background: var(--hover); }
#watchlist li.sel { background: var(--accent-soft); }
#watchlist li.sel::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
#watchlist .sym { min-width: 0; }
#watchlist .code { font-weight: 600; display: block; }
#watchlist .name { color: var(--muted); font-size: 11px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#watchlist .px { text-align: right; font-variant-numeric: tabular-nums; }
#watchlist .chg { text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 600; }
#watchlist .badge { font-size: 11px; color: var(--down); font-weight: 600; }
#watchlist .badge.wait { color: var(--muted); }
#watchlist .del {
  display: none;
  border: 0;
  background: var(--down);
  color: #fff;
  border-radius: 6px;
  height: 28px;
  padding: 0 10px;
  cursor: pointer;
  font-size: 12px;
}
#sidebar.editing #watchlist .del { display: inline-block; }
#sidebar.editing #watchlist .chg { display: none; }
#sidebar.editing #btnEdit { background: var(--accent-soft); color: var(--accent); }
#watchlist .empty { color: var(--muted); padding: 16px 12px; display: block; cursor: default; }
#sideFoot {
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  color: var(--muted);
  font-size: 12px;
  display: grid;
  gap: 4px;
}
#sideFoot a { color: var(--accent); text-decoration: none; }

/* ---------------------------------------------------------------- alt bar */
#rangebar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px max(8px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  min-height: var(--foot-h);
  overflow-x: auto;
  scrollbar-width: none;
}
#rangebar::-webkit-scrollbar { display: none; }
#status { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
#status a { color: var(--accent); }

/* ---------------------------------------------------------------- acilir panel */
.popover {
  position: fixed;
  z-index: 50;
  top: calc(var(--top-h) + env(safe-area-inset-top) + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: min(380px, calc(100vw - 16px));
  max-height: calc(100dvh - var(--top-h) - env(safe-area-inset-top) - 24px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 4px 0 8px;
}
.pop-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 14px; }
.pop-sec { padding: 8px 14px; border-top: 1px solid var(--border); }
.ind-row { display: flex; align-items: center; gap: 8px; padding: 7px 14px; min-height: 44px; }
.ind-row:hover { background: var(--hover); }
.ind-row label.main { display: flex; align-items: center; gap: 10px; flex: 1; cursor: pointer; min-width: 0; }
.ind-row input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.ind-row .swatch { width: 12px; height: 3px; border-radius: 2px; flex: none; }
.ind-row input[type=number], .ind-row select, .pop-sec select {
  width: 58px;
  height: 32px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  padding: 0 6px;
  font-size: 16px;
}
.ind-row select { width: 68px; font-size: 14px; }
.pop-sec label { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pop-sec select { width: auto; font-size: 14px; }

#banner {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 8px);
  transform: translateX(-50%);
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--down);
  border-radius: 10px;
  padding: 8px 8px 8px 14px;
  box-shadow: var(--shadow);
  max-width: calc(100vw - 16px);
}
#banner button { border: 0; background: var(--accent); color: #fff; border-radius: 6px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
#toast {
  position: fixed;
  z-index: 70;
  left: 50%;
  bottom: calc(var(--foot-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 24px);
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------------------------------------------------------- telefon / dar ekran */
@media (max-width: 899px) {
  /* cekmece #main icinde kalir; disari tasan kisim kirpilir (sayfa genislemesin) */
  #main { grid-template-columns: minmax(0, 1fr); overflow: hidden; }
  #app.list-closed #main { grid-template-columns: minmax(0, 1fr); }
  #sidebar {
    position: absolute;
    z-index: 40;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(88vw, 360px);
    padding-right: env(safe-area-inset-right);
    transform: translateX(105%);
    transition: transform .22s ease, visibility .22s;
    box-shadow: var(--shadow);
    display: flex !important;
    visibility: hidden;
  }
  #app.list-open #sidebar { transform: none; visibility: visible; }
  #sideFoot { padding-bottom: 8px; }
  #scrim { position: absolute; inset: 0; z-index: 39; background: rgba(0,0,0,.4); }
  #symName { display: none; }
  #btnInd span { display: none; }
  #btnInd { min-width: 36px; padding: 0 6px; }
}
@media (max-width: 520px) {
  #topbar { flex-wrap: wrap; row-gap: 0; }
  #symInfo { flex: 1 1 auto; padding-top: 6px; }
  #topRight { order: 2; padding-top: 4px; }
  #toolbar { order: 3; flex: 1 0 100%; padding: 2px 0 6px; }
  :root { --top-h: 92px; }
}
