/* Clariva Corpus — clean light document workspace */
:root {
  --bg: #ffffff;
  --bg-soft: #fafaf9;
  --surface: #ffffff;
  --ink: #1c1917;
  --ink-2: #57534e;
  --muted: #8c857d;
  --line: #e7e4df;
  --line-2: #f0ede8;
  --accent: #b8451e;
  --accent-soft: #fbf1ec;
  --accent-line: #f0d8cd;
  --ok: #15803d;
  --ok-soft: #f0f7f1;
  --radius: 10px;
  --radius-sm: 7px;
  --sidebar-w: 256px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.55;
}
.hidden { display: none !important; }
button { font-family: inherit; cursor: pointer; }
a { color: var(--accent); text-decoration: none; }

/* ---- brand mark ---- */
.brand-mark {
  width: 34px; height: 34px; flex: 0 0 34px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-weight: 700; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: -0.02em;
}
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }

/* ============ LOGIN ============ */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-soft);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04), 0 12px 32px rgba(0,0,0,0.05);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-hint { color: var(--ink-2); margin-bottom: 22px; font-size: 13px; }
.field-label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }
.text-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--bg);
  margin-bottom: 16px;
  transition: border-color .15s, box-shadow .15s;
}
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-error { color: var(--accent); font-size: 13px; margin-top: 10px; min-height: 18px; }

/* ---- buttons ---- */
.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 16px;
  font-size: 13px; font-weight: 500;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #a23c18; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; margin-top: 6px; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { background: var(--bg-soft); }

