:root {
  --bg: #0c0a08;
  --bg-elevated: #14110e;
  --panel: rgba(255, 248, 240, 0.035);
  --line: rgba(255, 240, 228, 0.09);
  --line-strong: rgba(207, 125, 78, 0.35);
  --text: #f6eee7;
  --muted: #b19f91;
  --accent: #cf7d4e;
  --accent-soft: rgba(207, 125, 78, 0.14);
  --danger: #e07a6b;
  --ok: #8fd4a2;
  --font-sans: "Source Sans 3", system-ui, sans-serif;
  --font-serif: "Newsreader", Georgia, serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --radius: 18px;
  --radius-lg: 24px;
  --max: 1180px;
  --nav-h: 52px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(207, 125, 78, 0.16), transparent 28%),
    linear-gradient(180deg, #151210 0%, var(--bg) 45%, #100d0b 100%);
  min-height: 100vh;
}

body.density-compact {
  --cell-pad: 10px 12px;
  --card-pad: 14px 16px;
}

body:not(.density-compact) {
  --cell-pad: 14px 16px;
  --card-pad: 18px 20px;
}

a {
  color: inherit;
}

.shell {
  width: min(var(--max), calc(100% - 28px));
  margin: 0 auto;
  padding: 20px 0 32px;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  padding: 8px 14px;
  background: var(--accent);
  color: #1a120c;
  font-weight: 700;
  border-radius: 8px;
  z-index: 100;
}

.skip-link:focus {
  left: 12px;
}

/* —— Top bar —— */
.portal-top {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(12, 10, 8, 0.94), rgba(12, 10, 8, 0.82));
  backdrop-filter: blur(12px);
}

.portal-top__inner {
  width: min(var(--max), calc(100% - 28px));
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--nav-h);
  padding: 8px 0;
}

.brand {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  line-height: 1.1;
}

.brand strong {
  font-family: var(--font-serif);
  font-size: 20px;
  letter-spacing: -0.03em;
}

.brand span {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.portal-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.portal-nav button {
  appearance: none;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 8px 11px;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.portal-nav button:hover {
  color: var(--text);
  border-color: rgba(207, 125, 78, 0.35);
}

.portal-nav button.is-active {
  background: var(--accent-soft);
  border-color: rgba(207, 125, 78, 0.45);
  color: #f4c0a1;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
  text-transform: uppercase;
}

.topbar-status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(143, 212, 162, 0.2);
}

.external-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.external-links a {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-decoration: none;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
}

.external-links a:hover {
  color: var(--text);
  border-color: rgba(207, 125, 78, 0.35);
}

/* —— Pages —— */
.page {
  display: none;
}

.page.is-visible {
  display: block;
}

.page-header {
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 700;
  color: #e8a878;
}

h1.page-title {
  margin: 10px 0 0;
  font-family: var(--font-serif);
  font-size: clamp(28px, 4.5vw, 44px);
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.lede {
  margin: 12px 0 0;
  max-width: 68ch;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

/* —— Cards & grids —— */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.metric {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  padding: var(--card-pad);
}

.metric strong {
  display: block;
  font-family: var(--font-serif);
  font-size: 32px;
  line-height: 1;
}

.metric span {
  display: block;
  margin-top: 8px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 16px;
  margin-top: 20px;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.015));
  padding: var(--card-pad);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-title {
  font-family: var(--font-serif);
  font-size: 22px;
  margin: 0;
}

.card-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(207, 125, 78, 0.35);
  color: #f4c0a1;
  background: var(--accent-soft);
}

.list-plain {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0;
}

.list-plain li {
  padding: 12px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.list-plain li:first-child {
  border-top: 0;
  padding-top: 0;
}

.list-plain strong {
  color: var(--text);
  font-weight: 600;
}

/* —— Tables —— */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.data th,
table.data td {
  text-align: left;
  padding: var(--cell-pad);
  border-bottom: 1px solid var(--line);
}

table.data th {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  background: rgba(0, 0, 0, 0.2);
}

table.data tr:last-child td {
  border-bottom: 0;
}

.mono {
  font-family: var(--font-mono);
  font-size: 13px;
}

.chip {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  background: var(--accent-soft);
  color: #f4c0a1;
}

.chip--urgent {
  border-color: rgba(224, 122, 107, 0.45);
  background: rgba(224, 122, 107, 0.12);
  color: #f5b5aa;
}

.chip--soon {
  border-color: rgba(207, 125, 78, 0.45);
}

.chip--planned {
  border-color: rgba(143, 212, 162, 0.35);
  background: rgba(143, 212, 162, 0.08);
  color: #b8e6c4;
}

.pattern-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.pattern-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.18);
}

.pattern-card code {
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
  color: #f4c0a1;
}

.cast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.cast-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--card-pad);
  background: linear-gradient(145deg, rgba(207, 125, 78, 0.08), transparent 55%);
}

.cast-card h3 {
  margin: 0 0 6px;
  font-family: var(--font-serif);
  font-size: 22px;
}

.cast-meta {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

/* —— Billing summary —— */
.billing-total {
  font-family: var(--font-serif);
  font-size: 36px;
  margin: 8px 0 0;
}

.billing-note {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

/* —— Settings —— */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 8px;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-field label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.settings-field input[type="text"],
.settings-field input[type="number"],
.settings-field select {
  font-family: var(--font-sans);
  font-size: 15px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
}

.settings-field input:focus,
.settings-field select:focus {
  outline: 2px solid rgba(207, 125, 78, 0.45);
  outline-offset: 1px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.btn {
  appearance: none;
  border: 0;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 10px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), #e08f5c);
  color: #1a120c;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid rgba(143, 212, 162, 0.45);
  background: rgba(20, 40, 28, 0.9);
  color: #d4f0dc;
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  z-index: 200;
}

.toast.is-visible {
  opacity: 1;
}

.page-footer {
  margin-top: 28px;
  font-size: 13px;
  color: var(--muted);
  text-align: right;
}

@media (max-width: 980px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  .portal-top__inner {
    flex-wrap: wrap;
  }

  .portal-nav {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }
}

@media (max-width: 520px) {
  .metric-grid {
    grid-template-columns: 1fr;
  }
}
