/* =========================================================================
   Songcraft — app.css
   Design tokens + shell layout + component library.
   Governing doc: /root/songcraft/design-system/MASTER.md
   RULE: no hardcoded color outside the :root[data-theme] blocks below.
   ========================================================================= */

/* ---------------------------------------------------------------------
   1. TOKENS
   --------------------------------------------------------------------- */

:root {
  /* base spacing unit (4/8px rhythm) + derived scale */
  --space: 4px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --space-8: 64px;

  /* type scale (px, per contract) */
  --text-xs: 12px;
  --text-sm: 14px;
  --text-base: 16px;
  --text-lg: 18px;
  --text-xl: 24px;
  --text-2xl: 32px;

  /* shape */
  --radius: 8px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  /* type family */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  /* motion: transform/opacity only, 150-300ms window */
  --transition: 180ms cubic-bezier(.2,.7,.3,1);
  --transition-slow: 260ms cubic-bezier(.2,.7,.3,1);

  /* layout constants */
  --header-h: 64px;
  --bottomnav-h: 64px;
  --sidebar-w: 240px;
  --content-max: 1200px;

  /* stacking */
  --z-header: 30;
  --z-nav: 30;
  --z-overlay: 40;
  --z-drawer: 50;
  --z-toast: 60;
}

/* Dark theme — DEFAULT */
:root,
:root[data-theme="dark"] {
  --bg: #0A0A0D;
  --surface: #141318;
  --surface-2: #1D1B24;
  --border: #322F3B;
  --text: #F4F3F6;
  --text-dim: #B4AFC0;
  --primary: #F5D90A;
  --primary-ink: #14121A;
  --accent: #FF4D8D;
  --danger: #FF5C5C;
  --success: #34D399;
  --warn: #FFB020;
  --focus: var(--accent);
  --shadow: 0 12px 32px rgba(0,0,0,.55);
  --overlay-bg: rgba(6,6,8,.72);
  --skeleton-shine: rgba(255,255,255,.06);
  color-scheme: dark;
}

/* Light theme */
:root[data-theme="light"] {
  --bg: #F7F5F2;
  --surface: #FFFFFF;
  --surface-2: #EFEBE4;
  --border: #D8D2C8;
  --text: #16141C;
  --text-dim: #55505F;
  --primary: #F5D90A;
  --primary-ink: #14121A;
  --accent: #C41E68;
  --danger: #B0233C;
  --success: #08633F;
  --warn: #8F5700;
  --focus: var(--accent);
  --shadow: 0 12px 32px rgba(22,20,28,.12);
  --overlay-bg: rgba(22,20,28,.45);
  --skeleton-shine: rgba(22,20,28,.06);
  color-scheme: light;
}

/* ---------------------------------------------------------------------
   2. RESET / BASE
   --------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html, body, div, span, h1, h2, h3, h4, h5, h6, p, ul, ol, li,
form, fieldset, table, th, td, figure { margin: 0; padding: 0; }
ul, ol { list-style: none; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden; /* belt + suspenders: components own their own scroll */
}

h1, h2, h3, h4 { font-weight: 800; letter-spacing: -0.01em; line-height: 1.15; }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); line-height: 1.25; }
h3 { font-size: var(--text-lg); font-weight: 700; line-height: 1.3; }
p  { line-height: 1.65; }

small, .text-sm { font-size: var(--text-sm); line-height: 1.5; }
.text-xs { font-size: var(--text-xs); line-height: 1.5; }
.text-dim { color: var(--text-dim); }

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

/* Focus visibility: never on plain :focus, always on :focus-visible */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--focus) 25%, transparent);
  border-radius: var(--radius);
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  display: inline-block;
  vertical-align: -0.2em;
  color: currentColor;
}
.icon-lg { width: 28px; height: 28px; }
.icon-xl { width: 48px; height: 48px; }

/* ---------------------------------------------------------------------
   3. APP SHELL LAYOUT
   --------------------------------------------------------------------- */

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---- Header ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 0 var(--space-4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand .brand-dot {
  width: 10px; height: 10px;
  border-radius: 999px;
  background: var(--primary);
  flex: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* ---- Body row: sidebar + main ---- */
.app-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

.app-sidebar {
  display: none;
  width: var(--sidebar-w);
  flex: none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--space-4) var(--space-3);
}

.app-main {
  flex: 1;
  min-width: 0;
}

#view {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-4);
  padding-bottom: calc(var(--bottomnav-h) + var(--space-6));
}

