:root {
  --bg: #f6f7f9; --panel: #fff; --text: #1d2330; --muted: #677085; --line: #e2e5eb;
  --accent: #1f5fbf; --ok: #1d8a4e; --warn: #b7791f; --bad: #c0392b;
  --ins-bg: #d8f5e1; --ins: #0f6b34; --del-bg: #fbdcdc; --del: #9b1c1c;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --panel: #1d2128; --text: #e6e9ef; --muted: #98a1b3; --line: #2e333d;
          --accent: #6ea3ff; --ins-bg: #173b26; --ins: #8fe0ad; --del-bg: #4a1f1f; --del: #ffaaaa; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.5 -apple-system, system-ui, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
header#topbar { display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--panel);
                border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
header nav { display: flex; gap: 16px; }
.brand { font-weight: 700; color: var(--text); }
.spacer { flex: 1; }
#whoami { color: var(--muted); font-size: 13px; }
main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 80px; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 28px 0 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 12px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.manual-card { display: block; color: inherit; }
.manual-card:hover { border-color: var(--accent); }
.muted { color: var(--muted); font-size: 13px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; }
.badge.ok { background: var(--ins-bg); color: var(--ins); }
.badge.warn { background: #fdf0d5; color: var(--warn); }
.badge.bad { background: var(--del-bg); color: var(--del); }
.badge.neutral { background: var(--line); color: var(--muted); }
button, .btn { font: inherit; padding: 7px 14px; border-radius: 7px; border: 1px solid var(--accent);
               background: var(--accent); color: #fff; cursor: pointer; }
button.secondary { background: transparent; color: var(--accent); }
button.danger { background: var(--bad); border-color: var(--bad); }
button.link { background: none; border: none; color: var(--accent); padding: 0; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px;
                          background: var(--panel); color: var(--text); }
form.row, .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
label.stack { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 14px; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }

/* Login */
.login { max-width: 360px; margin: 10vh auto; }
.login { display: flex; flex-direction: column; gap: 10px; }
.user-pick { text-align: left; display: flex; justify-content: space-between; }

/* Reader */
.reader { display: grid; grid-template-columns: 260px 1fr; gap: 24px; align-items: start; }
.toc { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; font-size: 14px; }
.toc a { display: flex; gap: 6px; padding: 4px 6px; border-radius: 5px; color: var(--text); }
.toc a:hover { background: var(--line); }
.toc .removed { text-decoration: line-through; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; flex: none; background: transparent; }
.dot.added { background: var(--ok); } .dot.modified { background: var(--warn); } .dot.removed { background: var(--bad); }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.section { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 20px; margin-bottom: 12px; scroll-margin-top: 80px; }
.section.changed { border-left: 4px solid var(--warn); }
.section.added { border-left: 4px solid var(--ok); }
.section.removed { border-left: 4px solid var(--bad); opacity: .85; }
.section h3 { margin: 0 0 8px; font-size: 17px; display: flex; gap: 10px; align-items: center; }
.section .lvl2 { font-size: 15px; } .section .lvl3 { font-size: 14px; }
.section p { margin: 6px 0; }
/* Manual content blocks (see backend/importer.py) */
.section p.li { display: grid; grid-template-columns: 2.2em 1fr; margin: 3px 0; }
.section p.li .mk { text-align: right; padding-right: .5em; color: var(--muted); }
.section p.lvl1 { margin-left: 1.6em; } .section p.lvl2 { margin-left: 3.2em; } .section p.lvl3 { margin-left: 4.8em; }
.section .tbl { overflow-x: auto; margin: 10px 0; border-radius: 6px; }
.section .tbl table { width: auto; min-width: 50%; background: transparent; }
.section .tbl td { border: 1px solid var(--line); padding: 6px 10px; vertical-align: top; font-size: 14px; }
.section .tbl tr:first-child td { font-weight: 600; background: var(--bg); }
.section figure.img { margin: 12px 0; }
.section figure.img img { max-width: 100%; height: auto; border-radius: 4px; display: block; }
.section .tbl.ins, .section figure.img.ins { outline: 3px solid var(--ok); outline-offset: 2px; }
.section .tbl.del, .section figure.img.del { outline: 3px solid var(--bad); outline-offset: 2px; opacity: .6; }
.section tr.ins td { background: var(--ins-bg); } .section tr.del td { background: var(--del-bg); }
.section p.fmt { border-left: 3px solid var(--warn); padding-left: 8px; }
ins { background: var(--ins-bg); color: var(--ins); text-decoration: none; }
del { background: var(--del-bg); color: var(--del); }
.ack-row { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); display: flex; gap: 10px; align-items: center; }
.ack-done { color: var(--ok); font-weight: 600; font-size: 14px; }
.doc-ack { position: sticky; bottom: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px;
           display: flex; gap: 14px; align-items: center; box-shadow: 0 -4px 16px rgba(0,0,0,.06); }
.notes { white-space: pre-wrap; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
         padding: 10px 18px; border-radius: 8px; z-index: 100; }
@media (max-width: 760px) { .reader { grid-template-columns: 1fr; } .toc { position: static; max-height: none; } }
