:root {
  color-scheme: light;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --page: #ffffff;
  --sidebar: #f3f3f3;
  --row-alternate: #f7f7f7;
  --rule: #d0d0d0;
  --rule-light: #e3e3e3;
  --text: #1a1a1a;
  --text-secondary: #595959;
  --link: #1d4f91;
  --link-visited: #1d4f91;
  --focus: #ffbf47;
  --problem: #a30000;
  --warning: #7a4d00;
  --warning-background: #fff6dc;
  --problem-background: #fdeeee;
  --button: #f0f0f0;
  --button-border: #a6a6a6;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; }

h1, h2, h3 { margin: 0; font-weight: 700; }
h1 { font-size: 26px; line-height: 1.2; }
h2 { font-size: 18px; line-height: 1.3; }
h3 { font-size: 15px; }
p { margin: 0; }

code, kbd, .mono { font-family: var(--font-mono); font-size: 0.93em; }
h1.mono { font-size: 26px; }
h1 .mono { font-size: inherit; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link { position: absolute; left: 8px; top: -40px; background: var(--focus); color: var(--text); padding: 6px 10px; z-index: 20; }
.skip-link:focus { top: 8px; }

.shell { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: 100vh; }

.sidebar { background: var(--sidebar); border-right: 1px solid var(--rule); padding: 16px 0; display: flex; flex-direction: column; }
.wordmark { display: block; padding: 0 16px 16px; font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.nav h2 { font-size: 13px; font-weight: 700; color: var(--text-secondary); padding: 0 16px; margin: 16px 0 4px; }
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav a { display: block; padding: 4px 16px; color: var(--text); text-decoration: none; }
.nav a:hover { text-decoration: underline; }
.nav a[aria-current="page"] { font-weight: 700; background: var(--page); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin-right: -1px; }
.account { margin-top: auto; padding: 16px; border-top: 1px solid var(--rule); color: var(--text-secondary); font-size: 14px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }

.link-button { background: none; border: 0; padding: 0; font: inherit; color: var(--link); text-decoration: underline; cursor: pointer; }

main { min-width: 0; padding: 24px 32px 64px; max-width: 1200px; }

.page-header { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: flex-end; justify-content: space-between; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--rule); }
.page-header .trail { font-size: 14px; margin-bottom: 4px; color: var(--text-secondary); }
.page-header .meta { color: var(--text-secondary); margin-top: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

.flash { margin-bottom: 20px; padding: 10px 14px; border: 1px solid var(--rule); background: #eef5ee; }
.flash-error { background: var(--problem-background); border-color: var(--problem); color: var(--problem); }

.button {
  display: inline-block; padding: 5px 12px;
  border: 1px solid var(--button-border); border-radius: 2px;
  background: var(--button); color: var(--text);
  font: inherit; font-size: 14px; line-height: 1.4; text-decoration: none; white-space: nowrap; cursor: pointer;
}
.button:hover { background: #e2e2e2; text-decoration: none; }
.button-primary { background: var(--link); border-color: var(--link); color: #ffffff; }
.button-primary:hover { background: #163d70; }
.button-quiet { background: none; border-color: transparent; color: var(--link); text-decoration: underline; padding-left: 4px; padding-right: 4px; }
.button-quiet:hover { background: none; text-decoration-thickness: 2px; }
.button-small { padding: 2px 8px; font-size: 13px; }
.button-danger { color: var(--problem); }
.button[disabled] { opacity: 0.5; cursor: not-allowed; }

.inline-form { display: inline; }

.panel { margin: 0; }
.panel + .panel, .section + .section { margin-top: 32px; }
.stack > .panel + .panel, .stack > * + * { margin-top: 0; }
.panel-header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-bottom: 6px; margin-bottom: 12px; border-bottom: 1px solid var(--rule); }
.panel-header p { color: var(--text-secondary); font-size: 14px; }
.panel-body { padding: 0; }
.panel-body + .panel-body { margin-top: 16px; }
.panel-footer { margin-top: 16px; display: flex; gap: 8px; }

.section-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.section-title .count { color: var(--text-secondary); font-weight: 400; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--rule-light); vertical-align: top; white-space: nowrap; }
th { font-weight: 700; font-size: 14px; border-bottom: 2px solid var(--text); }
tbody tr:nth-child(even) { background: var(--row-alternate); }
td.wrap { white-space: normal; min-width: 200px; }
td.numeric, th.numeric { text-align: right; }
td.muted { color: var(--text-secondary); }
td .secondary { display: block; color: var(--text-secondary); font-size: 13px; }
.empty-row td { color: var(--text-secondary); padding: 16px 10px; white-space: normal; }

.badge { font-size: inherit; white-space: nowrap; }
.badge.negative { color: var(--problem); font-weight: 700; }
.badge.caution { color: var(--warning); }
.badge.plain { color: var(--text-secondary); }

.grade { font-family: var(--font-mono); }
.grade-D, .grade-F { color: var(--problem); font-weight: 700; }

.filters { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.segments { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.segments a[aria-current="true"] { color: var(--text); font-weight: 700; text-decoration: none; }
.segments .count { color: var(--text-secondary); margin-left: 3px; }

.filter-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search svg { display: none; }

input[type="text"], input[type="password"], input[type="search"], input[type="date"], input[type="email"], select, textarea {
  width: 100%; padding: 5px 8px;
  border: 1px solid var(--button-border); border-radius: 0;
  background: #ffffff; color: var(--text); font: inherit;
}
textarea { min-height: 76px; resize: vertical; }
input[readonly] { background: var(--sidebar); color: var(--text-secondary); }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--focus); outline-offset: 0; }
.filter-form select, .filter-form input { width: auto; min-width: 150px; }
.search input[type="search"] { width: 240px; }

.form { display: grid; gap: 28px; max-width: 680px; }
.form fieldset { margin: 0; padding: 0; border: 0; display: grid; gap: 14px; }
.form legend { font-weight: 700; font-size: 18px; margin-bottom: 4px; padding: 0; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.field { display: grid; gap: 4px; align-content: start; }
.field > label, .field > .label { font-weight: 700; font-size: 14px; }
.field .hint { color: var(--text-secondary); font-size: 14px; }
.field .error { color: var(--problem); font-weight: 700; font-size: 14px; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border: 2px solid var(--problem); }
.field .optional { color: var(--text-secondary); font-weight: 400; }
.choice-list { display: flex; flex-wrap: wrap; gap: 8px 24px; }
.choice { display: inline-flex; gap: 6px; align-items: center; }
.choice input { margin: 0; }
.form-actions { display: flex; gap: 8px; padding-top: 4px; }
.form-errors { padding: 10px 14px; border: 2px solid var(--problem); color: var(--problem); font-weight: 700; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 24px; margin: 0; }
.facts dt { color: var(--text-secondary); }
.facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.facts-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 6px 40px; }

.layout-split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 40px; align-items: start; }
.stack { display: grid; gap: 32px; align-content: start; }

.summary-strip { display: flex; flex-wrap: wrap; gap: 4px 28px; margin: 0 0 28px; }
.summary-strip > div { display: flex; gap: 6px; align-items: baseline; }
.summary-strip dt { order: 2; color: var(--text-secondary); }
.summary-strip dd { order: 1; margin: 0; font-weight: 700; }
.summary-strip dd small { font-weight: 400; color: var(--text-secondary); margin-left: 4px; }
.summary-strip dd.negative { color: var(--problem); }

.queue { display: grid; gap: 28px; }
.queue-group header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-bottom: 4px; margin-bottom: 4px; border-bottom: 1px solid var(--rule); }
.queue-group h2 .faint { font-weight: 400; color: var(--text-secondary); }
.queue-group header .button-quiet { padding: 0; }
.queue-list { list-style: none; margin: 0; padding: 0; }
.queue-list li { border-bottom: 1px solid var(--rule-light); }
.queue-list a, .queue-list .row { display: grid; grid-template-columns: minmax(140px, 240px) minmax(0, 1fr) auto; gap: 16px; align-items: baseline; padding: 6px 0; }
.queue-list a { text-decoration: none; color: var(--text); }
.queue-list a .subject { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
.queue-list .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-list .detail { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-list .since { color: var(--text-secondary); font-size: 13px; }
.queue-list .chevron { display: none; }

.all-clear { padding: 16px 0; }
.all-clear strong { display: block; }

.stage-track { display: none; }
.stage-label { display: block; }

.config-preview {
  margin: 0; padding: 10px 12px; max-height: 420px; overflow: auto;
  background: var(--row-alternate); border: 1px solid var(--rule);
  font-family: var(--font-mono); font-size: 12px; line-height: 1.5; white-space: pre;
}

.diff { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 20px; }
.diff h3 { margin-bottom: 6px; }
.diff p + p { margin-top: 6px; }
.diff .changed { background: var(--warning-background); }

.notice { padding: 10px 14px; border-left: 4px solid var(--text-secondary); background: var(--row-alternate); }
.notice.caution { border-color: var(--warning); background: var(--warning-background); }
.notice.negative { border-color: var(--problem); background: var(--problem-background); }
.notice strong { display: block; }
.notice + .notice { margin-top: 12px; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 1fr auto; gap: 0 12px; padding: 6px 0; border-bottom: 1px solid var(--rule-light); }
.timeline .what { font-weight: 700; }
.timeline .who, .timeline .when { color: var(--text-secondary); font-size: 13px; }
.timeline .changes { grid-column: 1 / -1; color: var(--text-secondary); font-size: 12px; font-family: var(--font-mono); overflow-wrap: anywhere; }
.timeline-empty { color: var(--text-secondary); }

.roster-tools { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.roster { list-style: none; margin: 0; padding: 0; columns: 3 220px; column-gap: 24px; border-top: 1px solid var(--rule); }
.roster li { break-inside: avoid; border-bottom: 1px solid var(--rule-light); }
.roster label { display: flex; gap: 8px; align-items: center; padding: 5px 0; cursor: pointer; }
.roster input { margin: 0; }
.roster .rcs { color: var(--text-secondary); font-family: var(--font-mono); font-size: 13px; margin-left: auto; }
.roster li[hidden] { display: none; }
.sticky-actions { position: sticky; bottom: 0; background: var(--page); border-top: 1px solid var(--rule); padding: 10px 0; margin-top: 12px; display: flex; gap: 8px; }

.integration-list { list-style: none; margin: 0; padding: 0; }
.integration-list li { display: grid; grid-template-columns: 120px 90px 1fr; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--rule-light); }
.integration-list .detail { color: var(--text-secondary); font-size: 14px; overflow-wrap: anywhere; }

.login-page { min-height: 100vh; display: grid; place-items: start center; padding: 80px 16px; }
.login-card { width: 100%; max-width: 340px; }
.login-card .wordmark { padding: 0 0 16px; font-size: 20px; }
.login-card .panel-body { display: grid; gap: 14px; }
.login-card h1 { font-size: 22px; }
.login-note { margin-top: 16px; color: var(--text-secondary); font-size: 14px; }

dialog.confirm { max-width: 420px; width: calc(100% - 32px); padding: 20px; border: 1px solid var(--text); border-radius: 0; background: var(--page); color: var(--text); }
dialog.confirm::backdrop { background: rgb(0 0 0 / 0.3); }
dialog.confirm h2 { margin-bottom: 6px; }
dialog.confirm .panel-footer { margin-top: 16px; }

.muted { color: var(--text-secondary); }
.faint { color: var(--text-secondary); }
.nowrap { white-space: nowrap; }
.spaced > * + * { margin-top: 12px; }

@media (max-width: 900px) {
  .layout-split { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--rule); padding: 10px 0 0; }
  .nav { display: flex; flex-wrap: wrap; padding: 0 12px 8px; gap: 2px 0; }
  .nav h2 { display: none; }
  .nav ul { display: contents; }
  .nav a { padding: 3px 8px; }
  .nav a[aria-current="page"] { border: 0; margin: 0; background: none; text-decoration: underline; }
  .account { flex-direction: row; gap: 12px; padding: 8px 16px; }
  main { padding: 16px 16px 48px; }
  .filters, .filter-form, .search, .search input[type="search"] { width: 100%; }
  .queue-list a, .queue-list .row { grid-template-columns: minmax(0, 1fr) auto; gap: 0 12px; }
  .queue-list .detail { grid-column: 1 / -1; }
  .diff { grid-template-columns: 1fr; gap: 16px; }
  .facts { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .facts dd { margin-bottom: 8px; }
}

@media print {
  .sidebar, .actions, .filters { display: none !important; }
  .shell { display: block; }
}

.delete-form { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--rule); max-width: 680px; }
.delete-form p { color: var(--text-secondary); margin-bottom: 8px; }
.inline-edit { display: flex; gap: 6px; align-items: center; }
.inline-edit input[type="text"] { width: 220px; padding: 2px 6px; }
.spaced { margin-top: 16px; }

.row-actions { display: flex; flex-wrap: wrap; gap: 2px 12px; justify-content: flex-end; font-size: 14px; }
.row-actions form { display: inline; }
.row-actions .link-button { font-size: 14px; }
