/* ============ Tasarım değişkenleri ============ */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --hover: #eceef1;
  --border: #e5e7eb;
  --border-strong: #d0d5dd;
  --text: #111827;
  --text-2: #4b5563;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #2563eb;
  --accent-fg: #ffffff;
  --accent-soft: #eaf1ff;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --danger-border: #fecdca;
  --ok: #16a34a;
  --warn: #d97706;
  --code-bg: #f6f8fa;
  --code-head: #eceff3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 12px 32px rgba(16, 24, 40, .12);
  --scrim: rgba(17, 24, 39, .45);
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sb-w: 272px;
}
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111316;
  --sidebar: #0b0c0e;
  --surface: #17191d;
  --surface-2: #1d2025;
  --hover: #23272d;
  --border: #272b32;
  --border-strong: #363c46;
  --text: #e8eaed;
  --text-2: #b6bcc6;
  --muted: #8b929d;
  --accent: #2f6bed;
  --accent-hover: #4a80f5;
  --accent-text: #86adff;
  --accent-fg: #ffffff;
  --accent-soft: #172440;
  --danger: #f97066;
  --danger-bg: #2a1614;
  --danger-border: #55231f;
  --ok: #34d399;
  --warn: #fbbf24;
  --code-bg: #0d0f12;
  --code-head: #1a1d22;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 16px 40px rgba(0, 0, 0, .5);
  --scrim: rgba(0, 0, 0, .6);
}

/* ============ Temel ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.6 var(--font); -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
button:disabled { cursor: not-allowed; }
a { color: var(--accent-text); }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--accent-soft); }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 13px; height: 13px; }

/* Kaydırma çubukları */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }

/* ============ Düzen ============ */
.shell { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ============ Kenar çubuğu ============ */
.sidebar {
  width: var(--sb-w); flex: none; background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 12px 10px; gap: 10px;
  transition: margin-left .22s ease, transform .22s ease;
}
.shell.sb-collapsed .sidebar { margin-left: calc(var(--sb-w) * -1); }
.sb-top { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px 0; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 650; font-size: 1rem; letter-spacing: -.01em; }
.brand img { width: 28px; height: 28px; border-radius: 8px; display: block; }
.sidebar .sb-close { display: none; }

.new-chat {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 550; font-size: .9rem;
  transition: background .15s, border-color .15s;
}
.new-chat:hover { background: var(--hover); }

.chat-list { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -4px; padding: 0 4px 8px; }
.group-label { font-size: .72rem; font-weight: 600; color: var(--muted); padding: 14px 10px 6px; letter-spacing: .03em; }
.chat-item { display: flex; align-items: center; border-radius: 8px; position: relative; }
.chat-item:hover, .chat-item.cur { background: var(--hover); }
.ci-main {
  flex: 1; min-width: 0; text-align: left; padding: 8px 10px; font-size: .875rem; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 8px;
}
.chat-item.cur .ci-main, .chat-item:hover .ci-main { color: var(--text); }
.ci-del {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 4px; height: 28px; min-width: 28px; margin-right: 4px;
  border-radius: 6px; color: var(--muted); opacity: 0; font-size: .75rem; font-weight: 600; padding: 0 6px;
}
.chat-item:hover .ci-del, .chat-item:focus-within .ci-del, .chat-item.cur .ci-del { opacity: 1; }
.ci-del:hover { color: var(--danger); background: var(--surface-2); }
.ci-del.armed { color: var(--danger); background: var(--danger-bg); opacity: 1; }
@media (hover: none) { .ci-del { opacity: .7; } }

.list-empty { padding: 18px 12px; text-align: center; color: var(--muted); font-size: .85rem; line-height: 1.55; }
.list-empty .btn { margin-top: 12px; }

.sb-foot { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 10px; }
.sb-links { display: flex; gap: 14px; padding: 0 8px; }
.sb-links a { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: .8rem; text-decoration: none; }
.sb-links a:hover { color: var(--text); }
.account-wrap { position: relative; }
.account { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 10px; text-align: left; transition: background .15s; }
.account:hover, .account[aria-expanded="true"] { background: var(--hover); }
.avatar-sm { width: 32px; height: 32px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; font-weight: 650; font-size: .85rem; text-transform: uppercase; }
.acc-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.acc-name { font-size: .875rem; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acc-sub { font-size: .75rem; color: var(--muted); }

.menu {
  position: absolute; left: 0; right: 0; bottom: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 5px; z-index: 30;
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border-radius: 8px; font-size: .875rem; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu #menuLogout { color: var(--danger); }

.scrim { display: none; }

/* ============ Üst çubuk ============ */
.topbar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; min-height: 56px; }
.model { display: flex; align-items: center; gap: 8px; margin-left: 4px; min-width: 0; }
.model-name { font-weight: 600; letter-spacing: -.01em; }
.model-tag { font-size: .72rem; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; background: var(--surface); white-space: nowrap; }
.top-actions { margin-left: auto; display: flex; gap: 4px; }
.icon-btn { position: relative; width: 36px; height: 36px; border-radius: 9px; display: inline-grid; place-items: center; color: var(--text-2); transition: background .15s, color .15s; flex: none; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.key-dot { position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); border: 2px solid var(--bg); box-sizing: content-box; }
.key-dot.ok { background: var(--ok); }

/* ============ Konuşma ============ */
.thread { flex: 1; min-height: 0; overflow-y: auto; scroll-behavior: smooth; }
.thread-inner { max-width: 768px; margin: 0 auto; padding: 8px 20px 24px; min-height: 100%; display: flex; flex-direction: column; }
.messages { display: flex; flex-direction: column; }

.welcome { margin: auto; text-align: center; padding: 8vh 0 4vh; max-width: 640px; }
.welcome img { width: 56px; height: 56px; border-radius: 14px; box-shadow: 0 6px 20px rgba(37, 99, 235, .25); }
.welcome h1 { font-size: 1.75rem; font-weight: 650; letter-spacing: -.02em; margin: 20px 0 8px; line-height: 1.25; }
.welcome p { color: var(--muted); margin: 0 auto; max-width: 480px; }
.suggestions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 32px; text-align: left; }
.suggestions button {
  display: flex; flex-direction: column; gap: 3px; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface);
  transition: background .15s, border-color .15s, transform .15s;
}
.suggestions button:hover { background: var(--surface-2); border-color: var(--border-strong); }
.suggestions b { font-size: .85rem; font-weight: 600; }
.suggestions span { font-size: .83rem; color: var(--muted); line-height: 1.45; }

