:root {
  --bg: #faf8f5; --panel: #ffffff; --side: #f3efe9; --line: #e6e0d7; --text: #1f1b16; --muted: #7a7166;
  --accent: #f4561e; --accent-ink: #ffffff; --me: #1f1b16; --me-ink: #ffffff; --tool: #8a8076;
  --danger: #c0352b; --code: #f1ece4; --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412; --panel: #1f1c19; --side: #1b1916; --line: #34302b; --text: #ece6de; --muted: #9c938a;
    --accent: #ff6a33; --me: #ece6de; --me-ink: #161412; --tool: #8f867c; --danger: #ff6b5e; --code: #2a2622;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.err { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 9px 14px; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: transparent; font-size: 20px; padding: 6px 10px; cursor: pointer; }

.avatar { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.avatar.big { width: 56px; height: 56px; font-size: 26px; border-radius: 16px; margin: 0 auto 8px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 28px 22px; display: grid; gap: 12px; text-align: center; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card input { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 11px 12px; }

/* layout */
.app { display: grid; grid-template-columns: 280px 1fr; height: 100dvh; }
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); overflow-y: auto; }
.side-head { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; gap: 10px; align-items: center; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.side-sec { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 6px; }
.conv-list { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-height: 80px; overflow-y: auto; }
.conv-list button, .mem-list button { text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 10px; cursor: pointer; width: 100%; }
.conv-list button:hover, .mem-list button:hover { background: var(--line); }
.conv-list button.on, .mem-list button.on { background: var(--panel); box-shadow: 0 0 0 1px var(--line); }
.conv-list .t { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-list .s { display: block; font-size: 12px; color: var(--muted); }
.conv-list .live::before { content: "● "; color: var(--accent); }
.mem-list { display: flex; flex-direction: column; gap: 2px; }
.badge { font-size: 11px; color: var(--muted); }
.scrim { display: none; }

.main { display: flex; flex-direction: column; min-width: 0; height: 100dvh; }
.top { display: flex; align-items: center; gap: 8px; padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--panel); }
.top-title { flex: 1; min-width: 0; }
.top-title b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-title small { color: var(--muted); font-size: 12px; }
.view { flex: 1; overflow-y: auto; padding: 18px 16px; }
.inner { max-width: 760px; margin: 0 auto; }

/* chat */
.msg { margin: 0 0 14px; display: flex; gap: 10px; }
.msg .bubble { border-radius: var(--radius); padding: 10px 14px; max-width: 100%; overflow-x: auto; }
.msg.ramfa .bubble { background: var(--panel); border: 1px solid var(--line); }
.msg.farras { justify-content: flex-end; }
.msg.farras .bubble { background: var(--me); color: var(--me-ink); max-width: 85%; white-space: pre-wrap; word-wrap: break-word; }
.msg.sistem .bubble { background: transparent; border: 1px dashed var(--line); color: var(--muted); font-size: 13px; }
.tools { margin: -6px 0 12px 44px; font-size: 12.5px; color: var(--tool); }
.tools summary { cursor: pointer; list-style: none; }
.tools summary::-webkit-details-marker { display: none; }
.tools li { margin: 2px 0; }
.typing { color: var(--muted); font-size: 13px; margin-left: 44px; }
.typing::after { content: "…"; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.empty .avatar { margin: 0 auto 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.chips button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 7px 12px; cursor: pointer; font-size: 13.5px; }

/* markdown */
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 6px; line-height: 1.3; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; } .md h3, .md h4 { font-size: 15.5px; }
.md p { margin: 6px 0; } .md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md code { background: var(--code); border-radius: 5px; padding: 1px 5px; font-size: 13px; }
.md pre { background: var(--code); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; margin: 8px 0; font-size: 13.5px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.md th { background: var(--code); }
.md blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--line); color: var(--muted); }
.md a { color: var(--accent); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

/* memory view */
.doc { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; }
.doc-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.stat-row { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; min-width: 120px; }
.stat b { display: block; font-size: 22px; }
.stat small { color: var(--muted); }

/* composer */
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 10px 12px; max-height: 40vh; font-size: 16px; }

.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--me); color: var(--me-ink); padding: 8px 14px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: calc(100% - 32px); }
.toast.on { opacity: 1; }

.only-mobile { display: none; }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .only-mobile { display: inline-block; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 20; transform: translateX(-100%); transition: transform .2s; padding-top: calc(14px + env(safe-area-inset-top)); }
  .app.side-open .side { transform: none; }
  .app.side-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 10; }
  .view { padding: 14px 12px; }
  .tools { margin-left: 0; }
  .typing { margin-left: 0; }
  .msg .avatar { display: none; }
}
