:root {
    color-scheme: light;
    --ink: #1c2836;
    --muted: #5d6d7e;
    --paper: #e7eef5;
    --card: #ffffff;
    --sidebar: #f5f8fb;
    --titlebar: #1b4f82;
    --titlebar-ink: #f4f8fc;
    --line: #d3dee8;
    --line-strong: #b7c6d4;
    --accent: #1a6bb5;
    --accent-dark: #145892;
    --accent-soft: #e8f3fc;
    --good: #1f7a4d;
    --good-soft: #e5f6ed;
    --bad: #b4332a;
    --bad-soft: #fdeceb;
    --warn: #8a5a12;
    --warn-soft: #fff6e4;
    --info: #1d4f73;
    --info-soft: #e7f1f8;
    --shadow: 0 1px 2px rgba(22, 42, 66, 0.06);
    --sans: "Segoe UI", "Source Sans 3", sans-serif;
    --mono: Consolas, "Cascadia Mono", ui-monospace, monospace;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--sans);
    color: var(--ink);
    background: var(--paper);
    font-size: 14.5px;
    line-height: 1.45;
}

h1 {
    font-size: 1.35rem;
    font-weight: 650;
    letter-spacing: -0.02em;
    line-height: 1.2;
    margin: 0;
}

h2 {
    font-size: 0.95rem;
    font-weight: 650;
    margin: 0 0 12px;
}

p { margin: 0 0 8px; }

a { color: var(--accent-dark); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--titlebar); }

code {
    font-family: var(--mono);
    font-size: 0.92em;
    background: #f4f7fb;
    padding: 1px 5px;
    border-radius: 4px;
    border: 1px solid var(--line);
}

button, input, select, textarea { font: inherit; color: inherit; }

.skip {
    position: absolute;
    left: 12px;
    top: -40px;
    background: white;
    padding: 8px 12px;
    z-index: 20;
}
.skip:focus { top: 12px; }

.app {
    display: grid;
    grid-template-columns: 252px 1fr;
    grid-template-rows: 48px 1fr;
    min-height: 100vh;
}

.titlebar {
    grid-column: 1 / -1;
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 16px;
    height: 48px;
    padding: 0 14px 0 12px;
    background: var(--titlebar);
    color: var(--titlebar-ink);
    border-bottom: 1px solid #143e66;
}

.titlebar .brand {
    color: inherit;
    text-decoration: none;
    gap: 8px;
    flex: none;
}
.titlebar .brand strong { font-size: 15px; letter-spacing: -0.01em; }
.titlebar .brand small { display: none; }

.titlebar-context {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    padding-left: 12px;
    border-left: 1px solid rgba(255, 255, 255, 0.22);
}
.titlebar-context strong {
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.title-status {
    flex: none;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    color: white;
}

.titlebar-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.titlebar-user p { margin: 0; text-align: right; line-height: 1.2; }
.titlebar-user strong { display: block; font-size: 13px; }
.titlebar-user span { display: block; color: #c5d7e8; font-size: 12px; }
.titlebar .btn-ghost {
    color: #f4f8fc;
    border-color: rgba(255, 255, 255, 0.28);
    background: transparent;
}
.titlebar .btn-ghost:hover { background: rgba(255, 255, 255, 0.12); color: white; }

.sidebar {
    background: var(--sidebar);
    color: var(--ink);
    border-right: 1px solid var(--line);
    padding: 12px 10px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 48px;
    height: calc(100vh - 48px);
    overflow: auto;
}

.brand, .brand-lockup {
    display: flex;
    gap: 10px;
    align-items: center;
    color: inherit;
    text-decoration: none;
}
.brand strong, .brand-lockup strong { display: block; font-size: 15px; }
.brand small, .brand-lockup small { display: block; color: var(--muted); font-size: 12px; }
.mark { display: flex; }

.sidebar nav { display: grid; gap: 2px; align-content: start; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 6px;
    font-weight: 500;
    border: 1px solid transparent;
}
.sidebar nav a svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
}
.sidebar nav a:hover { background: #e7eef6; }
.sidebar nav a.active {
    background: var(--accent-soft);
    color: var(--titlebar);
    border-color: #c5dff3;
    font-weight: 650;
}

.sidebar nav a.nav-send {
    justify-content: center;
    height: 36px;
    margin: 8px 0 6px;
    background: var(--accent);
    color: white;
    border-color: var(--accent-dark);
    font-weight: 700;
    letter-spacing: 0.01em;
}
.sidebar nav a.nav-send:hover,
.sidebar nav a.nav-send[aria-current="page"] {
    background: var(--accent-dark);
    color: white;
}

.tree-back {
    color: var(--muted);
    font-size: 12.5px;
    padding: 4px 10px;
}
.tree-project {
    margin: 8px 10px 0;
    font-weight: 700;
    font-size: 14px;
    line-height: 1.3;
}
.tree-label {
    margin: 14px 10px 2px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #7d8ea0;
}
.tree a, .sidebar nav.tree a { padding-left: 12px; }

.main {
    padding: 20px 24px 56px;
    min-width: 0;
}
.wrap { max-width: 1040px; }
.wrap > * + * { margin-top: 14px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    padding-bottom: 2px;
}
.page-head p, .lede { color: var(--muted); max-width: 68ch; margin-top: 4px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card-pad { padding: 16px 18px; }
.card-pad > h2:first-child,
.card > .head-row h2 {
    font-size: 13px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #3e5266;
}
.card > .head-row {
    border-bottom: 1px solid var(--line);
    margin: 0;
}
.head-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.head-row h2 { margin: 0; }

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}
.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 12px 14px;
    box-shadow: var(--shadow);
}
.stat span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 650;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.stat strong {
    display: block;
    margin-top: 2px;
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--titlebar);
}

