/* ============================================================
   चिंतन (Chintan) — Claude-inspired professional UI
   Light + Dark themes · fully offline · no external fonts
   ============================================================ */

:root {
  --bg: #FAF9F5;
  --sidebar-bg: #F2F0E9;
  --surface: #FFFFFF;
  --surface-2: #F5F3EE;
  --text: #1F1E1D;
  --text-soft: #6B6862;
  --text-faint: #A3A09A;
  --accent: #C15F3C;
  --accent-soft: rgba(193, 95, 60, 0.12);
  --border: #E4E1D8;
  --border-soft: #ECE9E1;
  --user-bubble: #C15F3C;
  --user-bubble-text: #FFFFFF;
  --danger: #B3261E;
  --danger-soft: rgba(179, 38, 30, 0.10);
  --shadow: 0 2px 10px rgba(31, 30, 29, 0.07);
  --shadow-lg: 0 8px 30px rgba(31, 30, 29, 0.12);
}

html.dark {
  --bg: #262624;
  --sidebar-bg: #1F1F1E;
  --surface: #30302E;
  --surface-2: #363634;
  --text: #F0EEE8;
  --text-soft: #A8A49C;
  --text-faint: #6E6A64;
  --accent: #D97757;
  --accent-soft: rgba(217, 119, 87, 0.16);
  --border: #3E3D3A;
  --border-soft: #383735;
  --user-bubble: #D97757;
  --user-bubble-text: #26241F;
  --danger: #E57368;
  --danger-soft: rgba(229, 115, 104, 0.14);
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, "Noto Sans", "Noto Sans Devanagari",
               "Nirmala UI", "Mangal", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  overflow: hidden;
  font-size: 15.5px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

svg { display: block; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

/* ==================== SIDEBAR ==================== */
#sidebar {
  width: 264px;
  min-width: 264px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s ease, transform 0.25s ease;
  z-index: 40;
}

body.sb-collapsed #sidebar { margin-left: -264px; }

.sb-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
}

.sb-brand { display: flex; align-items: center; gap: 9px; }

.sb-logo {
  width: 30px; height: 30px;
  fill: var(--accent);
  flex-shrink: 0;
}

.sb-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.icon-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-soft);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }

.sb-new {
  margin: 4px 14px 14px;
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 14.5px;
  transition: border-color 0.15s, transform 0.1s;
}
.sb-new:hover { border-color: var(--accent); }
.sb-new:active { transform: scale(0.98); }
.sb-new svg { width: 15px; height: 15px; }

.sb-section-label {
  padding: 8px 20px 6px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
  color: var(--text-faint);
}

.sb-sessions {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px;
}
.sb-sessions::-webkit-scrollbar { width: 5px; }
.sb-sessions::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sb-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  text-align: left;
  font-size: 14px;
  color: var(--text-soft);
  margin-bottom: 2px;
}
.sb-item:hover { background: var(--surface-2); color: var(--text); }
.sb-item.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.sb-item .si-title {
  flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-item .si-time { font-size: 11.5px; color: var(--text-faint); flex-shrink: 0; }

.sb-empty {
  padding: 10px 20px;
  font-size: 13.5px;
  color: var(--text-faint);
}

.sb-bottom {
  padding: 10px 14px 14px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sb-memory {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-soft);
  transition: background 0.15s;
}
.sb-memory:hover { background: var(--surface-2); color: var(--text); }
.sb-memory svg { width: 17px; height: 17px; }
.sb-memory span:first-of-type { flex: 1; text-align: left; }

.mem-count {
  background: var(--accent);
  color: var(--bg);
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 8px;
}

#sb-theme { width: 100%; padding: 0 12px; justify-content: flex-start; gap: 10px; height: 36px; font-size: 14px; }
#sb-theme svg { width: 15px; height: 15px; }
html:not(.dark) .ic-sun { display: none; }
html.dark .ic-moon { display: none; }

.sb-status {
  display: flex; align-items: center; gap: 8px;
  padding: 2px 12px;
  font-size: 12.5px;
  color: var(--text-soft);
}

.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  flex-shrink: 0;
}
.dot.on { background: #4C9A5B; box-shadow: 0 0 6px rgba(76, 154, 91, 0.6); }
.dot.off { background: var(--danger); }

.sb-footer {
  font-size: 11.5px;
  color: var(--text-faint);
  padding: 4px 12px 0;
  line-height: 1.5;
}

/* ==================== MAIN ==================== */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  min-height: 54px;
}
.topbar h1 { font-size: 16px; font-weight: 700; }
#tb-menu, #tb-new { display: none; }

