:root {
  --bg: #F8F9FA;
  --surface: #FFFFFF;
  --surface-subtle: #F4F6F8;
  --ink: #0F172A;
  --ink-secondary: #475569;
  --muted: #64748B;
  --border: #E5E7EB;
  --border-strong: #CBD5E1;
  --accent: #0B5D4B;
  --accent-soft: #ECF5F2;
  --gold: #9A7B3F;
  --gold-soft: #FDF8EE;
  --danger: #B42318;
  --danger-soft: #FEF3F2;
  --radius: 10px;
  --radius-sm: 6px;
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font-sans); font-size: 14px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.full-width { width: 100%; }

/* Auth Gate */
.auth-gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; padding: 32px;
}
.auth-brand { display: flex; align-items: center; gap: 12px; }
.auth-title { font-size: 16.5px; font-weight: 700; letter-spacing: -0.02em; }
.auth-sub { font-size: 12px; color: var(--muted); }
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.auth-note { font-size: 13px; color: var(--ink-secondary); margin: 0 0 18px; }
.auth-footer { margin-top: 18px; text-align: center; font-size: 12px; }
.link-muted { color: var(--muted); text-decoration: none; }
.link-muted:hover { color: var(--accent); }
.link-accent { color: var(--accent); text-decoration: none; font-weight: 500; }

.monogram {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--ink); color: #FFF;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; letter-spacing: 0.04em; flex-shrink: 0;
}

.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-secondary); margin-bottom: 5px; }
.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); font-size: 13.5px; font-family: var(--font-sans);
  background: var(--surface); color: var(--ink); outline: none; margin-bottom: 12px;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11, 93, 75, 0.08); }
.check-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--ink-secondary); margin: 0 0 14px; cursor: pointer;
}
.check-row input { accent-color: var(--accent); width: 14px; height: 14px; }
.alert-error {
  font-size: 12.5px; color: var(--danger); background: var(--danger-soft);
  border: 1px solid #FECDCA; border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 12px;
}
.alert-ok {
  font-size: 12.5px; color: var(--accent); background: var(--accent-soft);
  border: 1px solid #B6DDD1; border-radius: var(--radius-sm); padding: 8px 10px;
}

.btn {
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: 8px 14px; font-size: 13px; font-weight: 500; font-family: var(--font-sans);
  cursor: pointer; transition: all 0.12s ease; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn-primary { background: var(--ink); color: #FFF; }
.btn-primary:hover { background: var(--accent); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-subtle { background: var(--surface); border-color: var(--border); color: var(--ink-secondary); }
.btn-subtle:hover { border-color: var(--border-strong); color: var(--ink); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.icon-btn {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
  width: 32px; height: 32px; font-size: 18px; line-height: 1; cursor: pointer; color: var(--ink-secondary);
}

/* Main Shell */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: 276px; flex-shrink: 0; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sidebar-top {
  padding: 16px 16px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.brand-lockup { display: flex; align-items: center; gap: 10px; }
.brand-name { font-size: 14px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.sidebar-actions { padding: 12px 14px 8px; }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 6px 12px 14px; }
.nav-label {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); padding: 6px 8px;
}

.specialist-list { display: flex; flex-direction: column; gap: 2px; }
.spec-btn {
  width: 100%; border: none; background: transparent; text-align: left;
  padding: 7px 9px; border-radius: var(--radius-sm); cursor: pointer;
  display: flex; align-items: center; gap: 8px; color: var(--ink-secondary);
  font-family: var(--font-sans); font-size: 12.8px; font-weight: 500;
}
.spec-btn:hover { background: var(--surface-subtle); color: var(--ink); }
.spec-btn.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.spec-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--border-strong); flex-shrink: 0; }
.spec-btn.active .spec-dot { background: var(--accent); }

.conv-list { display: flex; flex-direction: column; gap: 2px; }
.conv-item {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 7px 9px; border-radius: var(--radius-sm); cursor: pointer;
  font-size: 12.5px; color: var(--ink-secondary);
}
.conv-item:hover { background: var(--surface-subtle); color: var(--ink); }
.conv-item.active { background: var(--surface-subtle); color: var(--ink); font-weight: 600; }
.conv-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.conv-del {
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 0 4px; opacity: 0;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--danger); }

.sidebar-footer {
  border-top: 1px solid var(--border); padding: 10px 12px; display: flex; flex-direction: column; gap: 4px;
}
.side-link {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: transparent; color: var(--ink-secondary); text-decoration: none;
  font-family: var(--font-sans); font-size: 12.8px; font-weight: 500; cursor: pointer;
}
.side-link:hover { background: var(--surface-subtle); color: var(--ink); }
.badge {
  font-family: var(--font-mono); font-size: 11px; padding: 1px 6px;
  border-radius: 99px; background: var(--surface-subtle); color: var(--muted);
}
.status-pill {
  font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px;
  background: var(--gold-soft); color: var(--gold);
}
.status-pill.ok { background: var(--accent-soft); color: var(--accent); }

/* Main Column */
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; }
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 13px 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-kicker { font-size: 10px; font-weight: 700; letter-spacing: 0.1em; color: var(--accent); text-transform: uppercase; }
.topbar-title { margin: 1px 0 0; font-size: 15.5px; font-weight: 700; letter-spacing: -0.015em; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.toggle-chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); border-radius: 99px; padding: 5px 11px;
  font-size: 12px; font-weight: 500; color: var(--ink-secondary); cursor: pointer; background: var(--surface);
}
.toggle-chip input { accent-color: var(--accent); margin: 0; }

.setup-banner {
  background: var(--gold-soft); border-bottom: 1px solid #EAD7B0; color: #7A5F2B;
  padding: 10px 24px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 12.8px;
}

