:root {
  --green: #1f4d3a;
  --green-2: #2d6a4f;
  --green-soft: #e7f0ea;
  --saffron: #c8792b;
  --saffron-soft: #fbeedd;
  --ink: #1d2420;
  --muted: #66706a;
  --line: #e4ddcf;
  --paper: #faf6ee;
  --card: #ffffff;
  --ai: #3b5bdb;
  --ai-soft: #ebefff;
  --ok: #2b8a3e;
  --ok-soft: #e6f4ea;
  --warn: #a35d00;
  --warn-soft: #fff3d6;
  --bad: #c92a2a;
  --bad-soft: #ffe8e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 77, 58, .06), 0 6px 24px rgba(31, 77, 58, .06);
  --font: "Noto Sans", "Noto Sans Devanagari", "Noto Sans Gujarati", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Noto Serif", Georgia, serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: var(--paper); font-size: 15.5px; line-height: 1.6; }
button { font: inherit; cursor: pointer; }
a { color: var(--green-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

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

/* ---------- sidebar */
.sidebar { width: 280px; flex: 0 0 280px; background: var(--green); color: #e9f1ec; display: flex; flex-direction: column; padding: 18px 14px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 10px; }
.logo { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--saffron); color: #fff; font-size: 22px; font-family: "Noto Sans Devanagari", var(--font); }
.brand-title { font-family: var(--serif); font-size: 19px; color: #fff; line-height: 1.2; }
.brand-sub { font-size: 12.5px; opacity: .75; }
.new-chat { display: flex; gap: 8px; align-items: center; justify-content: center; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: #fff; padding: 10px 12px; border-radius: 10px; }
.new-chat:hover { background: rgba(255,255,255,.16); }
.history-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; opacity: .6; padding: 6px 6px 0; }
.history { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.history .item { display: flex; align-items: center; gap: 6px; border-radius: 8px; padding: 8px 8px; color: #dfe9e3; text-decoration: none; font-size: 14px; }
.history .item:hover, .history .item.active { background: rgba(255,255,255,.12); color: #fff; }
.history .item .t { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history .item .del { opacity: 0; border: 0; background: none; color: inherit; padding: 0 4px; }
.history .item:hover .del { opacity: .7; }
.history .empty { font-size: 13px; opacity: .55; padding: 6px; }
.side-foot { border-top: 1px solid rgba(255,255,255,.15); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.side-foot a { color: #cfe0d6; text-decoration: none; }
.side-foot a:hover { color: #fff; }
.kb-stat { opacity: .75; font-size: 12.5px; }

/* ---------- main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); background: rgba(250,246,238,.92); backdrop-filter: blur(6px); }
.top-title { flex: 1; display: flex; align-items: center; gap: 10px; font-weight: 600; min-width: 0; }
.top-title > span:first-child { white-space: nowrap; }
.mode-pill { font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 99px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mode-pill.ai { background: var(--green-soft); color: var(--green); }
.mode-pill.retrieval { background: var(--saffron-soft); color: var(--warn); }
.lang select { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 7px 10px; font: inherit; font-size: 14px; }
.icon-btn { border: 0; background: none; font-size: 20px; padding: 4px 8px; border-radius: 8px; }
.menu { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 24px 20px 12px; scroll-behavior: smooth; }
.messages > * { max-width: 820px; margin-left: auto; margin-right: auto; }

.welcome { text-align: center; padding: 6vh 8px 10px; }
.welcome-mark { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 18px; background: var(--saffron-soft); color: var(--saffron); display: grid; place-items: center; font-size: 32px; font-family: "Noto Sans Devanagari", var(--font); }
.welcome h1 { font-family: var(--serif); color: var(--green); font-size: 28px; margin: 6px 0; }
.welcome p { color: var(--muted); max-width: 560px; margin: 0 auto 20px; }
.samples { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-width: 680px; margin: 0 auto; }
.samples button { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 14px; color: var(--ink); font-size: 14.5px; box-shadow: var(--shadow); transition: transform .12s, border-color .12s; }
.samples button:hover { transform: translateY(-1px); border-color: var(--saffron); }
.legend { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 22px; }

.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px; letter-spacing: .01em; white-space: nowrap; }
.tag.classical { background: var(--saffron-soft); color: #8a4d12; }
.tag.ai { background: var(--ai-soft); color: var(--ai); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.pending { background: var(--warn-soft); color: var(--warn); }

/* ---------- messages */
.msg { margin: 0 auto 22px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { background: var(--green); color: #fff; border-radius: 16px 16px 4px 16px; padding: 10px 16px; max-width: 80%; white-space: pre-wrap; word-wrap: break-word; }
.msg.bot .card { background: var(--card); border: 1px solid var(--line); border-radius: 4px 16px 16px 16px; box-shadow: var(--shadow); padding: 16px 18px; }
.section { margin-bottom: 14px; }
.section:last-child { margin-bottom: 0; }
.section-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.section-h strong { font-size: 14px; color: var(--green); }
.section.classical { border-left: 3px solid var(--saffron); padding-left: 12px; }
.section.ai { border-left: 3px solid var(--ai); padding-left: 12px; }
.body p { margin: 0 0 8px; }
.body p:last-child { margin-bottom: 0; }
.body ul, .body ol { margin: 4px 0 8px; padding-left: 22px; }
.cite { display: inline-block; border: 0; background: var(--saffron-soft); color: #8a4d12; font-size: 11.5px; font-weight: 700; border-radius: 6px; padding: 0 5px; margin: 0 1px; vertical-align: 1px; }
.cite:hover { background: var(--saffron); color: #fff; }
.notice { font-size: 13.5px; border-radius: 10px; padding: 9px 12px; margin-bottom: 12px; }
.notice.warn { background: var(--warn-soft); color: #6d4300; }
.notice.bad { background: var(--bad-soft); color: #8a1c1c; }
.notice.info { background: var(--green-soft); color: var(--green); }

.refs { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
.refs-h { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.ref { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; background: #fffdf8; transition: box-shadow .2s, border-color .2s; }
.ref.flash { border-color: var(--saffron); box-shadow: 0 0 0 3px var(--saffron-soft); }
.ref-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; margin-bottom: 6px; }
.ref-n { font-weight: 700; color: #fff; background: var(--saffron); border-radius: 6px; font-size: 12px; padding: 0 6px; }
.ref-label { font-weight: 600; font-size: 14px; color: var(--green); flex: 1 1 260px; }
.skt { font-family: "Noto Serif", "Noto Sans Devanagari", Georgia, serif; font-style: italic; white-space: pre-line; color: #4a3a22; background: #fbf3e4; border-radius: 8px; padding: 8px 10px; margin: 6px 0; font-size: 14.5px; }
.meaning { font-size: 14.5px; }
.meaning .lang-note { color: var(--muted); font-size: 12px; }
.ref-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
details.related { margin-top: 6px; }
details.related summary { cursor: pointer; font-size: 13px; color: var(--muted); }

.followups { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.followups button { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 5px 12px; font-size: 13.5px; color: var(--green); }
.followups button:hover { border-color: var(--green-2); }
.actions { display: flex; gap: 4px; margin-top: 10px; }
.actions button { border: 0; background: none; color: var(--muted); padding: 4px 8px; border-radius: 8px; font-size: 13px; }
.actions button:hover, .actions button.on { background: var(--green-soft); color: var(--green); }

.typing { display: inline-flex; gap: 5px; align-items: center; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--saffron); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
.typing-text { color: var(--muted); font-size: 13.5px; margin-left: 8px; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- composer */
.composer { display: flex; gap: 10px; align-items: flex-end; max-width: 820px; width: calc(100% - 40px); margin: 0 auto; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 8px 8px 8px 16px; box-shadow: var(--shadow); }
.composer:focus-within { border-color: var(--green-2); }
.composer textarea { flex: 1; border: 0; outline: 0; resize: none; font: inherit; max-height: 180px; padding: 8px 0; background: transparent; }
.send { width: 42px; height: 42px; border: 0; border-radius: 12px; background: var(--green); color: #fff; font-size: 17px; }
.send:disabled { opacity: .5; cursor: default; }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 16px 2px; }
.powered { text-align: center; font-size: 11.5px; color: var(--muted); margin: 0 16px 10px; }
.powered a { color: var(--green-2); font-weight: 600; text-decoration: none; }
.powered a:hover { text-decoration: underline; }
.side-powered { font-size: 11.5px; opacity: .7; margin-top: 4px; }
.side-powered a { color: #fff !important; font-weight: 600; }

dialog { border: 0; border-radius: 16px; max-width: 560px; width: calc(100% - 32px); padding: 22px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 30, 25, .45); }
dialog h2 { font-family: var(--serif); color: var(--green); margin-top: 0; }
dialog li { margin-bottom: 6px; }
.btn { border: 0; background: var(--green); color: #fff; border-radius: 10px; padding: 9px 18px; }

/* ---------- mobile */
@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 30; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .22s ease; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .app.open .sidebar { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: none; }
  .app.open .scrim { display: block; }
  .menu { display: block; }
  .topbar { padding: 10px 12px; }
  .messages { padding: 16px 12px 8px; }
  .composer { width: calc(100% - 20px); }
  .samples { grid-template-columns: 1fr; }
  .welcome h1 { font-size: 23px; }
  .msg.user .bubble { max-width: 90%; }
  .msg.bot .card { padding: 14px; }
}
@media (max-width: 480px) { .mode-pill { display: none; } }
@media (min-width: 861px) { .side-powered { display: none; } }

.report-btn { border: 0; background: none; padding: 0; color: var(--muted); text-decoration: underline; font-size: 12px; }
.report-btn:hover { color: var(--bad); }
.ref-meta a { color: var(--green-2); }
.actions .timing { margin-left: auto; align-self: center; font-size: 12px; color: var(--muted); }
