/* AC Reporting — app shell and shared components (mockup: mockup/dashboard-mockup.png) */
:root {
  --bg: #f5f6fa;
  --card: #fff;
  --border: #e8eaf0;
  --border-strong: #d9dce6;
  --text: #1f2937;
  --text-2: #4b5563;
  --muted: #676c80;  /* 4.7:1 on --bg, 5.1:1 on white */
  --accent: #5b4ff5;
  --accent-600: #4a3fe0;
  --accent-50: #efedff;
  --link: #4f46e5;
  --nav-bg: #0f1535;
  --nav-text: #cfd3e8;
  --nav-muted: #7d83a6;
  --green: #15803d;  /* text-safe: 5.0:1 on white */
  --green-50: #e9f8ef;
  --red: #dc2626;
  --red-50: #fdecec;
  --orange: #b85c00;  /* text-safe: 4.6:1 on white */
  --orange-50: #fff3e3;
  --blue: #2563eb;
  --blue-50: #eaf1ff;
  --purple-50: #f0edff;
  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .03);
  --nav-w: 200px;
  --gap: 16px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono-num: "tnum" 1, "lnum" 1;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; margin: 0 0 12px; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 600; margin: 20px 0 10px; }
button, input, select { font: inherit; }
.icon { flex: none; display: block; }
.muted { color: var(--muted); }
.skip-link { position: absolute; left: 12px; top: -48px; z-index: 100; background: var(--accent); color: #fff; padding: 8px 14px;
  border-radius: var(--radius-sm); font-weight: 600; }
.skip-link:focus { top: 12px; text-decoration: none; }
main:focus { outline: none; }
.num { text-align: right; font-feature-settings: var(--mono-num); white-space: nowrap; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important;
  overflow: hidden !important; clip: rect(0 0 0 0) !important; white-space: nowrap !important; border: 0 !important; }
