/* ============ VARIABLES & BASE ============ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(34, 211, 238, 0.12), transparent 60%),
    radial-gradient(ellipse 60% 60% at 100% 100%, rgba(20, 184, 166, 0.08), transparent 60%),
    #0b1220;
  color: #e2e8f0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.005em;
}

/* Light theme override */
body.light {
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(8, 127, 117, 0.08), transparent 60%),
    #f8fbfb;
  color: #18232d;
}

/* ============ SHELL ============ */
.shell {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr) 320px;
  min-height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  background: rgba(15, 23, 42, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid #1f2937;
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
body.light .sidebar { background: rgba(255,255,255,0.85); border-right-color: #d9e4e5; }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; }
.logo {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #22d3ee, #14b8a6);
  border-radius: 12px;
  color: #0b1220;
  box-shadow: 0 8px 24px rgba(34, 211, 238, 0.25);
}
.logo svg { width: 22px; height: 22px; }
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: -0.02em; }
body.light .brand-name { color: #087f75; }
.brand-sub { font-size: 11px; color: #64748b; letter-spacing: 0.02em; font-weight: 500; }

.new-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 12px 16px;
  background: linear-gradient(135deg, #22d3ee, #14b8a6);
  color: #0b1220;
  border: 0;
  border-radius: 12px;
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
  box-shadow: 0 4px 14px rgba(20, 184, 166, 0.3);
}
.new-btn:hover { transform: translateY(-1px); box-shadow: 0 8px 22px rgba(20, 184, 166, 0.45); }
.new-btn:active { transform: translateY(0); }

.history-section { flex: 1; overflow-y: auto; margin-top: 28px; }
.history-label {
  font-size: 10.5px; letter-spacing: 0.18em; color: #64748b;
  font-weight: 700; margin-bottom: 10px;
}
.muted-history { color: #64748b; font-size: 12.5px; line-height: 1.55; }

.sidebar-footer { margin-top: 20px; padding-top: 18px; border-top: 1px solid #1f2937; }
body.light .sidebar-footer { border-top-color: #d9e4e5; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; color: #14b8a6;
  margin-bottom: 8px;
}
body.light .badge { color: #087f75; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: #14b8a6; box-shadow: 0 0 0 3px rgba(20,184,166,0.2); animation: pulse 2s ease infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 3px rgba(20,184,166,0.2);}50% { box-shadow: 0 0 0 7px rgba(20,184,166,0); } }
.sidebar-footer small { display: block; font-size: 10.5px; color: #64748b; line-height: 1.5; }

/* ============ MAIN ============ */
main { display: flex; flex-direction: column; padding: 28px 40px; max-width: 980px; width: 100%; margin: 0 auto; }

.topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; }
.kicker {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 11px; letter-spacing: 0.18em; font-weight: 700;
  color: #22d3ee;
}
body.light .kicker { color: #087f75; }
.kicker-dot { width: 6px; height: 6px; border-radius: 50%; background: #22d3ee; }
.main-title {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 500;
  margin: 6px 0 0;
  letter-spacing: -0.025em;
  line-height: 1.15;
}
.theme-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  background: rgba(34, 211, 238, 0.05);
  border: 1px solid #1f2937;
  border-radius: 50%;
  color: #94a3b8;
  cursor: pointer;
  transition: all .2s ease;
}
.theme-btn:hover { color: #22d3ee; border-color: #22d3ee; }
body.light .theme-btn { background: #fff; border-color: #d9e4e5; }

.messages {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 20px 0; min-height: 380px;
}

/* === Welcome === */
.welcome { text-align: center; max-width: 620px; margin: auto; }
.welcome-icon {
  width: 72px; height: 72px;
  display: grid; place-items: center;
  margin: 0 auto 22px;
  background: linear-gradient(135deg, rgba(34,211,238,0.18), rgba(20,184,166,0.12));
  border: 1px solid rgba(34, 211, 238, 0.22);
  border-radius: 22px;
  color: #22d3ee;
}
.welcome h2 {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: 28px; font-weight: 500;
  margin: 0 0 12px;
}
.welcome p {
  font-size: 14px; color: #94a3b8; line-height: 1.65; max-width: 480px; margin: 0 auto;
}
body.light .welcome p { color: #6a7b82; }

.suggestions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 28px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid #1f2937;
  border-radius: 99px;
  color: #cbd5e1;
  font-size: 12.5px; font-weight: 500;
  cursor: pointer;
  transition: all .18s ease;
}
.chip:hover { border-color: #22d3ee; color: #22d3ee; transform: translateY(-1px); }
.chip svg { color: #14b8a6; }
body.light .chip { background: #fff; border-color: #d9e4e5; color: #18232d; }

/* === Progress & Answer === */
.progress {
  display: flex; align-items: center; gap: 12px;
  padding: 22px;
  background: rgba(34, 211, 238, 0.05);
  border: 1px solid rgba(34, 211, 238, 0.18);
  border-radius: 16px;
  color: #22d3ee;
  font-size: 14px;
  max-width: 600px;
  margin: auto;
}
.progress::before {
  content: ''; width: 14px; height: 14px;
  border: 2px solid #22d3ee; border-top-color: transparent;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.answer {
  font-family: 'IBM Plex Serif', Georgia, serif;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid #1f2937;
  border-radius: 20px;
  padding: 32px 36px;
  line-height: 1.75;
  font-size: 15.5px;
  width: 100%;
  max-width: 920px;
  animation: fadein .5s ease;
}
body.light .answer { background: #fff; border-color: #d9e4e5; }
@keyframes fadein { from { opacity: 0; transform: translateY(8px);} to { opacity: 1; transform: translateY(0);} }

/* Streaming cursor */
.cursor {
  display: inline-block;
  width: 9px; height: 1.1em;
  background: linear-gradient(135deg, #22d3ee, #14b8a6);
  margin-left: 2px;
  vertical-align: -3px;
  animation: blink 1s step-end infinite;
  border-radius: 1px;
}
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

.answer h3 {
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 16px; font-weight: 700;
  color: #22d3ee; letter-spacing: -0.01em;
  margin: 22px 0 14px; padding-bottom: 8px;
  border-bottom: 1px solid #1f2937;
}
.answer h3:first-child { margin-top: 0; }
body.light .answer h3 { color: #087f75; border-bottom-color: #d9e4e5; }
.answer h3 + p, .answer h3 + ul { margin-top: 0; }

.answer ul { padding-left: 0; margin: 0; list-style: none; }
.answer li {
  position: relative;
  padding-left: 24px;
  margin: 10px 0;
  color: #cbd5e1;
}
body.light .answer li { color: #18232d; }
.answer li::before {
  content: ''; position: absolute; left: 4px; top: 11px;
  width: 6px; height: 6px; border-radius: 50%;
  background: linear-gradient(135deg, #22d3ee, #14b8a6);
}
.answer p { margin: 12px 0; color: #cbd5e1; }
body.light .answer p { color: #18232d; }

/* Numerical citation inline chips */
.answer .cite {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  margin: 0 2px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 10.5px; font-weight: 600;
  background: linear-gradient(135deg, #22d3ee, #14b8a6);
  color: #0b1220;
  border-radius: 6px;
  text-decoration: none;
  vertical-align: super;
  line-height: 1;
  transition: all .15s ease;
  border: 0;
  cursor: pointer;
}
.answer .cite:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(34, 211, 238, 0.4); }

.stat { font-family: 'IBM Plex Mono', monospace; font-size: 13px; color: #38bdf8; }
body.light .answer .stat { color: #0369a1; }

/* === Case section === */
.case-card {
  margin-top: 22px;
  background: linear-gradient(135deg, rgba(20, 184, 166, 0.08), rgba(34, 211, 238, 0.04));
  border: 1px solid rgba(20, 184, 166, 0.25);
  border-radius: 16px;
  padding: 22px 26px;
  font-family: 'IBM Plex Serif', Georgia, serif;
  animation: fadein .6s ease;
}
body.light .case-card { background: linear-gradient(135deg, rgba(8,127,117,0.06), rgba(8,127,117,0.02)); border-color: #a7e3df; }
.case-card .case-label {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-size: 10.5px; letter-spacing: 0.18em; font-weight: 700;
  color: #14b8a6; margin-bottom: 10px;
}
.case-card .case-label svg { width: 14px; height: 14px; }
.case-card p { font-size: 14.5px; line-height: 1.8; color: #cbd5e1; margin: 0; }
body.light .case-card p { color: #18232d; }

/* === Error === */
.error {
  color: #f87171; background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.25);
  padding: 14px 18px; border-radius: 12px; font-size: 13px;
}

/* ============ COMPOSER ============ */
.composer { margin-top: 20px; padding-bottom: 8px; }
.composer-input {
  display: flex; align-items: flex-end; gap: 10px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid #1f2937;
  border-radius: 18px;
  padding: 12px 12px 12px 18px;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.composer-input:focus-within { border-color: #22d3ee; box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.1); }
body.light .composer-input { background: #fff; border-color: #d9e4e5; }
body.light .composer-input:focus-within { border-color: #087f75; box-shadow: 0 0 0 4px rgba(8, 127, 117, 0.1); }
.composer-input textarea {
  flex: 1; resize: none;
  background: transparent; border: 0; outline: 0;
  color: inherit; font: inherit; font-size: 14.5px;
  padding: 8px 0; line-height: 1.6;
}
.composer-input textarea::placeholder { color: #64748b; }
.send-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #22d3ee, #14b8a6);
  color: #0b1220; border: 0; border-radius: 12px; cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.send-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(34, 211, 238, 0.35); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.composer-hint { display: block; margin-top: 10px; color: #64748b; font-size: 11px; padding-left: 4px; }

/* === Topbar actions (lang toggle + theme) === */
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.lang-toggle {
  display: inline-flex; padding: 3px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid #1f2937;
  border-radius: 999px;
}
body.light .lang-toggle { background: #fff; border-color: #d9e4e5; }
.lang-btn {
  padding: 4px 11px; border: 0; background: transparent;
  color: #64748b; font-size: 11px; font-weight: 700;
  letter-spacing: .1em; cursor: pointer; border-radius: 999px;
  transition: all .15s ease;
}
.lang-btn.active {
  background: linear-gradient(135deg, #22d3ee, #14b8a6);
  color: #0b1220; box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.18);
}
.lang-btn:not(.active):hover { color: #e2e8f0; }

/* === Mic button === */
.mic-btn {
  width: 40px; height: 40px; flex-shrink: 0;
  display: grid; place-items: center;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid #1f2937;
  color: #94a3b8; border-radius: 12px; cursor: pointer;
  transition: all .18s ease;
}
body.light .mic-btn { background: #fff; border-color: #d9e4e5; }
.mic-btn:hover { color: #22d3ee; border-color: #22d3ee; }
.mic-btn.recording {
  color: #fff;
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  border-color: #ef4444;
  animation: mic-pulse 1.3s ease infinite;
}
@keyframes mic-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50%     { box-shadow: 0 0 0 9px rgba(239, 68, 68, 0); }
}
.composer kbd {
  font-family: 'JetBrains Mono', monospace;
  background: rgba(34, 211, 238, 0.1);
  color: #22d3ee;
  border: 1px solid rgba(34, 211, 238, 0.22);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 600;
}

/* === History items === */
.history-section { display: flex; flex-direction: column; min-height: 0; }
#history { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; flex: 1; }
.history-item {
  padding: 9px 11px;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid #1f2937;
  border-radius: 9px;
  cursor: pointer;
  transition: all .15s ease;
  font-size: 12px; line-height: 1.5;
  color: #cbd5e1;
  font-weight: 500;
}
body.light .history-item { background: #fff; border-color: #d9e4e5; color: #18232d; }
.history-item:hover { border-color: #22d3ee; transform: translateX(-2px); }
.history-item.active { border-color: #22d3ee; box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1); }
.history-item .hist-date {
  display: block; font-size: 9.5px; color: #64748b;
  letter-spacing: .04em; margin-top: 3px; font-weight: 600;
}


.references {
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid #1f2937;
  padding: 28px 22px;
  display: flex; flex-direction: column;
  overflow-y: auto;
  height: 100vh;
  position: sticky;
  top: 0;
}
body.light .references { background: rgba(255,255,255,0.85); border-left-color: #d9e4e5; }
.refs-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.refs-title {
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: 22px; font-weight: 500;
  margin: 4px 0 0; letter-spacing: -0.02em;
}
.refs-count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; font-weight: 600;
  padding: 4px 9px;
  background: rgba(34, 211, 238, 0.15); color: #22d3ee;
  border-radius: 99px;
}
.refs-list { display: flex; flex-direction: column; gap: 10px; }
.muted-refs { color: #64748b; font-size: 12.5px; line-height: 1.55; }

.ref-card {
  padding: 14px 16px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid #1f2937;
  border-radius: 12px;
  cursor: pointer;
  transition: all .18s ease;
  scroll-margin-top: 16px;
}
body.light .ref-card { background: #fff; border-color: #d9e4e5; }
.ref-card:hover { border-color: #22d3ee; transform: translateX(-2px); }
.ref-card.highlight { border-color: #22d3ee; box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.15); animation: highlight 1.2s ease; }
@keyframes highlight { 0%,100% { background: rgba(15, 23, 42, 0.55);}50% { background: rgba(34, 211, 238, 0.1);} }

.ref-card a { color: #22d3ee; text-decoration: none; font-weight: 700; }
.ref-card a:hover { text-decoration: underline; }
.ref-card .ref-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px; font-weight: 700;
  background: linear-gradient(135deg, #22d3ee, #14b8a6);
  color: #0b1220;
  border-radius: 6px;
  margin-right: 8px;
  vertical-align: middle;
}
.ref-card .ref-title { display: inline; font-size: 12.5px; font-weight: 600; line-height: 1.45; color: #e2e8f0; }
body.light .ref-card .ref-title { color: #18232d; }
.ref-card .ref-meta {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin-top: 6px; font-size: 10.5px; color: #64748b;
}
.ref-card .ref-badges { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.ref-card .ref-badges span {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 9.5px; font-weight: 600;
  padding: 2px 7px; border-radius: 99px;
  background: rgba(34, 211, 238, 0.1); color: #22d3ee;
  border: 1px solid rgba(34, 211, 238, 0.18);
}
.ref-card .ref-badges .oa { background: rgba(34, 197, 94, 0.1); color: #4ade80; border-color: rgba(74, 222, 128, 0.18); }
.ref-card .ref-badges .type { background: rgba(168, 85, 247, 0.1); color: #c084fc; border-color: rgba(192, 132, 252, 0.2); }
.ref-card .ref-vancouver {
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed #1f2937;
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: 11.5px; line-height: 1.5; color: #94a3b8; font-style: italic;
}
body.light .ref-card .ref-vancouver { border-top-color: #d9e4e5; color: #6a7b82; }

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1f2937; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #22d3ee; }
body.light ::-webkit-scrollbar-thumb { background: #d9e4e5; }

/* ============ RESPONSIVE ============ */
@media (max-width: 1100px) {
  .shell { grid-template-columns: 220px 1fr 280px; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar, .references { position: relative; height: auto; border: 0; }
  .references { border-top: 1px solid #1f2937; }
}
