/* Rajasthan AI Government — shared styles (login + chat) */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --border: #dde3ee;
  --text: #16202f;
  --muted: #5d6b82;
  --primary: #0f3d7a;
  --primary-2: #1a56a8;
  --primary-ink: #ffffff;
  --accent: #e8850c;
  --accent-soft: #fff3e0;
  --user-bg: #0f3d7a;
  --user-ink: #ffffff;
  --danger: #b3261e;
  --ok: #1b7f4b;
  --shadow: 0 1px 2px rgba(16, 32, 60, .06), 0 6px 20px rgba(16, 32, 60, .06);
  --radius: 14px;
  --logo-bg: #051016;
  --font: "Inter", "Noto Sans Devanagari", "Nirmala UI", "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d121b; --surface: #151c29; --surface-2: #1b2434; --border: #27324a;
    --text: #e6ebf5; --muted: #93a1ba; --primary: #5b9bff; --primary-2: #86b4ff;
    --primary-ink: #08111f; --accent: #ffb04d; --accent-soft: #2b2113;
    --user-bg: #234a86; --user-ink: #ffffff; --danger: #ff8a80; --ok: #62d394;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--bg); color: var(--text); font-family: var(--font);
  font-size: 15px; line-height: 1.6; -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary-2); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- buttons / fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 10px; padding: 10px 16px; font-weight: 600;
  background: var(--primary); color: var(--primary-ink); transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); filter: none; }
.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 8px;
  border: 1px solid transparent; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label { font-weight: 600; font-size: 13px; color: var(--muted); }
.input {
  width: 100%; padding: 11px 13px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--primary-2); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-2) 25%, transparent); }

/* ---------- login ---------- */
.login-shell { min-height: 100%; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-brand {
  background: linear-gradient(160deg, #051016 0%, #051016 14%, #082746 50%, #0f3d7a 100%); color: #fff;
  padding: 56px 40px 64px; display: flex; flex-direction: column; justify-content: center; align-items: center;
  text-align: center; position: relative; overflow: hidden;
}
.login-brand::after {
  content: ""; position: absolute; inset: auto -120px -160px auto; width: 420px; height: 420px; border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 133, 12, .35), transparent 65%);
}
.emblem {
  width: 54px; height: 54px; border-radius: 14px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .25);
}
.brand-logo { display: block; width: 176px; height: auto; margin: 0 auto; mix-blend-mode: lighten; }
.login-brand h1 { font-size: 34px; line-height: 1.25; margin: 24px 0 8px; }
.login-brand h1 small { display: block; font-size: 19px; font-weight: 500; opacity: .85; margin-top: 6px; }
.login-brand p { max-width: 460px; opacity: .88; margin: 0 auto; }
.brand-points { list-style: none; padding: 0; margin: 28px auto 0; width: fit-content; max-width: 100%; text-align: left;
  display: grid; gap: 12px; position: relative; z-index: 1; }
.brand-points li { display: flex; gap: 10px; align-items: flex-start; opacity: .92; }
.brand-points svg { flex: none; margin-top: 4px; }
.login-foot { font-size: 12.5px; opacity: .7; position: absolute; left: 0; right: 0; bottom: 22px; text-align: center; z-index: 1; }
.login-panel { display: grid; place-items: center; padding: 32px; }
.login-card { width: min(400px, 100%); }
.login-card h2 { margin: 0 0 4px; font-size: 24px; }
.login-card .sub { color: var(--muted); margin: 0 0 26px; }
.pw-wrap { position: relative; }
.pw-wrap .icon-btn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.pw-wrap .input { padding-right: 44px; }
.form-error {
  background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  padding: 10px 12px; border-radius: 10px; margin-bottom: 16px; font-size: 14px;
}
.lang-switch { position: absolute; top: 18px; right: 22px; z-index: 5; }
.lang-switch button {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px;
  font-size: 13px; font-weight: 600; color: var(--muted);
}
@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-brand { padding: 28px 22px 26px; }
  .login-brand h1 { font-size: 24px; margin-top: 16px; }
  .brand-points, .login-foot { display: none; }
  .login-panel { padding: 24px 16px 40px; align-items: start; }
}

