:root {
  --paper: #f1eee6;
  --paper-deep: #e5e0d5;
  --ink: #191917;
  --muted: #68645c;
  --line: #c9c2b5;
  --accent: #e34a2f;
  --accent-dark: #a92d1b;
  --blue: #1b5f78;
  --green: #29715d;
  --amber: #9a6217;
  --red: #a4382b;
  --surface: rgba(255, 255, 255, .42);
  --shadow: 0 18px 48px rgba(35, 31, 24, .09);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: radial-gradient(circle at 78% 4%, rgba(227, 74, 47, .09), transparent 28rem), linear-gradient(90deg, transparent 0, transparent calc(100% - 1px), rgba(25, 25, 23, .025) calc(100% - 1px)); background-size: auto, 14px 14px; }
button, input, select, textarea { font: inherit; }
button { color: inherit; }
.skip { position: fixed; top: .5rem; left: .5rem; z-index: 100; padding: .65rem 1rem; color: white; background: var(--ink); transform: translateY(-150%); }
.skip:focus { transform: none; }

.masthead { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; min-height: 13rem; padding: 2.6rem clamp(1.4rem, 4vw, 4rem) 2rem calc(clamp(14rem, 21vw, 19rem) + clamp(1.4rem, 4vw, 4rem)); border-bottom: 1px solid var(--ink); }
.eyebrow, .kicker { margin: 0 0 .55rem; color: var(--accent-dark); font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.masthead h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(3rem, 7vw, 6.8rem); font-weight: 400; letter-spacing: -.065em; line-height: .86; }
.lede { max-width: 48rem; margin: 1rem 0 0; color: var(--muted); font-family: Georgia, serif; font-size: clamp(1rem, 1.5vw, 1.25rem); line-height: 1.45; }
.connection { display: flex; align-items: center; flex: 0 0 auto; gap: .55rem; padding-bottom: .3rem; font-size: .82rem; }
.dot { width: .68rem; height: .68rem; border: 1px solid var(--ink); border-radius: 50%; background: var(--paper-deep); }
.dot.online { border-color: var(--green); background: var(--green); box-shadow: 0 0 0 4px rgba(41, 113, 93, .12); }
.dot.offline { border-color: var(--red); background: var(--red); }

.rail { position: fixed; inset: 0 auto 0 0; z-index: 20; display: flex; flex-direction: column; width: clamp(14rem, 21vw, 19rem); padding: 2rem 0; overflow-y: auto; border-right: 1px solid var(--ink); background: rgba(229, 224, 213, .92); backdrop-filter: blur(10px); }
.rail::before { content: "APPLICATIONS"; padding: 0 1.25rem 1.3rem; color: var(--muted); font-size: .65rem; font-weight: 800; letter-spacing: .19em; }
.nav-item { display: grid; grid-template-columns: 2.2rem 1fr; align-items: baseline; gap: .35rem; width: 100%; padding: .82rem 1.25rem; border: 0; border-top: 1px solid transparent; border-bottom: 1px solid transparent; background: transparent; text-align: left; cursor: pointer; }
.nav-item span { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .65rem; }
.nav-item:hover { background: rgba(255, 255, 255, .42); }
.nav-item.active { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.nav-item.active span { color: #d4cec2; }

.workspace { margin-left: clamp(14rem, 21vw, 19rem); padding: clamp(1.5rem, 4vw, 4rem); }
.view { display: none; max-width: 92rem; margin: 0 auto; }
.view.active { display: block; animation: enter .22s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(5px); } }
.view-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 2rem; margin-bottom: 2.2rem; padding-bottom: 1.2rem; border-bottom: 3px double var(--ink); }
.view-heading h2 { margin: 0; font-family: Georgia, serif; font-size: clamp(2rem, 4vw, 4rem); font-weight: 400; letter-spacing: -.045em; line-height: .95; }

button { min-height: 2.55rem; padding: .55rem .9rem; border: 1px solid var(--ink); background: transparent; cursor: pointer; }
button:hover { background: var(--ink); color: var(--paper); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(27, 95, 120, .28); outline-offset: 2px; }
button.primary { border-color: var(--accent); background: var(--accent); color: white; font-weight: 750; }
button.primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
button.quiet { min-height: 1.8rem; padding: .3rem .55rem; border-color: transparent; text-decoration: underline; text-underline-offset: .18em; }
.icon-button { min-width: 2.5rem; border: 0; font-size: 1.8rem; line-height: 1; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1px; margin-bottom: 2rem; border: 1px solid var(--ink); background: var(--ink); }
.stat { min-height: 8.5rem; padding: 1rem; background: var(--paper); }
.stat strong { display: block; margin-top: 1.3rem; font-family: Georgia, serif; font-size: 2.6rem; font-weight: 400; letter-spacing: -.04em; }
.stat span { color: var(--muted); font-size: .7rem; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; }

