/* Kids Jukebox parent UI. Dark design system ported from Foundry (nib-factory). Page-only rules live in the
   .razor.css file next to each component; the simulator frame is in Simulator.razor.css. */
:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --surface-1: #11141b;
  --surface-2: #171b24;
  --surface-3: #1e2330;
  --border: #232836;
  --border-strong: #323948;
  --text: #e8eaf0;
  --muted: #8b92a5;
  /* Coral accent: warmer than Foundry's teal, still about 8:1 against the background with dark ink on top. */
  --accent: #ff8f5a;
  --accent-ink: #1a0e07;
  --accent-bg: color-mix(in srgb, var(--accent) 12%, var(--surface-1));
  --ok: #4cc38a;
  --warn: #f0c05a;
  --error: #ef6b6b;
  --info: #8fb8ff;
  --violet: #b9a4ff;
  --ok-bg: color-mix(in srgb, var(--ok) 12%, var(--surface-1));
  --warn-bg: color-mix(in srgb, var(--warn) 12%, var(--surface-1));
  --error-bg: color-mix(in srgb, var(--error) 12%, var(--surface-1));
  --info-bg: color-mix(in srgb, var(--info) 12%, var(--surface-1));
  --violet-bg: color-mix(in srgb, var(--violet) 14%, var(--surface-1));
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; background: var(--bg); color: var(--text); }
body { font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1[tabindex="-1"]:focus { outline: none; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

h1, h2, h3 { color: var(--text); font-weight: 600; letter-spacing: -0.012em; line-height: 1.25; margin: 0; }
h1 { font-size: 24px; letter-spacing: -0.02em; margin: 2px 0 6px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
p { margin: 0.5em 0; }
small { color: var(--muted); font-size: 12.5px; }
ul, ol { padding-left: 1.2em; }

.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; color: var(--muted); margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono, code, pre, kbd { font-family: var(--font-mono); font-size: 12px; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; padding: 0.08em 0.35em; overflow-wrap: anywhere; }
pre { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin: 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; opacity: 0; }

/* Buttons */
button, .button {
  font: inherit; font-size: 13px; font-weight: 500; line-height: 1.2;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 7px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
button:hover, .button:hover { background: var(--surface-3); text-decoration: none; }
button:disabled, .button:disabled { opacity: 0.5; cursor: not-allowed; background: var(--surface-2); }
button.primary, .button.primary, .primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600;
}
button.primary:hover, .button.primary:hover, .primary:hover { background: color-mix(in srgb, var(--accent) 88%, white); }
.danger-outline, button.danger-outline, .button.danger-outline {
  background: transparent; color: var(--error);
  border-color: color-mix(in srgb, var(--error) 50%, var(--border));
}
.danger-outline:hover:not(:disabled) { background: var(--error-bg); }
.icon-button { width: 34px; min-width: 34px; height: 34px; min-height: 0; padding: 0; }
.icon-button .icon { width: 16px; height: 16px; }
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* Forms. Inputs take full width unless a class says otherwise; :where keeps that overridable. */
label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; font-weight: 500; min-width: 0; }
label:has(> input[type="checkbox"]), label:has(> input[type="radio"]) { display: flex; align-items: center; gap: 8px; color: var(--text); }
input, select, textarea {
  font: inherit; font-size: 14px; line-height: 1.4; color: var(--text);
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 7px 10px; min-height: 34px; min-width: 0; max-width: 100%;
}
:where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea) { width: 100%; }
select { padding-right: 28px; }
textarea { min-height: 88px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
input:disabled, select:disabled, textarea:disabled { opacity: 0.6; cursor: not-allowed; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; min-height: 0; margin: 0; padding: 0; accent-color: var(--accent); flex: none; }
input.switch {
  appearance: none; -webkit-appearance: none; width: 36px; height: 20px; min-height: 0; margin: 0; padding: 0; flex: none;
  position: relative; border-radius: 999px; background: var(--surface-3); border: 1px solid var(--border-strong); cursor: pointer;
}
input.switch::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); transition: transform 0.15s ease;
}
input.switch:checked { background: var(--accent); border-color: var(--accent); }
input.switch:checked::before { transform: translateX(16px); background: var(--accent-ink); }
input.switch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field > span { color: var(--muted); font-size: 13px; font-weight: 500; }
.field > small { font-size: 12px; line-height: 1.45; }
.field > input, .field > select { align-self: start; }
.field.grow { flex: 1 1 260px; }
.settings-form { display: grid; gap: 16px; }
.key-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.device-key-value { flex: 1 1 260px; min-width: 0; padding: 7px 10px; font-size: 13px; word-break: break-all; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px 12px; align-items: flex-end; }
.inline-form > button { flex: none; }
.switch-row { display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

/* Shell: fixed sidebar, sticky header with breadcrumb, content column */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 216px; z-index: 5;
  display: flex; flex-direction: column; gap: 2px; padding: 16px 10px;
  background: var(--surface-1); border-right: 1px solid var(--border); overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-size: 15px; font-weight: 650; letter-spacing: -0.01em; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 55%, var(--violet)));
  color: var(--accent-ink);
}
.brand-mark .icon { width: 14px; height: 14px; stroke-width: 2.2; }
.navgroup { font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; color: var(--muted); padding: 14px 10px 6px; }
.sidebar a:not(.brand) {
  display: flex; align-items: center; gap: 10px; min-height: 32px; padding: 6px 10px;
  border-radius: var(--radius-sm); color: var(--muted); font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar a:not(.brand):hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar a.active { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.sidebar a.active .icon { color: var(--accent); }
.sidebar a > span:not(.status-dot) { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sidebar .status-dot { margin: 0 2px 0 4px; }
.count {
  margin-left: auto; min-width: 20px; height: 18px; padding: 0 6px; border-radius: 999px;
  background: var(--accent-bg); color: var(--accent); font-size: 11px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.sidefoot { margin-top: auto; border-top: 1px solid var(--border); padding: 14px 10px 6px; font-size: 12px; color: var(--text); line-height: 1.45; }
.sidefoot span { color: var(--muted); }

main { margin-left: 216px; min-width: 0; }
header {
  position: sticky; top: 0; z-index: 3; height: 52px;
  display: flex; align-items: center; gap: 14px; padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px);
}
.crumb { flex: 1 1 auto; min-width: 0; font-size: 13px; color: var(--muted); }
.crumb ol { display: flex; align-items: center; gap: 0; margin: 0; padding: 0; list-style: none; min-width: 0; overflow: hidden; white-space: nowrap; }
.crumb li { display: inline-flex; align-items: center; min-width: 0; }
.crumb li + li::before { content: "/"; padding: 0 8px; color: var(--border-strong); }
.crumb li:last-child { min-width: 0; color: var(--text); font-weight: 500; }
.crumb li:last-child > span { display: block; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumb li:not(:last-child) a { color: var(--muted); }
.env { font-size: 11px; letter-spacing: 0.03em; padding: 4px 9px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); white-space: nowrap; }
.menu-toggle, .header-brand { display: none; }
.menu-toggle { flex: none; align-items: center; justify-content: center; width: 34px; height: 34px; min-height: 0; padding: 0; border-radius: var(--radius-sm); }
.menu-toggle .icon { width: 18px; height: 18px; }
.header-brand { padding: 0; font-size: 14px; }
.header-brand .brand-mark { width: 20px; height: 20px; border-radius: 6px; }
.header-brand .brand-mark .icon { width: 12px; height: 12px; }
.content { padding: 28px 32px 56px; max-width: 1240px; margin: 0 auto; }
.content > .notice:first-child { margin-top: 0; }

/* Page heads, sections and panels */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap; margin: 4px 0 20px; }
.page-head > div { min-width: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); max-width: 64ch; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.panel { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; min-width: 0; }
.section { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-bottom: 16px; align-content: start; }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px 16px; flex-wrap: wrap; }
.section-head h2 { margin: 0 0 4px; }
.section-head p { margin: 0; color: var(--muted); font-size: 13px; max-width: 70ch; }
.section-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.empty { margin: 0; color: var(--muted); }
.empty-state { display: grid; gap: 6px; justify-items: start; }
.empty-state h2 { margin: 0; }
.empty-state p { margin: 0; }

/* Tables: wrap in .table-scroll so wide tables scroll sideways on phones */
.table-scroll { position: relative; overflow-x: auto; max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-1); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--surface-2); white-space: nowrap; }
td > .small { display: block; }
tbody tr:last-child td { border-bottom: 0; }

