/* GDC Legal AI Assistant — styled after the Gateway Program site:
   dark green wordmark, slate-green nav band, pale green hero, bold sans headings. */
:root {
  --green-900: #104612;
  --green-700: #1d6b20;
  --slate: #4b544d;
  --slate-700: #3a423c;
  --mint: #e4ece2;
  --mint-2: #d1e8d2;
  --ink: #111111;
  --ink-2: #444b46;
  --muted: #6b726d;
  --line: #d9dfd9;
  --bg: #f6f8f5;
  --card: #ffffff;
  --link: #0073aa;
  --warn-bg: #fff6e0; --warn-ink: #7a5300; --warn-line: #f0d48a;
  --danger-bg: #fdecec; --danger-ink: #8d1c1c; --danger-line: #f1b8b8;
  --ok-bg: #e7f5e8; --ok-ink: #18561b; --ok-line: #a9d8ac;
  --info-bg: #e8f1f8; --info-ink: #0b4a6b; --info-line: #b5d4e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 70, 18, .06), 0 4px 16px rgba(16, 70, 18, .06);
  --font: "Barlow", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 16px; line-height: 1.5; }
.hidden { display: none !important; }
a { color: var(--link); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h2 { font-size: 1.35rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: .5rem; }
.wrap { max-width: 1320px; margin: 0 auto; padding: 0 24px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .85rem; margin: .35rem 0 .75rem; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: .9rem; }

/* ---------- Header ---------- */
.site-header { background: #fff; position: sticky; top: 0; z-index: 20; box-shadow: 0 1px 0 var(--line); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 24px; max-width: 1320px; margin: 0 auto; }
.wordmark { display: inline-flex; flex-direction: column; background: var(--green-900); color: #fff; text-decoration: none;
  padding: 8px 14px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; font-size: .78rem; line-height: 1.25; text-align: center; }
.wordmark-lg { font-size: .95rem; padding: 12px 20px; margin-bottom: 18px; }
.topbar-right { display: flex; align-items: center; gap: 14px; font-size: .9rem; }
.badge { background: var(--mint); color: var(--green-900); border: 1px solid var(--mint-2); padding: 3px 10px; border-radius: 999px; font-weight: 600; font-size: .8rem; }
.user { font-weight: 600; }
.link-btn { background: none; border: 0; color: var(--link); cursor: pointer; font: inherit; padding: 0; }
.link-btn:hover { text-decoration: underline; }

.mainnav { background: var(--slate); display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; padding: 0 12px; }
.mainnav a { color: #fff; text-decoration: none; padding: 13px 18px; font-weight: 500; font-size: 1rem; border-bottom: 3px solid transparent; }
.mainnav a:hover { background: var(--slate-700); }
.mainnav a.active { border-bottom-color: #fff; font-weight: 700; }

.hero { background: var(--mint); border-bottom: 1px solid var(--mint-2); padding: 26px 0 22px; }
.hero h1 { font-size: 2.3rem; font-weight: 800; letter-spacing: -.01em; }
.hero p { margin: .4rem 0 0; color: var(--ink-2); font-size: 1.05rem; }

.notice { margin-top: 14px; }
.notice > div { border-radius: var(--radius); padding: 10px 14px; font-size: .92rem; }

/* ---------- Document bar ---------- */
.docbar { display: flex; gap: 24px; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; margin-top: 18px; }
.docbar .row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.docbar select { min-width: 360px; }
.or { color: var(--muted); }
.docbar-current { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; min-width: 300px; }
.doc-title { font-weight: 700; }
.doc-meta { font-size: .85rem; color: var(--muted); }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.tag-ocr { background: var(--info-bg); color: var(--info-ink); border: 1px solid var(--info-line); }

/* ---------- Layout ---------- */
.main { margin-top: 18px; margin-bottom: 40px; }
.layout { display: grid; grid-template-columns: minmax(360px, 5fr) 7fr; gap: 20px; align-items: start; }
.layout.no-viewer { grid-template-columns: 1fr; }
.layout.no-viewer .viewer { display: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: .4rem; }
.view { display: none; }
.view.active { display: block; }

.viewer { position: sticky; top: 124px; padding: 0; overflow: hidden; }
.viewer-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fafbfa; }
.viewer-body { height: calc(100vh - 210px); min-height: 420px; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; }
.viewer-body pre { margin: 0; padding: 14px; height: 100%; overflow: auto; white-space: pre-wrap; font-size: .82rem; font-family: Consolas, monospace; }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); padding: 30px; text-align: center; }

/* ---------- Forms ---------- */
.label { display: block; font-weight: 600; font-size: .9rem; margin: 12px 0 5px; color: var(--ink-2); }
input, select, textarea { font: inherit; width: 100%; padding: 9px 11px; border: 1px solid #c4ccc5; border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green-700); outline-offset: 0; border-color: var(--green-700); }
.docbar select { width: auto; }
textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: .95rem; }
.check input { width: auto; }
.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

.btn { font: inherit; font-weight: 700; border-radius: 6px; padding: 10px 20px; cursor: pointer; border: 2px solid var(--green-900); transition: background .15s, color .15s; display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--green-900); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-700); border-color: var(--green-700); }
.btn-ghost { background: #fff; color: var(--green-900); }
.btn-ghost:hover:not(:disabled) { background: var(--mint); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: .88rem; }
.btn-block { width: 100%; justify-content: center; margin-top: 16px; }
.upload-btn { padding: 8px 14px; font-size: .92rem; }

.seg { display: inline-flex; border: 1px solid #c4ccc5; border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; border: 0; background: #fff; padding: 7px 14px; cursor: pointer; font-size: .9rem; color: var(--ink-2); }
.seg button + button { border-left: 1px solid #c4ccc5; }
.seg button.active { background: var(--green-900); color: #fff; font-weight: 600; }
.seg-wide button { padding: 9px 18px; }

.risk { font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.risk-low { background: var(--ok-bg); color: var(--ok-ink); border: 1px solid var(--ok-line); }
.risk-med { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); }
.risk-high { background: var(--danger-bg); color: var(--danger-ink); border: 1px solid var(--danger-line); }

.callout { border-radius: 8px; padding: 10px 14px; margin: 10px 0; font-size: .93rem; border: 1px solid; }
.callout.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.callout.danger { background: var(--danger-bg); color: var(--danger-ink); border-color: var(--danger-line); }
.callout.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-line); }
.callout.info { background: var(--info-bg); color: var(--info-ink); border-color: var(--info-line); }
.error { color: var(--danger-ink); font-size: .9rem; }

/* ---------- Markdown output ---------- */
.md h2 { font-size: 1.15rem; margin: 1.2rem 0 .4rem; color: var(--green-900); border-bottom: 1px solid var(--mint-2); padding-bottom: 4px; }
.md h3 { font-size: 1rem; margin: 1rem 0 .3rem; }
.md ul { padding-left: 1.3rem; margin: .3rem 0; }
.md li { margin: .2rem 0; }
.md p { margin: .45rem 0; }
.md blockquote { margin: .6rem 0; padding: 6px 12px; border-left: 4px solid var(--mint-2); background: #fafbfa; }
.md code { background: #f0f2f0; padding: 1px 5px; border-radius: 4px; font-size: .9em; }

/* ---------- Chat ---------- */
.chat-card { display: flex; flex-direction: column; min-height: 560px; }
.chat-log { flex: 1; overflow-y: auto; max-height: calc(100vh - 380px); min-height: 300px; padding: 8px 2px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 85%; padding: 10px 14px; border-radius: 14px; font-size: .96rem; }
.msg.bot .bubble { background: var(--mint); border: 1px solid var(--mint-2); border-bottom-left-radius: 4px; }
.msg.user .bubble { background: var(--green-900); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.bot .bubble.md h2 { font-size: 1rem; border: 0; margin: .5rem 0 .2rem; }
.bubble .note { font-size: .82rem; color: var(--warn-ink); margin-top: 6px; }
.typing span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--slate); margin-right: 3px; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.chip { font: inherit; font-size: .85rem; background: #fff; border: 1px solid var(--mint-2); color: var(--green-900); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.chip:hover { background: var(--mint); }
.chat-input { display: flex; gap: 10px; align-items: flex-end; border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------- Redaction ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stat { background: #fafbfa; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.5rem; font-weight: 800; color: var(--green-900); }
.stat span { font-size: .8rem; color: var(--muted); }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.pending { font-size: .9rem; font-weight: 600; color: var(--warn-ink); }
.pending.done { color: var(--ok-ink); }
.flags { display: flex; flex-direction: column; gap: 8px; }
.flag { border: 1px solid var(--line); border-left: 5px solid #c4ccc5; border-radius: 8px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; }
.flag.accept { border-left-color: var(--green-900); background: #f6faf6; }
.flag.reject { border-left-color: #b9bfba; background: #fafafa; opacity: .75; }
.flag-text { font-weight: 600; word-break: break-word; }
.flag.accept .flag-text { text-decoration: none; background: #111; color: #fff; padding: 0 4px; border-radius: 3px; }
.flag-meta { font-size: .82rem; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.flag-why { font-size: .86rem; color: var(--ink-2); grid-column: 1 / -1; }
.cat { font-weight: 700; color: var(--slate); }
.src { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; padding: 1px 6px; border-radius: 4px; background: #eef1ee; }
.conf { display: inline-flex; align-items: center; gap: 6px; }
.conf i { display: inline-block; width: 60px; height: 6px; background: #e3e7e3; border-radius: 3px; position: relative; overflow: hidden; }
.conf i::after { content: ""; position: absolute; inset: 0; width: var(--w); background: var(--green-700); }
.decide { display: flex; gap: 6px; align-items: flex-start; }
.decide button { font: inherit; font-size: .85rem; font-weight: 600; padding: 5px 12px; border-radius: 6px; border: 1px solid #c4ccc5; background: #fff; cursor: pointer; }
.decide button.on.acc { background: var(--green-900); color: #fff; border-color: var(--green-900); }
.decide button.on.rej { background: #6b726d; color: #fff; border-color: #6b726d; }
.pdf-frame { width: 100%; height: 640px; border: 1px solid var(--line); border-radius: 8px; margin-top: 8px; }

/* ---------- Library ---------- */
.lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; margin-top: 10px; }
.lib-item { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 6px; background: #fff; }
.lib-item h4 { margin: 0; font-size: 1rem; }
.lib-type { font-size: .72rem; font-weight: 800; color: #fff; background: var(--slate); padding: 2px 8px; border-radius: 4px; align-self: flex-start; }
.lib-item .actions { margin-top: auto; padding-top: 8px; }
.lib-src { font-size: .8rem; word-break: break-all; }

/* ---------- Audit table ---------- */
.table-wrap { overflow-x: auto; max-height: 640px; overflow-y: auto; }
.table { border-collapse: collapse; width: 100%; font-size: .86rem; }
.table th { position: sticky; top: 0; background: var(--slate); color: #fff; text-align: left; padding: 8px 10px; font-weight: 600; }
.table td { border-bottom: 1px solid var(--line); padding: 7px 10px; vertical-align: top; }
.table tr:nth-child(even) td { background: #fafbfa; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(180deg, var(--mint) 0%, var(--bg) 60%); padding: 24px; }
.login-card { background: #fff; border-radius: 14px; box-shadow: var(--shadow); padding: 34px 34px 26px; width: 100%; max-width: 420px; text-align: center; border-top: 6px solid var(--green-900); }
.login-card h1 { font-size: 1.9rem; font-weight: 800; }
.login-card form { text-align: left; margin-top: 10px; }
.login-card label { display: block; font-weight: 600; font-size: .9rem; margin-top: 12px; }
.login-card label input { margin-top: 5px; }
.fineprint { font-size: .8rem; color: var(--muted); margin-top: 18px; }

/* ---------- Footer, toast, busy ---------- */
.site-footer { background: var(--slate-700); color: #fff; padding: 20px 0; font-size: .9rem; }
.site-footer .wrap { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.muted-inv { color: #c9d1ca; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 60; max-width: 90vw; }
.toast.err { background: var(--danger-ink); }
.busy { position: fixed; inset: 0; background: rgba(255, 255, 255, .6); display: flex; align-items: center; justify-content: center; gap: 12px; z-index: 50; font-weight: 600; color: var(--green-900); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--mint-2); border-top-color: var(--green-900); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .viewer { position: static; }
  .viewer-body { height: 520px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .topbar { flex-direction: column; gap: 8px; padding: 10px 16px; }
  .mainnav a { padding: 10px 10px; font-size: .9rem; }
  .hero h1 { font-size: 1.7rem; }
  .docbar select { min-width: 0; width: 100%; }
  .docbar-current { min-width: 0; width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  .flag { grid-template-columns: 1fr; }
}

/* ---------- Feedback rounds ---------- */
.flag-comment { grid-column: 1 / -1; font-size: .86rem; padding: 6px 10px; background: #fcfdfc; }
.flag.is-new { box-shadow: 0 0 0 2px #e0b13a inset; }
.new-badge { display: inline-block; font-size: .7rem; font-weight: 800; letter-spacing: .05em; color: #7a5300; background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 4px; padding: 1px 6px; margin-bottom: 4px; }
.revise-box, .recheck-box { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }
.round-badge { font-size: .75rem; font-weight: 700; color: var(--green-900); background: var(--mint); border: 1px solid var(--mint-2); border-radius: 999px; padding: 2px 9px; margin-left: 6px; vertical-align: middle; }
.miss { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--danger-line); background: #fffafa; border-radius: 8px; padding: 8px 10px; margin: 6px 0; cursor: pointer; }
.miss input { width: auto; margin-top: 4px; }

/* ---------- Masking + redacted preview ---------- */
.decide button.on.msk { background: #8a6d1f; color: #fff; border-color: #8a6d1f; }
.flag.mask { border-left-color: #8a6d1f; background: #fdfaf2; }
.flag.mask .flag-text { background: none; color: inherit; }
.mask-row { grid-column: 1 / -1; font-size: .86rem; display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.mask-row code { background: #fff; border: 1px solid #e5d7ad; padding: 2px 8px; border-radius: 4px; font-size: .95rem; }
.mask-row select { width: auto; padding: 2px 6px; }
.upd-badge { background: var(--info-bg); color: var(--info-ink); border-color: var(--info-line); margin-left: 4px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flag.flash { box-shadow: 0 0 0 3px var(--green-700) inset; transition: box-shadow .2s; }
#rd-changes ul { margin: 6px 0 0; padding-left: 1.2rem; }
#rd-changes code { background: #fff; padding: 1px 5px; border-radius: 3px; }
.pv-legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: .8rem; background: #fafbfa; }
.pv-legend b, .pv-legend mark { font-weight: 600; padding: 0 4px; border-radius: 3px; }
.viewer-body pre.pv-doc { height: calc(100% - 38px); }
.pv { cursor: pointer; border-radius: 2px; }
.pv-redact { background: #111; color: #fff; padding: 0 3px; font-size: .75em; }
.pv-mask { background: #fdf3d6; color: #111; outline: 1px solid #e5d7ad; }
mark.pv-pending, .pv-legend mark.pv-pending { background: #ffe680; color: inherit; }
.pv-keep { text-decoration: underline; text-decoration-color: #6b9e6e; text-decoration-thickness: 2px; }