.brand-chip {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  padding: 2px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ==================== CHAT AREA ==================== */
#chat {
  flex: 1;
  overflow-y: hidden;
  display: flex;
  flex-direction: column;
  scroll-behavior: smooth;
}
#chat::-webkit-scrollbar { width: 8px; }
#chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; }
#chat::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

.msgs { overflow-y: auto; padding: 26px 18px 10px; }

.msg { max-width: 780px; margin: 0 auto 26px; display: flex; gap: 13px; }

/* user bubble */
.msg.user { justify-content: flex-end; }
.msg.user .u-bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  padding: 11px 17px;
  border-radius: 18px 18px 5px 18px;
  max-width: 78%;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow);
  font-size: 15px;
}

/* assistant block */
.msg.assistant { align-items: flex-start; }
.a-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 6px;
  font-weight: 700;
  font-size: 13.5px;
}
.a-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow);
}
.a-avatar svg { width: 14px; height: 14px; fill: currentColor; }
.a-meta { font-weight: 400; font-size: 12px; color: var(--text-faint); }

.a-body {
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 15.5px;
}
.a-body code {
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: 13.5px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 1px 6px;
}
.a-body pre {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
  white-space: pre;
}
.a-body pre code { background: none; border: none; padding: 0; }
.a-body strong, .a-body b { font-weight: 700; }

/* streaming caret */
.caret {
  display: inline-block;
  width: 8px; height: 17px;
  background: var(--accent);
  border-radius: 2px;
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.9s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* thinking dots */
.thinking { display: inline-flex; gap: 5px; padding: 9px 2px; }
.thinking span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  animation: pulse 1.2s ease-in-out infinite;
}
.thinking span:nth-child(2) { animation-delay: 0.18s; }
.thinking span:nth-child(3) { animation-delay: 0.36s; }
@keyframes pulse { 0%, 60%, 100% { transform: scale(0.85); opacity: 0.45; } 30% { transform: scale(1.15); opacity: 1; } }

/* memory badges */
.badges { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.badge {
  font-size: 12px;
  padding: 3px 11px;
  border-radius: 20px;
  display: inline-flex; align-items: center; gap: 6px;
}
.badge.added { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge.used { border: 1px dashed var(--border); color: var(--text-soft); }

/* error bubble */
.msg.assistant.error .a-body { color: var(--danger); }

/* ==================== EMPTY HERO ==================== */
#empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 20px; overflow-y: auto; }
.hero { max-width: 560px; text-align: center; }
.hero-logo {
  width: 52px; height: 52px;
  margin: 0 auto 18px;
  color: var(--accent);
}
.hero-logo svg { width: 100%; height: 100%; }
.hero h2 { font-size: 27px; font-weight: 700; margin-bottom: 10px; }
.hero-sub { color: var(--text-soft); font-size: 15px; margin-bottom: 26px; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 22px;
  padding: 9px 17px;
  font-size: 14px;
  color: var(--text-soft);
  box-shadow: var(--shadow);
  transition: border-color 0.15s, color 0.15s, transform 0.1s;
}
.chip:hover { border-color: var(--accent); color: var(--text); transform: translateY(-1px); }

/* ==================== COMPOSER ==================== */
.composer-wrap { padding: 8px 18px 16px; background: var(--bg); }
.composer {
  max-width: 780px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 10px 10px 20px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
}
.composer textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 15.5px;
  max-height: 190px;
  padding: 6px 0;
  line-height: 1.55;
}
.composer textarea::placeholder { color: var(--text-faint); }

.send {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s, background 0.15s;
}
.send svg { width: 17px; height: 17px; }
.send:hover:not(:disabled) { transform: scale(1.06); }
.send:disabled { opacity: 0.35; cursor: not-allowed; }
body.busy .send { background: var(--text-faint); }

.hint {
  max-width: 780px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* ==================== MEMORY DRAWER ==================== */
#drawer-overlay, #sb-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 14, 13, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s;
  z-index: 45;
}
body.drawer-open #drawer-overlay, body.sb-open #sb-overlay { opacity: 1; pointer-events: auto; }

#drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 410px;
  max-width: 92vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  z-index: 50;
  display: flex;
  flex-direction: column;
}
body.drawer-open #drawer { transform: translateX(0); }

