:root {
  --bg: #0f1420; --panel: #171e2e; --panel2: #1d2740; --line: #2a3550;
  --text: #e8ecf4; --muted: #8b96ad; --accent: #4f8cff; --accent2: #37c28e;
  --warn: #e0a23e; --bad: #e05e5e;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
#shell { display: flex; min-height: 100vh; }
#sidebar { width: 220px; background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; flex-shrink: 0; }
.brand { font-size: 17px; font-weight: 700; margin: 0 8px 18px; letter-spacing: .3px; }
#nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--muted); text-decoration: none; margin-bottom: 2px; cursor: pointer; }
#nav a:hover { background: var(--panel2); color: var(--text); }
#nav a.active { background: var(--panel2); color: var(--text); font-weight: 600; }
#main { flex: 1; padding: 24px 28px; max-width: 1100px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 22px 0 8px; }
.sub { color: var(--muted); margin-bottom: 16px; }
.loading { color: var(--muted); padding: 40px 0; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: var(--panel2); border: 1px solid var(--line); }
.badge.Closing { border-color: var(--accent2); color: var(--accent2); }
.badge.Pre-closing { border-color: var(--accent); color: var(--accent); }
.badge.Title { border-color: var(--warn); color: var(--warn); }
button { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; }
button.ghost { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
button.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
.btnrow { display: flex; gap: 8px; margin: 14px 0; flex-wrap: wrap; }
input, select { background: var(--panel2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 7px 10px; font-size: 13px; }
label { display: block; color: var(--muted); font-size: 12px; margin: 10px 0 3px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.cards .card .big { font-size: 24px; font-weight: 700; }
.cards .card .lbl { color: var(--muted); font-size: 12px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin: 18px 0 14px; }
.tabs a { padding: 8px 12px; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; font-size: 13px; }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.formgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 4px 16px; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.bad { color: var(--bad); }
.ok { color: var(--accent2); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.rec { border-left: 3px solid var(--accent); }
.rec.Risk { border-left-color: var(--bad); }
.rec.Vendor { border-left-color: var(--accent2); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 7px 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border-bottom: none; }
.back { color: var(--muted); cursor: pointer; margin-bottom: 10px; display: inline-block; }
.back:hover { color: var(--text); }

/* Sign-in */
body.login #shell { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 340px; }
.login-card .brand { margin: 0 0 4px; }
.login-card h1 { margin-bottom: 16px; }
.login-card label { display: block; margin: 12px 0 4px; color: var(--muted); font-size: 12px; }
.login-card input { width: 100%; }
.login-card .btnrow { margin-top: 18px; }
.login-card .card.bad { margin-top: 12px; }

/* Signed-in user bar */
#userbar { margin-top: 18px; padding: 10px 8px 0; border-top: 1px solid var(--line); font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
#userbar .who { font-weight: 600; }
#userbar a { color: var(--accent); cursor: pointer; }

/* Viewers are read-only */
body.role-viewer #main button { display: none; }

/* Expandable sidebar groups */
#nav .navgroup { margin-bottom: 2px; }
#nav a.group { font-weight: 600; color: var(--text); }
#nav a.group .chev { display: inline-block; width: 14px; color: var(--muted); }
#nav .kids { display: none; }
#nav .kids.open { display: block; }
#nav a.sub { display: block; padding: 6px 10px 6px 32px; border-radius: 8px; color: var(--muted); cursor: pointer; font-size: 13px; }
#nav a.sub:hover { background: var(--panel2); color: var(--text); }
#nav a.sub.active { background: var(--panel2); color: var(--text); font-weight: 600; }

/* Narrow screens: sidebar becomes a top bar */
@media (max-width: 720px) {
  #shell { flex-direction: column; }
  #sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--line); padding: 10px 12px; }
  .brand { margin: 0 4px 8px; }
  #nav a { display: inline-block; margin-bottom: 0; }
  #nav .navgroup { display: inline-block; vertical-align: top; }
  #nav a.sub { padding: 6px 10px; }
  #userbar { margin-top: 8px; flex-direction: row; gap: 10px; align-items: center; }
  #main { padding: 16px 14px; max-width: none; }
  table { font-size: 13px; }
  th, td { padding: 7px 8px; }
}

/* Month calendar */
.calgrid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 12px 0 22px; }
.calhead { font-size: 12px; font-weight: 600; color: var(--muted); text-align: center; padding: 4px 0; }
.calcell { min-height: 78px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: var(--panel); }
.calcell.empty { border: none; background: transparent; }
.calday { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.calitem { font-size: 11px; background: var(--panel2); border-left: 3px solid var(--accent); border-radius: 3px; padding: 2px 4px; margin-bottom: 2px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.calitem:hover { border-left-color: var(--accent2); }
.calmonth { margin: 0; font-size: 16px; }
@media (max-width: 700px) { .calcell { min-height: 54px; padding: 2px; } .calitem { font-size: 10px; } }

/* Email-this-document modal */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto; }
.modal { max-width: 620px; width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px; }
label.check { display: block; font-weight: 400; margin: 2px 0; }