/* Status, badges and covers */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; flex: none;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font-size: 12px; font-weight: 500; white-space: nowrap;
}
.pill.ok { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.pill.warn { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.pill.error { color: var(--error); background: var(--error-bg); border-color: transparent; }
.pill.info { color: var(--info); background: var(--info-bg); border-color: transparent; }
.pill.kind-playlist { color: var(--accent); background: var(--accent-bg); border-color: transparent; }
.pill.kind-album { color: var(--info); background: var(--info-bg); border-color: transparent; }
.pill.kind-track { color: var(--violet); background: var(--violet-bg); border-color: transparent; }
.status-dot { display: inline-block; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--muted); opacity: 0.55; }
.status-dot.online { background: var(--ok); opacity: 1; box-shadow: 0 0 0 3px var(--ok-bg); }

.cover {
  position: relative; display: grid; place-items: center; width: 100%; aspect-ratio: 1; overflow: hidden;
  border-radius: 12px; border: 1px solid var(--border);
  background: linear-gradient(145deg, color-mix(in srgb, var(--accent) 32%, var(--surface-3)), color-mix(in srgb, var(--violet) 22%, var(--surface-3)));
  color: var(--text);
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover .icon { width: 34%; height: 34%; opacity: 0.8; }
.cover-trigger {
  display: grid; gap: 6px; width: 132px; min-height: 0; padding: 0; border: 0; background: none;
  color: var(--text); font-weight: 400; text-align: inherit; cursor: pointer;
}
.cover-trigger:hover { background: none; }
.cover-trigger.compact { width: 52px; }
.cover-trigger:focus-visible { outline: none; }
.cover-trigger:focus-visible .cover { outline: 2px solid var(--accent); outline-offset: 2px; }
.cover-trigger:hover .cover { filter: brightness(1.08); }
.cover-caption {
  display: inline-flex; align-items: center; justify-content: center; min-height: 30px; padding: 4px 10px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  font-size: 12.5px; font-weight: 500;
}
.cover-trigger:hover .cover-caption { background: var(--surface-3); }

/* Cover dialog: a native modal, so Escape, the focus trap and focus return come from the browser */
.cover-dialog {
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; overflow: auto;
  border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  background: var(--surface-1); color: var(--text); box-shadow: 0 24px 60px rgb(0 0 0 / 0.5);
}
.cover-dialog::backdrop { background: rgb(0 0 0 / 0.6); }
.cover-dialog-body { display: grid; gap: 14px; padding: 18px; }
.cover-dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.cover-dialog-head h2 { font-size: 16px; }
.cover-tabs {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 4px; padding: 4px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.cover-tab {
  min-height: 30px; padding: 4px 8px; border: 0; background: transparent; color: var(--muted); font-weight: 500;
}
.cover-tab:hover { background: transparent; color: var(--text); }
.cover-tab[aria-selected="true"] { background: var(--surface-3); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.cover-panel { display: grid; gap: 8px; }
.cover-drop {
  display: grid; justify-items: center; gap: 6px; padding: 24px 16px; text-align: center;
  border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
}
.cover-drop p { margin: 0; font-weight: 500; }
.cover-drop .icon { width: 28px; height: 28px; color: var(--accent); }
.cover-drop.over { border-color: var(--accent); background: var(--accent-bg); }
.cover-drop:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.cover-preview { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 14px; align-items: center; }
.cover-preview .cover { width: 132px; }
.cover-preview-body { display: grid; gap: 8px; min-width: 0; }
.cover-preview-body h3 { font-size: 14px; }
.cover-dialog-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 12px; border-top: 1px solid var(--border); }
.cover-dialog-foot:empty { display: none; }
.cover-dialog-close { margin-left: auto; }

/* Notices and toasts */
.notice {
  margin: 12px 0; padding: 10px 12px; border-radius: var(--radius-sm); font-size: 13px; line-height: 1.5;
  background: var(--info-bg); border-left: 3px solid var(--info); color: var(--text);
}
.notice p { margin: 0.2em 0; }
.notice-warn { background: var(--warn-bg); border-left-color: var(--warn); }
.notice-error { background: var(--error-bg); border-left-color: var(--error); }
.notice-ok { background: var(--ok-bg); border-left-color: var(--ok); }
.field-error { margin: 6px 0 0; color: var(--error); font-size: 13px; }
.spinner {
  width: 14px; height: 14px; flex: none; display: inline-block; border: 2px solid var(--border-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* Responsive: tablet and narrow desktop */
@media (max-width: 1100px) {
  .content { padding: 24px 24px 48px; }
}

/* Responsive: sidebar becomes an off-canvas drawer with a backdrop */
@media (max-width: 800px) {
  .shell { display: block; }
  .sidebar {
    width: min(280px, 84vw); z-index: 30; padding-top: 14px;
    transform: translateX(-100%); visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  .menu-open .sidebar {
    transform: none; visibility: visible; transition: transform 0.2s ease;
    box-shadow: 12px 0 40px rgb(0 0 0 / 0.45);
  }
  .nav-backdrop { position: fixed; inset: 0; z-index: 25; background: rgb(0 0 0 / 0.5); }
  .menu-toggle, .header-brand { display: inline-flex; }
  main { margin: 0; }
  header { height: auto; min-height: 52px; flex-wrap: wrap; padding: 8px 14px; gap: 8px 10px; }
  .crumb { flex: 1 1 140px; }
  .content { padding: 20px 16px 40px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Responsive: phone */
@media (max-width: 520px) {
  header { padding: 8px 12px; }
  .env { display: none; }
  .crumb li:not(:last-child) { display: none; }
  .crumb li:last-child::before { content: none; }
  .content { padding: 18px 13px 40px; }
  .page-head h1 { font-size: 21px; }
  .panel { padding: 14px; }
  .inline-form > .field, .inline-form > button { flex: 1 1 100%; }
  .cover-preview { grid-template-columns: minmax(0, 1fr); }
  .cover-preview .cover { width: min(132px, 100%); }
  .section-head > button { width: 100%; }

  /* Touch targets: 40px for buttons, fields, icon buttons and drawer links */
  button, .button, input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select { min-height: 40px; }
  .icon-button, .menu-toggle { width: 40px; height: 40px; min-width: 40px; }
  .small-button { min-height: 40px; }
  .cover-tab { min-height: 40px; }
  .cover-trigger { min-height: 40px; }
  .switch-row { min-height: 40px; }
  .sidebar a:not(.brand) { min-height: 40px; }

  /* Dialogs fill the phone screen: the body scrolls and the footer stays in reach */
  .cover-dialog {
    width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh;
    inset: 0; margin: 0; border: 0; border-radius: 0;
  }
  .cover-dialog-foot {
    position: sticky; bottom: 0; z-index: 1; margin: 0 -18px -18px; padding: 12px 18px;
    background: var(--surface-1); border-top: 1px solid var(--border);
  }
  .cover-dialog-body { min-height: 100%; }
}

/* Parent sign-in page */
.login-page { margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.login-card { width: min(24rem, 100%); display: grid; gap: 14px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card .notice { margin: 0; }
.login-brand { padding: 0; }

/* Sign out in the sidebar footer */
.signout-form { margin: 6px 0 0; }
.link-button { min-height: 0; padding: 0; border: 0; background: none; color: var(--accent); font-size: 12px; font-weight: 600; }
.link-button:hover { background: none; text-decoration: underline; }

/* First-flash wizard */
.flash-install { margin: 4px 0 12px; }
.flash-install esp-web-install-button { display: inline-block; }