/* ---------- chat layout ---------- */
.app { height: 100vh; height: 100dvh; display: grid; grid-template-columns: 290px 1fr; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column;
  min-height: 0; z-index: 30;
}
.side-head { padding: 16px 16px 12px; display: flex; align-items: center; gap: 10px; }
.side-logo { width: 44px; height: 44px; border-radius: 11px; flex: none; background: var(--logo-bg); box-shadow: 0 0 0 1px var(--border); }
.top-logo { display: none; width: 30px; height: 30px; border-radius: 8px; flex: none; background: var(--logo-bg); }
.side-head b { display: block; line-height: 1.2; font-size: 14.5px; }
.side-head span { font-size: 12px; color: var(--muted); }
.side-new { padding: 0 16px 12px; }
.side-new .btn { width: 100%; }
.conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-label { padding: 8px 10px 4px; font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.conv {
  display: flex; align-items: center; gap: 4px; border-radius: 9px; padding: 2px 4px 2px 10px; margin-bottom: 2px;
  cursor: pointer; border: 1px solid transparent;
}
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--surface-2); border-color: var(--border); }
.conv-title { flex: 1; min-width: 0; padding: 8px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: none; border: 0; text-align: left; }
.conv .icon-btn { width: 28px; height: 28px; opacity: 0; }
.conv:hover .icon-btn, .conv.active .icon-btn, .conv:focus-within .icon-btn { opacity: 1; }
.empty-hint { padding: 16px 12px; color: var(--muted); font-size: 13.5px; }
.side-foot { border-top: 1px solid var(--border); padding: 12px 16px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 700; display: grid; place-items: center; flex: none; }
.who { flex: 1; min-width: 0; line-height: 1.25; }
.who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.who span { font-size: 12px; color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar h1 { font-size: 15.5px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .menu-btn { display: none; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.scroller { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.thread { max-width: 860px; margin: 0 auto; padding: 24px 20px 12px; display: grid; gap: 22px; }

.welcome { max-width: 720px; margin: 9vh auto 0; padding: 0 20px; text-align: center; }
.hero-logo { display: block; width: 150px; height: auto; margin: 0 auto 20px; border-radius: 18px; background: var(--logo-bg); box-shadow: var(--shadow); }
.welcome h2 { font-size: 26px; margin: 0 0 8px; }
.welcome p { color: var(--muted); margin: 0 auto 24px; max-width: 560px; }
.scope { margin: -10px auto 20px; font-size: 12.5px; color: var(--muted); max-width: 640px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 8px 14px;
  font-size: 13.5px; text-align: left; transition: border-color .15s, background .15s; box-shadow: var(--shadow);
}
.chip:hover { border-color: var(--primary-2); background: var(--surface-2); }

.msg { display: flex; gap: 12px; }
.msg.user { justify-content: flex-end; }
.msg .bubble { max-width: min(86%, 700px); }
.msg.user .bubble { background: var(--user-bg); color: var(--user-ink); padding: 10px 16px; border-radius: 18px 18px 4px 18px; white-space: pre-wrap; word-break: break-word; }
.msg.bot .avatar-bot { width: 32px; height: 32px; border-radius: 10px; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; flex: none; margin-top: 2px; }
.msg.bot .bubble { flex: 1; min-width: 0; max-width: 100%; }
.answer { background: var(--surface); border: 1px solid var(--border); border-radius: 4px 18px 18px 18px; padding: 14px 18px; box-shadow: var(--shadow); word-break: break-word; }
.answer > :first-child { margin-top: 0; }
.answer > :last-child { margin-bottom: 0; }
.answer p { margin: 0 0 10px; }
.answer ul, .answer ol { margin: 0 0 10px; padding-left: 22px; }
.answer li { margin: 3px 0; }
.answer h3, .answer h4 { margin: 14px 0 6px; font-size: 15px; }
.answer table { border-collapse: collapse; width: 100%; margin: 6px 0 12px; font-size: 13.5px; display: block; overflow-x: auto; }
.answer th, .answer td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; vertical-align: top; }
.answer th { background: var(--surface-2); }
.answer code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }
.cite {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 4px; margin: 0 1px;
  border-radius: 5px; border: 0; background: var(--accent-soft); color: var(--accent); font-size: 11px; font-weight: 700;
  vertical-align: 1px; line-height: 1;
}
.cite:hover { background: var(--accent); color: #fff; }
.typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite both; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
.answer.error { border-color: color-mix(in srgb, var(--danger) 45%, transparent); }

.tools { display: flex; gap: 4px; margin-top: 6px; }
.tools .icon-btn { width: 30px; height: 30px; }

.block-title { margin: 14px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.sources { display: grid; gap: 8px; grid-template-columns: 1fr; }
.source-card { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 10px 12px; font-size: 13px; display: grid; gap: 4px; transition: box-shadow .3s, border-color .3s; }
.source-card.flash { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent); }
.source-top { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.source-top .badge { background: var(--accent-soft); color: var(--accent); border-radius: 5px; padding: 0 6px; font-weight: 700; font-size: 11.5px; }
.source-top .meta { color: var(--muted); font-size: 12px; }
.source-heading { font-weight: 600; line-height: 1.45; flex: 1; min-width: 0; }
.source-card .meta { color: var(--muted); font-size: 12.5px; }
.source-subject { color: var(--muted); font-size: 12.5px; }
.source-text summary { cursor: pointer; color: var(--primary-2); font-weight: 600; font-size: 12.5px; }
.source-text pre { white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; padding: 8px 10px; max-height: 240px; overflow: auto;
  background: var(--surface-2); border-radius: 8px; font-family: inherit; font-size: 12.5px; line-height: 1.55; }
.source-snippet { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.source-card a { justify-self: start; color: var(--primary-2); font-weight: 600; text-decoration: none; display: inline-flex; gap: 5px; align-items: center; }
.source-card a:hover { text-decoration: underline; }
.related { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.related .chip { box-shadow: none; }

.composer-wrap { padding: 8px 20px calc(18px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 70%, transparent); }
.composer {
  max-width: 860px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px; padding: 8px 8px 8px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
}
.composer:focus-within { border-color: var(--primary-2); }
.composer textarea { flex: 1; border: 0; outline: 0; resize: none; background: transparent; padding: 8px 0; max-height: 180px; line-height: 1.5; }
.send-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--primary); color: var(--primary-ink); display: grid; place-items: center; flex: none; }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }
.send-btn.stop { background: var(--danger); color: #fff; }
.hint { max-width: 860px; margin: 6px auto 0; text-align: center; font-size: 12px; color: var(--muted); }

.scrim { display: none; }
@media (max-width: 860px) {
  .topbar .top-logo { display: block; }
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); transform: translateX(-102%); transition: transform .2s; box-shadow: var(--shadow); }
  .app.nav-open .sidebar { transform: none; }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 20; }
  .topbar .menu-btn { display: inline-grid; }
  .topbar { padding: 10px 12px; }
  .thread { padding: 16px 12px 8px; }
  .composer-wrap { padding: 6px 10px 12px; }
  .msg .bubble { max-width: 94%; }
  .msg.bot .avatar-bot { display: none; }
  .hint { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .brand-logo { width: 96px; }
  .login-brand h1 small { font-size: 15px; }
  .login-brand p { font-size: 14px; }
  .hero-logo { width: 116px; }
  .welcome { margin-top: 4vh; }
  .welcome h2 { font-size: 21px; }
  .chip { width: 100%; text-align: left; }
  .chips { flex-direction: column; }
  .input, .composer textarea { font-size: 16px; }            /* stops iOS zooming into the field */
  .answer { padding: 12px 14px; }
  .source-card { font-size: 13px; }
}
@media (max-width: 420px) {
  .login-panel { padding: 20px 14px 32px; }
  .topbar h1 { font-size: 14px; }
  .msg .bubble { max-width: 100%; }
}
@media (min-width: 1500px) { .thread, .composer, .hint { max-width: 960px; } }
.scope { display: grid; gap: 2px; justify-items: center; }
.scope strong { font-weight: 600; color: var(--text); opacity: .8; }
.scope-office { display: block; max-width: 100%; }
@media (max-width: 860px) {
  .login-shell { grid-template-rows: auto 1fr; }            /* banner only as tall as its content; form gets the rest */
  .login-brand { justify-content: flex-start; }
  .login-brand::after { width: 260px; height: 260px; inset: auto -90px -120px auto; }
}