/* ---- Nav items (shared visual language for sidebar + bottom nav) ---- */
.nav-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: var(--text-sm);
  font-weight: 600;
  border-left: 3px solid transparent;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-left-color: var(--accent);
}
.nav-item .icon { color: inherit; }

/* ---- Bottom nav (<768px) ---- */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: var(--z-nav);
  height: var(--bottomnav-h);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav .nav-item {
  flex: 1;
  flex-direction: column;
  gap: var(--space-1);
  justify-content: center;
  border-left: none;
  border-top: 3px solid transparent;
  border-radius: 0;
  text-align: center;
  font-size: var(--text-xs);
  min-height: 44px;
}
.bottom-nav .nav-item.is-active {
  background: transparent;
  border-top-color: var(--accent);
}
.bottom-nav .nav-item .icon { margin: 0 auto; }

/* ≥768px: hide bottom nav, but sidebar not yet shown (transitional zone) */
@media (min-width: 768px) {
  .bottom-nav { display: none; }
  #view { padding: var(--space-5); padding-bottom: var(--space-6); }
}

/* ≥1024px: sidebar layout */
@media (min-width: 1024px) {
  .app-sidebar { display: block; }
  #view { padding: var(--space-6); }
}

@media (min-width: 1440px) {
  #view { padding: var(--space-7) var(--space-6); }
}

/* ---------------------------------------------------------------------
   4. THEME TOGGLE
   --------------------------------------------------------------------- */

.theme-toggle {
  position: relative;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
  flex: none;
}
.theme-toggle:hover { background: var(--border); }
.theme-toggle:active { transform: scale(.94); }
.theme-toggle .icon { color: var(--text); }
.theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

/* ---------------------------------------------------------------------
   5. BUTTONS
   --------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  background: transparent;
  transition: background var(--transition), border-color var(--transition), transform var(--transition), opacity var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-ink);
}
.btn-primary:hover { filter: brightness(1.06); }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }

.btn-sm { min-height: 36px; padding: var(--space-1) var(--space-3); font-size: var(--text-sm); }
.btn-icon { min-width: 44px; padding: 0; }
.btn-block { width: 100%; }

/* ---------------------------------------------------------------------
   6. FORMS
   --------------------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
}

.field-label {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text);
}
.field-label .req { color: var(--danger); margin-left: var(--space-1); }

.field-input,
.field-select,
.field-textarea {
  min-height: 44px;
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-base);
  font-family: var(--font-sans);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field-textarea { min-height: 120px; resize: vertical; line-height: 1.6; padding-top: var(--space-3); }
.field-input::placeholder,
.field-textarea::placeholder { color: var(--text-dim); opacity: .8; }

.field-input:hover, .field-select:hover, .field-textarea:hover { border-color: var(--text-dim); }
.field-input:focus-visible,
.field-select:focus-visible,
.field-textarea:focus-visible {
  border-color: var(--focus);
}

.field-hint { font-size: var(--text-xs); color: var(--text-dim); }
.field-error { font-size: var(--text-xs); color: var(--danger); font-weight: 600; }
.field.has-error .field-input,
.field.has-error .field-select,
.field.has-error .field-textarea { border-color: var(--danger); }

.field-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}
@media (min-width: 768px) {
  .field-row.cols-2 { grid-template-columns: 1fr 1fr; }
  .field-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
}

/* checkbox / radio: keep native but size the hit target */
.field-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  font-size: var(--text-sm);
}
.field-check input[type="checkbox"],
.field-check input[type="radio"] {
  width: 20px; height: 20px;
  accent-color: var(--accent);
  flex: none;
}

/* ---------------------------------------------------------------------
   7. CARDS
   --------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.card-raised { box-shadow: var(--shadow); }
.card-hover { transition: transform var(--transition), box-shadow var(--transition); }
.card-hover:hover { transform: translateY(-2px); box-shadow: var(--shadow); }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}
.card-title { font-size: var(--text-lg); font-weight: 700; }
.card-body { color: var(--text-dim); font-size: var(--text-sm); line-height: 1.6; }

.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}
@media (min-width: 768px) {
  .card-grid.cols-2 { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1024px) {
  .card-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
  .card-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ---------------------------------------------------------------------
   8. CHIPS / TAGS / BADGES
   --------------------------------------------------------------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 26px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}

.chip-accent  { color: var(--accent);  background: color-mix(in srgb, var(--accent) 16%, var(--surface));  border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.chip-success { color: var(--success); background: color-mix(in srgb, var(--success) 16%, var(--surface)); border-color: color-mix(in srgb, var(--success) 40%, var(--border)); }
.chip-warn    { color: var(--warn);    background: color-mix(in srgb, var(--warn) 16%, var(--surface));    border-color: color-mix(in srgb, var(--warn) 40%, var(--border)); }
.chip-danger  { color: var(--danger);  background: color-mix(in srgb, var(--danger) 16%, var(--surface));  border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

/* filterable chip acting as a tappable control needs full touch target */
button.chip { min-height: 44px; cursor: pointer; transition: background var(--transition), color var(--transition); }

