/* Case File viewer — no external fonts or assets. */
:root {
  --bg: #fbfbfa;
  --panel: #ffffff;
  --ink: #1f2328;
  --ink-2: #4b5563;
  --muted: #6b7280;
  --line: #e7e7e4;
  --line-2: #d9d9d4;
  --accent: #2f5bea;
  --accent-ink: #ffffff;
  --accent-soft: #eef2ff;
  --focus: 0 0 0 3px rgba(47, 91, 234, .25);
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-l: 0 12px 32px rgba(16, 24, 40, .14);

  /* parties */
  --isaiah-bg: #e8efff; --isaiah-line: #c7d6ff;
  --miracle-bg: #f2f3f5; --miracle-line: #e1e3e8;
  --alf-bg: #f6efe2; --alf-line: #e8dcc3;
  --neway-bg: #e8f5ec; --neway-line: #c9e7d3;
  --notary-bg: #eef6f8; --notary-line: #cfe6ec;
  --other-bg: #f5f3ff; --other-line: #e2dcfb;

  --wa: #128c4b; --wa-bg: #e3f6eb;
  --msgr: #6d3fd1; --msgr-bg: #efe8fd;
  --mail: #475569; --mail-bg: #eef1f5;

  --note-bg: #fff7e0; --note-line: #f1d58a; --note-ink: #6b4e00;
  --mark: #ffe28a;
  --warn: #b45309;
  --danger: #c0352b;

  --topbar-h: 56px;
  --drawer-w: 460px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overflow: hidden; }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
mark { background: var(--mark); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-2); background: var(--panel); color: var(--ink);
  padding: 6px 12px; border-radius: var(--radius-s); font-size: 14px; line-height: 1.3;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f6f6f4; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #2549c4; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #f1f1ee; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; padding: 10px 14px; }
