:root {
    color-scheme: light;
    --bg: #e8edf2;
    --surface: #ffffff;
    --field: #f7f9fb;
    --ink: #15202b;
    --muted: #5d6b7b;
    --line: #d8e0e8;
    --accent: #0f6e56;
    --accent-ink: #f4fbf8;
    --accent-soft: #e6f5f0;
    --danger: #9f2d2d;
    --danger-soft: #fdecec;
    --shadow: 0 1px 2px rgba(16, 24, 32, 0.04), 0 12px 32px rgba(16, 24, 32, 0.06);
    --font: "Segoe UI", "Avenir Next", sans-serif;
    --rail: #10161d;
    --rail-ink: #d7e0ea;
    --rail-muted: #8b98a8;
    --radius: 12px;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0d1218;
    --surface: #161d26;
    --field: #10171f;
    --ink: #eef3f8;
    --muted: #a8b4c2;
    --line: #2a3542;
    --accent: #3dbe9a;
    --accent-ink: #06241b;
    --accent-soft: #16352c;
    --danger: #ffb4a8;
    --danger-soft: #3a2220;
    --shadow: none;
    --rail: #0a0e13;
    --rail-ink: #d7e0ea;
    --rail-muted: #8b98a8;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--ink);
    line-height: 1.5;
    font-size: 15px;
}
a { color: var(--accent); }
h1, h2 { font-weight: 650; letter-spacing: -0.03em; margin: 0; }
h1 { font-size: 1.7rem; }
button, input, select, textarea { font: inherit; color: inherit; }
.skip {
    position: absolute; left: 12px; top: -40px; background: var(--surface); padding: 8px 12px; z-index: 5;
}
.skip:focus { top: 12px; }

.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.rail {
    padding: 22px 14px;
    background: var(--rail);
    color: var(--rail-ink);
    display: flex;
    flex-direction: column;
    gap: 22px;
}
.brand { display: flex; gap: 12px; align-items: center; text-decoration: none; color: inherit; padding: 0 8px; }
.brand strong { display: block; font-size: 1.15rem; letter-spacing: -0.03em; }
.brand small { color: var(--rail-muted); letter-spacing: 0.12em; text-transform: uppercase; font-size: 0.68rem; }
.mark {
    width: 34px; height: 34px; border-radius: 10px; flex: none;
    background: linear-gradient(145deg, #1d9a78, #0c4e3e);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.16);
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a, .signout button {
    display: block;
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    text-decoration: none;
    color: var(--rail-ink);
    border-radius: 8px;
    padding: 9px 12px;
    cursor: pointer;
    font-weight: 550;
}
.nav a:hover, .signout button:hover { background: rgba(255, 255, 255, 0.06); }
.nav a.is-current { background: #1a7a60; color: #f4fffb; }
.signout { margin-top: auto; }
.workspace { min-width: 0; }
.top {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    min-height: 64px;
    padding: 0 32px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}
.content { padding: 28px 32px 56px; max-width: 1120px; }
.page-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-end; margin-bottom: 20px; }
.page-head p, .quiet { color: var(--muted); margin: 4px 0 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stats article, .panel, .empty, .gate-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow);
}
.stats article { padding: 16px 18px; }
.stats span { display: block; color: var(--muted); font-size: 0.78rem; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; }
.stats strong { display: block; margin-top: 8px; font-size: 1.9rem; letter-spacing: -0.04em; }
.empty { margin-top: 16px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--field); }
th { color: var(--muted); font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 700; background: var(--field); }
.actions { display: flex; gap: 8px; align-items: center; }
.actions form { margin: 0; }
form.panel, .panel { display: grid; gap: 14px; max-width: 720px; padding: 22px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 0.82rem; font-weight: 650; color: var(--muted); }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: var(--field);
    border-radius: 8px;
    padding: 10px 12px;
    min-height: 42px;
    color: var(--ink);
    font-weight: 450;
}
textarea { min-height: 96px; resize: vertical; }
select {
    appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 18px) calc(50% - 2px), calc(100% - 12px) calc(50% - 2px);
    background-size: 6px 6px, 6px 6px;
    background-repeat: no-repeat;
    padding-right: 32px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 550; color: var(--ink); }
.check input { width: auto; min-height: 0; }
.form-actions, .status-panel { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.button, .panel button[type="submit"], .gate-card button[type="submit"], .wizard-next {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
}
.button:hover, .panel button[type="submit"]:hover, .gate-card button[type="submit"]:hover, .wizard-next:hover { filter: brightness(1.06); }
.panel button.ghost, .panel button.ghost:hover {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    filter: none;
}
.ghost, .form-actions > a, .wizard-prev {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    cursor: pointer;
    font-weight: 600;
}
.link {
    border: 0;
    background: transparent;
    color: var(--danger);
    padding: 0;
    cursor: pointer;
    font-weight: 600;
}
.alert, .field-validation-error { color: var(--danger); margin: 0; }
.validation-summary-valid { display: none; }
.callout {
    margin: 0;
    padding: 12px 14px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 450;
}
.steps { display: flex; gap: 8px; padding: 0; margin: 0; list-style: none; }
.wizard-tab {
    color: var(--muted);
    padding: 6px 2px 8px;
    border-bottom: 2px solid transparent;
    font-size: 0.82rem;
    font-weight: 650;
}
.wizard-tab.is-active { color: var(--ink); border-color: var(--accent); }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 3px 10px; background: var(--field); font-size: 0.78rem; font-weight: 700; }
.status-connected { background: var(--accent-soft); color: var(--accent); }
.status-disconnected, .status-expired { background: var(--field); color: var(--muted); }
.status-failed, .status-permissionrequired { background: var(--danger-soft); color: var(--danger); }
.status-line { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.status-line p { margin: 0; }

.gate {
    display: grid;
    grid-template-columns: minmax(280px, 420px) 1fr;
    min-height: 100vh;
    padding: 0;
    background: var(--bg);
}
.gate-aside {
    background: var(--rail);
    color: var(--rail-ink);
    padding: 40px 32px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}
.gate-aside strong { display: block; font-size: 2rem; letter-spacing: -0.04em; }
.gate-aside p { color: var(--rail-muted); max-width: 28ch; }
.gate-main { display: grid; place-items: center; padding: 32px; }
.gate-card { width: min(420px, 100%); display: grid; gap: 14px; }
.gate-card form { display: grid; gap: 14px; }
.eyebrow { letter-spacing: 0.16em; text-transform: uppercase; color: #7dceB8; margin: 0; font-size: 0.75rem; font-weight: 700; }
.office { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.office h2 { font-size: 1rem; margin-bottom: 10px; }
.character { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.character.is-working, .character.is-queued, .character.is-handoff { border-left: 3px solid var(--accent); padding-left: 10px; }
.character.is-waiting { border-left: 3px solid #b5812f; padding-left: 10px; }
.character.is-failed, .character.is-cancelled { border-left: 3px solid var(--danger); padding-left: 10px; }
.character.is-completed { border-left: 3px solid var(--accent); padding-left: 10px; }

@media (max-width: 860px) {
    .shell, .gate { grid-template-columns: 1fr; }
    .rail { border-bottom: 1px solid #1c2632; }
    .stats { grid-template-columns: 1fr 1fr; }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .signout { margin-top: 0; }
    .content, .top { padding-left: 16px; padding-right: 16px; }
    .gate-aside { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    * { scroll-behavior: auto; transition: none !important; }
}