.msg { display: flex; gap: 14px; margin: 0 0 26px; }
.msg.user { justify-content: flex-end; }
.msg .bubble {
  background: var(--surface-2); padding: 10px 16px; border-radius: 18px 18px 5px 18px; max-width: 84%;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
}
.msg .avatar { width: 28px; height: 28px; border-radius: 8px; flex: none; margin-top: 1px; }
.msg .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.msg.error .body { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger); border-radius: 12px; padding: 10px 14px; flex: 0 1 auto; }
.msg.error .body strong { color: inherit; }
.chip { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-text); margin-bottom: 6px; }
.bubble .chip { display: table; }
.bubble img.pic { display: block; max-width: 100%; max-height: 260px; border-radius: 10px; margin-bottom: 8px; }
.bubble .note { font-size: .8rem; color: var(--muted); margin-bottom: 4px; }

.status { color: var(--muted); display: inline-flex; align-items: center; gap: 10px; }
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.actions { display: flex; gap: 2px; margin-top: 8px; }
.act-btn { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 7px; color: var(--muted); font-size: .78rem; }
.act-btn:hover { background: var(--hover); color: var(--text); }
.act-btn .i { width: 15px; height: 15px; }

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .85em; }
.md h2, .md h3, .md h4, .md h5 { margin: 1.3em 0 .5em; line-height: 1.3; letter-spacing: -.01em; }
.md h2 { font-size: 1.25rem; } .md h3 { font-size: 1.1rem; } .md h4, .md h5 { font-size: 1rem; }
.md ul, .md ol { margin: 0 0 .85em; padding-left: 1.5em; }
.md li { margin: .25em 0; padding-left: .2em; }
.md li::marker { color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--border); margin: 1.4em 0; }
.md blockquote { margin: 0 0 .85em; padding: 2px 0 2px 14px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.md code { font-family: var(--mono); font-size: .86em; background: var(--surface-2); padding: .15em .4em; border-radius: 5px; }
.md strong { font-weight: 650; }
.md a { text-underline-offset: 2px; }
.codeblock { margin: 0 0 1em; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--code-bg); }
.cb-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 6px 14px; background: var(--code-head); color: var(--muted); font-size: .75rem; font-family: var(--mono); }
.cb-copy { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 6px; color: var(--muted); font: inherit; font-family: var(--font); }
.cb-copy:hover { background: var(--hover); color: var(--text); }
.cb-copy .i { width: 14px; height: 14px; }
.md pre { margin: 0; padding: 14px; overflow-x: auto; }
.md pre code { background: none; padding: 0; font-size: .85rem; line-height: 1.6; white-space: pre; }
.table-wrap { overflow-x: auto; margin: 0 0 1em; border: 1px solid var(--border); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.md th, .md td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.md th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }

/* Görsel oluşturma */
.gen-cap { font-weight: 550; margin-bottom: 10px; }
.gen-img { display: block; width: 100%; max-width: 480px; aspect-ratio: 1 / 1; object-fit: cover; border-radius: 12px; border: 1px solid var(--border); background: var(--surface-2); }
.gen-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); font-size: .8rem; font-weight: 550; text-decoration: none; color: var(--text); transition: background .15s;
}
.pill:hover { background: var(--hover); }
.pill .i { width: 14px; height: 14px; }
.gen-prompt { margin-top: 10px; font-size: .82rem; color: var(--muted); }
.gen-prompt summary { cursor: pointer; }
.gen-prompt p { margin: 6px 0 0; }