.btn[disabled], .btn.disabled { opacity: .45; pointer-events: none; }
.icon-btn {
  border: 0; background: transparent; width: 30px; height: 30px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2);
}
.icon-btn:hover { background: #f1f1ee; }
.link { border: 0; background: none; color: var(--accent); padding: 0; font-size: 13px; }
.link:hover { text-decoration: underline; }
input[type=text], input[type=search], input[type=password], input[type=date], select, textarea {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: var(--radius-s);
  padding: 6px 10px; font-size: 14px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); cursor: pointer; white-space: nowrap; }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 20;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark, .login-mark {
  width: 26px; height: 26px; border-radius: 7px; background: var(--ink); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 15px;
}
.nav { display: flex; gap: 2px; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--ink-2); font-size: 14px; }
.nav a:hover { background: #f3f3f0; text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.search { flex: 1; display: flex; align-items: center; gap: 4px; max-width: 520px; margin-left: auto; }
.search input { flex: 1; padding: 7px 12px; background: #f6f6f4; border-color: transparent; }
.search input:focus { background: var(--panel); }
.search-count { font-size: 12px; color: var(--muted); min-width: 64px; text-align: right; white-space: nowrap; }
.seg { display: inline-flex; background: #f1f1ee; border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 7px; font-size: 13px; color: var(--ink-2); }
.seg button.active { background: var(--panel); color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.author { width: 132px; }
.dev-banner { background: #fff4d6; color: var(--note-ink); text-align: center; font-size: 13px; padding: 4px; border-bottom: 1px solid var(--note-line); }

/* ---------- Layout ---------- */
.shell { position: relative; height: calc(100% - var(--topbar-h) - 28px); display: flex; }
.view { flex: 1; overflow-y: auto; overflow-x: hidden; scroll-behavior: auto; }
.view:focus { outline: none; }
.kbd-hint {
  height: 28px; display: flex; align-items: center; justify-content: center; gap: 18px;
  font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); background: var(--panel);
}
.kbd-hint kbd {
  font-family: inherit; font-size: 11px; border: 1px solid var(--line-2); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; margin-right: 4px; background: #fafaf8;
}
.loading, .empty { padding: 64px 24px; text-align: center; color: var(--muted); }

/* ---------- Filter bar ---------- */
.filterbar {
  position: sticky; top: 0; z-index: 5; background: rgba(251, 251, 250, .94); backdrop-filter: saturate(1.4) blur(6px);
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 24px; border-bottom: 1px solid var(--line);
}
.filterbar .grow { flex: 1; }
.filterbar .count { font-size: 12px; color: var(--muted); white-space: nowrap; }
.filterbar select, .filterbar input[type=date] { font-size: 13px; padding: 4px 8px; }
.filterbar .sep { width: 1px; height: 20px; background: var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 999px; padding: 3px 11px; font-size: 13px; color: var(--ink-2);
}
.chip-btn.active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- Timeline ---------- */
.timeline { max-width: 940px; margin: 0 auto; padding: 8px 24px 120px; }
.day { display: flex; align-items: center; gap: 12px; margin: 26px 0 10px; color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.day::before, .day::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.thread-h {
  display: flex; align-items: center; gap: 8px; margin: 14px 0 6px; font-size: 12.5px; color: var(--ink-2); font-weight: 600;
}
.thread-h .t-label { color: var(--muted); font-weight: 500; text-transform: uppercase; font-size: 10.5px; letter-spacing: .06em; }
.row { display: flex; flex-direction: column; align-items: flex-start; margin: 6px 0; content-visibility: auto; contain-intrinsic-size: auto 150px; }
.row.mine { align-items: flex-end; }
.bubble {
  position: relative; max-width: min(680px, 88%); min-width: 220px; padding: 10px 14px 8px; border-radius: 14px;
  background: var(--miracle-bg); border: 1px solid var(--miracle-line); cursor: pointer;
  transition: box-shadow .12s ease, border-color .12s ease;
}
.bubble:hover { box-shadow: var(--shadow); }
.bubble.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(47, 91, 234, .18); }
.row.hit-current .bubble { box-shadow: 0 0 0 3px var(--mark); }
.row.mine .bubble { border-bottom-right-radius: 5px; }
.row.theirs .bubble { border-bottom-left-radius: 5px; }
.p-isaiah { background: var(--isaiah-bg); border-color: var(--isaiah-line); }
.p-miracle { background: var(--miracle-bg); border-color: var(--miracle-line); }
.p-altamirano { background: var(--alf-bg); border-color: var(--alf-line); }
.p-neway { background: var(--neway-bg); border-color: var(--neway-line); }
.p-notary { background: var(--notary-bg); border-color: var(--notary-line); }
.p-other { background: var(--other-bg); border-color: var(--other-line); }
.bh { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin-bottom: 4px; flex-wrap: wrap; }
.bh .who { font-weight: 650; color: var(--ink); }
.bh .party { color: var(--muted); }
.bh time { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; line-height: 1.55; }
.body.clamp { max-height: 18.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 75%, transparent); mask-image: linear-gradient(#000 75%, transparent); }
.bubble .more { margin-top: 2px; }
.trflag { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.trflag.warn { color: var(--warn); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 650; letter-spacing: .03em; text-transform: uppercase; padding: 1px 7px; border-radius: 999px; }
.badge.email { color: var(--mail); background: var(--mail-bg); }
.badge.whatsapp { color: var(--wa); background: var(--wa-bg); }
.badge.messenger { color: var(--msgr); background: var(--msgr-bg); }
.tag { font-size: 10.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: #fff; border: 1px solid var(--line-2); color: var(--ink-2); }
.tag.rc { border-color: #f4c38b; color: var(--warn); background: #fff6ec; }
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%; font-size: 12.5px; color: var(--ink-2);
  background: rgba(255, 255, 255, .75); border: 1px solid var(--line-2); border-radius: 8px; padding: 3px 9px;
}
.chip:hover { text-decoration: none; border-color: var(--accent); color: var(--accent); }
.chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 300px; }
.chip.small { font-size: 12px; padding: 2px 8px; }
.bf { display: flex; justify-content: flex-end; margin-top: 4px; }
.note-btn {
  border: 0; background: transparent; color: var(--muted); font-size: 12px; padding: 2px 6px; border-radius: 6px;
  opacity: 0; transition: opacity .12s ease;
}
.bubble:hover .note-btn, .bubble:focus-within .note-btn, .note-btn.has, .frow:hover .note-btn, .fcard:hover .note-btn, .note-btn.always { opacity: 1; }
.note-btn:hover { background: rgba(0, 0, 0, .05); color: var(--note-ink); }
.note-btn.has { color: var(--note-ink); }

/* ---------- Notes ---------- */
.notes { width: min(680px, 88%); margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }
.row.mine .notes { align-self: flex-end; }
.note {
  background: var(--note-bg); border: 1px solid var(--note-line); border-left: 4px solid #e8b931;
  border-radius: 10px; padding: 8px 12px; font-size: 13.5px; color: #3d3000;
}
.note-meta { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--note-ink); margin-bottom: 2px; }
.note-meta b { font-weight: 650; }
.note-actions { margin-left: auto; display: inline-flex; gap: 4px; }
.note-actions button { border: 0; background: transparent; color: var(--note-ink); font-size: 12px; padding: 1px 6px; border-radius: 5px; }
.note-actions button:hover { background: rgba(0, 0, 0, .06); }
.note-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.composer { background: var(--note-bg); border: 1px solid var(--note-line); border-radius: 10px; padding: 8px; }
.composer textarea { width: 100%; min-height: 72px; resize: vertical; background: #fff; border-color: var(--note-line); }
.composer-actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; margin-top: 6px; }
.composer-actions .hint { font-size: 12px; color: var(--note-ink); margin-right: auto; }

/* ---------- Drawer ---------- */
.drawer {
  width: var(--drawer-w); flex: 0 0 var(--drawer-w); height: 100%; background: var(--panel); border-left: 1px solid var(--line);
  display: none; flex-direction: column; box-shadow: -8px 0 24px rgba(16, 24, 40, .05);
}
.drawer.open { display: flex; }
.drawer-head { display: flex; align-items: center; gap: 6px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.drawer-title { flex: 1; font-weight: 650; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px 48px; }
.drawer-body h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin: 22px 0 8px; font-weight: 650; }
.drawer-body h3:first-child { margin-top: 0; }
dl.meta { display: grid; grid-template-columns: 128px 1fr; gap: 6px 12px; margin: 0; font-size: 13.5px; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; overflow-wrap: anywhere; }
.people { display: flex; flex-direction: column; gap: 2px; }
.person b { font-weight: 600; }
.person .email { color: var(--muted); font-size: 12.5px; }
.person.added { background: #e8f7ee; border-radius: 4px; padding: 0 4px; }
.rc-box { margin-top: 14px; border: 1px solid #f4c38b; background: #fff8ef; border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.rc-box b { color: var(--warn); display: block; margin-bottom: 4px; }
.rc-box .rc-line { display: flex; gap: 6px; flex-wrap: wrap; }
.rc-box .rc-line span.k { color: var(--muted); min-width: 72px; }
.rc-box .add { color: #11703b; }
.rc-box .rem { color: var(--danger); text-decoration: line-through; }
.dbody { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; line-height: 1.6; background: #fafaf8; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.att-list { display: flex; flex-direction: column; gap: 6px; }
.att-row { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.att-row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.dl-group { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.preview { width: 100%; height: 62vh; border: 1px solid var(--line); border-radius: 10px; background: #f3f3f0; }
img.preview { height: auto; max-height: 62vh; object-fit: contain; display: block; }
.preview-empty { padding: 28px; text-align: center; color: var(--muted); border: 1px dashed var(--line-2); border-radius: 10px; font-size: 13.5px; }
.linked { display: flex; flex-direction: column; gap: 6px; }
.linked a { font-size: 13.5px; }

/* ---------- Files ---------- */
.files-wrap { max-width: 1120px; margin: 0 auto; padding: 8px 24px 120px; }
.flist { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.frow-wrap { display: flex; flex-direction: column; }
.frow {
  display: grid; grid-template-columns: 34px minmax(0, 1fr) minmax(0, 260px) auto; gap: 12px; align-items: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
.frow:hover { border-color: var(--line-2); box-shadow: var(--shadow); }
.ficon { font-size: 20px; text-align: center; }
.fmain { min-width: 0; cursor: pointer; }
.fname { font-weight: 550; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fmeta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.flinks { display: flex; gap: 4px; flex-wrap: wrap; min-width: 0; }
.factions { display: flex; gap: 4px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.fcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px;
}
.fcard:hover { border-color: var(--line-2); box-shadow: var(--shadow); }
.fcard .ficon { font-size: 34px; text-align: left; }
.fcard .fname { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.fcard .factions { justify-content: flex-start; margin-top: auto; }
.fcard .notes, .frow-wrap .notes { width: 100%; }
.kind { font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-2); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* ---------- Ask ---------- */
.ask { max-width: 820px; margin: 0 auto; padding: 24px 24px 0; height: 100%; display: flex; flex-direction: column; }
.ask-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-bottom: 16px; }
.ask-intro h2 { margin: 18px 0 4px; font-size: 22px; }
.ask-intro p { margin: 0 0 16px; color: var(--muted); }
.suggest { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.suggest button { border: 1px solid var(--line-2); background: var(--panel); border-radius: 10px; padding: 8px 12px; text-align: left; font-size: 14px; color: var(--ink-2); }
.suggest button:hover { border-color: var(--accent); color: var(--accent); }
.qa { display: flex; flex-direction: column; gap: 6px; }
.qa.user { align-items: flex-end; }
.qa .qbody { max-width: 86%; padding: 10px 14px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14.5px; }
.qa.user .qbody { background: var(--isaiah-bg); border: 1px solid var(--isaiah-line); }
.qa.assistant .qbody { background: var(--panel); border: 1px solid var(--line); }
.qa.system .qbody { background: #fff8ef; border: 1px solid #f4c38b; color: var(--warn); }
.qa .cites { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.ask-form { display: flex; gap: 8px; align-items: flex-end; padding: 12px 0 18px; border-top: 1px solid var(--line); background: var(--bg); }
.ask-form textarea { flex: 1; min-height: 48px; max-height: 200px; resize: vertical; }
.thinking { color: var(--muted); font-size: 13.5px; }
.thinking::after { content: "…"; animation: dots 1.2s steps(3, end) infinite; display: inline-block; width: 1em; overflow: hidden; vertical-align: bottom; }
@keyframes dots { from { width: 0; } to { width: 1em; } }

/* ---------- Notes view ---------- */
.notes-wrap { max-width: 860px; margin: 0 auto; padding: 18px 24px 120px; }
.notes-wrap h2 { font-size: 20px; margin: 6px 0 14px; }
.ncard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.ncard .ntarget { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); margin-bottom: 8px; flex-wrap: wrap; }
.ncard .ntarget .lbl { color: var(--muted); }
.ncard .ntarget a { font-weight: 600; }
.ncard .excerpt { font-size: 12.5px; color: var(--muted); margin: -4px 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow-l);
  transition: opacity .18s ease, transform .18s ease; z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

/* ---------- Login ---------- */
body.login-page { overflow: auto; display: flex; align-items: center; justify-content: center; min-height: 100%; background: var(--bg); }
.login-card { width: min(380px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow-l); }
.login-card h1 { font-size: 20px; margin: 14px 0 4px; }
.login-card p { margin: 0 0 18px; font-size: 14px; }
.login-card input { width: 100%; padding: 10px 12px; font-size: 15px; margin-bottom: 12px; }
.login-err { color: var(--danger); font-size: 13.5px; min-height: 1.4em; margin: 10px 0 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .author { width: 110px; }
  .drawer { position: absolute; right: 0; top: 0; bottom: 0; z-index: 15; box-shadow: var(--shadow-l); }
}
@media (max-width: 860px) {
  :root { --topbar-h: 104px; --drawer-w: 100vw; }
  .topbar { flex-wrap: wrap; height: auto; min-height: var(--topbar-h); padding: 8px 12px; gap: 8px; }
  .search { order: 5; max-width: none; flex-basis: 100%; margin-left: 0; }
  .author { display: none; }
  .timeline, .files-wrap, .notes-wrap { padding-left: 12px; padding-right: 12px; }
  .filterbar { padding: 8px 12px; }
  .frow { grid-template-columns: 28px minmax(0, 1fr); }
  .frow .flinks, .frow .factions { grid-column: 2; justify-content: flex-start; }
  .bubble { max-width: 94%; min-width: 0; }
  .notes { width: 94%; }
  .kbd-hint { display: none; }
  .shell { height: calc(100% - var(--topbar-h)); }
}
@media print {
  .topbar, .kbd-hint, .drawer, .filterbar, .note-btn, .bf { display: none !important; }
  body { overflow: visible; }
  .shell, .view { height: auto; overflow: visible; display: block; }
  .row { content-visibility: visible; }
}