.msg { padding: 10px 14px; background: #fef3c7; border: 1px solid #fde68a; border-radius: var(--radius-sm); margin-bottom: 14px; color: #713f12; }
.msg-info { background: var(--blue-50); border-color: #c7d7fe; color: #1e3a8a; }
.msg-success { background: var(--green-50); border-color: #b7e4c7; color: #14532d; }
.msg-error { background: var(--red-50); border-color: #f7c4c4; color: #7f1d1d; }
.msg ul { margin: 6px 0 0; padding-left: 18px; }
::selection { background: rgba(91, 79, 245, .18); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sidebar :focus-visible { outline-color: #b9b2ff; }

/* ---------- layout */
.app { display: grid; grid-template-columns: var(--nav-w) minmax(0, 1fr); min-height: 100vh; }
html.rail { --nav-w: 64px; }
.main-col { min-width: 0; display: flex; flex-direction: column; }
.content { padding: 4px 24px 32px; min-width: 0; }
.content.narrow { max-width: 1100px; }

/* ---------- sidebar */
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--nav-bg); color: var(--nav-text);
  padding: 16px 10px 12px; display: flex; flex-direction: column; z-index: 40; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 16px; color: #fff; text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, #e8e6ff, #b9b2ff); color: #3a2fd0; font-weight: 800; font-size: 13px; letter-spacing: -.02em; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 15px; font-weight: 700; }
.brand-text small { font-size: 11.5px; color: var(--nav-muted); }
.nav { flex: 1; }
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav-heading { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--nav-muted);
  margin: 16px 10px 6px; line-height: 1.2; }
.nav-rule { display: none; border: 0; border-top: 1px solid rgba(255, 255, 255, .08); margin: 10px 8px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; margin: 1px 0; border-radius: var(--radius-sm);
  color: var(--nav-text); font-size: 13px; text-decoration: none; white-space: nowrap; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(91, 79, 245, .35); }
.nav-collapse { align-self: flex-start; margin: 12px 6px 0; width: 28px; height: 28px; border-radius: 7px; border: 0; cursor: pointer;
  display: grid; place-items: center; background: var(--accent); color: #fff; }
html.rail .nav-collapse .icon { transform: rotate(180deg); }
html.rail .label, html.rail .nav-heading { display: none; }
html.rail .nav-rule { display: block; }
html.rail .nav a { justify-content: center; padding: 9px 0; }
html.rail .brand { justify-content: center; padding-left: 0; padding-right: 0; }
html.rail .nav-collapse { align-self: center; }
.scrim { display: none; }

/* ---------- top bar */
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 16px 24px 12px; }
.page-heading { min-width: 0; }
.page-heading h1 { margin: 0; }
.page-heading p { margin: 2px 0 0; color: var(--text-2); font-size: 12.5px; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.pill-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 12px;
  display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.pill-box strong { font-size: 12.5px; font-weight: 600; }
.pill-box small { font-size: 11px; color: var(--muted); }
.book-box { min-width: 200px; }
.nav-burger { display: none; border: 1px solid var(--border); background: var(--card); border-radius: var(--radius-sm); width: 38px; height: 38px;
  place-items: center; cursor: pointer; color: var(--text); flex: none; }
.icon-btn { position: relative; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: var(--text-2); }
.icon-btn:hover { background: #eceef4; text-decoration: none; }
.icon-btn .count { position: absolute; top: 1px; right: 0; min-width: 17px; height: 17px; border-radius: 9px; padding: 0 4px;
  background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--bg); }
.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 2px 4px; border-radius: var(--radius-sm); }
.user-menu summary::-webkit-details-marker { display: none; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.user-text { display: flex; flex-direction: column; line-height: 1.2; }
.user-text strong { font-size: 13px; font-weight: 600; }
.user-text small { font-size: 11.5px; color: var(--muted); }
.user-menu-panel { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(16, 24, 40, .12); padding: 6px; min-width: 160px; z-index: 50; }
.user-menu-panel a, .user-menu-panel button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: none;
  border-radius: 6px; color: var(--text); cursor: pointer; font-size: 13px; }
.user-menu-panel a:hover, .user-menu-panel button:hover { background: var(--bg); text-decoration: none; }

/* ---------- AutoCount status pill (header, every page) */
.status-pill { color: inherit; min-width: 150px; text-decoration: none; }
.status-pill:hover { text-decoration: none; border-color: var(--border-strong); }
.status-pill small { display: flex; align-items: center; gap: 6px; font-weight: 500; font-size: 11.5px; }
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.status-pill.state-healthy small { color: var(--green); } .status-pill.state-healthy .dot { background: #22c55e; }
.status-pill.state-degraded small, .status-pill.state-stale small { color: var(--orange); }
.status-pill.state-degraded .dot, .status-pill.state-stale .dot { background: #f59e0b; }
.status-pill.state-failed small { color: var(--red); } .status-pill.state-failed .dot { background: #ef4444; }
.status-pill.is-running small { color: var(--accent); } .status-pill.is-running .dot { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
@media (prefers-reduced-motion: reduce) { .status-pill.is-running .dot { animation: none; } }

/* ---------- buttons, forms */
.btn-primary, .btn { display: inline-flex; align-items: center; gap: 8px; border-radius: var(--radius-sm); padding: 8px 16px;
  font-weight: 600; font-size: 13px; cursor: pointer; border: 1px solid transparent; text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 6px rgba(91, 79, 245, .3); }
.btn-primary:hover { background: var(--accent-600); text-decoration: none; }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn { background: var(--card); color: var(--text); border-color: var(--border-strong); }
.btn-sm { padding: 4px 10px; font-size: 12px; gap: 6px; }
.btn-primary:disabled, .btn:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }
.btn:hover { background: var(--bg); text-decoration: none; }
.content input:not([type]), .content input[type=text], .content input[type=search], .content input[type=date],
.content input[type=number], .content select, .content textarea,
.bare-card input { border: 1px solid var(--border-strong); border-radius: 7px; padding: 6px 9px; background: #fff; color: var(--text); }
.content button:not([class]) { border: 1px solid var(--border-strong); background: #fff; border-radius: 7px; padding: 6px 12px; cursor: pointer; }
.content button:not([class]):hover { background: var(--bg); }

/* ---------- cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-title { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: -.005em; white-space: nowrap; }
.card-link { font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.card-sub { font-size: 12px; color: var(--muted); }

/* ---------- tables (legacy pages get the base look; .table is the dense dashboard style) */
.content table { border-collapse: collapse; width: 100%; background: var(--card); }
.content th, .content td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
.content th { font-weight: 600; font-size: 12.5px; color: var(--text-2); background: #fafbfd; }
.table { font-size: 12px; }
.content .table th { background: none; font-size: 11px; font-weight: 500; color: var(--text-2); padding: 8px 6px; border-bottom: 1px solid var(--border); }
.content .table td { padding: 8px 6px; border-bottom: 1px solid #f0f1f5; height: 31px; white-space: nowrap; }
.content .table th { white-space: nowrap; }
.content .table tr:last-child td { border-bottom: 0; }
.content .table .num, .content .table th.num { text-align: right; }
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; position: relative; /* contains .sr-only labels */ }

/* ---------- badges, tones */
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.badge-red { color: #b91c1c; background: var(--red-50); }      /* 5.9:1 */
.badge-orange { color: #8a4500; background: var(--orange-50); } /* 6.6:1 */
.badge-green { color: var(--green); background: var(--green-50); }
.badge-grey { color: var(--text-2); background: #eef0f4; }
.badge-blue { color: var(--blue); background: var(--blue-50); }
.t-red { color: var(--red); } .t-orange { color: var(--orange); } .t-green { color: var(--green); } .t-blue { color: var(--blue); }

/* ---------- grid */
.grid-12 { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap); }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; } .span-8 { grid-column: span 8; } .span-12 { grid-column: span 12; }

/* ---------- skeleton */
.skeleton { background: linear-gradient(90deg, #eef0f5 25%, #f6f7fa 50%, #eef0f5 75%); background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

/* ---------- login */
body.bare { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.bare-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 10px 30px rgba(16, 24, 40, .08);
  padding: 28px; width: 100%; max-width: 380px; }
.brand-light { color: var(--text); padding: 0 0 18px; }
.brand-light .brand-text small { color: var(--muted); }
.login-sub { margin: -6px 0 16px; color: var(--text-2); font-size: 13px; }
.bare-card label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; }
.bare-card input { width: 100%; padding: 9px 11px; }
.bare-card .btn-primary { width: 100%; justify-content: center; padding: 10px; }

/* ---------- responsive shell */
@media (max-width: 1023px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 240px; height: auto; transform: translateX(-100%);
    visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; }
  html.nav-open .sidebar { transform: none; visibility: visible; transition: transform .2s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .3); }
  html.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(15, 21, 53, .4); z-index: 30; }
  .nav-collapse { display: none; }
  .nav-burger { display: grid; }
  .topbar { flex-wrap: wrap; padding: 12px 16px; }
  .topbar-right { width: 100%; justify-content: flex-start; }
  .content { padding: 4px 16px 24px; }
  .user-text { display: none; }
  .user-menu { margin-left: auto; }
}
@media (max-width: 1023px) and (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
@media (max-width: 767px) {
  .book-box { min-width: 0; flex: 1 1 100%; }
  [data-priority="low"] { display: none; }
}

/* ---------- shared page patterns (AR, Sync, Bank) */
.page-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px 16px; flex-wrap: wrap; margin: 0 0 var(--gap); }
.page-toolbar form { margin: 0; }
.page-toolbar-end { justify-content: flex-end; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar-stat { margin: 0; font-size: 13px; color: var(--text-2); }
.toolbar-stat strong { color: var(--text); }
.content > .card + .card, .content > section + section { margin-top: var(--gap); }
.card-note { margin: 12px 0 0; font-size: 12px; color: var(--text-2); max-width: 90ch; }
.empty-line { color: var(--muted); font-size: 13px; }
.cell-strong { font-weight: 500; }
.nowrap { white-space: nowrap; }
.content .table .strong { font-weight: 600; }
.credit { color: var(--text-2); font-style: italic; }
.content .table tfoot th { border-top: 1px solid var(--border-strong); border-bottom: 0; color: var(--text); font-size: 12px; font-weight: 700; padding-top: 10px; }
.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; padding-bottom: 14px; margin-bottom: 6px; border-bottom: 1px solid var(--border); }
.filter-bar .field { display: flex; flex-direction: column; gap: 4px; }
.filter-bar label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.filter-bar input[type=text] { width: 110px; }
.filter-bar .check { display: flex; align-items: center; gap: 6px; font-weight: 500; color: var(--text); padding-bottom: 7px; }
.filter-bar .btn-primary { margin-left: auto; }
.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-form input[type=text] { flex: 0 1 220px; min-width: 0; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text); margin: 0; }
.check-result { margin: 10px 0 0; font-weight: 600; font-size: 13px; }
.content .table td.changes { white-space: normal; font-size: 12px; color: var(--text-2); }
.change { display: inline-block; margin-right: 8px; }
.content .table td.problem { white-space: normal; color: var(--red); font-size: 12px; max-width: 360px; }

/* sortable tables + search */
.table-tools { display: flex; align-items: center; gap: 12px; margin: 0 0 8px; flex-wrap: wrap; }
.table-search { width: 280px; max-width: 100%; }
.sort-btn { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
.sort-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.sort-btn::after { content: "↕"; font-size: 10px; opacity: .35; }
th[aria-sort="ascending"] .sort-btn::after { content: "▲"; opacity: .8; }
th[aria-sort="descending"] .sort-btn::after { content: "▼"; opacity: .8; }
th.num .sort-btn { justify-content: flex-end; }
a.sort-link { color: inherit; display: inline-flex; gap: 4px; }
a.sort-link:hover { color: var(--text); text-decoration: none; }
th[aria-sort="ascending"] a.sort-link::after { content: "▲"; font-size: 10px; opacity: .8; }
th[aria-sort="descending"] a.sort-link::after { content: "▼"; font-size: 10px; opacity: .8; }
.sync-health small { display: block; margin-top: 4px; font-size: 12.5px; opacity: .9; }
.sync-ok { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; color: var(--green); font-size: 13px; font-weight: 500; }
