:root {
  --bg: #f4f6f8; --surface: #ffffff; --surface-2: #f8fafc; --text: #0f172a; --muted: #5b6577; --border: #dde3ea; --border-strong: #b6c0cc;
  --primary: #1d4ed8; --primary-hover: #1e40af; --primary-text: #ffffff; --focus: #2563eb; --link: #1d4ed8;
  --critical: #b42318; --critical-bg: #fef3f2; --critical-border: #f4b7b0;
  --warning: #9a4a0c; --warning-bg: #fff7e6; --warning-border: #f3cf8f;
  --info: #364152; --info-bg: #eef2f6; --info-border: #cfd8e3;
  --ok: #067647; --ok-bg: #ecfdf3; --ok-border: #abefc6;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .06);
  --radius: 10px; --radius-sm: 6px; --sidebar: 236px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --surface: #171d26; --surface-2: #1d2530; --text: #e6ebf2; --muted: #98a4b5; --border: #2a3441; --border-strong: #3d4a5a;
    --primary: #5b8def; --primary-hover: #7aa3f5; --primary-text: #0b1220; --focus: #8ab4ff; --link: #8ab4ff;
    --critical: #ff8a80; --critical-bg: #2b1614; --critical-border: #6b2a25;
    --warning: #f5b96b; --warning-bg: #2b2012; --warning-border: #6a4a1d;
    --info: #c4cdd9; --info-bg: #222b37; --info-border: #3a4656;
    --ok: #6fd39a; --ok-bg: #12291c; --ok-border: #24553a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; }
a { color: var(--link); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -9999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 50; border-radius: var(--radius-sm); }
.skip-link:focus { left: 8px; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
/* Signed out: no sidebar column, so the login card isn't squeezed into the 236px gutter. */
.shell.signed-out { grid-template-columns: 1fr; }
.shell.signed-out main { max-width: none; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; padding: 4px 8px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--primary); color: var(--primary-text); display: grid; place-items: center; font-size: .8rem; font-weight: 800; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { margin-top: 14px; }
.nav-label { font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 0 10px; margin: 0 0 6px; }
.nav-group a { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; padding: 0 10px; border-radius: var(--radius-sm); color: var(--text); text-decoration: none; font-weight: 500; }
.nav-group a:hover { background: var(--surface-2); }
.nav-group a[aria-current="page"] { background: var(--info-bg); color: var(--text); font-weight: 600; box-shadow: inset 3px 0 0 var(--primary); }
.nav-count { font-size: .72rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--critical-bg); color: var(--critical); border: 1px solid var(--critical-border); }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; font-size: .85rem; color: var(--muted); }
.sidebar-foot .who { overflow-wrap: anywhere; }
.topbar { display: none; }
main { min-width: 0; padding: 28px 32px 72px; max-width: 1200px; width: 100%; }
main:focus { outline: none; }

/* ---------- page header ---------- */
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 12px 24px; margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 62ch; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.crumb { font-size: .85rem; margin-bottom: 8px; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin: 0 0 16px; box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.stack > * + * { margin-top: 16px; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 28px 0 10px; }
.section-title h2 { margin: 0; }
.empty { color: var(--muted); padding: 22px; text-align: center; border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface); }

