/* FlowMusic API control room — Anthropic/Claude palette.
   Warm paper background, near-black type, terracotta accent, serif headings.
   No build step, no external fonts, no framework. */

:root {
  /* Claude surface tokens */
  --paper: #f0efea;
  --surface: #ffffff;
  --surface-sunken: #e8e6e0;
  --ink: #191919;
  --ink-mid: #3d3d3a;
  --ink-soft: #666666;
  --ink-faint: #8c8b86;
  --line: #d1d1d1;
  --line-soft: #e3e1db;
  --accent: #d0684e;
  --accent-deep: #b4543c;
  --accent-wash: #f7ebe6;
  --success: #3f7d5c;
  --success-wash: #e8f0eb;
  --warn: #a97a24;
  --warn-wash: #f6efdf;
  --danger: #b04a3f;
  --danger-wash: #f8e9e6;

  --radius-lg: 16px;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(25, 25, 25, 0.04);
  --shadow-md: 0 2px 10px rgba(25, 25, 25, 0.06);
  --shadow-lg: 0 18px 48px rgba(25, 25, 25, 0.12);

  --serif: "Noto Serif", "Iowan Old Style", "Palatino Linotype", Georgia, "Songti SC", serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Restrained paper texture: one soft warm highlight, no glow. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(900px 420px at 50% -12%, rgba(255, 255, 255, 0.85), transparent 70%);
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--paper); }
::-webkit-scrollbar-thumb { background: #cdcac2; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #b3afa6; }

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 60;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: #fbfaf7;
  font-size: 12px;
  text-decoration: none;
}
.skip-link:focus-visible { left: 16px; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 28px;
  background: rgba(240, 239, 234, 0.88);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 26px; height: 26px; color: var(--accent); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong {
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.brand-text span {
  color: var(--ink-faint);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.topbar-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  font-size: 12px;
  color: var(--ink-mid);
  max-width: 300px;
}
.pill-label {
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 9.5px;
}
#credits-value { color: var(--ink); font-variant-numeric: tabular-nums; font-weight: 500; }
#session-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); }
.dot.ok { background: var(--success); }
.dot.bad { background: var(--danger); }

/* --------------------------------------------------------------- controls */
.ghost-btn,
.primary-btn,
.icon-btn,
.seg-btn {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.ghost-btn {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-mid);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
}
.ghost-btn:hover { border-color: var(--ink-faint); color: var(--ink); }

.primary-btn {
  padding: 10px 24px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fbfaf7;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.01em;
}
.primary-btn:hover { background: #333330; border-color: #333330; }
.primary-btn:disabled { opacity: 0.45; cursor: progress; }

.icon-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 17px;
  line-height: 1;
}
.icon-btn:hover { color: var(--ink); border-color: var(--ink-faint); }

/* ------------------------------------------------------------------ layout */
.layout {
  position: relative;
  z-index: 1;
  max-width: 1320px;
  margin: 0 auto;
  padding: 26px 28px 88px;
  display: grid;
  gap: 18px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.stat-label {
  margin: 0 0 8px;
  font-size: 10px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.stat-value {
  margin: 0;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat-value small { font-size: 12px; font-family: var(--sans); color: var(--ink-faint); margin-left: 3px; font-weight: 400; }
.stat-value.is-ok { color: var(--success); }
.stat-value.is-warn { color: var(--warn); }
.stat-value.is-bad { color: var(--danger); }
.stat-foot { margin: 6px 0 0; font-size: 11px; color: var(--ink-faint); }

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.panel-hint { color: var(--ink-soft); font-size: 12px; }

/* ---------------------------------------------------------------- composer */
.composer { padding: 18px 22px 22px; display: grid; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.grow { grid-column: 1 / -1; }
.field.narrow { max-width: 88px; }
.field-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 14px; align-items: end; }
.field-row .switch { align-self: center; }

.field label {
  font-size: 10.5px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 500;
}
.muted { color: var(--ink-faint); text-transform: none; letter-spacing: 0; font-weight: 400; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fbfaf7;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}
textarea { resize: vertical; min-height: 46px; line-height: 1.55; }
input:focus, select:focus, textarea:focus {
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(208, 104, 78, 0.14);
}
::placeholder { color: #a8a59e; }

.switch { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-mid); cursor: pointer; }
.switch input { width: auto; accent-color: var(--accent); }

.composer-actions { display: flex; align-items: center; gap: 16px; }
.form-status { font-size: 12px; color: var(--ink-soft); }
.form-status.error { color: var(--danger); }
.form-status.ok { color: var(--success); }

/* ------------------------------------------------------------------- tasks */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-sunken);
}
.seg-btn {
  padding: 5px 14px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 500;
}
.seg-btn:hover { color: var(--ink); }
.seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

.search { width: 220px; height: 30px; font-size: 12px; border-radius: 999px; padding: 0 14px; }

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.25;
  transition: opacity 0.2s ease;
}
.live-dot.pulse { opacity: 1; }

.task-list { display: flex; flex-direction: column; }

.task-row {
  display: grid;
  grid-template-columns: 1.6fr 104px 180px 112px 88px;
  gap: 16px;
  align-items: center;
  padding: 13px 22px;
  border-bottom: 1px solid var(--line-soft);
  cursor: pointer;
  transition: background 0.14s ease;
}
.task-row:last-child { border-bottom: none; }
.task-row:hover { background: #faf9f6; }
.task-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

.task-main { min-width: 0; }
.task-prompt {
  margin: 0;
  font-size: 13px;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.task-sub {
  margin: 3px 0 0;
  font-size: 11px;
  color: var(--ink-faint);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  background: var(--surface-sunken);
  white-space: nowrap;
}
.badge.completed { color: var(--success); border-color: #c3d8ca; background: var(--success-wash); }
.badge.failed { color: var(--danger); border-color: #e2c4bf; background: var(--danger-wash); }
.badge.running { color: var(--accent-deep); border-color: #e6c8be; background: var(--accent-wash); }
.badge.queued { color: var(--warn); border-color: #e3d5b8; background: var(--warn-wash); }
.badge.needs_input { color: #7a5a9e; border-color: #d9cbe6; background: #f3eefa; }

.bar {
  position: relative;
  height: 4px;
  border-radius: 999px;
  background: var(--surface-sunken);
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--ink-mid);
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.bar.is-done > span { background: var(--success); }
.bar.is-failed > span { background: var(--danger); }
.bar.is-idle > span { background: #c9c6be; }
.bar.is-active > span { background: var(--accent); }

.task-stage { display: flex; flex-direction: column; gap: 6px; }
.task-stage-label {
  font-size: 11px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.task-meta {
  font-size: 11px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.empty-state { padding: 32px 22px; margin: 0; color: var(--ink-faint); font-size: 13px; text-align: center; }

/* ------------------------------------------------------------------ drawer */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(25, 25, 25, 0.24);
  z-index: 30;
}
.drawer[hidden],
.scrim[hidden] { display: none !important; }

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(580px, 100vw);
  z-index: 40;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  animation: slide-in 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--line-soft);
}
.drawer-kicker {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-family: var(--mono);
}
.drawer-head h2 {
  margin: 5px 0 0;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.01em;
}

.drawer-body { padding: 20px 22px 36px; overflow-y: auto; display: grid; gap: 20px; align-content: start; }
.drawer-body h3 {
  margin: 4px 0 0;
  font-size: 10.5px;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 600;
}

.drawer-progress { display: grid; gap: 8px; }
.drawer-progress .bar { height: 6px; }
.drawer-progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.kv { display: grid; grid-template-columns: 118px 1fr; gap: 7px 16px; margin: 0; font-size: 12px; }
.kv dt { color: var(--ink-faint); }
.kv dd { margin: 0; color: var(--ink-mid); font-family: var(--mono); font-size: 11.5px; word-break: break-all; }

.event-log { margin: 0; padding: 0; list-style: none; display: grid; gap: 5px; max-height: 240px; overflow-y: auto; }
.event-log li {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  padding: 7px 11px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: #fbfaf7;
  font-size: 11px;
  font-family: var(--mono);
  color: var(--ink-soft);
}
.event-log li .seq { color: var(--ink-faint); }
.event-log li .etype { color: var(--ink-mid); }
.event-log li .etype.progress { color: var(--accent-deep); }
.event-log li .etype.terminal { color: var(--success); font-weight: 600; }

.song-list { display: grid; gap: 8px; }
.song-card {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 13px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: #fbfaf7;
}
.song-cover { width: 48px; height: 48px; border-radius: 7px; background: var(--surface-sunken); object-fit: cover; }
.song-title { margin: 0; font-size: 13px; font-weight: 500; }
.song-meta { margin: 3px 0 0; font-size: 11px; color: var(--ink-faint); font-family: var(--mono); }
.song-actions { display: flex; gap: 6px; }
.song-actions a {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 11px;
  background: var(--surface);
}
.song-actions a:hover { color: var(--ink); border-color: var(--ink-faint); }

.raw {
  margin: 0;
  padding: 13px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: #fbfaf7;
  color: var(--ink-soft);
  font-family: var(--mono);
  font-size: 11px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ------------------------------------------------------------------ dialog */
.key-dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  padding: 0;
  width: min(420px, 92vw);
  box-shadow: var(--shadow-lg);
}
.key-dialog::backdrop { background: rgba(25, 25, 25, 0.28); }
.key-dialog form { padding: 24px; display: grid; gap: 14px; }
.key-dialog h2 { margin: 0; font-family: var(--serif); font-size: 18px; font-weight: 700; }
.key-dialog p { margin: 0; font-size: 12px; color: var(--ink-soft); }
.key-dialog code { font-family: var(--mono); color: var(--accent-deep); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ------------------------------------------------------------------ toast */
.toast-stack { position: fixed; right: 22px; bottom: 22px; z-index: 60; display: grid; gap: 8px; }
.toast {
  min-width: 250px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 12px;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.2s ease;
}
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }

/* -------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .task-row { grid-template-columns: 1.5fr 96px 156px 88px; }
  .task-meta.hide-md { display: none; }
}

@media (max-width: 860px) {
  .topbar { flex-direction: column; align-items: flex-start; gap: 12px; padding: 14px 18px; }
  .layout { padding: 18px 16px 72px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .task-row { grid-template-columns: 1fr 88px; gap: 8px 14px; }
  .task-row .task-stage,
  .task-row .task-meta { grid-column: 1 / -1; text-align: left; }
  .toolbar { width: 100%; }
  .search { width: 100%; }
  .drawer { width: 100vw; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