.steps { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.step {
    display: grid;
    grid-template-columns: 32px 1fr auto;
    gap: 12px;
    align-items: center;
    padding: 8px;
    border-radius: 8px;
}
.step p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.step .n {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #e7eef5;
    font-weight: 700;
}
.step.now { background: var(--accent-soft); }
.step.now .n { background: var(--accent); color: white; }
.step.done .n { background: var(--good); color: white; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 34px;
    padding: 0 14px;
    border-radius: 6px;
    border: 1px solid var(--accent-dark);
    background: var(--accent);
    color: white;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
}
.btn:hover { background: var(--accent-dark); color: white; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-secondary {
    background: white;
    color: var(--ink);
    border-color: var(--line-strong);
}
.btn-secondary:hover { background: #f4f8fb; color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink); border-color: transparent; }
.btn-ghost:hover { background: rgba(27, 79, 130, 0.06); color: var(--ink); }
.btn-danger { background: white; color: var(--bad); border-color: #f0c2be; }
.btn-danger:hover { background: var(--bad-soft); color: var(--bad); }
.btn-small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-large { height: 42px; padding: 0 22px; font-size: 15px; }
.send-panel { display: grid; gap: 12px; }
.send-panel p { margin: 0; }

.form { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field > span { font-weight: 650; font-size: 13px; color: #314457; }
.field small, .help, .muted { color: var(--muted); font-size: 12.5px; }
.err { color: var(--bad); font-size: 12.5px; }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.align-start { align-items: start; }
.create-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}
.create-row .field { width: min(420px, 100%); }

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    width: 100%;
    background: white;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    padding: 7px 10px;
    min-height: 34px;
}
input[type="checkbox"],
input[type="radio"] {
    width: 16px;
    height: 16px;
    min-width: 16px;
    min-height: 16px;
    margin: 2px 0 0;
    padding: 0;
    flex: 0 0 auto;
    accent-color: var(--accent);
    background: transparent;
    border: 0;
    box-shadow: none;
}
textarea {
    font-family: var(--mono);
    font-size: 13px;
    line-height: 1.5;
    resize: vertical;
    min-height: 0;
}
input:not([type="checkbox"]):not([type="radio"]):focus,
select:focus,
textarea:focus,
.btn:focus-visible,
.sidebar nav a:focus-visible {
    outline: 2px solid transparent;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26, 107, 181, 0.18);
}
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.invalid { border-color: var(--bad); }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; border: 0; padding: 0; margin: 0; }
.choice {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fbfcfe;
    cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 3px; }
.choice span { display: grid; gap: 2px; }
.choice small { color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
    text-align: left;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #4c6074;
    font-weight: 700;
    padding: 9px 12px;
    background: #f4f8fb;
    border-bottom: 1px solid var(--line);
}
td { padding: 9px 12px; border-bottom: 1px solid #e6eef5; vertical-align: middle; }
tbody tr:hover td { background: #f7fbfe; }
tr:last-child td { border-bottom: 0; }
td form { display: inline; }

.pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    background: #e8eef4;
    color: #41566a;
    white-space: nowrap;
}
.pill-sent, .pill-finished, .pill-active { background: var(--good-soft); color: var(--good); }
.pill-failed, .pill-draft { background: #eef2f6; color: #41566a; }
.pill-failed { background: var(--bad-soft); color: var(--bad); }
.pill-sending, .pill-claimed { background: var(--warn-soft); color: var(--warn); }
.pill-paused, .pill-skipped { background: var(--info-soft); color: var(--info); }
.pill-draft { background: #eef2f6; color: #41566a; }

.flash { padding: 10px 12px; border-radius: 6px; border: 1px solid transparent; }
.flash-success { background: var(--good-soft); color: var(--good); border-color: #b7e4c9; }
.flash-error { background: var(--bad-soft); color: var(--bad); border-color: #f3c1bd; }
.notice { background: var(--warn-soft); color: var(--warn); padding: 10px 12px; border-radius: 6px; border: 1px solid #f0ddb4; }
.empty { padding: 8px 18px 18px; color: var(--muted); }

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters a { text-decoration: none; color: var(--muted); padding: 4px 10px; border-radius: 999px; border: 1px solid transparent; }
.filters a.on, .filters a:hover { background: var(--titlebar); color: white; }
.searchbar { display: flex; gap: 8px; }
.searchbar input { width: 280px; }
.pager { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.danger-zone { margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--line); }

.editor {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
    gap: 14px;
    align-items: start;
}
.preview { position: sticky; top: 14px; }
.preview-frame {
    width: 100%;
    height: 280px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
}
.editor .preview-frame { height: 420px; }
.subject-line { font-weight: 650; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
    border: 1px solid var(--line-strong);
    background: white;
    border-radius: 999px;
    padding: 3px 9px;
    cursor: pointer;
    font-size: 12.5px;
    color: var(--titlebar);
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }

.summary { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0 0 14px; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; }
.missing { margin: 0; padding-left: 18px; display: grid; gap: 8px; }

.progress { height: 8px; background: #e1e9f1; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, #1a6bb5, #2f8fd0); }

body.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 28px 16px;
    background:
        linear-gradient(180deg, #1b4f82 0 120px, transparent 120px),
        var(--paper);
}
.auth-card { width: min(440px, 100%); }
body.setup .auth-card { width: min(680px, 100%); }
.auth-card h1 { font-size: 1.45rem; }
.auth .brand-lockup { margin-bottom: 16px; }

[hidden] { display: none !important; }

.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 28px; }
.check-line { display: flex; gap: 8px; align-items: flex-start; margin: 8px 0; cursor: pointer; }
.check-line:has(input:disabled) { cursor: not-allowed; color: var(--muted); }
input:disabled:not([type="checkbox"]):not([type="radio"]),
textarea:disabled,
select:disabled {
    background: #f4f7fb;
    color: #6d7f91;
    cursor: not-allowed;
}
input[type="checkbox"]:disabled,
input[type="radio"]:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}
.rotate-box {
    display: grid;
    gap: 10px;
    margin-top: 4px;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}
.rotate-list { display: grid; gap: 10px; }
.check-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.check-list li { display: grid; gap: 2px; }
.check-ok strong { color: var(--good); }
.check-bad strong { color: var(--bad); }
.plain-list { margin: 0; padding-left: 18px; }
.plain-list li + li { margin-top: 4px; }
.option-lines {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 28px;
}
.option-lines li {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 7px 0;
    border-bottom: 1px solid #e6eef5;
    font-size: 13px;
}
.option-lines span { color: var(--muted); }
.option-lines strong { font-weight: 650; text-align: right; }
.preview-block { margin-top: 14px; }
.text-preview {
    white-space: pre-wrap;
    background: #f4f7fb;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
    min-height: 160px;
}
.preview-picker { max-width: 420px; margin-top: 12px; }

@media (max-width: 860px) {
    .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; }
    .titlebar { grid-column: 1; position: relative; flex-wrap: wrap; height: auto; padding: 8px 12px; gap: 8px; }
    .titlebar-context { border-left: 0; padding-left: 0; }
    .titlebar-user { width: 100%; }
    .sidebar { position: relative; top: auto; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
    .sidebar nav {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 4px;
        align-items: center;
    }
    .tree-label, .tree-project { display: none; }
    .sidebar nav a, .tree-back { white-space: nowrap; flex: none; }
    .sidebar nav a.nav-send { width: auto; margin: 0; padding: 0 14px; }
    .main { padding: 16px 14px 40px; }
    .page-head, .stats, .split, .choices, .editor, .searchbar, .create-row, .options-grid, .option-lines {
        grid-template-columns: 1fr;
    }
    .page-head { align-items: start; }
    .stats { grid-template-columns: 1fr 1fr; }
    .searchbar input { width: 100%; }
    .preview { position: static; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; }
}
