:root {
  --bg: #f6f4ef;
  --panel: #ffffff;
  --text: #283329;
  --muted: #766f66;
  --olive: #7f8965;
  --accent: #c97852;
  --sage: #5f7e78;
  --line: #e4ddd2;
  --ok: #4c7a5a;
  --warn: #b07a3a;
  --err: #b0483c;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(40,51,41,.07), 0 8px 24px rgba(40,51,41,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}
#app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 188px; background: #2b352c; color: #e9e4da; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 14px; border-bottom: 1px solid rgba(255,255,255,.08); }
.logo {
  width: 38px; height: 38px; border-radius: 50%; background: var(--accent);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 700; flex-shrink: 0;
}
.brand-text { font-weight: 700; font-size: 14px; line-height: 1.15; }
.brand-text span { font-weight: 400; font-size: 10px; opacity: .75; }
.sidebar nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-btn {
  background: transparent; border: none; color: #cfd6c9; text-align: left;
  padding: 9px 12px; border-radius: 7px; font-size: 13px; cursor: pointer;
}
.nav-btn:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-btn.active { background: var(--accent); color: #fff; font-weight: 600; }
.side-stats { padding: 12px 14px; border-top: 1px solid rgba(255,255,255,.08); font-size: 11px; color: #aebaa6; line-height: 1.6; }
.side-stats b { color: #fff; }

/* ---------- Content ---------- */
.content { flex: 1; padding: 26px 32px 60px; overflow-x: hidden; }
.view { display: none; }
.view.active { display: block; }
h1 { margin: 0 0 4px; font-size: 24px; }
.subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.toolbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; gap: 16px; flex-wrap: wrap; }
.toolbar-right input {
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; width: 260px; font-size: 14px; background: var(--panel);
}
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 999px;
  cursor: pointer; font-size: 13px; color: var(--text);
}
.chip.active { background: var(--sage); border-color: var(--sage); color: #fff; font-weight: 600; }

.table-wrap { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1280px; }
th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .03em;
  color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); background: #faf8f4; white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid #f0ebe3; vertical-align: middle; font-size: 13px; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #fbfaf6; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill.gray { background: #eeeae2; color: #6b6559; }
.pill.green { background: #e3efe4; color: #4c7a5a; }
.pill.orange { background: #f7e9d3; color: #b07a3a; }
.pill.red { background: #f6dcd7; color: var(--err); }
.pill.sage { background: #e2ece9; color: var(--sage); }
.pill.dark { background: #e7e0d4; color: #6f6248; }
.pill.ok { background: #e3efe4; color: #4a7a4a; }
.pill.bad { background: #f6dcd7; color: var(--err); }
.name-cell { font-weight: 600; }
.ch-logo {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 5px; flex: 0 0 auto;
  margin-right: 6px; vertical-align: middle; overflow: hidden;
}
.ch-logo svg { display: block; }
.ch-logo-tg { background: #2F8FD8; }
.ch-logo-max { background: #6552D9; }
.sub-cell { color: var(--muted); font-size: 10px; margin-top: 1px; }
.attn-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 5px; }
.test-badge { display: inline-block; margin-left: 5px; padding: 0 6px; border-radius: 10px; font-size: 10px; font-weight: 600; background: var(--sage, #4a5a4a); color: #fff; vertical-align: middle; }
.cell-nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.cell-reply-link { color: var(--text); text-decoration: none; cursor: pointer; display: inline-block; max-width: 170px; font-size: 12px; }
.cell-reply-link:hover { color: var(--sage); }

/* ---------- Back ---------- */
.back-btn { background: none; border: none; color: var(--sage); font-size: 14px; cursor: pointer; padding: 0 0 14px; }
.back-btn:hover { text-decoration: underline; }

/* ---------- Card ---------- */
.card-head {
  background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 24px; margin-bottom: 18px; display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap;
}
.card-head .big { font-size: 22px; font-weight: 700; }
.card-head .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  border: none; padding: 11px 20px; border-radius: 10px; font-size: 14px; font-weight: 600;
  cursor: pointer; color: #fff;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--ok); }
.btn.primary:hover:not(:disabled) { background: #3f6a4c; }
.btn.warn { background: var(--warn); }
.btn.warn:hover:not(:disabled) { background: #9a6730; }
.btn.danger { background: var(--err); }
.btn.danger:hover:not(:disabled) { background: #95382e; }
.btn.ghost { background: #efece5; color: var(--text); }
.btn.ghost:hover:not(:disabled) { background: #e5e0d5; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tab-btn { background: none; border: none; padding: 10px 16px; font-size: 14px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tab-btn.active { color: var(--sage); border-bottom-color: var(--sage); font-weight: 600; }

.panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 26px; }
.panel h3 { margin: 0 0 10px; font-size: 15px; }
.panel .hint { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.panel pre {
  white-space: pre-wrap; word-break: break-word; font-family: Georgia, "Times New Roman", serif;
  font-size: 14.5px; line-height: 1.55; margin: 0; color: var(--text); max-height: 72vh; overflow: auto;
}
.panel pre.mono { font-family: "Consolas", monospace; font-size: 12.5px; }

/* preview */
.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.preview-page {
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; cursor: zoom-in;
}
.preview-page img { width: 100%; display: block; }
.preview-page .pno { text-align: center; font-size: 11px; color: var(--muted); padding: 5px 0; }
.pdf-frame { width: 100%; height: 80vh; border: none; border-radius: 8px; }

/* file list */
.file-list { display: flex; flex-direction: column; gap: 6px; }
.file-row {
  display: flex; justify-content: space-between; align-items: center; padding: 9px 12px;
  background: #faf8f4; border: 1px solid var(--line); border-radius: 8px;
}
.file-row .fname { font-family: "Consolas", monospace; font-size: 12.5px; }
.file-actions a { color: var(--sage); font-size: 12.5px; text-decoration: none; margin-left: 12px; font-weight: 600; }
.file-actions a:hover { text-decoration: underline; }

/* status cards */
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.stat-card .label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.stat-card .value { font-size: 16px; font-weight: 700; }
.stat-card .sub { font-size: 11px; color: var(--muted); margin-top: 6px; word-break: break-all; }

/* generations/audit blocks */
.rev-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #f0ebe3; gap: 10px; }
.rev-row:last-child { border-bottom: none; }
.audit-line { padding: 8px 0; border-bottom: 1px solid #f2eee6; font-size: 13px; display: flex; gap: 12px; }
.audit-line .at { color: var(--muted); white-space: nowrap; font-size: 12px; }
.audit-line .act { font-weight: 600; white-space: nowrap; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(30,38,30,.5); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal.hidden { display: none; }
.modal-box { background: var(--panel); border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.25); width: 480px; max-width: 92vw; max-height: 88vh; overflow: auto; padding: 26px; }
.modal-box h2 { margin: 0 0 6px; font-size: 20px; }
.modal-box .m-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; flex-wrap: wrap; }
.modal-box label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 6px; }
.modal-box select, .modal-box textarea {
  width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit;
}
.radio-line { display: flex; align-items: center; gap: 8px; padding: 8px 0; cursor: pointer; font-size: 14px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: #283329; color: #fff; padding: 12px 22px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 100;
}
.toast.hidden { display: none; }
.toast.ok { background: var(--ok); }
.toast.err { background: var(--err); }

.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.mono { font-family: "Consolas", monospace; }
.small { font-size: 12px; }
a { color: var(--sage); }
