:root {
  --navy: #041A72; --navy-light: #2B3F8C; --navy-dark: #030F52;
  --bg: #F7F8F9; --surface: #FFFFFF; --border: #ECECEC; --border-strong: #D5D8DC;
  --text: #111318; --muted: #555960; --row-hover: #F1F3FA; --info-bg: #E7E9F5;
  --ok: #2E7D32; --ok-bg: #E7F3E8; --warn: #8A5A00; --warn-bg: #FEF3DA; --bad: #C62828; --bad-bg: #FBE7E7;
  --accent: #041A72; --accent-text: #FFFFFF; --link: #041A72;
}
:root[data-theme="dark"] {
  --bg: #0E1220; --surface: #161B2E; --border: #262D47; --border-strong: #343D5E;
  --text: #E8EBF5; --muted: #9AA3C0; --row-hover: #1D2440; --info-bg: #1C2547;
  --ok: #6FD28A; --ok-bg: #16301F; --warn: #F2C45C; --warn-bg: #36290E; --bad: #F28B8B; --bad-bg: #3A1B1B;
  --accent: #6F86E8; --accent-text: #0A1030; --link: #8FA2F0;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Helvetica Neue", Helvetica, Arial, sans-serif; }
button, input { font: inherit; color: var(--text); }
button { cursor: pointer; }
[hidden] { display: none !important; }

/* shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: linear-gradient(180deg, var(--navy) 0%, var(--navy-dark) 100%); color: #fff; display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.brand { background: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 22px; display: flex; }
.brand img { width: 100%; height: auto; display: block; }
.side .label { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.55); margin: 4px 10px 8px; }
.nav a { display: flex; gap: 10px; align-items: center; color: rgba(255,255,255,.85); text-decoration: none; padding: 9px 10px; border-radius: 8px; }
.nav a.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav { margin-bottom: auto; }
.side-btn { display: flex; gap: 10px; align-items: center; justify-content: center; margin: 0 2px 12px; padding: 10px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.1); color: #fff; font-weight: 600; }
.side-btn:hover { background: rgba(255,255,255,.2); }
.side .foot { font-size: 11px; color: rgba(255,255,255,.5); padding: 0 10px; }
.main { min-width: 0; display: flex; flex-direction: column; }

/* top bar */
.top { height: 60px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; position: sticky; top: 0; z-index: 5; }
.top h1 { font-size: 16px; margin: 0; }
.top .sub { color: var(--muted); font-size: 12px; }
.right { display: flex; align-items: center; gap: 12px; }
.user { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--navy-light); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.user .name { font-weight: 600; line-height: 1.15; }
.user .role { color: var(--muted); font-size: 12px; }
.btn { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 14px; }
.btn:hover { background: var(--row-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { width: 36px; height: 36px; padding: 0; display: grid; place-items: center; }

/* content */
.content { padding: 20px; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 16px; }
label.f { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); gap: 3px; }
input[type=date], input[type=search] { background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--navy-light); outline-offset: 1px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.quick .btn { padding: 7px 10px; font-size: 12px; }
.quick .btn.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.spacer { flex: 1; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; text-align: left; border-left: 4px solid var(--border-strong); }
.tile.active { box-shadow: 0 0 0 2px var(--navy-light); }
.tile .n { font-size: 26px; font-weight: 700; }
.tile .l { color: var(--muted); font-size: 12px; }
.tile.k-ok { border-left-color: var(--ok); } .tile.k-warn { border-left-color: #F9A825; } .tile.k-bad { border-left-color: var(--bad); } .tile.k-all { border-left-color: var(--navy); }
.banner { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--warn-bg); color: var(--warn); }
.banner.error { background: var(--bad-bg); color: var(--bad); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.toolbar input[type=search] { min-width: 260px; flex: 1; max-width: 440px; }
.count { color: var(--muted); font-size: 12px; margin-left: auto; }
.table-wrap { overflow: auto; max-height: calc(100vh - 360px); min-height: 280px; }
table { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
th { position: sticky; top: 0; background: var(--bg); z-index: 2; cursor: pointer; user-select: none; font-size: 12px; color: var(--muted); font-weight: 600; }
th.sorted { color: var(--navy); } :root[data-theme="dark"] th.sorted { color: var(--link); }
td.long { max-width: 320px; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--row-hover); }
th.chk, td.chk { width: 36px; min-width: 36px; padding-right: 4px; position: sticky; left: 0; background: var(--surface); z-index: 1; }
th.chk { z-index: 3; background: var(--bg); }
tr.selected td { background: var(--info-bg); }
tr.colfilters th { top: 37px; background: var(--surface); padding: 6px 8px; cursor: default; z-index: 2; }
tr.colfilters input, tr.colfilters select { width: 100%; min-width: 90px; font-size: 12px; padding: 4px 6px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px; color: var(--text); }
.bulk { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 10px 14px; background: var(--info-bg); border-bottom: 1px solid var(--border); }
th.sticky, td.sticky { position: sticky; left: 36px; background: var(--surface); z-index: 1; font-weight: 600; }
th.sticky { z-index: 3; background: var(--bg); }
tbody tr:hover td.sticky { background: var(--row-hover); }
.pill { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.ok { background: var(--ok-bg); color: var(--ok); } .pill.warn { background: var(--warn-bg); color: var(--warn); } .pill.bad { background: var(--bad-bg); color: var(--bad); }
.pager { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.pager select { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 6px; padding: 4px 6px; }
.pager .inline { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.pnums { display: inline-flex; gap: 4px; }
.pnums button { min-width: 34px; padding: 5px 8px; }
.pnums button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }
.empty { padding: 44px; text-align: center; color: var(--muted); }

/* detail drawer */
aside.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100%); background: var(--surface); border-left: 1px solid var(--border); padding: 0; overflow: hidden; display: flex; flex-direction: column; transform: translateX(100%); transition: transform .18s; z-index: 20; }
aside.drawer.open { transform: none; box-shadow: -8px 0 28px rgba(3,15,82,.18); }
aside.drawer h2 { margin: 0 0 2px; font-size: 16px; }
aside.drawer dt { color: var(--muted); font-size: 11px; margin-top: 12px; text-transform: uppercase; letter-spacing: .04em; }
aside.drawer dd { margin: 2px 0 0; white-space: pre-wrap; word-break: break-word; }
.close { float: right; }
.d-head { padding: 18px 20px 12px; display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.d-body { padding: 0 20px 20px; overflow: auto; flex: 1; display: grid; gap: 14px; align-content: start; }
.box { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: var(--surface); }
.box h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.bhead { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.bhead h3 { margin: 0; }
.summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 18px; }
.summary .k { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.summary .v { margin-top: 2px; word-break: break-word; font-weight: 600; }
.mark { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-weight: 800; font-size: 13px; line-height: 1; }
.mark.ok { background: var(--ok-bg); color: var(--ok); } .mark.bad { background: var(--bad-bg); color: var(--bad); }
td.mk, th.mk { text-align: center; }
.box.validation { border-color: var(--navy-light); box-shadow: 0 0 0 1px var(--navy-light) inset; }
.box.validation h3 { display: flex; justify-content: space-between; align-items: center; color: var(--navy); } :root[data-theme="dark"] .box.validation h3 { color: var(--link); }
.vlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.vrow { display: grid; grid-template-columns: 22px 1fr; gap: 10px; align-items: start; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); }
.vrow.fail { background: var(--bad-bg); border-color: transparent; }
.vrow .vt { font-weight: 600; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.vrow .vd { color: var(--muted); font-size: 13px; margin-top: 2px; word-break: break-word; white-space: pre-wrap; }
.vrow.fail .vd { color: var(--text); }
.reasoning { white-space: pre-wrap; word-break: break-word; line-height: 1.55; min-height: 64px; }
.reasoning.none { color: var(--muted); font-style: italic; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
details.more dl { margin: 10px 0 0; }
.actions { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface); }
.btn.approve { background: var(--ok); border-color: var(--ok); color: #fff; font-weight: 600; }
.btn.reject { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.btn.approve:hover, .btn.reject:hover { filter: brightness(1.08); }
dialog { border: 1px solid var(--border-strong); border-radius: 14px; padding: 0; width: min(480px, calc(100% - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 20px 50px rgba(3,15,82,.3); }
dialog::backdrop { background: rgba(3,15,82,.45); }
dialog form { padding: 20px; display: grid; gap: 12px; }
dialog h3 { margin: 0; font-size: 16px; }
dialog .who { color: var(--muted); font-size: 12px; margin-top: -6px; }
dialog label.f { font-size: 12px; }
dialog textarea { width: 100%; min-height: 110px; resize: vertical; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; font: inherit; }
dialog .check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 13px; }
dialog .err { color: var(--bad); font-size: 12px; min-height: 16px; }
dialog .row { display: flex; justify-content: flex-end; gap: 10px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy-dark); color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 40; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

/* signed-out / error screens */
.gate { min-height: 100vh; display: grid; place-items: center; background: var(--bg); padding: 24px; }
.gate .box { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; max-width: 440px; width: 100%; text-align: center; }
.gate img { width: 220px; max-width: 80%; margin-bottom: 18px; }
.gate h2 { margin: 0 0 8px; color: var(--navy); font-size: 18px; } :root[data-theme="dark"] .gate h2 { color: var(--text); }
.gate p { margin: 0; color: var(--muted); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; padding: 10px 14px; gap: 14px; }
  .brand { margin: 0; padding: 6px 10px; width: 150px; } .side .label, .side .foot, .nav { display: none; }
  .user .who { display: none; } .top .sub { display: none; }
  .table-wrap { max-height: none; }
}

/* loading state of the table area */
.table-wrap { position: relative; }
.table-wrap.is-loading table { opacity: .45; pointer-events: none; }
.loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); font-weight: 500; }
.loading[hidden] { display: none; }
.spinner { width: 20px; height: 20px; border: 3px solid var(--border-strong); border-top-color: var(--navy-light); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* Excel export progress */
.export-panel { position: fixed; right: 20px; bottom: 20px; width: min(380px, calc(100% - 40px)); background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 12px; padding: 14px 16px; z-index: 45; box-shadow: 0 12px 32px rgba(3,15,82,.28); }
.export-head { display: flex; align-items: center; gap: 10px; }
.export-head strong { flex: 1; }
.export-percent { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--navy); }
:root[data-theme="dark"] .export-percent { color: var(--link); }
.export-track { height: 8px; border-radius: 99px; background: var(--border); margin: 10px 0 8px; overflow: hidden; }
.export-bar { height: 100%; width: 0; background: var(--navy-light); border-radius: 99px; transition: width .4s ease; }
.export-panel.done .export-bar { background: var(--ok); } .export-panel.failed .export-bar { background: var(--bad); }
.export-detail { color: var(--muted); font-size: 13px; min-height: 18px; word-break: break-word; }
.export-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 3px solid var(--border-strong); border-top-color: var(--navy-light); animation: spin .8s linear infinite; }
.tick, .cross { display: none; width: 18px; height: 18px; border-radius: 50%; place-items: center; font-weight: 800; font-size: 12px; color: #fff; }
.tick { background: var(--ok); } .cross { background: var(--bad); }
.export-panel.done .spinner, .export-panel.failed .spinner { display: none; }
.export-panel.done .tick, .export-panel.failed .cross { display: grid; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } .export-bar { transition: none; } }
.side-btn:disabled { opacity: .6; cursor: progress; }