/* stat tiles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); text-align: left; font: inherit; color: var(--text); cursor: pointer; box-shadow: var(--shadow); }
.stat[aria-pressed="true"] { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.stat .n { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: .8rem; color: var(--muted); }
.stat.critical .n { color: var(--critical); } .stat.warning .n { color: var(--warning); } .stat.ok .n { color: var(--ok); }
div.stat { cursor: default; }

/* ---------- buttons ---------- */
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
button:hover, .button:hover { background: var(--surface-2); }
button.primary, .button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button.danger { color: var(--critical); border-color: var(--critical-border); }
button.danger:hover { background: var(--critical-bg); }
button.ghost { border-color: transparent; background: transparent; color: var(--link); }
button.ghost:hover { background: var(--info-bg); }
button.sm, .button.sm { min-height: 32px; padding: 0 10px; font-size: .85rem; }
button:disabled { opacity: .55; cursor: progress; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 12px; min-width: 0; }
.field label, .field > .label { font-weight: 600; font-size: .9rem; }
.hint { margin: 0; color: var(--muted); font-size: .8rem; }
input, select, textarea { min-width: 0; font: inherit; min-height: 40px; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); width: 100%; }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--primary); }
input[type="time"] { padding: 4px 8px; min-height: 36px; }
textarea { min-height: 84px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px 4px; margin: 0 0 16px; min-width: 0; }
legend { font-weight: 600; padding: 0 4px; font-size: .9rem; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.form-grid .span-2 { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.check label { font-weight: 500; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filters .field { margin: 0; min-width: 170px; }

/* hours editor */
.hours { display: grid; grid-template-columns: 3.2rem auto minmax(0, 1fr) auto minmax(0, 1fr) auto; gap: 8px 10px; align-items: center; }
.hours .day { font-weight: 600; }
.hours .dash { color: var(--muted); text-align: center; }
.hours .add { justify-self: start; }
.hours .shift2 { grid-column: 3 / -1; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; gap: 8px 10px; align-items: center; }
.hours .closed { opacity: .5; }
.hours-head { display: contents; font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tbody th { font-size: .95rem; text-transform: none; letter-spacing: 0; color: var(--text); background: transparent; font-weight: 600; }
tbody tr:hover td, tbody tr:hover th { background: var(--surface-2); }
td .actions { justify-content: flex-start; }

/* ---------- badges & chips ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; border: 1px solid transparent; white-space: nowrap; }
.badge-critical { color: var(--critical); background: var(--critical-bg); border-color: var(--critical-border); }
.badge-warning { color: var(--warning); background: var(--warning-bg); border-color: var(--warning-border); }
.badge-info { color: var(--info); background: var(--info-bg); border-color: var(--info-border); }
.badge-ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-border); }
.badge-muted { color: var(--muted); background: var(--surface-2); border-color: var(--border); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: .8rem; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); flex: none; }
.dot.ok { background: var(--ok); } .dot.critical { background: var(--critical); } .dot.warning { background: #dc6803; } .dot.info { background: var(--border-strong); }

/* ---------- issues ---------- */
.biz-group { margin-bottom: 26px; }
.biz-group > h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 10px; font-size: 1rem; }
.issue { position: relative; padding: 14px 16px 12px 18px; border-left-width: 4px; margin-bottom: 10px; }
.issue.critical { border-left-color: var(--critical); }
.issue.warning { border-left-color: #dc6803; }
.issue.info { border-left-color: var(--border-strong); }
.issue-top { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-bottom: 4px; }
.issue h3 { font-size: 1rem; margin: 0 0 6px; overflow-wrap: anywhere; }
.issue ul { margin: 6px 0 0 18px; padding: 0; }
.issue details { margin: 6px 0 0; }
.issue summary { cursor: pointer; color: var(--link); font-size: .9rem; }
.issue .meta { font-size: .78rem; color: var(--muted); margin: 8px 0 10px; }
.issue .actions .ghost { margin-left: auto; }
.more { position: relative; }
.more > summary { list-style: none; display: inline-flex; }
.more > summary::-webkit-details-marker { display: none; }
.more-menu { position: absolute; right: 0; z-index: 5; min-width: 220px; margin-top: 4px; padding: 6px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(15, 23, 42, .15); display: flex; flex-direction: column; gap: 2px; }
.more-menu button { justify-content: flex-start; border-color: transparent; min-height: 36px; text-align: left; white-space: normal; }

/* ---------- business cards ---------- */
.biz-card { display: flex; flex-direction: column; gap: 10px; text-decoration: none; color: inherit; }
.biz-card:hover { border-color: var(--border-strong); }
.biz-card .name { font-weight: 700; font-size: 1.05rem; color: var(--text); }
.biz-card .name span { color: var(--muted); font-weight: 400; font-size: .85rem; }
.matrix td, .matrix th { font-size: .88rem; }
.matrix td { max-width: 260px; overflow-wrap: anywhere; }
td { overflow-wrap: anywhere; }
th { overflow-wrap: normal; }
.matrix th { white-space: nowrap; }
.matrix td:first-of-type { min-width: 11rem; }
.matrix .cell-ok { color: var(--ok); } .matrix .cell-critical { color: var(--critical); font-weight: 600; } .matrix .cell-warning { color: var(--warning); font-weight: 600; } .matrix .cell-info { text-decoration: underline dotted; text-underline-offset: 3px; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 8px 0 0; }
dt { font-weight: 600; color: var(--muted); font-size: .85rem; } dd { margin: 0; } dd ul { margin: 0; padding-left: 18px; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: 8px; border-radius: var(--radius-sm); font-size: .78rem; max-width: 52ch; }
.login { max-width: 440px; margin: 12vh auto 0; text-align: center; padding: 28px 28px 22px; }
.login .muted { margin: 4px 0 0; }
.login .row { justify-content: center; margin: 16px 0 10px; }
.login .brand-mark { width: 44px; height: 44px; margin: 0 auto 12px; font-size: 1.1rem; }

/* ---------- flash ---------- */
.flash-region { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60; width: min(560px, calc(100% - 32px)); pointer-events: none; }
.flash { padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid; background: var(--surface); box-shadow: 0 8px 24px rgba(15, 23, 42, .18); pointer-events: auto; }
.flash-ok { color: var(--ok); border-color: var(--ok-border); }
.flash-error { color: var(--critical); border-color: var(--critical-border); }
.alert { padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--critical-border); background: var(--critical-bg); color: var(--critical); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 40; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(300px, 86vw); z-index: 45; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .sidebar[data-open="true"] { transform: none; }
  .scrim { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 44; }
  main { padding: 18px 14px 64px; }
  .page-head { margin-bottom: 14px; }
  .card { padding: 14px; }
  th, td { padding: 8px 10px; }
  .hours { grid-template-columns: 2.4rem auto minmax(0, 1fr) auto minmax(0, 1fr); gap: 8px 6px; }
  .hours-head span:last-child { display: none; }
  .hours .add { grid-column: 2 / -1; }
  .hours .shift2 { grid-column: 2 / -1; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto; }
  input[type="time"] { padding: 4px 4px; }
  .issue .actions .ghost { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