.two-column { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin-bottom: 1.25rem; }
.panel { position: relative; padding: 1.5rem; border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 1rem; font-family: Georgia, serif; font-size: 1.55rem; font-weight: 400; }
.panel-number { position: absolute; top: 1rem; right: 1rem; margin: 0; color: var(--accent); font-family: ui-monospace, monospace; font-size: .7rem; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.definition-list { margin: 1.5rem 0 0; }
.definition-list div { display: grid; grid-template-columns: 7rem 1fr; gap: 1rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.definition-list dt { color: var(--muted); font-size: .73rem; font-weight: 800; text-transform: uppercase; }
.definition-list dd { margin: 0; }
.note { color: var(--muted); font-size: .82rem; line-height: 1.5; }
.integrity-card { padding: 1rem; border-left: 4px solid var(--amber); background: rgba(154, 98, 23, .08); }
.integrity-card.good { border-color: var(--green); background: rgba(41, 113, 93, .09); }
.integrity-card.bad { border-color: var(--red); background: rgba(164, 56, 43, .09); }
.spinner { display: inline-block; width: .75rem; height: .75rem; margin-right: .5rem; border: 2px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }

.flow-panel { margin-top: 1.25rem; }
.flow { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0; margin: 1.5rem 0 0; padding: 0; list-style: none; counter-reset: flow; }
.flow li { position: relative; min-height: 10rem; padding: 2.7rem 1rem 1rem; border-top: 1px solid var(--ink); border-right: 1px solid var(--line); counter-increment: flow; }
.flow li::before { content: "0" counter(flow); position: absolute; top: .7rem; color: var(--accent); font-family: ui-monospace, monospace; font-size: .72rem; }
.flow strong, .flow span { display: block; }
.flow span { margin-top: .65rem; color: var(--muted); font-family: Georgia, serif; line-height: 1.42; }

.query-bar, .filters, .scan-controls { display: flex; align-items: end; flex-wrap: wrap; gap: .8rem; margin: 0 0 1.5rem; padding: 1rem; border: 1px solid var(--line); background: rgba(255, 255, 255, .25); }
label { display: grid; gap: .35rem; color: var(--muted); font-size: .72rem; font-weight: 750; letter-spacing: .04em; }
input, select, textarea { width: 100%; min-height: 2.55rem; padding: .55rem .65rem; border: 1px solid var(--line); border-radius: 0; background: rgba(255, 255, 255, .54); color: var(--ink); }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .78rem; line-height: 1.55; }
.query-bar label { min-width: min(28rem, 70vw); }
.filters label { min-width: 12rem; }
.scan-controls label { display: flex; align-items: center; gap: .5rem; }
.scan-controls input[type="checkbox"] { width: 1rem; min-height: 1rem; }

.result { margin-bottom: 1.5rem; }
.empty-state { min-height: 8rem; padding: 2rem; border: 1px dashed var(--line); color: var(--muted); font-family: Georgia, serif; font-size: 1.05rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 1rem; }
.card { position: relative; min-height: 13rem; padding: 1.2rem; border: 1px solid var(--line); background: var(--surface); }
.card:hover { border-color: var(--ink); }
.card h3 { margin: .4rem 0 .7rem; font-family: Georgia, serif; font-size: 1.4rem; font-weight: 400; line-height: 1.1; }
.card p { color: var(--muted); line-height: 1.45; }
.card footer { display: flex; align-items: center; justify-content: space-between; gap: .7rem; margin-top: 1.2rem; padding-top: .7rem; border-top: 1px solid var(--line); }
.meta { color: var(--muted); font-family: ui-monospace, monospace; font-size: .68rem; }
.badge { display: inline-flex; align-items: center; min-height: 1.45rem; padding: .15rem .45rem; border: 1px solid currentColor; color: var(--blue); font-size: .67rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.badge.pass, .badge.compliant, .badge.published { color: var(--green); }
.badge.fail, .badge.non-compliant, .badge.critical { color: var(--red); }
.badge.review, .badge.at-risk, .badge.contested { color: var(--amber); }
.badge.insufficient-data { color: var(--muted); }
.score { font-family: Georgia, serif; font-size: 2.2rem; letter-spacing: -.04em; }
.score small { font-family: inherit; font-size: .8rem; }

.detail-drawer { margin-top: 1.5rem; padding: 1.5rem; border: 1px solid var(--ink); background: var(--paper); box-shadow: var(--shadow); }
.detail-drawer h3 { margin-top: 0; font-family: Georgia, serif; font-size: 2rem; font-weight: 400; }
.detail-drawer pre { max-height: 28rem; overflow: auto; padding: 1rem; background: var(--ink); color: var(--paper); font-size: .72rem; line-height: 1.5; }
.callout { margin-bottom: 1.5rem; padding: 1rem 1.2rem; border-left: 4px solid var(--blue); background: rgba(27, 95, 120, .08); line-height: 1.5; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .7rem .6rem; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: .68rem; letter-spacing: .07em; text-transform: uppercase; }
td.number { font-family: ui-monospace, monospace; text-align: right; }
.bar { height: .42rem; margin-top: .35rem; overflow: hidden; background: var(--paper-deep); }
.bar span { display: block; height: 100%; background: var(--accent); }

.alert-list { display: grid; gap: .7rem; margin-bottom: 1.5rem; }
.alert { padding: 1rem 1.2rem; border: 1px solid var(--line); border-left: 5px solid var(--amber); background: var(--surface); }
.alert.critical { border-left-color: var(--red); }
.alert h3 { margin: 0 0 .35rem; font-family: Georgia, serif; font-weight: 400; }
.alert p { margin: 0; color: var(--muted); }

.stack-list { display: grid; gap: .7rem; margin-top: 1rem; }
.stack-item { padding: .9rem 0; border-top: 1px solid var(--line); }
.stack-item:first-child { border-top-color: var(--ink); }
.stack-item h4 { margin: .3rem 0; font-family: Georgia, serif; font-size: 1.15rem; font-weight: 400; }
.stack-item p { margin: .25rem 0; color: var(--muted); font-size: .82rem; line-height: 1.45; }
.stack-item footer { display: flex; align-items: center; justify-content: space-between; gap: .7rem; margin-top: .55rem; }
.ai-control-grid { align-items: start; }
.ai-queue-panel { margin-top: 1.25rem; }
.operations-context { display: grid; grid-template-columns: minmax(14rem, 24rem) auto 1fr; align-items: end; gap: .8rem; margin-bottom: 1.5rem; padding: 1rem; border: 1px solid var(--line); background: rgba(255, 255, 255, .25); }
.operations-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.operations-span-two { grid-column: 1 / -1; }
.delivery-attempts { color: var(--muted); font-family: ui-monospace, monospace; font-size: .68rem; }
.destination-health { display: inline-flex; gap: .4rem; align-items: center; color: var(--muted); font-size: .75rem; }
.destination-health::before { content: ""; width: .55rem; height: .55rem; border-radius: 50%; background: var(--green); }
.destination-health.degraded::before { background: var(--amber); }
.destination-health.failed::before { background: var(--red); }
.decision-strip { display: grid; grid-template-columns: minmax(8rem, .3fr) 1fr; gap: 1rem; margin-bottom: 1rem; padding: 1rem; border-left: 5px solid var(--amber); background: rgba(154, 98, 23, .08); }
.decision-strip.allow { border-color: var(--green); background: rgba(41, 113, 93, .09); }
.decision-strip.block { border-color: var(--red); background: rgba(164, 56, 43, .09); }
.decision-strip strong { font-family: Georgia, serif; font-size: 2rem; font-weight: 400; text-transform: capitalize; }
.check-list { display: grid; gap: 1px; margin: 1rem 0; background: var(--line); }
.check { display: grid; grid-template-columns: 7rem 1fr minmax(8rem, auto); gap: 1rem; padding: .75rem; background: var(--paper); }
.check code { font-size: .7rem; }
.check.failed { border-left: 4px solid var(--red); }
.check.warning { border-left: 4px solid var(--amber); }

.audit-list { margin: 1.5rem 0; padding: 0; list-style: none; }
.audit-list li { display: grid; grid-template-columns: 11rem 10rem 1fr; gap: 1rem; padding: .8rem 0; border-top: 1px solid var(--line); }
.audit-list time, .audit-list code { font-family: ui-monospace, monospace; font-size: .7rem; }
.audit-action strong { display: block; }
.audit-action span { color: var(--muted); font-size: .78rem; }

dialog { width: min(48rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; overflow: auto; border: 1px solid var(--ink); border-radius: 0; background: var(--paper); color: var(--ink); box-shadow: 0 30px 90px rgba(0, 0, 0, .28); }
dialog::backdrop { background: rgba(25, 25, 23, .55); backdrop-filter: blur(3px); }
dialog form { display: grid; gap: 1rem; padding: 1.5rem; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; gap: 2rem; padding-bottom: 1rem; border-bottom: 1px solid var(--ink); }
.dialog-heading h2 { margin: 0; font-family: Georgia, serif; font-size: 2rem; font-weight: 400; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .7rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.form-error { min-height: 1.2rem; color: var(--red); font-size: .82rem; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 100; display: grid; gap: .5rem; width: min(24rem, calc(100vw - 2rem)); }
.toast { padding: .85rem 1rem; border: 1px solid var(--ink); background: var(--ink); color: var(--paper); box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast.error { border-color: var(--red); background: var(--red); color: white; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 900px) {
  .rail { position: static; width: auto; padding: .5rem; flex-flow: row wrap; border-right: 0; border-bottom: 1px solid var(--ink); }
  .rail::before { display: none; }
  .nav-item { width: auto; grid-template-columns: auto 1fr; padding: .55rem .65rem; }
  .masthead { min-height: 0; padding: 2rem 1rem; }
  .workspace { margin-left: 0; padding: 1.2rem 1rem 3rem; }
  .two-column, .flow, .operations-grid, .operations-context { grid-template-columns: 1fr; }
  .operations-span-two { grid-column: auto; }
  .flow li { min-height: 7rem; }
}

@media (max-width: 620px) {
  .masthead, .view-heading { align-items: flex-start; flex-direction: column; }
  .masthead h1 { font-size: 3.5rem; }
  .nav-item span { display: none; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .card-grid { grid-template-columns: 1fr; }
  .audit-list li { grid-template-columns: 1fr; gap: .25rem; }
  .query-bar label, .filters label { min-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
