/* ===== Illinois Policy Institute — Deep Research ===== */

:root {
  --navy-900: #0c1b34;
  --navy-800: #11233f;
  --navy-700: #1a3358;
  --navy-600: #24416b;
  --red: #c8102e;
  --red-dark: #a30d26;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e7ee;
  --border-strong: #cdd4e0;
  --text: #16233b;
  --text-muted: #5e6a80;
  --text-faint: #8a93a6;
  --shadow: 0 1px 3px rgba(12, 27, 52, 0.08), 0 8px 24px rgba(12, 27, 52, 0.06);
  --radius: 12px;
  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
textarea, input, select { font-family: inherit; }

.app { display: flex; height: 100vh; overflow: hidden; }

/* ===== Login gate ===== */
.login-gate {
  position: fixed; inset: 0; z-index: 200;
  display: grid; place-items: center;
  background: var(--navy-900);
}
.login-gate.hidden { display: none; }
.login-card {
  text-align: center; padding: 48px 40px;
  background: var(--surface); border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
  max-width: 380px; width: 90%;
}
.login-mark {
  width: 64px; height: 80px; margin: 0 auto 20px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, var(--red), var(--red-dark));
  color: #fff; border-radius: 16px;
  box-shadow: 0 6px 20px rgba(200, 16, 46, 0.3);
}
.login-card h1 {
  font-family: var(--serif); font-size: 24px; margin: 0 0 4px;
  color: var(--navy-900);
}
.login-sub {
  font-size: 13px; text-transform: uppercase; letter-spacing: 1.2px;
  color: var(--red); font-weight: 600; margin: 0 0 28px;
}
#loginForm { display: flex; flex-direction: column; gap: 12px; }
#loginPassword {
  width: 100%; padding: 12px 16px; border: 1px solid var(--border-strong);
  border-radius: 10px; font-size: 15px; text-align: center;
  outline: none; transition: border-color 0.15s; background: var(--surface);
  color: var(--text);
}
#loginPassword:focus { border-color: var(--navy-600); }
.login-btn {
  width: 100%; padding: 12px;
  background: var(--red); color: #fff; border: none;
  border-radius: 10px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: background 0.15s;
}
.login-btn:hover { background: var(--red-dark); }
.login-error {
  color: var(--red-dark); font-size: 13px; margin: 6px 0 0;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 268px;
  flex-shrink: 0;
  background: var(--navy-900);
  color: #dbe3f0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  transition: margin-left 0.22s ease;
}
.sidebar.collapsed { margin-left: -268px; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
.brand-mark {
  width: 32px; height: 44px;
  flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--red);
  color: #fff;
  border-radius: 9px;
  font-size: 20px;
  box-shadow: 0 2px 8px rgba(200, 16, 46, 0.4);
}
.brand-name {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 15px;
  line-height: 1.15;
  color: #fff;
  letter-spacing: 0.1px;
}
.brand-sub {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--red);
  font-weight: 600;
  margin-top: 3px;
}

.new-chat {
  margin: 16px 14px 8px;
  padding: 11px 14px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #fff;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  display: flex; align-items: center; gap: 9px;
  transition: background 0.15s, border-color 0.15s;
}
.new-chat:hover { background: rgba(255, 255, 255, 0.11); border-color: rgba(255,255,255,0.22); }
.new-chat .plus { font-size: 18px; color: var(--red); font-weight: 700; line-height: 1; }

