:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  --bg: #0d1117;
  --surface: #151b23;
  --surface-raised: #1b232e;
  --border: #303946;
  --border-strong: #465264;
  --text: #e8edf3;
  --muted: #9aa8b8;
  --accent: #5ca9ff;
  --accent-strong: #88c1ff;
  --success: #57c98d;
  --warning: #e5b454;
  --danger: #ff7b7b;
  --focus: #ffd166;
  --radius: 0.55rem;
}

* { box-sizing: border-box; }
html { min-width: 20rem; background: var(--bg); }
body { margin: 0; color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--accent); text-underline-offset: 0.16em; }
a:hover { color: var(--accent-strong); }
button, input, select, textarea { font: inherit; }
button, .button {
  display: inline-flex;
  min-height: 2.5rem;
  align-items: center;
  justify-content: center;
  border: 1px solid #438bd6;
  border-radius: 0.4rem;
  padding: 0.5rem 0.85rem;
  color: #06101a;
  background: #70b6ff;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}
button:hover, .button:hover { color: #06101a; background: #9bceff; }
.button-secondary { color: var(--text); border-color: var(--border-strong); background: var(--surface-raised); }
.button-secondary:hover { color: #fff; background: #263241; }
.button-danger { color: #fff; border-color: #a33f46; background: #7d3036; }
.button-danger:hover { color: #fff; background: #984047; }
.button-quiet { min-height: auto; padding: 0.3rem 0.5rem; color: var(--muted); border-color: transparent; background: transparent; }
.button-quiet:hover { color: var(--text); background: var(--surface-raised); }
.button-link { align-self: end; padding: 0.55rem 0.2rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.skip-link { position: fixed; z-index: 100; top: 0.75rem; left: 0.75rem; transform: translateY(-160%); padding: 0.5rem 0.75rem; color: #111; background: var(--focus); font-weight: 700; }
.skip-link:focus { transform: translateY(0); }
.site-header { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 1.5rem; align-items: center; min-height: 4rem; padding: 0.7rem clamp(1rem, 3vw, 2.5rem); border-bottom: 1px solid var(--border); background: #111720; }
.brand { display: inline-flex; gap: 0.55rem; align-items: center; color: var(--text); font-size: 1.05rem; font-weight: 800; text-decoration: none; white-space: nowrap; }
.brand span:first-child { color: var(--accent); }
.primary-nav { display: flex; gap: 0.2rem; align-items: center; overflow-x: auto; scrollbar-width: thin; }
.primary-nav a { padding: 0.45rem 0.6rem; color: var(--muted); border-radius: 0.35rem; font-size: 0.9rem; text-decoration: none; white-space: nowrap; }
.primary-nav a:hover, .primary-nav a[aria-current="page"] { color: var(--text); background: var(--surface-raised); }
.primary-nav a[aria-current="page"] { box-shadow: inset 0 -2px var(--accent); }
.account-actions { display: flex; gap: 0.5rem; align-items: center; white-space: nowrap; }
.account-actions form { margin: 0; }
.quiet-link { color: var(--muted); font-size: 0.88rem; }

main { width: min(100% - 2rem, 96rem); margin: 0 auto; padding: clamp(1.25rem, 3vw, 2.5rem) 0 4rem; }
h1, h2, h3 { margin-top: 0; line-height: 1.2; letter-spacing: -0.02em; }
h1 { margin-bottom: 0.45rem; font-size: clamp(1.7rem, 3vw, 2.45rem); }
h2 { margin-bottom: 0.8rem; font-size: 1.18rem; }
h3 { margin-top: 1.5rem; font-size: 1rem; }
p { margin-top: 0; }
.eyebrow { margin-bottom: 0.25rem; color: var(--accent-strong); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.11em; text-transform: uppercase; }
.lede, .muted, .field-help { color: var(--muted); }
.lede { max-width: 52rem; margin-bottom: 0; }
.field-help { margin: -0.25rem 0 0.25rem; font-size: 0.85rem; }
.page-heading { display: flex; gap: 1rem; align-items: end; justify-content: space-between; margin-bottom: 1.5rem; }
.detail-heading { align-items: start; }
.section-heading { display: flex; gap: 1rem; align-items: start; justify-content: space-between; }
.section-heading h2 { margin-bottom: 0; }
.breadcrumb { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 1.1rem; color: var(--muted); font-size: 0.9rem; }

.panel, .table-panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 0.7rem 2.2rem rgb(0 0 0 / 0.12); }
.panel { padding: clamp(1rem, 2vw, 1.35rem); }
.panel + .panel { margin-top: 1rem; }
.compact-panel { padding: 1rem; }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.9rem; margin-bottom: 1rem; }
.metric-card { display: flex; min-height: 8.5rem; flex-direction: column; gap: 0.2rem; justify-content: center; padding: 1.1rem; color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-decoration: none; }
.metric-card:hover { color: var(--text); border-color: var(--border-strong); background: var(--surface-raised); }
.metric-card strong { font-size: clamp(1.4rem, 2vw, 1.85rem); }
.metric-card > span:last-child, .metric-label { color: var(--muted); font-size: 0.86rem; }
.metric-label { font-weight: 700; }
.warning-card { border-color: #725d30; }
.budget-line { display: flex; gap: 1rem; align-items: center; justify-content: space-between; }
.budget-line > div { display: flex; flex-direction: column; }
progress { width: min(100%, 32rem); height: 0.7rem; accent-color: var(--accent); }
.notice { margin: 1rem 0 0; padding: 0.8rem; border: 1px solid var(--border); border-radius: 0.4rem; background: var(--surface-raised); }
.notice.warning { color: #ffdda0; border-color: #725d30; }
.compact-list { margin: 0; padding: 0; list-style: none; }
.compact-list li { display: flex; gap: 1rem; align-items: center; justify-content: space-between; padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.compact-list li:last-child { border-bottom: 0; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin-bottom: 1rem; padding: 0.85rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.filter-bar label, .stack-form label, .form-grid label, .inline-form label { color: var(--muted); font-size: 0.83rem; font-weight: 700; }
.filter-bar label { display: flex; min-width: 9rem; flex: 1 1 9rem; flex-direction: column; gap: 0.3rem; }
input, select, textarea { width: 100%; min-height: 2.5rem; border: 1px solid var(--border-strong); border-radius: 0.35rem; padding: 0.48rem 0.58rem; color: var(--text); background: #0f151d; }
textarea { resize: vertical; }
input::placeholder { color: #718095; }
.stack-form { display: flex; flex-direction: column; gap: 0.55rem; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 0.5rem; align-items: end; margin-top: 1rem; }
.inline-form label { grid-column: 1 / -1; }
.narrow-form, .auth-panel { width: min(100%, 32rem); }
.auth-panel { margin: 8vh auto 0; padding: 1.5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }

.table-panel { overflow: hidden; }
.table-summary { padding: 0.7rem 1rem; color: var(--muted); border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.bulk-bar { display: grid; grid-template-columns: auto minmax(9rem, 0.6fr) minmax(12rem, 1fr) auto; gap: 0.65rem; align-items: end; padding: 0.7rem 1rem; border-bottom: 1px solid var(--border); background: #111820; }
.bulk-bar strong { align-self: center; }
.bulk-bar label { display: flex; flex-direction: column; gap: 0.25rem; color: var(--muted); font-size: 0.76rem; font-weight: 700; }
.selection-label { display: inline-flex; align-items: center; }
.selection-label input { width: 1.15rem; min-height: 1.15rem; margin: 0; accent-color: var(--accent); }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th { color: var(--muted); background: #111820; font-size: 0.76rem; letter-spacing: 0.035em; text-align: left; text-transform: uppercase; }
th, td { padding: 0.75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgb(255 255 255 / 0.018); }
td strong, td > span { display: block; }
td > span + span { margin-top: 0.2rem; color: var(--muted); font-size: 0.82rem; }
.pagination { display: grid; grid-template-columns: 1fr auto 1fr; gap: 1rem; align-items: center; padding: 0.85rem 1rem; border-top: 1px solid var(--border); font-size: 0.9rem; }
.pagination a:last-child { justify-self: end; }
.pagination > span { color: var(--muted); }

.badge-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.badge { display: inline-flex; width: fit-content; gap: 0.35rem; align-items: center; border: 1px solid var(--border); border-radius: 999px; padding: 0.16rem 0.5rem; color: var(--muted); background: var(--surface-raised); font-size: 0.76rem; font-weight: 700; white-space: nowrap; }
.badge-success, .badge-succeeded, .badge-done, .badge-already_present { color: #9ae9bb; border-color: #2c6849; }
.badge-warning, .badge-new, .badge-paused_budget, .badge-ignored_until { color: #f1ce87; border-color: #725d30; }
.badge-danger, .badge-failed, .badge-wrong_artist { color: #ffaaaa; border-color: #743d43; }
.badge-running, .badge-in_progress, .badge-confirmed_missing { color: #a8d2ff; border-color: #355f8c; }
.badge-muted, .badge-queued, .badge-cancelled, .badge-ignored_permanently { color: #b0bac7; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(18rem, 0.85fr); gap: 1rem; align-items: start; }
.content-column, .action-column { min-width: 0; }
.action-column { position: sticky; top: 1rem; }
.definition-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.75rem; }
.definition-grid div, .definition-list div, .budget-summary div { padding: 0.65rem; border: 1px solid var(--border); border-radius: 0.4rem; background: #111820; }
dt { color: var(--muted); font-size: 0.76rem; font-weight: 700; text-transform: uppercase; }
dd { margin: 0.2rem 0 0; overflow-wrap: anywhere; }
.definition-list, .budget-summary { display: grid; gap: 0.5rem; margin: 0; }
.tracklist { padding-left: 1.5rem; columns: 2; }
.source-evidence { margin: 0; padding: 0; list-style: none; }
.source-evidence > li { padding: 0.8rem 0; border-bottom: 1px solid var(--border); }
.source-evidence > li:last-child { border-bottom: 0; }
.source-evidence ul { margin: 0.45rem 0; color: var(--muted); }
.notes-list { padding-left: 1.2rem; }
.timeline { margin: 0; padding: 0 0 0 1rem; border-left: 1px solid var(--border-strong); list-style: none; }
.timeline li { position: relative; margin-bottom: 1rem; }
.timeline li::before { position: absolute; top: 0.35rem; left: -1.32rem; width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--accent); content: ""; }
.timeline span { display: block; color: var(--muted); font-size: 0.78rem; }
.timeline p { margin: 0.25rem 0 0; font-size: 0.88rem; }
.action-panel { display: flex; gap: 1rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.action-panel > div:first-child { max-width: 35rem; }
.action-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: end; }
.run-steps { margin: 1rem 0 0; padding: 0; list-style: none; }
.run-steps li { display: flex; gap: 1rem; align-items: center; justify-content: space-between; padding: 0.65rem 0; border-bottom: 1px solid var(--border); }
.error-log { overflow-x: auto; margin-bottom: 0; padding: 0.8rem; color: #ffc2c2; border: 1px solid #743d43; border-radius: 0.4rem; background: #1c1215; white-space: pre-wrap; overflow-wrap: anywhere; }
.error-text { color: var(--danger); overflow-wrap: anywhere; }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.settings-grid .panel { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.8rem; margin-top: 1rem; }
.form-grid label { display: flex; flex-direction: column; gap: 0.3rem; }
.form-grid label span { color: var(--muted); font-size: 0.78rem; font-weight: 400; }
.wide-field { grid-column: 1 / -1; }
.budget-summary { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-top: 1rem; }
code { padding: 0.12rem 0.25rem; border-radius: 0.25rem; background: #0b1016; overflow-wrap: anywhere; }
.empty-state { padding: 1rem; color: var(--muted); text-align: center; }
[role="alert"] { padding: 0.75rem; color: #ffd0d0; border: 1px solid #743d43; border-radius: 0.4rem; background: #28171b; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 72rem) {
  .site-header { grid-template-columns: auto 1fr; }
  .primary-nav { grid-column: 1 / -1; grid-row: 2; }
  .account-actions { justify-self: end; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .budget-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 52rem) {
  main { width: min(100% - 1rem, 96rem); }
  .site-header { gap: 0.65rem; padding-inline: 0.75rem; }
  .quiet-link { display: none; }
  .page-heading, .action-panel, .budget-line { align-items: stretch; flex-direction: column; }
  .detail-grid, .settings-grid { grid-template-columns: 1fr; }
  .bulk-bar { grid-template-columns: 1fr 1fr; }
  .action-column { position: static; }
  .action-buttons { justify-content: start; }
  .table-scroll { overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  tbody { padding: 0.55rem; }
  tbody tr { margin-bottom: 0.65rem; padding: 0.35rem; border: 1px solid var(--border); border-radius: 0.45rem; background: #111820; }
  tbody tr:last-child { margin-bottom: 0; }
  tbody td { display: grid; grid-template-columns: minmax(7rem, 0.42fr) minmax(0, 1fr); gap: 0.65rem; padding: 0.45rem; border-bottom: 1px solid var(--border); }
  tbody td:last-child { border-bottom: 0; }
  tbody td::before { color: var(--muted); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.03em; text-transform: uppercase; content: attr(data-label); }
  tbody td[colspan] { display: block; }
  tbody td[colspan]::before { content: none; }
  .pagination { grid-template-columns: 1fr 1fr; }
  .pagination > span { display: none; }
  .definition-grid, .form-grid { grid-template-columns: 1fr; }
  .wide-field { grid-column: auto; }
  .budget-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 34rem) {
  .brand span:last-child { font-size: 0.95rem; }
  .account-actions .button-quiet { font-size: 0.78rem; }
  .primary-nav { margin-inline: -0.75rem; padding: 0 0.75rem 0.2rem; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 7rem; }
  .filter-bar { align-items: stretch; flex-direction: column; }
  .bulk-bar { display: flex; align-items: stretch; flex-direction: column; }
  .filter-bar label { width: 100%; }
  .filter-bar button, .filter-bar .button-link, .action-buttons form, .action-buttons button { width: 100%; }
  .inline-form { grid-template-columns: 1fr; }
  .inline-form label { grid-column: auto; }
  .tracklist { columns: 1; }
  .budget-summary { grid-template-columns: 1fr; }
  tbody td { grid-template-columns: 1fr; gap: 0.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