/* ---------------------------------------------------------------------
   9. KANBAN (Pipeline)
   --------------------------------------------------------------------- */

.kanban {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x proximity;
  padding-bottom: var(--space-3);
  margin: 0 calc(var(--space-4) * -1);
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

.kanban-col {
  flex: none;
  width: 280px;
  scroll-snap-align: start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--header-h) - var(--space-8));
}

.kanban-col-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border);
  font-size: var(--text-sm);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-dim);
}

.kanban-col-body {
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  overflow-y: auto;
}

.kanban-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  cursor: grab;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.kanban-card:hover { border-color: var(--text-dim); box-shadow: var(--shadow); }
.kanban-card:active { cursor: grabbing; transform: scale(.98); }

.kanban-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.kanban-card-title { font-size: var(--text-sm); font-weight: 700; line-height: 1.4; }
.kanban-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-dim);
}
.kanban-card .drag-handle { color: var(--text-dim); flex: none; cursor: grab; }

/* ---------------------------------------------------------------------
   10. DRAWER / MODAL
   --------------------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-overlay);
  background: var(--overlay-bg);
  opacity: 0;
  animation: overlay-in var(--transition-slow) forwards;
}
@keyframes overlay-in { to { opacity: 1; } }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  z-index: var(--z-drawer);
  width: min(420px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  animation: drawer-in var(--transition-slow) forwards;
}
@keyframes drawer-in { to { transform: translateX(0); } }

.modal {
  position: fixed;
  top: 50%; left: 50%;
  z-index: var(--z-drawer);
  width: min(560px, calc(100vw - var(--space-6)));
  max-height: calc(100vh - var(--space-8));
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%,-50%) scale(.96);
  animation: modal-in var(--transition-slow) forwards;
}
@keyframes modal-in { to { opacity: 1; transform: translate(-50%,-50%) scale(1); } }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.panel-head h2 { font-size: var(--text-lg); }
.panel-body { padding: var(--space-4); overflow-y: auto; flex: 1; }
.panel-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4);
  border-top: 1px solid var(--border);
  flex: none;
}

/* ---------------------------------------------------------------------
   11. TABLES
   --------------------------------------------------------------------- */

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  min-width: 560px;
}
.table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  text-align: left;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------------
   12. EMPTY STATES
   --------------------------------------------------------------------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-3);
  padding: var(--space-8) var(--space-4);
  color: var(--text-dim);
}
.empty-state .icon { color: var(--text-dim); }
.empty-state h3 { color: var(--text); font-size: var(--text-lg); }
.empty-state p { max-width: 42ch; font-size: var(--text-sm); }

/* ---------------------------------------------------------------------
   13. SKELETON LOADER
   --------------------------------------------------------------------- */

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius);
  background-image: linear-gradient(
    90deg,
    transparent 0%,
    var(--skeleton-shine) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shine 1.4s ease-in-out infinite;
}
@keyframes skeleton-shine {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}
.skeleton-line { height: 14px; margin-bottom: var(--space-2); }
.skeleton-line.w-60 { width: 60%; }
.skeleton-line.w-40 { width: 40%; }
.skeleton-card { height: 96px; border-radius: var(--radius-lg); }

/* ---------------------------------------------------------------------
   14. MISC UTILITIES
   --------------------------------------------------------------------- */

.stack { display: flex; flex-direction: column; }
.cluster { display: flex; align-items: center; flex-wrap: wrap; }
.gap-1 { gap: var(--space-1); } .gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); } .gap-4 { gap: var(--space-4); }
.mt-2 { margin-top: var(--space-2); } .mt-4 { margin-top: var(--space-4); }
.mb-2 { margin-bottom: var(--space-2); } .mb-4 { margin-bottom: var(--space-4); }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.text-right { text-align: right; }

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}
.page-head h1 { margin-bottom: var(--space-1); }
.page-head .lede { color: var(--text-dim); font-size: var(--text-sm); }

.error-banner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--danger) 40%, var(--border));
  color: var(--danger);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-weight: 600;
}