.dr-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.dr-head h2 { font-size: 17px; }
.dr-actions { display: flex; align-items: center; gap: 8px; }

.danger {
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 13px;
  border-radius: 8px;
  transition: background 0.15s;
}
.danger:hover { background: var(--danger); color: #fff; }

.dr-stats {
  display: flex; gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-soft);
}
.dr-stat {
  flex: 1;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 13px;
}
.dr-stat b { display: block; font-size: 19px; }
.dr-stat span { font-size: 12px; color: var(--text-soft); }

.dr-list { flex: 1; overflow-y: auto; padding: 12px 18px 20px; }
.dr-list::-webkit-scrollbar { width: 5px; }
.dr-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.dr-item {
  display: flex; gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  margin-bottom: 8px;
  background: var(--bg);
}
.dr-tag {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 12px;
  height: fit-content;
  margin-top: 2px;
}
.dr-tag.fact { background: var(--accent-soft); color: var(--accent); }
.dr-tag.episode { background: var(--surface-2); color: var(--text-soft); }
.dr-item p { font-size: 13.5px; word-break: break-word; }
.dr-empty { text-align: center; color: var(--text-faint); padding: 34px 10px; font-size: 14px; }

/* ==================== MOBILE ==================== */
@media (max-width: 900px) {
  body { font-size: 15px; }

  #sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    margin-left: 0 !important;
  }
  body.sb-open #sidebar { transform: translateX(0); }
  body.sb-collapsed #sidebar { transform: translateX(-100%); }

  #tb-menu, #tb-new { display: flex; }
  #sb-collapse { display: none; }

  .msg { margin-bottom: 20px; gap: 10px; }
  .composer-wrap { padding: 6px 10px 12px; }
  .hero h2 { font-size: 23px; }
  .hero-sub { font-size: 14px; }
  .chips { gap: 8px; }
  .chip { font-size: 13px; padding: 8px 14px; }

  #drawer { width: 100vw; max-width: 100vw; }
}

@media (min-width: 901px) {
  #sb-overlay { display: none; }
}

/* ==================== BROWSER EDITION: gate + loading ==================== */
.dot.wait { background: #D97757; box-shadow: 0 0 6px rgba(217, 119, 87, 0.6); animation: chintan-pulse 1.1s ease-in-out infinite; }
@keyframes chintan-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.gate {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.gate[hidden] { display: none; }
.gate-card {
  width: min(380px, 90vw);
  background: var(--panel, #FFFFFF);
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  padding: 30px 26px 26px;
  text-align: center;
  box-shadow: 0 12px 44px rgba(0, 0, 0, 0.10);
}
.gate-logo { color: var(--accent, #C15F3C); margin-bottom: 10px; }
.gate-logo svg { width: 46px; height: 46px; }
.gate-card h2 { margin: 4px 0 6px; font-size: 1.25rem; }
.gate-card p { margin: 0 0 18px; font-size: 0.88rem; line-height: 1.5; color: var(--text-dim, #6B6A65); }
#gate-input {
  width: 100%; box-sizing: border-box;
  padding: 11px 14px; font-size: 1rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); color: inherit; text-align: center;
}
#gate-input:focus { outline: 2px solid var(--accent, #C15F3C); outline-offset: -1px; }
#gate-btn {
  margin-top: 12px; width: 100%;
  padding: 11px 14px; font-size: 0.95rem; font-weight: 600;
  color: var(--bg); background: var(--accent, #C15F3C);
  border: none; border-radius: 10px; cursor: pointer;
}
#gate-btn:hover { filter: brightness(1.05); }
.gate-err { margin-top: 10px; color: var(--danger, #C44); font-size: 0.85rem; }
.gate-err[hidden] { display: none; }
.gate-card.shake { animation: chintan-shake 0.35s; }
@keyframes chintan-shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); } 75% { transform: translateX(7px); }
}