/* Chat Area */
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.messages-scroll { flex: 1; overflow-y: auto; padding: 28px 24px 20px; }
.welcome-pane { max-width: 820px; margin: 20px auto 0; }
.welcome-eyebrow { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; color: var(--accent); }
.welcome-heading { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; margin: 8px 0 8px; }
.welcome-sub { font-size: 14px; color: var(--ink-secondary); margin: 0 0 24px; max-width: 650px; }

.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.quick-card {
  text-align: left; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 16px; cursor: pointer;
  transition: border-color 0.15s ease, transform 0.12s ease; font-family: var(--font-sans);
}
.quick-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.quick-tag { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--accent); }
.quick-title { font-size: 13.8px; font-weight: 600; color: var(--ink); margin: 4px 0 3px; }
.quick-desc { font-size: 12.2px; color: var(--muted); }

.messages-list { max-width: 860px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; flex-direction: column; }
.msg-user { align-items: flex-end; }
.msg-user .msg-bubble {
  background: var(--ink); color: #FFFFFF; border-radius: 12px 12px 2px 12px;
  padding: 12px 16px; max-width: 78%; font-size: 13.8px; white-space: pre-wrap;
}
.msg-assistant .msg-bubble {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px 22px; width: 100%;
}
.msg-meta {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
  font-size: 11.5px; color: var(--muted);
}
.msg-role-tag { font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: 0.06em; font-size: 10.5px; }
.msg-actions { display: flex; gap: 6px; margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border); flex-wrap: wrap; }

/* Rich Markdown inside replies */
.md h1 { font-size: 17px; margin: 14px 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.md h2 { font-size: 15px; margin: 14px 0 6px; color: var(--accent); }
.md h3 { font-size: 13.8px; margin: 12px 0 5px; }
.md p { margin: 0 0 9px; }
.md ul, .md ol { margin: 4px 0 10px 20px; padding: 0; }
.md li { margin-bottom: 4px; }
.md blockquote {
  margin: 10px 0; padding: 9px 14px; background: var(--accent-soft);
  border-left: 3px solid var(--accent); border-radius: 0 6px 6px 0; color: var(--ink);
}
.md code {
  font-family: var(--font-mono); font-size: 12px; background: var(--surface-subtle);
  padding: 1px 5px; border-radius: 4px;
}
.md pre {
  background: #0F172A; color: #F8FAFC; padding: 12px 14px; border-radius: 8px; overflow-x: auto;
}
.md pre code { background: transparent; color: inherit; padding: 0; }
.md table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 12.8px; }
.md th { background: var(--surface-subtle); text-align: left; padding: 8px 10px; border: 1px solid var(--border); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; }
.md td { padding: 8px 10px; border: 1px solid var(--border); vertical-align: top; }

.sources-box {
  margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}
.source-chip {
  font-size: 11.5px; color: var(--accent); background: var(--accent-soft);
  text-decoration: none; padding: 3px 9px; border-radius: 99px; font-weight: 500;
}
.source-chip:hover { text-decoration: underline; }

/* Composer */
.composer-wrap {
  padding: 12px 24px 20px; background: var(--bg);
}
.composer-box {
  max-width: 860px; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 12px; padding: 10px 14px;
}
.composer-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11, 93, 75, 0.07); }
.composer-box textarea {
  width: 100%; border: none; outline: none; resize: none;
  font-family: var(--font-sans); font-size: 14px; line-height: 1.5;
  max-height: 180px; background: transparent; color: var(--ink);
}
.composer-bar {
  display: flex; align-items: center; justify-content: space-between; margin-top: 8px;
}
.composer-meta { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.dot-live { width: 6px; height: 6px; border-radius: 50%; background: #10B981; }
.sep { color: var(--border-strong); }

/* Document Studio */
.docs-view { flex: 1; overflow-y: auto; padding: 24px; }
.docs-inner { max-width: 1160px; margin: 0 auto; }
.docs-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.docs-grid { display: grid; grid-template-columns: 1.35fr 0.9fr; gap: 20px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.panel-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.panel-body { padding: 18px; }
.chip-row { display: flex; gap: 5px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink-secondary);
  padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 500; cursor: pointer;
}
.chip.active { background: var(--ink); color: #FFF; border-color: var(--ink); }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.line-item-row {
  display: grid; grid-template-columns: 2fr 0.7fr 1.1fr auto; gap: 8px; margin-bottom: 8px; align-items: center;
}
.line-item-row .input { margin-bottom: 0; }
.saved-docs-list { max-height: 620px; overflow-y: auto; }
.saved-doc-item {
  padding: 13px 18px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
}
.saved-doc-item:last-child { border-bottom: none; }
.doc-pill {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 2px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent);
}

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.3); z-index: 40; }
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: calc(100% - 32px); max-width: 480px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 14px; z-index: 50; overflow: hidden;
}
.modal-head {
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; justify-content: space-between;
}
.modal-body { padding: 20px 22px; }

.thinking { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--border-strong);
  border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.mobile-only { display: none; }
@media (max-width: 960px) {
  .docs-grid { grid-template-columns: 1fr; }
  .quick-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .mobile-only { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; left: -290px; top: 0; bottom: 0; z-index: 35; transition: left 0.2s ease;
  }
  .sidebar.open { left: 0; box-shadow: 12px 0 36px rgba(15, 23, 42, 0.16); }
  .topbar { padding: 12px 14px; }
  .messages-scroll { padding: 16px 14px; }
  .composer-wrap { padding: 10px 14px 14px; }
  .form-row-2 { grid-template-columns: 1fr; }
  .line-item-row { grid-template-columns: 1fr 1fr; }
}
