:root {
  --ink: #241714;
  --muted: #6f5d54;
  --paper: #f3eee6;
  --card: #fffdf9;
  --line: #e4d7c8;
  --sidebar: #2b1614;
  --gold: #c6a15b;
  --maroon: #8d2434;
  --good: #1d6b45;
  --good-bg: #e7f5ee;
  --warn: #8a5a10;
  --warn-bg: #fbf3df;
  --bad: #9d2430;
  --bad-bg: #fdecee;
  --info: #1d4f73;
  --info-bg: #e7f2f8;
  --shadow: 0 16px 40px rgba(58, 28, 16, 0.06);
  --serif: "Literata", Georgia, serif;
  --sans: "Manrope", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}
a { color: var(--maroon); text-decoration-thickness: 1px; text-underline-offset: 3px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 560; letter-spacing: -0.02em; }
h1 { margin: 0; font-size: 2rem; line-height: 1.15; }
h2 { margin: 0; font-size: 1.35rem; }
p { margin: 0 0 0.8rem; overflow-wrap: anywhere; }
code {
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.92em;
  background: #f6efe4;
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}

.shell { display: grid; grid-template-columns: 268px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: #f6efe6;
  padding: 1.4rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.brand { display: flex; gap: 0.8rem; align-items: flex-start; padding: 0.2rem 0.5rem 1.2rem; }
.brand-kicker {
  margin: 0;
  color: var(--gold);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
.brand-name { margin: 0.2rem 0 0; font-family: var(--serif); font-size: 0.98rem; line-height: 1.35; }
.seal {
  flex: 0 0 auto;
  width: 2.4rem;
  height: 2.4rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 0.7rem;
  color: var(--gold);
  font-family: var(--serif);
  font-size: 1.25rem;
}
.seal-large { width: 3.2rem; height: 3.2rem; font-size: 1.6rem; margin-bottom: 1rem; }
.nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav a {
  color: #f3e7dc;
  text-decoration: none;
  padding: 0.62rem 0.75rem;
  border-radius: 0.7rem;
}
.nav a:hover, .nav a.active { background: rgba(198, 161, 91, 0.16); color: white; }
.signout {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.8rem 0.4rem 0.2rem;
  color: #d9c7b8;
}
.signout button, .row-actions button, .pager a, .button-quiet {
  background: transparent;
}
.signout button {
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
}

.workspace { min-width: 0; }
.topbar { padding: 1.6rem 2rem 0.4rem; }
.eyebrow { margin: 0 0 0.25rem; color: var(--muted); font-size: 0.82rem; }
.page { padding: 0.6rem 2rem 2.5rem; }
.lede { max-width: 68rem; color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 1.1rem;
  box-shadow: var(--shadow);
  padding: 1.15rem 1.2rem 1.2rem;
  margin-bottom: 1rem;
}
.card-head, .lone { display: flex; justify-content: space-between; gap: 1rem; align-items: center; flex-wrap: wrap; }
.card-head { margin-bottom: 0.8rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.8rem; margin-bottom: 1rem; }
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 1rem;
  padding: 0.95rem 1rem;
}
.stat span, .stat small { display: block; color: var(--muted); }
.stat strong { display: block; margin: 0.2rem 0; font-family: var(--serif); font-size: 1.8rem; }
.split { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 1rem; }
.split > * { min-width: 0; }
.template-list { display: grid; gap: 0.8rem; }
.send-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 1.4rem; }

