:root {
  --bg: #f3f4f6; --surface: #ffffff; --surface2: #f8fafc; --text: #111827; --muted: #6b7280;
  --border: #e5e7eb; --primary: #2563eb; --primary-text: #fff; --accent: #059669;
  --high: #dc2626; --med: #d97706; --low: #2563eb;
  --left: rgba(37, 99, 235, .22); --right: rgba(234, 88, 12, .25);
  --paper-font: 17px;
}
[data-theme="dark"] {
  --bg: #0b0f14; --surface: #121821; --surface2: #18202b; --text: #e5e7eb; --muted: #8b95a3;
  --border: #253041; --primary: #3b82f6; --accent: #10b981;
  --left: rgba(59, 130, 246, .35); --right: rgba(249, 115, 22, .35);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); display: flex; flex-direction: column; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 11px; cursor: pointer; white-space: nowrap; }
button:hover { border-color: var(--primary); }
button:disabled { opacity: .5; cursor: progress; }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
button.icon { padding: 6px 9px; }
input, select, textarea { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; width: 100%; }
textarea { resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
code { background: var(--surface2); padding: 1px 4px; border-radius: 4px; }
.muted { color: var(--muted); } .small { font-size: 12.5px; }
.sep { width: 1px; height: 22px; background: var(--border); display: inline-block; margin: 0 4px; }
.grow { flex: 1; }
.row { display: flex; gap: 8px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.row select { width: auto; flex: 1; }

.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 16px; } .brand span { font-weight: 400; color: var(--muted); margin-left: 4px; }
.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; flex: 1; }
.right { display: flex; gap: 6px; align-items: center; }
.chip { font-size: 12px; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface2); color: var(--muted); }
.chip.ok { color: var(--accent); border-color: var(--accent); }
.chip.warn { color: var(--med); border-color: var(--med); }
.chip.err { color: var(--high); border-color: var(--high); }

.dropdown { position: relative; }
.menu { position: absolute; top: 110%; left: 0; z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; min-width: 220px; padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; }
.menu button:hover { background: var(--surface2); }

.layout { flex: 1; display: grid; grid-template-columns: 220px minmax(0, 1fr) 340px; min-height: 0; }
.sidebar, .panel { background: var(--surface); border-right: 1px solid var(--border); padding: 12px; overflow: auto; }
.panel { border-right: 0; border-left: 1px solid var(--border); }
.side-head { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 0 8px; font-weight: 600; }
.side-head .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }
.hint { font-size: 12px; color: var(--muted); }
#history { list-style: none; margin: 0; padding: 0; }
#history li { padding: 7px 8px; border-radius: 8px; cursor: pointer; display: flex; justify-content: space-between; gap: 6px; }
#history li:hover { background: var(--surface2); }
#history li.active { background: var(--surface2); outline: 1px solid var(--primary); }
#history .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#history .d { font-size: 11.5px; color: var(--muted); }
#history .x { visibility: hidden; border: 0; background: none; padding: 0 4px; color: var(--muted); }
#history li:hover .x { visibility: visible; }

.paper-wrap { display: flex; flex-direction: column; padding: 14px 22px; overflow: auto; min-height: 0; }
.title { font-size: 18px; font-weight: 600; border: 0; background: transparent; padding: 6px 2px; }
.title:focus { outline: none; border-bottom: 1px solid var(--primary); border-radius: 0; }
.toolbar { display: flex; gap: 4px; align-items: center; padding: 6px 0; flex-wrap: wrap; }
.toolbar button { padding: 4px 9px; }
.paper { flex: 1; min-height: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 26px 30px; font-size: var(--paper-font); line-height: 1.6; outline: none; font-family: Georgia, "Times New Roman", serif; }
.paper:focus { border-color: var(--primary); }
.paper:empty::before { content: attr(data-placeholder); color: var(--muted); }
::highlight(side-left) { background-color: var(--left); }
::highlight(side-right) { background-color: var(--right); }
::highlight(critical) { text-decoration: underline wavy #dc2626; text-decoration-thickness: 1.5px; }
::highlight(found) { background-color: rgba(250, 204, 21, .55); }

.card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; background: var(--surface); }
.card.soft { background: var(--surface2); }
.issue .head { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; padding: 1px 7px; border-radius: 999px; color: #fff; }
.badge.high { background: var(--high); } .badge.medium { background: var(--med); } .badge.low { background: var(--low); }
.cat { font-size: 12px; color: var(--muted); }
.diff { font-size: 13px; margin: 6px 0; }
.diff del { color: var(--high); } .diff ins { color: var(--accent); text-decoration: none; font-weight: 500; }
.issue .btns { display: flex; gap: 6px; }
.issue .btns button { padding: 3px 9px; font-size: 12.5px; }
.issue.done { opacity: .45; }
.lat { display: flex; gap: 8px; align-items: center; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.crit { color: var(--high); font-weight: 600; }
pre.sent, pre.prompt { white-space: pre-wrap; font-size: 12px; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; max-height: 260px; overflow: auto; }

dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); max-width: 460px; width: 92vw; padding: 18px 20px; }
dialog.wide { max-width: 760px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin: 0 0 8px; }
.tabs { display: flex; gap: 4px; margin: 8px 0 12px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; }
.tabs button.active { border-bottom-color: var(--primary); color: var(--primary); }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.check input { width: auto; }
.field { display: block; margin: 10px 0; }
.learn-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; }
.learn-item input { width: auto; margin-top: 4px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 9px 16px; border-radius: 10px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1100px) { .layout { grid-template-columns: 0 minmax(0, 1fr) 320px; } .sidebar { display: none; } }
@media (max-width: 800px) { .layout { grid-template-columns: 1fr; } .panel { border-left: 0; border-top: 1px solid var(--border); } }
.actions { flex-wrap: nowrap; }
.chip { white-space: nowrap; }
@media (max-width: 1560px) { .brand span { display: none; } }
@media (max-width: 1250px) { .actions { flex-wrap: wrap; } }