.history {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
}
.history-item {
  padding: 9px 11px;
  border-radius: 8px;
  font-size: 13.5px;
  color: #b9c4d6;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: none; border: none; text-align: left; width: 100%;
  transition: background 0.12s, color 0.12s;
  position: relative;
}
.history-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.history-item.active { background: rgba(200, 16, 46, 0.16); color: #fff; }
.history-item .del {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  opacity: 0; color: var(--text-faint); padding: 2px 6px; border-radius: 6px;
  font-size: 12px; background: none; border: none;
}
.history-item:hover .del { opacity: 1; }
.history-item .del:hover { color: #fff; background: rgba(255,255,255,0.12); }
.history-empty { color: var(--text-faint); font-size: 12.5px; padding: 10px 11px; }

.sidebar-footer {
  padding: 12px 14px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}
.settings-btn {
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cdd7e6;
  border-radius: 9px;
  font-size: 13.5px;
  display: flex; align-items: center; gap: 9px;
  transition: background 0.15s;
}
.settings-btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.gear { font-size: 15px; }
.powered { margin-top: 12px; font-size: 11px; color: var(--text-faint); text-align: center; letter-spacing: 0.3px; }

/* ===== Main ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.topbar {
  height: 56px;
  flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-title {
  font-weight: 500; font-size: 14.5px; color: var(--text);
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.icon-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 17px; width: 34px; height: 34px; border-radius: 8px;
  display: grid; place-items: center; transition: background 0.12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.menu-toggle { margin-left: -6px; }
.model-badge {
  font-size: 12px; font-weight: 600; color: var(--navy-700);
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 5px 11px; border-radius: 20px; letter-spacing: 0.2px;
}

/* ===== Messages ===== */
.messages { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
.messages-inner, .empty-state, .msg-wrap { max-width: 800px; margin: 0 auto; }
.msg-wrap { padding: 0 24px; }

/* Empty state */
.empty-state {
  padding: 56px 24px 40px;
  text-align: center;
}
.empty-mark {
  width: 48px; height: 68px; margin: 0 auto 22px;
  display: grid; place-items: center;
  background: linear-gradient(160deg, var(--red), var(--red-dark));
  color: #fff; border-radius: 15px; font-size: 30px;
  box-shadow: 0 6px 20px rgba(200, 16, 46, 0.3);
}
.empty-state h1 {
  font-family: var(--serif); font-weight: 600; font-size: 30px;
  margin: 0 0 12px; color: var(--navy-900); letter-spacing: -0.2px;
}
.empty-lede {
  font-size: 15.5px; line-height: 1.6; color: var(--text-muted);
  max-width: 560px; margin: 0 auto 30px;
}
.examples {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  text-align: left; margin-bottom: 18px;
}
.example {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 16px;
  font-size: 13.8px; line-height: 1.45; color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.example:hover { border-color: var(--red); box-shadow: var(--shadow); transform: translateY(-1px); }

/* Message rows */
.msg { padding: 22px 0; animation: fade 0.25s ease; }
.msg + .msg { border-top: 1px solid var(--border); }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg-role {
  display: flex; align-items: center; gap: 9px;
  font-size: 12px; font-weight: 600; letter-spacing: 0.5px;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 10px;
}
.role-dot { width: 22px; height: 28px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; color: #fff; }
.msg.user .role-dot { background: var(--navy-700); }
.msg.assistant .role-dot { background: var(--red); }

.msg-body { font-size: 15px; line-height: 1.65; color: var(--text); }
.msg.user .msg-body { color: var(--text); white-space: pre-wrap; }

/* Markdown */
.msg-body h1, .msg-body h2, .msg-body h3 { font-family: var(--serif); color: var(--navy-900); line-height: 1.25; margin: 1.2em 0 0.5em; }
.msg-body h1 { font-size: 22px; }
.msg-body h2 { font-size: 19px; }
.msg-body h3 { font-size: 16.5px; }
.msg-body p { margin: 0.7em 0; }
.msg-body ul, .msg-body ol { margin: 0.6em 0; padding-left: 1.5em; }
.msg-body li { margin: 0.3em 0; }
.msg-body a { color: var(--red-dark); text-decoration: underline; text-underline-offset: 2px; }
.msg-body strong { font-weight: 600; color: var(--navy-900); }
.msg-body code { background: transparent; padding: 0; font-size: 13.5px; font-family: "SFMono-Regular", Consolas, monospace; color: var(--navy-700); }
.msg-body pre { background: transparent; color: var(--text); padding: 4px 0; overflow-x: auto; font-size: 13.5px; }
.msg-body pre code { background: none; color: inherit; padding: 0; }
.msg-body blockquote { border-left: 3px solid var(--red); margin: 0.7em 0; padding: 2px 0 2px 16px; color: var(--text-muted); }
.msg-body table { border-collapse: collapse; width: 100%; margin: 0.8em 0; font-size: 14px; }
.msg-body th, .msg-body td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.msg-body th { background: var(--surface-2); font-weight: 600; }
.msg-body hr { border: none; border-top: 1px solid var(--border); margin: 1.2em 0; }

/* Thinking block */
.thinking-block {
  margin: 4px 0 14px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); overflow: hidden;
}
.thinking-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 13px; font-size: 12.5px; font-weight: 600;
  color: var(--text-muted); cursor: pointer; user-select: none;
  background: var(--surface-2);
}
.thinking-head .chev { transition: transform 0.18s; font-size: 10px; }
.thinking-block.collapsed .chev { transform: rotate(-90deg); }
.thinking-block.collapsed .thinking-body { display: none; }
.thinking-body {
  padding: 12px 14px; font-size: 13.5px; line-height: 1.6;
  color: var(--text-muted); white-space: pre-wrap;
  border-top: 1px solid var(--border); max-height: 320px; overflow-y: auto;
}
.thinking-spinner { color: var(--red); }

/* Tool call chips */
.tool-call {
  margin: 10px 0; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); overflow: hidden;
}
.tool-head {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 13px; font-size: 13px; cursor: pointer; user-select: none;
}
.tool-icon { font-size: 14px; }
.tool-name { font-weight: 600; color: var(--navy-700); }
.tool-name .server { color: var(--text-faint); font-weight: 400; }
.tool-status { margin-left: auto; font-size: 11.5px; color: var(--text-faint); display: flex; align-items: center; gap: 6px; }
.tool-call.running .tool-status { color: var(--red); }
.tool-call.done .tool-status { color: #1a8a4a; }
.spinner {
  width: 12px; height: 12px; border: 2px solid var(--border-strong);
  border-top-color: var(--red); border-radius: 50%;
  animation: spin 0.7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tool-body { display: none; border-top: 1px solid var(--border); }
.tool-call.open .tool-body { display: block; }
.tool-section { padding: 10px 13px; }
.tool-section + .tool-section { border-top: 1px solid var(--border); }
.tool-section-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text-faint); margin-bottom: 5px; font-weight: 600; }
.tool-section pre {
  margin: 0; font-size: 12px; font-family: "SFMono-Regular", Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
  background: var(--surface-2); color: var(--text);
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  max-height: 260px; overflow-y: auto;
}

/* Streaming caret */
.caret { display: inline-block; width: 7px; height: 16px; background: var(--red); margin-left: 2px; vertical-align: text-bottom; animation: blink 1s step-end infinite; border-radius: 1px; }
@keyframes blink { 50% { opacity: 0; } }

/* Usage / meta footer */
.msg-meta { margin-top: 12px; font-size: 11.5px; color: var(--text-faint); display: flex; gap: 14px; flex-wrap: wrap; }
.msg-error { background: #fff5f6; border: 1px solid #f3c9d0; color: var(--red-dark); border-radius: 9px; padding: 11px 14px; font-size: 13.5px; }

/* Message actions (edit / retry / copy) */
.msg-actions { display: flex; gap: 7px; margin-top: 12px; opacity: 0; transition: opacity 0.12s; }
.msg:hover .msg-actions, .msg-actions.always { opacity: 1; }
.msg-action {
  background: var(--surface); border: 1px solid var(--border); color: var(--text-muted);
  border-radius: 7px; padding: 4px 11px; font-size: 12px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.msg-action:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }

/* Inline edit box */
.edit-box { margin-top: 4px; }
.edit-box textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: 10px;
  padding: 11px 13px; font-size: 15px; line-height: 1.5; color: var(--text);
  font-family: inherit; resize: none; outline: none; background: var(--surface);
}
.edit-box textarea:focus { border-color: var(--navy-600); }
.edit-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; margin-top: 8px; }
.edit-hint { margin-right: auto; font-size: 11.5px; color: var(--text-faint); }
.btn-sm { padding: 7px 14px; font-size: 13px; border-radius: 8px; }

/* ===== Composer ===== */
.composer {
  flex-shrink: 0; padding: 14px 24px 18px;
  background: linear-gradient(to top, var(--bg) 65%, transparent);
}
.composer-inner {
  max-width: 800px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 16px; padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow); transition: border-color 0.15s;
}
.composer-inner:focus-within { border-color: var(--navy-600); }
#input {
  flex: 1; border: none; outline: none; resize: none;
  font-size: 15px; line-height: 1.5; color: var(--text);
  background: none; max-height: 220px; padding: 8px 0;
}
.send-btn, .stop-btn {
  width: 38px; height: 38px; flex-shrink: 0; border: none; border-radius: 10px;
  color: #fff; font-size: 17px; display: grid; place-items: center;
  transition: background 0.15s, opacity 0.15s; align-self: flex-end;
}
.send-btn { background: var(--red); }
.send-btn:hover { background: var(--red-dark); }
.send-btn:disabled { background: var(--border-strong); cursor: not-allowed; }
.stop-btn { background: var(--navy-700); font-size: 13px; }
.stop-btn:hover { background: var(--navy-900); }
.composer-foot { max-width: 800px; margin: 8px auto 0; display: flex; align-items: baseline; justify-content: space-between; gap: 14px; }
.composer-hint { font-size: 11.5px; color: var(--text-faint); }
.cost-total { font-size: 11.5px; color: var(--text-muted); font-weight: 600; white-space: nowrap; }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12, 27, 52, 0.5);
  display: grid; place-items: center; z-index: 100; padding: 24px;
  animation: fade 0.18s ease;
}
.modal {
  background: var(--surface); border-radius: 16px; width: 100%; max-width: 620px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(12, 27, 52, 0.35);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-family: var(--serif); font-size: 20px; margin: 0; color: var(--navy-900); }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 22px; border-top: 1px solid var(--border);
}

