:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --panel: #ffffff;
  --panel-muted: #f8f9fb;
  --ink: #1f2933;
  --muted: #66727f;
  --line: #d9dee5;
  --line-strong: #bcc5cf;
  --sidebar: #171b21;
  --sidebar-muted: #aab2bd;
  --blue: #1769aa;
  --blue-soft: #e8f2fa;
  --green: #147d64;
  --green-soft: #e7f5ef;
  --amber: #9a5a12;
  --amber-soft: #fff3df;
  --red: #b42318;
  --red-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; color: var(--ink); background: var(--bg); font-size: 14px; letter-spacing: 0; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 20px 14px 16px; background: var(--sidebar); color: #fff; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 0 7px; }
.brand-mark { width: 36px; height: 36px; flex: 0 0 36px; display: grid; place-items: center; border-radius: 6px; background: #2f7f9d; color: #fff; font-size: 17px; font-weight: 700; }
.brand strong, .brand small, .sidebar-user strong, .sidebar-user small { display: block; }
.brand strong { font-size: 15px; }
.brand small { margin-top: 3px; color: var(--sidebar-muted); font-size: 11px; }
.nav { margin-top: 27px; display: flex; flex-direction: column; gap: 3px; }
.nav-label { margin: 17px 10px 5px; color: #77818e; font-size: 11px; font-weight: 700; }
.nav a { min-height: 36px; padding: 9px 11px; border-radius: 5px; color: #cbd1d8; font-weight: 500; }
.nav a:hover { background: #232a33; color: #fff; }
.nav a.active { background: #2b3540; color: #fff; box-shadow: inset 3px 0 #4d9fc1; }
.sidebar-user { margin-top: auto; padding: 14px 7px 0; border-top: 1px solid #2c333c; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-user strong { font-size: 12px; }
.sidebar-user small { margin-top: 3px; color: var(--sidebar-muted); font-size: 11px; }

.main { min-width: 0; padding: 28px 34px 52px; }
.page-header { max-width: 1440px; margin: 0 auto 24px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.page-header h1 { margin: 4px 0 0; font-size: 25px; line-height: 1.2; letter-spacing: 0; }
.eyebrow { margin: 0; color: var(--blue); font-size: 11px; font-weight: 700; }
.header-meta { color: var(--muted); font-size: 12px; text-align: right; }
.content { max-width: 1440px; margin: 0 auto; }

.notice { max-width: 1440px; min-height: 42px; margin: 0 auto 16px; padding: 10px 12px 10px 14px; border: 1px solid var(--line); border-radius: 5px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--panel); }
.notice-success { color: #0f654f; border-color: #aed8c9; background: var(--green-soft); }
.notice-warning { color: #79430d; border-color: #e9cb9d; background: var(--amber-soft); }
.notice-error { color: #922018; border-color: #f0b5b0; background: var(--red-soft); }
.notice-close { border: 0; background: transparent; color: currentColor; cursor: pointer; font-size: 20px; line-height: 1; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric-card { min-height: 134px; padding: 18px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); box-shadow: var(--shadow); }
.metric-card.accent { border-top: 3px solid var(--blue); padding-top: 16px; }
.metric-label { margin: 0; color: var(--muted); font-size: 12px; font-weight: 600; }
.metric-value { margin: 16px 0 7px; font-size: 31px; line-height: 1; font-weight: 720; font-variant-numeric: tabular-nums; white-space: nowrap; }
.metric-value small { margin-right: 3px; font-size: 13px; color: var(--muted); font-weight: 600; }
.metric-meta { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.metric-positive { color: var(--green); }
.metric-negative { color: var(--red); }

.review-strip { margin: 14px 0; padding: 13px 15px; border-left: 3px solid var(--amber); background: var(--amber-soft); display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.review-strip strong { display: block; margin-bottom: 3px; }
.review-strip p { margin: 0; color: #72502a; font-size: 12px; }

.layout-two { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(290px, 0.85fr); gap: 16px; margin-top: 16px; }
.layout-even { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.section { min-width: 0; margin-top: 16px; }
.layout-two > .section, .layout-even > .section { margin-top: 0; }
.section-panel { border: 1px solid var(--line); border-radius: 6px; background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.section-head { min-height: 52px; padding: 13px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-head h2 { margin: 0; font-size: 15px; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.section-body { padding: 16px; }
.section-actions { display: flex; align-items: center; gap: 8px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { padding: 10px 12px; border-bottom: 1px solid var(--line-strong); background: var(--panel-muted); color: #5a6571; font-size: 11px; text-align: left; white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid #e8ebef; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfc; }
.number { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.muted { color: var(--muted); }
.subtext { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 1.35; }
.strong { font-weight: 700; }
.truncate { display: block; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.status { display: inline-flex; align-items: center; min-height: 22px; padding: 3px 7px; border-radius: 4px; background: #edf0f3; color: #4b5560; font-size: 11px; font-weight: 650; white-space: nowrap; }
.status-good, .status-confirmed, .status-completed, .status-issued, .status-used { color: #11634f; background: var(--green-soft); }
.status-warning, .status-pending, .status-unissued, .status-reference, .status-screenshot_reviewed, .status-pending_match, .status-unused, .status-partial { color: #825018; background: var(--amber-soft); }
.status-bad, .status-failed { color: #96251c; background: var(--red-soft); }
.status-running, .status-queued, .status-received, .status-statutory, .status-finance_reference, .status-tax_screenshot { color: #165f94; background: var(--blue-soft); }
.status-ready_for_precheck, .status-imported { color: #11634f; background: var(--green-soft); }
.status-review_required { color: #96251c; background: var(--red-soft); }

.button { min-height: 36px; padding: 8px 13px; border: 1px solid var(--line-strong); border-radius: 5px; background: #fff; color: var(--ink); cursor: pointer; font-weight: 650; }
.button:hover { border-color: #8e9aa7; background: #f8fafb; }
.button-primary { border-color: var(--blue); background: var(--blue); color: #fff; }
.button-primary:hover { border-color: #10588f; background: #10588f; }
.button-danger { border-color: #d9aaa6; color: var(--red); }
.button-small { min-height: 30px; padding: 5px 9px; font-size: 11px; }
.button-quiet { border-color: transparent; background: transparent; color: #b8c0c9; }
.button-block { width: 100%; }

.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 13px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { min-width: 0; }
.field.span-2 { grid-column: span 2; }
.field.span-full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 6px; color: #46515d; font-size: 11px; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 37px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 4px; background: #fff; color: var(--ink); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 2px rgba(23, 105, 170, 0.12); }
textarea { min-height: 76px; resize: vertical; }
.form-actions { margin-top: 14px; display: flex; justify-content: flex-end; gap: 8px; }
.filter-bar { padding: 12px 14px; border-bottom: 1px solid var(--line); display: grid; grid-template-columns: repeat(3, minmax(160px, 230px)) auto; gap: 8px; align-items: end; background: var(--panel-muted); }
.filter-bar label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; font-weight: 700; }
.filter-bar input, .filter-bar select { min-height: 34px; }
.inline-form { display: flex; align-items: center; gap: 6px; }
.inline-form select, .inline-form input { min-width: 120px; min-height: 31px; padding: 5px 7px; font-size: 11px; }
.compact-form { display: grid; grid-template-columns: minmax(110px, 1fr) minmax(105px, 0.7fr) auto; gap: 6px; min-width: 300px; }
.compact-form input, .compact-form select { min-height: 31px; padding: 5px 7px; font-size: 11px; }
.file-picker { padding: 18px; border: 1px dashed #aab5c0; border-radius: 5px; background: var(--panel-muted); text-align: center; }
.file-picker input { padding: 7px; background: #fff; }
.file-picker [data-file-name] { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.form-error { margin: 2px 0 0; color: var(--red); font-size: 12px; }

.definition-list { margin: 0; }
.definition-row { padding: 11px 0; border-bottom: 1px solid #e8ebef; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.definition-row:last-child { border-bottom: 0; }
.definition-row dt { color: var(--muted); }
.definition-row dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 36px 20px; color: var(--muted); text-align: center; }
.source-list { margin: 0; padding: 0; list-style: none; }
.source-list li { padding: 10px 0; border-bottom: 1px solid #e8ebef; display: flex; justify-content: space-between; gap: 16px; }
.source-list li:last-child { border-bottom: 0; }
.progress { width: 100%; height: 7px; border-radius: 3px; overflow: hidden; background: #e4e8ed; }
.progress > span { display: block; height: 100%; background: var(--blue); }
.pagination { padding: 12px 14px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.pagination-links { display: flex; gap: 7px; }
.job-output { max-width: 520px; max-height: 92px; margin: 0; overflow: auto; white-space: pre-wrap; color: #53606d; font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef1f4; }
.login-panel { width: min(400px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 7px; background: #fff; box-shadow: 0 12px 34px rgba(24, 31, 40, 0.09); }
.login-brand { display: flex; align-items: center; gap: 12px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.login-brand strong, .login-brand small { display: block; }
.login-brand strong { font-size: 18px; }
.login-brand small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.login-form { margin-top: 22px; display: grid; gap: 15px; }
.login-foot { margin: 22px 0 0; color: #89929c; font-size: 10px; text-align: center; }

details.entry { border-top: 1px solid var(--line); }
details.entry summary { padding: 12px 16px; cursor: pointer; color: var(--blue); font-weight: 700; }
details.entry[open] summary { border-bottom: 1px solid var(--line); }
details.entry .section-body { background: var(--panel-muted); }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-value { font-size: 28px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-bar { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 12px 14px; }
  .brand { padding: 0; }
  .brand small, .sidebar-user, .nav-label { display: none; }
  .nav { margin-top: 12px; padding-bottom: 2px; flex-direction: row; overflow-x: auto; }
  .nav a { flex: 0 0 auto; min-height: 34px; padding: 8px 10px; }
  .nav a.active { box-shadow: inset 0 -3px #4d9fc1; }
  .main { padding: 22px 16px 40px; }
  .page-header { align-items: flex-start; }
  .layout-two, .layout-even { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .metric-grid, .form-grid, .form-grid.three, .filter-bar { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: auto; }
  .metric-card { min-height: 118px; }
  .metric-value { font-size: 25px; }
  .page-header { display: block; }
  .header-meta { margin-top: 7px; text-align: left; }
  .review-strip { align-items: flex-start; flex-direction: column; }
  .section-head { align-items: flex-start; }
  .section-actions { flex-wrap: wrap; justify-content: flex-end; }
  .compact-form { min-width: 260px; }
}
