:root {
  --navy: #1f3a5f;
  --navy-2: #2c5282;
  --ink: #1a202c;
  --ink-2: #4a5568;
  --ink-3: #718096;
  --line: #e2e8f0;
  --line-2: #cbd5e0;
  --bg: #f5f7fa;
  --card: #ffffff;
  --hover: #edf2f7;
  --accent: #2b6cb0;
  --red: #c53030;
  --red-bg: #fff5f5;
  --green: #2f855a;
  --green-bg: #f0fff4;
  --amber: #b7791f;
  --amber-bg: #fffaf0;
  --tick: #c53030;
  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--accent); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--ink); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* top bar */
.topbar { background: var(--navy); color: #fff; display: flex; align-items: center; gap: 16px; padding: 0 20px; height: 52px; position: sticky; top: 0; z-index: 20; }
.topbar .brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; color: #fff; }
.topbar .brand svg { width: 22px; height: 22px; }
.topbar nav a { color: #cbd5e0; margin-right: 14px; font-size: 13.5px; }
.topbar nav a.active, .topbar nav a:hover { color: #fff; text-decoration: none; }
.topbar .user { margin-left: auto; font-size: 13px; color: #cbd5e0; display: flex; gap: 12px; align-items: center; }
.topbar .user a { color: #fff; }

.page { padding: 20px; max-width: 1500px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }

/* buttons + inputs */
button, .btn { font: inherit; border: 1px solid var(--line-2); background: #fff; color: var(--ink); padding: 6px 12px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: var(--hover); text-decoration: none; }
button.primary, .btn.primary { background: var(--navy-2); border-color: var(--navy-2); color: #fff; }
button.primary:hover { background: var(--navy); }
button.danger { color: var(--red); border-color: #feb2b2; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button.sm { padding: 3px 8px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; border: 1px solid var(--line-2); border-radius: var(--radius); padding: 6px 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid #90cdf4; outline-offset: -1px; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 10px; }
label.field input, label.field select, label.field textarea { font-size: 14px; color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

/* tables */
table.t { border-collapse: collapse; width: 100%; background: #fff; }
table.t th, table.t td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-2); background: #f7fafc; position: sticky; top: 0; z-index: 2; border-bottom: 1px solid var(--line-2); }
table.t th.num { text-align: right; }
table.t tbody tr:hover { background: #f7fafc; }
table.t tr.total td { font-weight: 700; border-top: 1px solid var(--ink-2); }
table.t tr.grand td { font-weight: 700; border-top: 1px solid var(--ink-2); border-bottom: 3px double var(--ink-2); }
table.t tr.section td { background: #edf2f7; font-weight: 700; font-size: 12.5px; color: var(--navy); }
table.t tr.sub td { background: #fbfcfe; font-size: 13px; }
table.t tr.sub td:first-child { padding-left: 28px; }
table.t tr.warn td { background: var(--red-bg); }
table.t tr.selected td { background: #ebf8ff; }
.tablewrap { overflow: auto; max-height: calc(100vh - 240px); border: 1px solid var(--line); border-radius: var(--radius); }

/* engagement layout */
.eng-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.eng-head .title { flex: 1; min-width: 260px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-2); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; color: var(--ink-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--navy); border-color: var(--navy); font-weight: 600; text-decoration: none; }
.tabs a:hover { text-decoration: none; color: var(--navy); }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 10px; background: var(--hover); color: var(--ink-2); font-weight: 600; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.blue { background: #ebf8ff; color: var(--accent); }
.checks { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.check { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; min-width: 170px; }
.check .k { font-size: 11.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em; }
.check .v { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.check.ok { border-left: 4px solid var(--green); }
.check.bad { border-left: 4px solid var(--red); }

/* workpaper references (tickmark style) */
.ref { display: inline-block; font-family: var(--mono); font-size: 11.5px; font-weight: 700; color: var(--tick); border: 1px solid #feb2b2; background: #fff; border-radius: 4px; padding: 0 5px; margin: 1px 3px 1px 0; cursor: pointer; line-height: 18px; }
.ref:hover { background: var(--red-bg); text-decoration: none; }
.addref { font-size: 11.5px; color: var(--ink-3); border: 1px dashed var(--line-2); border-radius: 4px; padding: 0 5px; cursor: pointer; line-height: 18px; display: inline-block; }
.addref:hover { color: var(--accent); border-color: var(--accent); }
.grp-btn { border: 1px solid transparent; background: none; padding: 2px 6px; font-size: 12.5px; text-align: left; max-width: 340px; overflow: hidden; text-overflow: ellipsis; display: block; width: 100%; }
.grp-btn:hover { border-color: var(--line-2); background: #fff; }
.grp-btn.unmapped { color: var(--red); font-weight: 600; }

/* binder */
.binder { display: grid; grid-template-columns: 1fr; gap: 0; }
.folder-head { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: #edf2f7; border: 1px solid var(--line); border-radius: var(--radius) var(--radius) 0 0; margin-top: 10px; font-weight: 700; color: var(--navy); }
.folder-head .fref { font-family: var(--mono); }
.wp-row { display: grid; grid-template-columns: 70px 1fr 120px 90px 90px 70px; gap: 8px; align-items: center; padding: 7px 10px; border: 1px solid var(--line); border-top: 0; background: #fff; cursor: pointer; }
.wp-row:hover { background: #f7fafc; }
.wp-row .wref { font-family: var(--mono); font-weight: 700; color: var(--tick); }
.wp-empty { padding: 8px 10px; border: 1px solid var(--line); border-top: 0; background: #fff; color: var(--ink-3); font-size: 12.5px; }
.signoff { font-size: 11.5px; color: var(--ink-3); }
.signoff b { color: var(--green); }
.fileicon { display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 4px; border-radius: 3px; color: #fff; margin-right: 6px; vertical-align: 1px; }
.fi-xlsx { background: #1d6f42; } .fi-docx { background: #2b579a; } .fi-pdf { background: #c53030; } .fi-other { background: #718096; } .fi-none { background: #cbd5e0; }

/* modal + drawer */
.overlay { position: fixed; inset: 0; background: rgba(26, 32, 44, .45); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; }
.modal { background: #fff; border-radius: 8px; width: 100%; max-width: 560px; padding: 20px; box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.modal.wide { max-width: 1000px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.drawer-overlay { position: fixed; inset: 0; background: rgba(26,32,44,.3); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: #fff; z-index: 41; box-shadow: -8px 0 24px rgba(0,0,0,.15); overflow: auto; padding: 20px; }
.drawer h2 { display: flex; gap: 8px; align-items: baseline; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 10px; font-size: 13px; margin: 10px 0; }
.kv .k { color: var(--ink-3); }
.openbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; padding: 12px; background: #f7fafc; border: 1px solid var(--line); border-radius: var(--radius); }
.list { border: 1px solid var(--line); border-radius: var(--radius); }
.list > div { padding: 6px 10px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; font-size: 13px; }
.list > div:last-child { border-bottom: 0; }
.picker-list { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); margin-top: 8px; }
.picker-list .sec { padding: 4px 10px; background: #edf2f7; font-size: 11.5px; font-weight: 700; color: var(--navy); position: sticky; top: 0; }
.picker-list .opt { padding: 5px 10px; cursor: pointer; font-size: 13px; }
.picker-list .opt:hover, .picker-list .opt.kb { background: #ebf8ff; }

/* login */
.login { max-width: 380px; margin: 10vh auto; }
.login .card { padding: 28px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; }
.notice { padding: 10px 12px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; }
.notice.warn { background: var(--amber-bg); border: 1px solid #fbd38d; }
.notice.info { background: #ebf8ff; border: 1px solid #bee3f8; }
.notice.bad { background: var(--red-bg); border: 1px solid #feb2b2; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius); font-size: 13.5px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 100; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--red); }

.client-list .client { display: grid; grid-template-columns: 1fr 180px 120px 200px; gap: 10px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.client-list .client:hover { background: #f7fafc; }

@media (max-width: 800px) {
  .topbar { padding: 0 12px; gap: 10px; }
  .topbar .uname, .topbar .brand-name { display: none; }
  .topbar nav a { margin-right: 8px; }
  .wp-row { grid-template-columns: 60px 1fr 70px; }
  .wp-row .hide-sm { display: none; }
  .client-list .client { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .page { padding: 12px; }
}

@media print {
  .topbar, .tabs, .noprint, button, .addref { display: none !important; }
  body { background: #fff; }
  .page { padding: 0; max-width: none; }
  .tablewrap { max-height: none; overflow: visible; border: 0; }
  .card { border: 0; padding: 0; }
  table.t th { position: static; }
  .ref { border: 0; padding: 0; }
  .print-head { display: block !important; }
}
.print-head { display: none; margin-bottom: 10px; }