.field { margin-bottom: 18px; }
.field-row { display: flex; gap: 16px; }
.field-row .field { flex: 1; }
.label-row { display: flex; align-items: center; justify-content: space-between; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 7px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: 9px; font-size: 14px; color: var(--text); background: var(--surface);
  outline: none; transition: border-color 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--navy-600); }
.field textarea { resize: vertical; line-height: 1.55; font-size: 13px; }
#systemPrompt { font-family: "SFMono-Regular", Consolas, monospace; }
.field-help { font-size: 12px; color: var(--text-muted); margin: 7px 0 0; line-height: 1.45; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }
.link-btn { background: none; border: none; color: var(--red-dark); font-size: 12.5px; font-weight: 600; padding: 0; text-decoration: underline; }
.advanced { margin-top: 6px; border: 1px solid var(--border); border-radius: 10px; padding: 4px 14px; }
.advanced summary { padding: 10px 0; font-size: 13.5px; font-weight: 600; color: var(--text-muted); cursor: pointer; }
.advanced[open] summary { margin-bottom: 8px; border-bottom: 1px solid var(--border); }

.btn-primary, .btn-secondary {
  padding: 10px 20px; border-radius: 9px; font-size: 14px; font-weight: 600; border: 1px solid transparent;
}
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: var(--red-dark); }
.btn-secondary { background: var(--surface); color: var(--text-muted); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }

/* ===== Responsive ===== */
@media (max-width: 760px) {
  .sidebar { position: absolute; z-index: 50; height: 100%; box-shadow: var(--shadow); }
  .sidebar.collapsed { margin-left: -268px; }
  .examples { grid-template-columns: 1fr; }
  .field-row { flex-direction: column; gap: 0; }
}
