:root {
  --bg: #ffffff;
  --side: #f9f9f8;
  --border: #ececec;
  --text: #1f1f1f;
  --muted: #8a8a8a;
  --soft: #f3f3f2;
  --hover: #efefee;
  --accent: #1f1f1f;
  --radius: 20px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button { font: inherit; color: inherit; cursor: pointer; }

.app { display: flex; height: 100vh; height: 100dvh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 260px; flex-shrink: 0; background: var(--side); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 12px 10px;
}
.new-chat {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff; font-size: 14px;
}
.new-chat:hover { background: var(--hover); }
.history-label { font-size: 12px; color: var(--muted); padding: 18px 10px 6px; }
.history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.history-item {
  display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-radius: 8px;
  font-size: 14px; cursor: pointer; text-decoration: none; color: var(--text);
}
.history-item:hover, .history-item.active { background: var(--hover); }
.history-item span { flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.history-item .del { visibility: hidden; border: 0; background: none; color: var(--muted); padding: 0 4px; font-size: 16px; }
.history-item:hover .del { visibility: visible; }
.history-item .del:hover { color: #c0392b; }
.history-empty { font-size: 13px; color: var(--muted); padding: 6px 10px; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px 6px 2px; }
.privacy-note { font-size: 12px; color: var(--muted); line-height: 1.4; }
.link-btn { border: 0; background: none; padding: 6px 0 0; font-size: 12px; color: var(--muted); text-decoration: underline; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: none; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.topbar-title { font-size: 15px; font-weight: 500; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.icon-btn {
  border: 0; background: none; padding: 6px; border-radius: 8px; color: #555; display: inline-flex;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.on { color: var(--text); background: var(--soft); }

.thread { flex: 1; overflow-y: auto; }
.messages { max-width: 760px; margin: 0 auto; padding: 32px 20px 24px; display: flex; flex-direction: column; gap: 28px; }

.empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding: 0 20px 28px; }
.empty h1 { font-size: 28px; font-weight: 500; margin: 0 0 22px; letter-spacing: -0.01em; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.suggestions button {
  border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 7px 14px; font-size: 14px; color: #444;
}
.suggestions button:hover { background: var(--soft); }
.has-messages .empty { display: none; }
.app:not(.has-messages) .thread { flex: 1; }
.app:not(.has-messages) .composer-wrap { flex: 1; }

/* ---------- Messages ---------- */
.msg { display: flex; flex-direction: column; }
.msg.user { align-items: flex-end; }
.msg.user .bubble {
  background: var(--soft); border-radius: 18px; padding: 10px 16px; max-width: 85%;
  white-space: pre-wrap; line-height: 1.55; font-size: 15px; overflow-wrap: anywhere;
}
.msg.assistant .bubble { line-height: 1.65; font-size: 15px; overflow-wrap: anywhere; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 17px; margin: 20px 0 8px; }
.bubble p { margin: 0 0 12px; }
.bubble ul, .bubble ol { padding-left: 22px; margin: 0 0 12px; }
.bubble li { margin: 3px 0; }
.bubble pre {
  background: #fafafa; border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px;
  white-space: pre-wrap; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13.5px; line-height: 1.6;
}
.bubble code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.9em; background: var(--soft); padding: 1px 5px; border-radius: 5px; }
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; margin: 0 0 12px; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.bubble blockquote { margin: 0 0 12px; padding-left: 14px; border-left: 3px solid var(--border); color: #555; }

.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.meta .tag { background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 2px 9px; }
.meta button { border: 0; background: none; color: var(--muted); padding: 2px 4px; border-radius: 6px; font-size: 12px; }
.meta button:hover { background: var(--soft); color: var(--text); }

.thinking { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 14px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: #bbb; animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; }
.dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.error { color: #b3261e; font-size: 14px; }

.bubble pre.petition {
  font-family: "Times New Roman", Georgia, serif; font-size: 15px; line-height: 1.6; background: #fff;
  border-radius: 10px 10px 0 0; margin-bottom: 0; padding: 22px 26px; max-height: 560px; overflow-y: auto;
}
.bubble pre.petition code { font-family: inherit; font-size: inherit; }
.petition-bar {
  display: flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 10px 10px; padding: 6px 10px; margin-bottom: 14px; background: #fafafa; font-size: 13px;
}
.petition-bar span { color: var(--muted); margin-right: auto; }
.petition-bar button {
  border: 1px solid var(--border); background: #fff; border-radius: 8px; padding: 4px 10px; font-size: 13px;
}
.petition-bar button:hover { background: var(--soft); }
.petition-bar button:disabled { opacity: .5; }

/* ---------- Composer ---------- */
.composer-wrap { padding: 0 20px 14px; }
.composer {
  max-width: 760px; margin: 0 auto; border: 1px solid #e3e3e3; border-radius: var(--radius); background: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.04); padding: 10px 12px 8px;
}
.composer:focus-within { border-color: #cfcfcf; }
.composer textarea {
  width: 100%; border: 0; outline: none; resize: none; font: inherit; font-size: 15px; line-height: 1.5;
  max-height: 240px; padding: 4px 4px; background: transparent;
}
.composer-bar { display: flex; justify-content: space-between; align-items: center; }
.left-tools { display: flex; gap: 2px; }
.send {
  width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}
.send:disabled { background: #d6d6d6; cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:not(:empty) { margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; background: var(--soft); border-radius: 10px;
  padding: 6px 8px 6px 10px; font-size: 13px; max-width: 100%;
}
.chip span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: 260px; }
.chip small { color: var(--muted); }
.chip button { border: 0; background: none; color: var(--muted); padding: 0 2px; font-size: 15px; line-height: 1; }
.chip.loading { opacity: .6; }
.chip.err { background: #fdecea; color: #b3261e; }
.secrets input {
  width: 100%; border: 1px dashed #d8d8d8; border-radius: 10px; padding: 7px 10px; font: inherit; font-size: 13px;
  margin-bottom: 6px; outline: none;
}
.disclaimer { text-align: center; font-size: 11.5px; color: var(--muted); padding-top: 8px; }
.app:not(.has-messages) .composer-wrap { padding-bottom: 22vh; }
.app:not(.has-messages) .empty { justify-content: flex-end; }

/* ---------- Dialog ---------- */
dialog { border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: min(400px, 90vw); }
dialog::backdrop { background: rgba(0,0,0,.25); }
.key-form h2 { margin: 0 0 6px; font-size: 18px; font-weight: 500; }
.key-form p { margin: 0 0 14px; font-size: 14px; color: #555; }
.key-form input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; font: inherit; margin-bottom: 12px; }
.primary { background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 9px 16px; }

/* ---------- Mobile ---------- */
@media (max-width: 800px) {
  .topbar { display: flex; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 10; transform: translateX(-100%);
    transition: transform .2s; box-shadow: 4px 0 20px rgba(0,0,0,.08);
  }
  .sidebar.open { transform: none; }
  .messages { padding: 20px 16px; }
  .composer-wrap { padding: 0 12px 10px; }
  .empty h1 { font-size: 23px; }
}

/* ---------- Login ---------- */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; min-height: 100dvh; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 26px; font-weight: 500; margin: 0 0 6px; text-align: center; letter-spacing: -0.01em; }
.login-sub { text-align: center; color: var(--muted); margin: 0 0 28px; font-size: 14px; }
.login-card label { display: block; font-size: 13px; color: #555; margin-bottom: 14px; }
.login-card input {
  display: block; width: 100%; margin-top: 6px; padding: 11px 13px; border: 1px solid #e0e0e0; border-radius: 12px;
  font: inherit; font-size: 15px; outline: none; background: #fff;
}
.login-card input:focus { border-color: #bdbdbd; }
.login-card .primary { width: 100%; padding: 11px; font-size: 15px; border-radius: 12px; margin-top: 4px; }
.login-card .primary:disabled { opacity: .6; }
.login-error { color: #b3261e; font-size: 13px; min-height: 18px; margin: -4px 0 8px; }
.login-foot { text-align: center; color: var(--muted); font-size: 12px; margin-top: 28px; }

/* ---------- Kullanıcı satırı ---------- */
.user-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: #e7e7e5; display: inline-flex;
  align-items: center; justify-content: center; font-size: 12px; font-weight: 600; color: #555;
}
.user-row .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .link-btn { padding: 0; }

/* ---------- Logo ---------- */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 14px; font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.brand img { border-radius: 7px; display: block; }
.topbar-logo { border-radius: 6px; display: block; }
.login-logo { display: block; margin: 0 auto 18px; border-radius: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.08); }

/* ---------- Emsal ile güçlendir ---------- */
.mode-btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: #fff;
  border-radius: 999px; padding: 4px 11px 4px 9px; font-size: 13px; color: #555; margin-left: 4px;
}
.mode-btn:hover { background: var(--soft); }
.mode-btn.on { background: #1c1c1c; color: #fff; border-color: #1c1c1c; }
.mode-btn.on svg { color: #c9a45c; }
.bubble a[href^="#karar/"] { color: inherit; text-decoration: underline; text-decoration-color: #c9a45c; text-underline-offset: 3px; }

/* ---------- Karar penceresi ---------- */
.decision-dialog { width: min(820px, 94vw); max-height: 86vh; padding: 0; display: none; }
.decision-dialog[open] { display: flex; flex-direction: column; }
.decision-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.decision-head h2 { flex: 1; margin: 0; font-size: 15px; font-weight: 600; }
.decision-body {
  overflow-y: auto; padding: 18px 24px 24px; white-space: pre-wrap; font-family: "Times New Roman", Georgia, serif;
  font-size: 15px; line-height: 1.6;
}
@media (max-width: 800px) { .mode-btn { font-size: 12px; } }