/* ============ APP SHELL ============ */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 20px 14px;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  width: 100%; text-align: left;
  background: transparent; border: none;
  padding: 9px 11px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; color: var(--ink-2);
  transition: background .12s, color .12s;
}
.nav-item:hover { background: #f1eee9; color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-ico { width: 16px; text-align: center; font-size: 14px; opacity: .9; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding: 0 4px; }
.sidebar-link { font-size: 12.5px; color: var(--muted); padding: 5px 7px; border-radius: 6px; }
.sidebar-link:hover { background: #f1eee9; color: var(--ink-2); }
.user-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; padding: 10px 7px 2px; border-top: 1px solid var(--line);
}
.user-name { font-size: 13px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout-btn { background: transparent; border: none; color: var(--muted); font-size: 16px; padding: 2px 6px; border-radius: 6px; }
.logout-btn:hover { background: #f1eee9; color: var(--accent); }

/* ---- main ---- */
.main { flex: 1; overflow-y: auto; background: var(--bg); }
.view { display: none; padding: 32px 40px 56px; max-width: 1100px; }
.view.active { display: block; }
.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 26px; }
.view-title { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.view-desc { color: var(--ink-2); font-size: 13.5px; margin-top: 3px; max-width: 620px; }

/* ---- pills / badges ---- */
.pill { font-size: 11.5px; font-weight: 500; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill-accent { background: var(--accent-soft); color: var(--accent); border: 1px solid var(--accent-line); }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-muted { background: var(--bg-soft); color: var(--muted); border: 1px solid var(--line); }

.type-badge {
  display: inline-block; font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 5px; text-transform: capitalize;
  background: var(--bg-soft); color: var(--ink-2); border: 1px solid var(--line);
}

/* ---- dashboard ---- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat-val { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-foot { font-size: 11.5px; color: var(--ink-2); margin-top: 8px; }

.dash-cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel-head {
  font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  padding: 13px 18px; border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center; gap: 8px;
}
.count-tag { background: var(--bg-soft); color: var(--muted); font-weight: 500; border-radius: 5px; padding: 1px 7px; font-size: 11.5px; }

.recent-list { display: flex; flex-direction: column; }
.recent-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line-2); cursor: pointer; }
.recent-item:last-child { border-bottom: none; }
.recent-item:hover { background: var(--bg-soft); }
.recent-title { font-weight: 500; font-size: 13.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-sub { font-size: 11.5px; color: var(--muted); }

.sample-qs { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.sample-q { text-align: left; background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; color: var(--ink-2); transition: border-color .12s, color .12s; }
.sample-q:hover { border-color: var(--accent-line); color: var(--accent); }

/* ---- library ---- */
.dropzone { border: 1.5px dashed var(--line); border-radius: var(--radius); background: var(--bg-soft); cursor: pointer; transition: border-color .15s, background .15s; margin-bottom: 14px; }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-inner { padding: 30px; text-align: center; color: var(--ink-2); }
.dropzone-ico { font-size: 24px; color: var(--accent); margin-bottom: 8px; }
.dropzone-sub { font-size: 12px; color: var(--muted); margin-top: 5px; }
.upload-status { min-height: 22px; font-size: 13px; margin-bottom: 14px; color: var(--ink-2); }
.upload-status .err { color: var(--accent); }
.upload-status .ok { color: var(--ok); }

.table-wrap { overflow-x: auto; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc-table th { text-align: left; font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 11px 18px; border-bottom: 1px solid var(--line-2); }
.doc-table td { padding: 12px 18px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.doc-table tr:last-child td { border-bottom: none; }
.doc-table tbody tr { cursor: pointer; }
.doc-table tbody tr:hover { background: var(--bg-soft); }
.td-title { font-weight: 500; color: var(--ink); }
.row-del { background: transparent; border: none; color: var(--muted); font-size: 14px; padding: 3px 7px; border-radius: 6px; }
.row-del:hover { background: var(--accent-soft); color: var(--accent); }
.row-actions { white-space: nowrap; text-align: right; }
.row-dl { background: transparent; border: none; color: var(--muted); font-size: 14px; padding: 3px 7px; border-radius: 6px; margin-right: 2px; }
.row-dl:hover { background: var(--accent-soft); color: var(--accent); }
.doc-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--line-2); }
.doc-actions-empty { font-size: 12.5px; color: var(--muted); }
.empty-row td { color: var(--muted); text-align: center; padding: 28px; }

/* ---- chat / ask ---- */
.chat { display: flex; flex-direction: column; height: calc(100vh - 150px); }
.chat-thread { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 22px; padding-bottom: 14px; }
.msg { max-width: 860px; }
.msg-user { align-self: flex-end; background: var(--accent-soft); border: 1px solid var(--accent-line); color: var(--ink); padding: 10px 14px; border-radius: 12px 12px 2px 12px; font-size: 13.5px; }
.msg-assistant { align-self: stretch; }
.answer { font-size: 14px; line-height: 1.65; color: var(--ink); }
.answer p { margin: 0 0 10px; }
.answer ul, .answer ol { margin: 0 0 10px 20px; }
.answer strong { font-weight: 600; }
.answer code { background: var(--bg-soft); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 12.5px; }
.cite-ref { display: inline-flex; align-items: center; justify-content: center; min-width: 16px; height: 16px; padding: 0 4px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 600; border-radius: 4px; vertical-align: super; margin: 0 1px; cursor: pointer; }
.thinking { color: var(--muted); font-size: 13px; display: inline-flex; gap: 8px; align-items: center; }
.dot-pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }
.typing { display: inline-flex; align-items: center; gap: 5px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); opacity: 0.3; animation: typing-bounce 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes typing-bounce { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-4px); } }

.cite-block { margin-top: 14px; }
.cite-block-title, .ent-block-title { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 8px; }
.cite-card { display: flex; gap: 10px; background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; margin-bottom: 8px; cursor: pointer; transition: border-color .12s; }
.cite-card:hover { border-color: var(--accent-line); }
.cite-num { flex: 0 0 18px; height: 18px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 600; border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.cite-meta { flex: 1; min-width: 0; }
.cite-doc { font-size: 12.5px; font-weight: 500; color: var(--ink); }
.cite-snip { font-size: 12px; color: var(--ink-2); margin-top: 3px; line-height: 1.5; }

.ent-block { margin-top: 16px; }
.ent-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.ent-chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: 12.5px; color: var(--ink-2); transition: border-color .12s, color .12s; }
.ent-chip:hover { border-color: var(--accent-line); color: var(--accent); }
.ent-chip .ent-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }

.chat-input { display: flex; gap: 10px; align-items: flex-end; border-top: 1px solid var(--line); padding-top: 14px; }
.ask-textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 13px; font-family: inherit; font-size: 14px; color: var(--ink); max-height: 160px; transition: border-color .15s, box-shadow .15s; }
.ask-textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.ask-empty { text-align: center; color: var(--muted); margin: auto; max-width: 420px; }
.ask-empty .ico { font-size: 30px; color: var(--accent-line); }
.ask-empty h3 { font-size: 16px; font-weight: 600; color: var(--ink); margin: 10px 0 6px; }

/* ---- drawer ---- */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(28,25,23,0.28); }
.drawer-panel { position: absolute; top: 0; right: 0; height: 100%; width: min(560px, 92vw); background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,0.08); }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 24px; border-bottom: 1px solid var(--line-2); }
.drawer-title { font-size: 16px; font-weight: 600; }
.drawer-meta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.drawer-close { background: transparent; border: none; font-size: 16px; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.drawer-close:hover { background: var(--bg-soft); color: var(--ink); }
.drawer-body { overflow-y: auto; padding: 18px 24px 32px; }
.chunk { border: 1px solid var(--line-2); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 10px; }
.chunk-idx { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.chunk-text { font-size: 12.5px; color: var(--ink-2); white-space: pre-wrap; line-height: 1.55; }

/* ---- compare ---- */
.cmp-hint { font-weight: 400; color: var(--muted); }
.cmp-pick-panel { margin-bottom: 18px; }
.cmp-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; padding: 14px 16px; }
.cmp-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; transition: border-color .12s, background .12s; }
.cmp-item:hover { border-color: var(--accent-line); }
.cmp-item.sel { border-color: var(--accent); background: var(--accent-soft); }
.cmp-item input { accent-color: var(--accent); width: 15px; height: 15px; flex: 0 0 auto; cursor: pointer; }
.cmp-item-main { min-width: 0; }
.cmp-item-title { display: block; font-size: 13.5px; font-weight: 500; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmp-item-sub { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.cmp-results { display: flex; flex-direction: column; gap: 16px; }
.cmp-analysis { padding: 16px 18px; font-size: 14px; line-height: 1.65; color: var(--ink); }
.cmp-analysis h4.cmp-h { font-size: 13px; font-weight: 600; color: var(--accent); margin: 16px 0 7px; }
.cmp-analysis h4.cmp-h:first-child { margin-top: 0; }
.cmp-analysis p { margin: 0 0 10px; }
.cmp-analysis ul { margin: 0 0 10px 18px; }
.cmp-analysis li { margin-bottom: 4px; }
.cmp-pair-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cmp-vs { color: var(--accent); font-weight: 700; }
.cmp-match-list { display: flex; flex-direction: column; }
.cmp-match { display: grid; grid-template-columns: 52px 1fr; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); align-items: start; }
.cmp-match:last-child { border-bottom: none; }
.cmp-legend { font-size: 12px; color: var(--muted); line-height: 1.5; padding: 0 2px 4px; }
.cmp-empty { padding: 16px 18px; font-size: 13px; color: var(--muted); }
.cmp-score { font-size: 13px; font-weight: 700; border-radius: 6px; padding: 6px 0; text-align: center; border: 1px solid; }
.cmp-score.cmp-high { color: var(--accent); background: var(--accent-soft); border-color: var(--accent-line); }
.cmp-score.cmp-mid { color: var(--ink-2); background: var(--bg-soft); border-color: var(--line); }
.cmp-score.cmp-low { color: var(--muted); background: var(--bg-soft); border-color: var(--line); }
.cmp-sides { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cmp-side { background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; transition: border-color .12s; }
.cmp-side:hover { border-color: var(--accent-line); }
.cmp-side-label { font-size: 11px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.cmp-side-text { font-size: 12.5px; color: var(--ink-2); line-height: 1.5; }
@media (max-width: 720px) { .cmp-sides { grid-template-columns: 1fr; } }

/* ---- responsive ---- */
@media (max-width: 820px) {
  .sidebar { display: none; }
  .view { padding: 22px 18px 48px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-cols { grid-template-columns: 1fr; }
}
