/* ============================================================
   Fund Copilot — web client styles
   ============================================================ */
:root {
  --bg: #0f172a;
  --bg-soft: #1e293b;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --accent: #059669;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 8px 24px rgba(15, 23, 42, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface-2);
  font-size: 14px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
code { background: #eef2ff; padding: 1px 6px; border-radius: 6px; font-size: 12px; color: var(--primary-dark); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

/* ---------------- Buttons ---------------- */
.btn { font-family: inherit; font-size: 14px; font-weight: 600; border: 1px solid transparent;
  border-radius: 9px; padding: 9px 16px; cursor: pointer; transition: .15s; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.icon-btn { background: none; border: none; font-size: 16px; cursor: pointer; color: var(--muted); }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }

/* ---------------- Login ---------------- */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center;
  justify-content: center; background: radial-gradient(1200px 600px at 50% -10%, #1e293b, #0f172a); padding: 20px; }
.login-card { background: var(--surface); width: 100%; max-width: 400px; border-radius: 16px;
  padding: 32px; box-shadow: var(--shadow); }
.brand { display: flex; gap: 14px; align-items: center; margin-bottom: 24px; }
.brand h1 { font-size: 19px; }
.brand p { margin: 2px 0 0; font-size: 13px; }
.brand-mark { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, var(--primary), #6366f1);
  color: #fff; display: grid; place-items: center; font-weight: 800; letter-spacing: .02em; }
.brand-mark.sm { width: 30px; height: 30px; font-size: 13px; border-radius: 8px; }
#login-form label, .modal-body label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 14px; }
#login-form input, .modal-body input, .modal-body select, .modal-body textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 9px; font-family: inherit; font-size: 14px; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; margin: 8px 0 0; }
.login-hint { margin-top: 18px; font-size: 12px; text-align: center; }
.login-footnote { margin-top: 20px; font-size: 12px; color: #94a3b8; }

/* ---------------- App shell ---------------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--bg); color: #cbd5e1; display: flex; flex-direction: column; padding: 18px 14px; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; padding: 6px 8px 18px; }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 10px; background: none; border: none; color: #cbd5e1;
  text-align: left; padding: 10px 12px; border-radius: 9px; font-size: 14px; font-weight: 550; cursor: pointer; font-family: inherit; }
.nav-item span { font-size: 15px; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-x { display: inline-flex; align-items: center; gap: 8px; background: #eef2ff; color: var(--primary-dark); border: 1px solid #c7d2fe; border-radius: 20px; padding: 4px 10px; font-size: 13px; font-weight: 600; }
.chip-x .x { cursor: pointer; color: var(--muted); font-size: 11px; }
.chip-x .x:hover { color: var(--danger); }
.sidebar-foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 4px 8px; border-radius: 6px; align-self: flex-start; background: #334155; color: #cbd5e1; }
.badge.live { background: rgba(5,150,105,.2); color: #34d399; }
.badge.offline { background: rgba(217,119,6,.2); color: #fbbf24; }
.user-box { font-size: 13px; }
.user-name { color: #fff; font-weight: 600; }
.user-role { font-size: 12px; text-transform: capitalize; }

/* ---------------- Content ---------------- */
.content { padding: 28px 32px; overflow-y: auto; max-height: 100vh; }
.view-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; gap: 16px; }
.view-head h2 { font-size: 22px; }
.view-head p { margin: 4px 0 0; font-size: 13px; max-width: 640px; }

/* ---------------- Copilot ---------------- */
.copilot-grid { display: grid; grid-template-columns: 220px 1fr; gap: 18px; height: calc(100vh - 150px); }
.convo-list { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.convo-item { padding: 10px 12px; border-radius: 9px; background: var(--surface); border: 1px solid var(--border);
  cursor: pointer; font-size: 13px; }
.convo-item:hover { border-color: #c7d2fe; }
.convo-item.active { border-color: var(--primary); background: #eef2ff; }
.convo-item .ct { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden; }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 80%; }
.msg.user { align-self: flex-end; }
.msg.assistant { align-self: flex-start; max-width: 92%; }
.bubble { padding: 12px 15px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
/* Rendered markdown inside an assistant bubble */
.bubble.markdown { white-space: normal; }
.bubble.markdown > :first-child { margin-top: 0; }
.bubble.markdown > :last-child { margin-bottom: 0; }
.bubble.markdown p { margin: 8px 0; }
.bubble.markdown ul, .bubble.markdown ol { margin: 6px 0; padding-left: 18px; }
.bubble.markdown li { margin-bottom: 3px; }
.bubble.markdown h1, .bubble.markdown h2, .bubble.markdown h3 { font-size: 15px; margin: 10px 0 4px; }
.bubble.markdown sup { color: var(--primary-dark); font-weight: 700; }
.bubble.markdown code { font-size: 12px; }
.citations { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.cite { font-size: 12px; background: #eef2ff; color: var(--primary-dark); border: 1px solid #c7d2fe;
  padding: 3px 8px; border-radius: 20px; cursor: pointer; }
.cite:hover { background: #e0e7ff; }
.chat-input { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--border); }
.chat-input input { flex: 1; padding: 11px 14px; border: 1px solid var(--border); border-radius: 10px; font-family: inherit; font-size: 14px; }
.empty-state { margin: auto; text-align: center; padding: 40px; }
.empty-state h3 { margin-bottom: 6px; }
.typing { font-style: italic; color: var(--muted); }

/* ---------------- Search ---------------- */
.search-bar { display: flex; gap: 10px; margin-bottom: 20px; }
.search-bar input { flex: 1; padding: 11px 14px; border: 1px solid var(--border); border-radius: 10px; font-family: inherit; font-size: 14px; }
.search-bar select { padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; font-family: inherit; }
.results { display: flex; flex-direction: column; gap: 12px; }
.result-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.result-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 2px 8px; border-radius: 6px; }
.tag.filing { background: #eff6ff; color: #2563eb; }
.tag.transcript { background: #f0fdf4; color: #16a34a; }
.tag.news { background: #fef2f2; color: #dc2626; }
.tag.memo { background: #fefce8; color: #ca8a04; }
.tag.note { background: #f5f3ff; color: #7c3aed; }
.tag.other { background: #f1f5f9; color: #475569; }
.score { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--accent); }
.result-title { font-weight: 650; margin-bottom: 4px; }
.result-snippet { color: #334155; font-size: 13px; }

/* ---------------- Library ---------------- */
.lib-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.lib-search { flex: 1; min-width: 200px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 9px; font-family: inherit; font-size: 14px; }
.lib-ctl { padding: 9px 10px; border: 1px solid var(--border); border-radius: 9px; font-family: inherit; font-size: 13px; background: var(--surface); cursor: pointer; }
.lib-count { font-size: 12px; margin-left: auto; }
.doc-list { display: flex; flex-direction: column; gap: 18px; }
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.doc-group-head { display: flex; align-items: center; gap: 8px; padding: 8px 4px; cursor: pointer; user-select: none; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.doc-group-head:hover { color: var(--primary-dark); }
.doc-group-head .caret { font-size: 11px; color: var(--muted); width: 12px; }
.doc-group-title { font-weight: 700; font-size: 14px; }
.doc-group-count { font-size: 11px; font-weight: 700; background: #eef2ff; color: var(--primary-dark); padding: 1px 8px; border-radius: 20px; }
.doc-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.doc-title { font-weight: 650; }
.doc-sub { font-size: 12px; color: var(--muted); }
.doc-meta { font-size: 11px; }
.doc-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 6px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.status-dot.ready { background: var(--accent); }
.status-dot.processing { background: var(--warn); }
.status-dot.failed { background: var(--danger); }

/* ---------------- Briefings ---------------- */
.briefing-grid { display: grid; grid-template-columns: 260px 1fr; gap: 18px; }
.briefing-list { display: flex; flex-direction: column; gap: 8px; max-height: calc(100vh - 230px); overflow-y: auto; }
.brief-bucket-head { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 10px 2px 2px; }
.brief-bucket-head:first-child { margin-top: 0; }
.briefing-item { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer; }
.briefing-item:hover { border-color: #c7d2fe; }
.briefing-item.active { border-color: var(--primary); background: #eef2ff; }
.briefing-view { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; min-height: 400px; }
.briefing-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-bottom: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--border); }
.briefing-view h1 { font-size: 20px; margin-bottom: 6px; }
.briefing-view h2 { font-size: 16px; margin: 18px 0 8px; }
.briefing-view ul { padding-left: 20px; }
.briefing-view li { margin-bottom: 4px; }
.markdown p { margin: 8px 0; }
.markdown strong { font-weight: 700; }
.markdown ol { padding-left: 20px; margin: 8px 0; }
.markdown a { color: var(--primary); text-decoration: underline; }
.markdown blockquote { border-left: 3px solid var(--primary); margin: 8px 0; padding: 2px 12px; color: var(--muted); background: var(--surface-2); border-radius: 0 6px 6px 0; }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.markdown table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.markdown th { background: var(--surface-2); font-weight: 650; }

/* ---------------- Admin ---------------- */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.row { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.row:last-child { border-bottom: none; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; background: #eef2ff; color: var(--primary-dark); text-transform: capitalize; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; text-align: center; }
.tile-val { font-size: 24px; font-weight: 750; color: var(--primary-dark); }
.tile-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.audit-list { max-height: 480px; overflow-y: auto; }
.audit-row { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.audit-action { font-weight: 700; color: var(--primary-dark); }
.audit-time { color: var(--muted); font-size: 11px; }

/* ---------------- Modal & toast ---------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15,23,42,.5); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 540px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: #fff; }
.modal-body { padding: 22px; }
.modal-body textarea { min-height: 150px; resize: vertical; font-family: inherit; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--bg); color: #fff;
  padding: 12px 20px; border-radius: 10px; font-size: 13px; z-index: 60; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .copilot-grid, .briefing-grid, .admin-grid { grid-template-columns: 1fr; }
  .convo-list { max-height: 120px; }
}
