:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --text: #1c2321;
  --muted: #5d6865;
  --border: #d8ddda;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --up: #15803d;
  --down: #b91c1c;
  --user-bg: #0f766e;
  --user-text: #ffffff;
  --danger-bg: #fdecec;
  --radius: 14px;
  --sidebar-w: 320px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101514;
    --surface: #182120;
    --surface-2: #202b29;
    --text: #e8eeec;
    --muted: #9aa8a4;
    --border: #2c3836;
    --accent: #2dd4bf;
    --accent-text: #05211d;
    --up: #4ade80;
    --down: #f87171;
    --user-bg: #0f766e;
    --user-text: #ffffff;
    --danger-bg: #3a1c1c;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.15rem; }
h2 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input, textarea {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.primary, button.secondary {
  border: 0;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  min-height: 44px;
}
button.primary { background: var(--accent); color: var(--accent-text); }
button.secondary { background: var(--surface-2); border: 1px solid var(--border); }
button.primary:disabled { opacity: 0.55; cursor: default; }
button.wide { width: 100%; }
button.icon {
  background: none; border: 0; font-size: 1.3rem; width: 44px; height: 44px; border-radius: 10px;
}
button.icon:hover { background: var(--surface-2); }
button.link { background: none; border: 0; color: var(--accent); padding: 8px; }

/* giris */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 28px 24px; display: grid; gap: 14px;
}
.login-card label { display: grid; gap: 6px; font-size: 0.9rem; color: var(--muted); }
.login-card input { color: var(--text); }
.error { color: var(--down); min-height: 1.4em; margin: 0; font-size: 0.9rem; }

/* uygulama */
.app { display: flex; height: 100dvh; }
.sidebar {
  width: var(--sidebar-w); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
}
.side-head { padding: 16px 16px 8px; }
.panel { padding: 12px 16px; border-top: 1px solid var(--border); }
.panel.grow { flex: 1; min-height: 120px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.side-foot {
  padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.hint { font-size: 0.78rem; color: var(--muted); margin: 6px 0 0; }

.watchlist, .convs { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.watchlist li {
  display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center;
  padding: 8px 6px 8px 10px; border-radius: 10px; background: var(--surface-2);
}
.w-sym { font-weight: 650; }
.w-name { display: block; font-size: 0.75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.w-px { text-align: right; font-variant-numeric: tabular-nums; font-size: 0.92rem; }
.w-chg { display: block; font-size: 0.78rem; }
.w-chg.up { color: var(--up); }
.w-chg.down { color: var(--down); }
.w-remove { background: none; border: 0; color: var(--muted); font-size: 1.1rem; width: 32px; height: 32px; border-radius: 8px; }
.w-remove:hover { background: var(--surface); }
.watch-form { display: flex; gap: 8px; margin-top: 10px; }
.watch-form input { min-width: 0; }
.watch-form button { min-height: 0; padding: 8px 12px; }

.convs li { display: flex; align-items: center; border-radius: 10px; }
.convs li.active { background: var(--surface-2); }
.convs .c-open {
  flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 9px 10px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.convs .c-del { background: none; border: 0; color: var(--muted); width: 32px; height: 32px; border-radius: 8px; }
.convs .c-del:hover { background: var(--surface-2); }

.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; padding-top: calc(6px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.topbar h1 { flex: 1; }
#menu { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; }
.msg { max-width: min(760px, 92%); padding: 10px 14px; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--user-bg); color: var(--user-text); white-space: pre-wrap; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.error { align-self: center; background: var(--danger-bg); border: 1px solid var(--down); color: var(--text); }
.msg > :first-child { margin-top: 0; }
.msg > :last-child { margin-bottom: 0; }
.msg p { margin: 0.5em 0; }
.msg h3, .msg h4 { margin: 0.9em 0 0.3em; font-size: 1rem; text-transform: none; letter-spacing: 0; color: inherit; }
.msg ul, .msg ol { margin: 0.4em 0; padding-left: 1.3em; }
.msg code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 0.9em; }
.msg pre { background: var(--surface-2); padding: 10px; border-radius: 10px; overflow-x: auto; }
.msg pre code { background: none; padding: 0; }
.msg a { color: var(--accent); }
.msg hr { border: 0; border-top: 1px solid var(--border); margin: 0.8em 0; }
.table-wrap { overflow-x: auto; margin: 0.5em 0; }
.msg table { border-collapse: collapse; font-size: 0.9rem; min-width: 60%; }
.msg th, .msg td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; font-variant-numeric: tabular-nums; }
.msg th { background: var(--surface-2); }

.typing { align-self: flex-start; color: var(--muted); padding: 6px 4px; font-size: 0.92rem; }
.typing span { display: inline-block; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.2; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .typing span { animation: none; } .messages { scroll-behavior: auto; } }

.welcome { margin: auto; max-width: 560px; text-align: center; padding: 16px 0; }
.welcome h2 { font-size: 1.4rem; text-transform: none; letter-spacing: 0; color: var(--text); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.chip { background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 10px 14px; min-height: 44px; }
.chip:hover { border-color: var(--accent); }

.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 12px 4px; background: var(--bg); }
.composer textarea { resize: none; max-height: 160px; line-height: 1.4; }
.disclaimer {
  margin: 0; padding: 2px 14px calc(8px + env(safe-area-inset-bottom)); font-size: 0.72rem; color: var(--muted); text-align: center;
}

.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); z-index: 9; }

@media (max-width: 820px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 10; width: min(88vw, 340px);
    transform: translateX(-100%); transition: transform 0.2s ease; padding-top: env(safe-area-inset-top);
  }
  .sidebar.open { transform: none; }
  #menu { display: inline-block; }
  .msg { max-width: 96%; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