.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.8rem; }
.steps li { padding-left: 1.7rem; position: relative; }
.steps li::before {
  content: "";
  width: 0.75rem;
  height: 0.75rem;
  border: 2px solid var(--maroon);
  border-radius: 50%;
  position: absolute;
  left: 0;
  top: 0.3rem;
}
.steps li.done::before { background: var(--good); border-color: var(--good); }
.steps p, .muted { color: var(--muted); }
.facts { margin: 0; display: grid; gap: 0.55rem; }
.facts div { display: grid; grid-template-columns: 11rem 1fr; gap: 0.6rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.facts-top { margin-top: 1rem; }

label { display: block; font-weight: 600; margin: 0 0 0.85rem; max-width: 100%; }
input, select, button { font: inherit; }
input[type="text"], input[type="password"], input[type="search"], input:not([type]), select, input[type="file"] {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 0.7rem;
  border-radius: 0.7rem;
  border: 1px solid #ddcfc0;
  background: white;
  color: var(--ink);
}
.check { display: grid; grid-template-columns: 1.1rem minmax(0, 1fr); column-gap: 0.55rem; align-items: start; font-weight: 500; max-width: 100%; }
.check input { width: auto; margin-top: 0.25rem; }
fieldset { border: 1px solid var(--line); border-radius: 0.8rem; margin: 0 0 1rem; padding: 0.7rem 0.9rem; }
legend { padding: 0 0.3rem; font-weight: 700; }
.button, .danger-button {
  border: 0;
  border-radius: 999px;
  padding: 0.7rem 1.05rem;
  background: var(--maroon);
  color: white;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.button-quiet { background: transparent; color: var(--maroon); border: 1px solid #e3c3c8; }
.danger-button, button.danger { background: transparent; color: var(--bad); }
.button-row, .row-actions, .filters, .badge-row, .counts { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }
.filters { justify-content: flex-end; }
.filters input, .filters select { width: 13.5rem; margin-top: 0; }
.row-actions form { margin: 0; }
.row-actions button {
  border: 0;
  background: transparent;
  color: var(--info);
  cursor: pointer;
  padding: 0;
  font-weight: 700;
}
.narrow { max-width: 28rem; }
.note, .banner, .flash {
  border-radius: 0.8rem;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.8rem;
}
.note, .banner { background: #f8f1e4; border: 1px solid #ead7b4; }
.banner[data-tone="warn"] { background: var(--warn-bg); }
.flash[data-tone="good"] { background: var(--good-bg); color: var(--good); }
.flash[data-tone="bad"] { background: var(--bad-bg); color: var(--bad); }
.flash[data-tone="info"] { background: var(--info-bg); color: var(--info); }
.flashes { padding: 0.8rem 2rem 0; }
.gate .flashes { padding: 0 0 0.5rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.65rem 0.45rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 0.12rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
  background: #f3ece3;
}
.badge[data-tone="good"] { background: var(--good-bg); color: var(--good); }
.badge[data-tone="bad"] { background: var(--bad-bg); color: var(--bad); }
.badge[data-tone="warn"] { background: var(--warn-bg); color: var(--warn); }
.badge[data-tone="info"] { background: var(--info-bg); color: var(--info); }
.preview {
  white-space: pre-wrap;
  font-family: var(--sans);
  background: #faf6f0;
  border-radius: 0.8rem;
  padding: 0.8rem;
  margin: 0 0 0.8rem;
}
.slot-row { border-top: 1px solid var(--line); padding-top: 0.8rem; margin-top: 0.4rem; }
.slot-label { font-weight: 700; }
.bar { height: 0.55rem; background: #efe4d6; border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--maroon), var(--gold)); }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 0.84rem; word-break: break-all; }
.empty { color: var(--muted); margin: 0; }
.pager { display: flex; gap: 1rem; align-items: center; margin-top: 0.8rem; }
.plain { margin: 0; padding-left: 1.1rem; }

.phone {
  width: min(100%, 320px);
  background: #1c1412;
  border-radius: 1.6rem;
  padding: 0.7rem;
  margin-top: 0.6rem;
}
.phone-notch { width: 5rem; height: 0.35rem; border-radius: 999px; background: #3a2b27; margin: 0.15rem auto 0.55rem; }
.phone-screen { background: #efe6da; border-radius: 1.1rem; padding: 0.85rem; min-height: 8rem; }
.phone-screen p, .phone-screen strong, .phone-screen small { display: block; white-space: pre-wrap; }
.phone-screen small { color: var(--muted); margin-top: 0.45rem; }
.phone-media { font-size: 0.8rem; color: var(--info); margin-bottom: 0.4rem; word-break: break-all; }
.phone-btn { margin-top: 0.45rem; text-align: center; color: var(--info); font-weight: 700; border-top: 1px solid #e0d3c4; padding-top: 0.35rem; }

.gate {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
}
.gate-story {
  background:
    radial-gradient(circle at top left, rgba(198, 161, 91, 0.28), transparent 28%),
    var(--sidebar);
  color: #f7f1e8;
  padding: 4.5rem 4rem;
}
.gate-story h1 { font-size: clamp(2.2rem, 4vw, 3.6rem); max-width: 12ch; }
.gate-story p { max-width: 36rem; color: #eadfD4; font-size: 1.05rem; }
.gate-panel { display: flex; flex-direction: column; justify-content: center; padding: 3rem 4rem; background: var(--paper); }
.gate-panel h2 { margin-bottom: 1rem; }

button:disabled { opacity: 0.5; cursor: not-allowed; }
:focus-visible { outline: 3px solid rgba(141, 36, 52, 0.35); outline-offset: 2px; }

@media (max-width: 980px) {
  .shell, .split, .send-layout, .stats, .gate { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .signout { margin-top: 0.8rem; }
  .page, .topbar { padding-left: 1rem; padding-right: 1rem; }
  .gate-story, .gate-panel { padding: 2rem 1.2rem; }
  .facts div { grid-template-columns: 1fr; gap: 0.1rem; }
}
@media print {
  .sidebar, .topbar, .no-print, .flashes, .banner { display: none !important; }
  .shell { display: block; }
  .page { padding: 0; }
  .card { box-shadow: none; }
}