/* ============ Mesaj kutusu ============ */
.composer-area { padding: 0 20px calc(14px + env(safe-area-inset-bottom)); }
.composer-inner { max-width: 768px; margin: 0 auto; }
.composer {
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 18px; padding: 10px 10px 8px 16px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04); transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.composer textarea { display: block; width: 100%; resize: none; border: 0; outline: 0; background: transparent; line-height: 1.55; max-height: 200px; padding: 4px 0; }
.composer textarea::placeholder { color: var(--muted); }
.comp-row { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.comp-left { display: flex; gap: 4px; align-items: center; }
.tool-btn { height: 32px; min-width: 32px; padding: 0 8px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--text-2); font-size: .8rem; font-weight: 550; transition: background .15s, color .15s; }
.tool-btn:hover { background: var(--hover); color: var(--text); }
.tool-toggle[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }
.send-btn { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-fg); transition: background .15s, opacity .15s; }
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: .3; }
.footnote { margin: 10px 4px 0; text-align: center; font-size: .72rem; color: var(--muted); line-height: 1.45; }
.notice { display: flex; align-items: center; gap: 10px; padding: 9px 14px; margin-bottom: 10px; border-radius: 12px; background: var(--accent-soft); color: var(--text); font-size: .85rem; }
.notice .i { color: var(--accent-text); }
.link-btn { margin-left: auto; color: var(--accent-text); font-weight: 600; font-size: .85rem; white-space: nowrap; }
.link-btn:hover { text-decoration: underline; }
.attach-strip { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: rgba(0, 0, 0, .7); color: #fff; display: grid; place-items: center; }
.thumb button .i { width: 12px; height: 12px; stroke-width: 2.2; }

/* ============ Modal ============ */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--scrim); backdrop-filter: blur(2px); animation: fade .15s ease; }
.modal-card { position: relative; width: 100%; max-width: 400px; max-height: 92vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 26px 22px; box-shadow: var(--shadow); animation: pop .18s ease; }
.modal-x { position: absolute; top: 10px; right: 10px; }
.modal-logo { width: 40px; height: 40px; border-radius: 10px; display: block; margin-bottom: 14px; }
.modal h2 { margin: 0 0 6px; font-size: 1.2rem; font-weight: 650; letter-spacing: -.015em; }
.modal .sub { margin: 0 0 18px; color: var(--muted); font-size: .88rem; line-height: 1.5; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--surface-2); border-radius: 10px; padding: 3px; margin-bottom: 16px; }
.tabs button { padding: 7px; border-radius: 8px; font-size: .86rem; font-weight: 550; color: var(--muted); transition: background .15s, color .15s; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .8rem; font-weight: 550; margin-bottom: 6px; color: var(--text-2); }
.field small { display: block; margin-top: 6px; color: var(--muted); font-size: .76rem; }
.field input, .input-group input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--bg); outline: 0;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .input-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.form-err { min-height: 1.3em; margin: -4px 0 10px; font-size: .82rem; color: var(--danger); }
.form-err.info { color: var(--muted); }
.fine { margin: 16px 0 0; font-size: .76rem; color: var(--muted); line-height: 1.5; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: .9rem; border: 1px solid var(--border-strong); background: var(--surface); transition: background .15s, opacity .15s; }
.btn:hover:not(:disabled) { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; }
.set-sec { margin-top: 20px; }
.set-sec h3 { margin: 0 0 10px; font-size: .85rem; font-weight: 600; }
.input-group { display: flex; gap: 6px; align-items: center; }
.hint { margin: 8px 0 0; font-size: .78rem; color: var(--muted); line-height: 1.5; }
.hint.ok { color: var(--ok); }
.hint.err { color: var(--danger); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface-2); border-radius: 10px; padding: 3px; }
.segmented button { padding: 7px; border-radius: 8px; font-size: .85rem; font-weight: 550; color: var(--muted); }
.segmented button[aria-checked="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(16, 24, 40, .12); }

/* Bildirimler */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 80; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .86rem; box-shadow: var(--shadow); animation: pop .2s ease; transition: opacity .35s; }
.toast.err { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ============ Mobil ============ */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 40; inset: 0 auto 0 0; width: min(86vw, 300px); margin-left: 0 !important; transform: translateX(-100%); }
  .shell.sb-open .sidebar { transform: none; box-shadow: var(--shadow); }
  .shell.sb-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: var(--scrim); }
  .sidebar .sb-close { display: inline-grid; }
}
@media (max-width: 560px) {
  .suggestions { grid-template-columns: 1fr; }
  .suggestions button:nth-child(n+3) { display: none; }
  .welcome h1 { font-size: 1.45rem; }
  .model-tag { display: none; }
  .thread-inner { padding: 4px 14px 20px; }
  .composer-area { padding: 0 12px calc(10px + env(safe-area-inset-bottom)); }
  .msg .bubble { max-width: 92%; }
  .tool-toggle span { display: none; }
  .footnote { font-size: .68rem; }
  .modal-card { padding: 24px 20px 18px; }
}

.select { width: 100%; padding: 10px 12px; margin-bottom: 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; }
#localLoad { width: 100%; }
.progress-wrap { margin: 10px 0 0; }
.progress-track { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.progress-bar { height: 100%; width: 0%; border-radius: 99px; background: var(--accent); transition: width .25s ease; }
