:root {
    color-scheme: light;
    --ink: #261e1b;
    --muted: #635952;
    --paper: #f6f2ed;
    --surface: #fffdf9;
    --line: #ded4c8;
    --rail: #2d2220;
    --rail-ink: #f7eee4;
    --accent: #9c332a;
    --accent-dark: #742218;
    --gold: #efbc72;
    --corner: .7rem;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--paper);
    color: var(--ink);
    font-size: 16px;
    line-height: 1.52;
}

*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, h3, p, dl, dd { margin: 0; }
body { min-width: 0; }
button, input { font: inherit; }
a { color: var(--accent-dark); text-underline-offset: .18em; }
:focus-visible { outline: .18rem solid #aa4c35; outline-offset: .22rem; }
.skip { position: fixed; z-index: 2; top: .8rem; left: .8rem; transform: translateY(-175%); padding: .6rem 1rem; border-radius: .4rem; background: var(--surface); }
.skip:focus { transform: none; }

.portal { min-height: 100vh; display: grid; grid-template-columns: 14rem minmax(0, 1fr); }
.rail { display: flex; flex-direction: column; padding: 2rem 1.15rem; background: var(--rail); color: var(--rail-ink); }
.brand { display: inline-flex; align-items: center; gap: .7rem; width: fit-content; color: inherit; font-size: 1.05rem; line-height: 1.2; font-weight: 740; text-decoration: none; }
.brand small { display: block; margin-top: .25rem; font-size: .73rem; font-weight: 500; opacity: .82; }
.brand-mark { display: grid; place-items: center; width: 2.45rem; height: 2.45rem; border-radius: .48rem; background: var(--gold); color: var(--rail); font-weight: 850; font-size: 1.38rem; }
.rail-nav { display: grid; gap: .3rem; margin-block: 2.5rem; }
.rail-nav a, .logout button { text-align: start; padding: .65rem .82rem; border: 0; border-radius: .42rem; background: transparent; color: var(--rail-ink); text-decoration: none; font-weight: 650; font-size: .88rem; }
.rail-nav a:hover, .logout button:hover { background: #493733; }
.rail-nav a[aria-current="page"] { background: #51403a; color: #ffdb9f; }
.rail :focus-visible { outline-color: var(--gold); }
.logout { margin-top: auto; }
.logout button { width: 100%; cursor: pointer; }

.workspace { width: min(100%, 80rem); padding: clamp(1.6rem, 4vw, 3.8rem) clamp(1.1rem, 4vw, 3.8rem) 4rem; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.1rem; margin-bottom: 1.85rem; }
.page-heading h1, .entry h1 { font-size: clamp(1.85rem, 4vw, 2.65rem); font-weight: 760; letter-spacing: -.042em; line-height: 1.12; }
.page-heading p { margin-top: .5rem; color: var(--muted); }
.page-heading .button { margin-top: .25rem; flex: none; }
.button { display: inline-flex; justify-content: center; align-items: center; min-height: 2.7rem; padding: .56rem 1rem; border: .08rem solid var(--accent); border-radius: .43rem; background: var(--accent); color: #fff; font-weight: 680; font-size: .9rem; cursor: pointer; text-decoration: none; }
.button:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.button-secondary { background: transparent; border-color: #c7ab9b; color: var(--accent-dark); }
.button-secondary:hover { background: #faeee6; border-color: var(--accent); }
.notice { margin-bottom: 1rem; padding: .72rem .92rem; border: .06rem solid #aac4ac; border-radius: .45rem; background: #eaf3e9; color: #225238; }
.notice-error { border-color: #dab4aa; background: #faece8; color: #792a21; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .78rem; margin-bottom: 1.4rem; }
.stats div { padding: 1rem 1.1rem; border: .06rem solid var(--line); border-radius: var(--corner); background: var(--surface); }
.stats dt { min-width: 0; color: var(--muted); font-size: .83rem; overflow-wrap: anywhere; }
.stats dd { margin-top: .2rem; font-size: 1.9rem; font-weight: 740; line-height: 1.2; }
.registry, .wizard-card { border: .06rem solid var(--line); border-radius: var(--corner); background: var(--surface); }
.registry-head { display: flex; justify-content: space-between; align-items: baseline; gap: .7rem; padding: 1rem 1.18rem; border-bottom: .06rem solid var(--line); }
.registry h2 { font-size: 1.1rem; letter-spacing: -.02em; }
.registry-head a { font-size: .82rem; }
.empty { padding: 2.25rem 1.2rem; text-align: center; }
.empty p { margin-top: .45rem; color: var(--muted); }
.tenant-list { margin: 0; padding: 0; list-style: none; }
.tenant { display: grid; grid-template-columns: 1.15fr 1.2fr 1fr auto; grid-template-areas: "identity endpoint state action" "identity admin state action"; align-items: center; gap: .38rem 1rem; padding: .95rem 1.18rem; }
.tenant + .tenant { border-top: .06rem solid var(--line); }
.tenant > * { min-width: 0; overflow-wrap: anywhere; }
.tenant-identity { grid-area: identity; }
.tenant-identity h3 { font-size: .99rem; line-height: 1.3; }
.tenant-id { display: block; margin-top: .2rem; color: var(--muted); font-size: .8rem; }
.tenant-endpoint { grid-area: endpoint; }
.tenant-admin { grid-area: admin; }
.tenant-state { grid-area: state; }
.tenant-state small { display: block; margin-top: .2rem; color: var(--accent-dark); }
.tenant-action { grid-area: action; }
.tenant-endpoint, .tenant-admin { font-size: .85rem; }
.field-label { display: block; color: var(--muted); font-size: .72rem; font-weight: 620; }
.badge { display: inline-block; padding: .16rem .52rem; border-radius: .38rem; font-size: .74rem; line-height: 1.4; font-weight: 690; }
.badge-draft { background: #ece5db; color: #534337; }
.badge-live { background: #e1eee0; color: #295638; }
.badge-work { background: #fff0ce; color: #6d4717; }
.badge-error { background: #f7e0da; color: #821f19; }

.back { display: inline-block; margin-bottom: 1.1rem; font-size: .89rem; }
.wizard-heading { margin-bottom: 1.35rem; }
.wizard-heading .step { margin: 0 0 .35rem; color: var(--accent-dark); font-size: .84rem; font-weight: 690; }
.wizard-card { max-width: 41rem; padding: clamp(1rem, 3vw, 1.75rem); }
.form { display: grid; gap: 1rem; }
.field { display: grid; gap: .29rem; }
.form label { font-size: .91rem; font-weight: 660; }
.form input { width: 100%; min-height: 2.8rem; padding: .54rem .68rem; border: .06rem solid #c4b6a8; border-radius: .4rem; outline-offset: .12rem; background: #fff; color: var(--ink); }
.form input::placeholder { color: #6f645d; opacity: 1; }
.form input[aria-invalid="true"] { border-color: var(--accent); }
.field small { color: var(--muted); font-size: .8rem; }
.field .field-error { color: var(--accent-dark); }
.actions { display: flex; justify-content: flex-end; margin-top: .5rem; }
.review { display: grid; }
.review div { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1fr); padding: .6rem 0; gap: .2rem .75rem; border-bottom: .06rem solid var(--line); }
.review dt { color: var(--muted); }
.review dd { font-weight: 620; overflow-wrap: anywhere; }
.review-note { margin-block: 1.15rem; color: var(--muted); font-size: .87rem; }

.entry { display: grid; place-items: center; min-height: 100vh; padding: 1.15rem; background: var(--rail); }
.entry-card { width: min(100%, 28rem); padding: clamp(1.35rem, 4.5vw, 2.5rem); border-radius: .85rem; background: var(--surface); }
.entry-card .brand { margin-bottom: 1.7rem; }
.entry-card .brand small { color: var(--muted); }
.entry-card h1 { margin-bottom: 1.12rem; font-size: clamp(1.55rem, 4vw, 2.1rem); }
.entry-card p + .button { margin-top: .9rem; }
.entry-card .form { gap: .68rem; }
.entry-card .button { margin-top: .42rem; }

@media (max-width: 68rem) {
    .tenant { grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) minmax(0, .75fr); grid-template-areas: "identity endpoint state" "identity admin action"; }
}

@media (max-width: 54rem) {
    .portal { grid-template-columns: minmax(0, 1fr); }
    .rail { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .65rem 1rem; padding: .8rem 1rem; }
    .rail-nav { grid-column: 1 / -1; grid-row: 2; display: flex; margin: 0; }
    .logout { margin: 0; }
    .logout button { width: auto; }
}

@media (max-width: 37rem) {
    .page-heading { align-items: flex-start; flex-direction: column; }
    .stats { gap: .4rem; }
    .stats div { padding: .72rem .5rem; }
    .stats dd { font-size: 1.52rem; }
    .tenant { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "identity state" "endpoint endpoint" "admin action"; gap: .55rem .65rem; }
    .tenant-state { max-width: 7rem; }
    .review div { grid-template-columns: minmax(0, 1fr); }
}
