/* Songbook — shared design system. Every colour, radius and font routes through
   the --sb-* theme tokens emitted by /themes.css (src/themes.js), so the whole
   UI (including chord diagrams) recolours for free across themes + light/dark.
   Fallback values keep the page sane if the theme sheet is slow to load. */

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; scroll-behavior: smooth; }
body { min-height: 100vh; }
img, svg, video { display: block; max-width: 100%; }
img, video { height: auto; }
input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: inherit; }
ul, ol { padding: 0; }
:where(h1, h2, h3, h4) { line-height: 1.2; }

/* ── Base ──────────────────────────────────────────────────────────────────── */
:root { color-scheme: light dark; }
body.sb-body,
body.sb-admin-body {
  background: var(--sb-bg, #f7f3ea);
  color: var(--sb-text, #2b2620);
  font-family: var(--sb-font-body, system-ui, sans-serif);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body.sb-body { min-height: 100vh; display: flex; flex-direction: column; }

h1, h2, h3, h4 {
  font-family: var(--sb-font-heading, inherit);
  color: var(--sb-heading, #1a1611);
  font-weight: 700;
  letter-spacing: -0.01em;
}
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.2rem; }
p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }
a { color: var(--sb-link, #8a4b1f); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, samp, pre { font-family: var(--sb-font-mono, ui-monospace, monospace); }
code { font-size: 0.9em; background: var(--sb-tab-bg, #f0ead9); padding: 0.1em 0.35em; border-radius: 4px; }
hr { border: none; border-top: 1px solid var(--sb-hairline, #eadfce); margin: 1.5rem 0; }
:focus-visible { outline: 2px solid var(--sb-accent, #b5652c); outline-offset: 2px; border-radius: 3px; }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.sb-container { width: 100%; max-width: 1100px; margin-inline: auto; padding-inline: 1.25rem; }
.sb-section { padding-block: 2rem; }
.sb-narrow { max-width: 560px; }
main { flex: 1 0 auto; }
.sb-muted { color: var(--sb-subtle, #6f6555); }
.sb-small { font-size: 0.875rem; }
.sb-stack > * + * { margin-top: 1rem; }

.sb-skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--sb-panel, #fff); color: var(--sb-text); padding: 0.6rem 1rem;
  border: 1px solid var(--sb-panel-border, #ddd); border-radius: var(--sb-radius, 8px);
}
.sb-skip:focus { left: 1rem; top: 1rem; }

/* ── Header + nav ──────────────────────────────────────────────────────────── */
.sb-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--sb-panel, #fffdf8) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--sb-hairline, #eadfce);
}
.sb-header-inner { display: flex; align-items: center; gap: 1rem; min-height: 60px; }
.sb-brand {
  font-family: var(--sb-font-heading, inherit); font-weight: 800; font-size: 1.15rem;
  color: var(--sb-heading, #1a1611); letter-spacing: -0.02em; white-space: nowrap;
}
.sb-brand:hover { text-decoration: none; }
.sb-nav { display: flex; align-items: center; gap: 0.3rem; margin-left: auto; }
.sb-nav-link {
  color: var(--sb-text, #2b2620); padding: 0.45rem 0.7rem; border-radius: var(--sb-radius, 8px);
  font-weight: 500; font-size: 0.95rem;
}
.sb-nav-link:hover { background: var(--sb-hairline, #eadfce); text-decoration: none; }
.sb-login { color: var(--sb-link); }
.sb-nav-actions { display: flex; align-items: center; gap: 0.4rem; margin-left: 0.4rem; }

.sb-caret { font-size: 0.7em; opacity: 0.7; margin-left: 0.2em; }

/* Dropdowns + user menu: open on hover/focus (CSS) or .open (JS click). */
.sb-drop, .sb-menu { position: relative; }
.sb-drop-toggle, .sb-menu-toggle {
  display: inline-flex; align-items: center; gap: 0.15rem;
  color: var(--sb-text); padding: 0.45rem 0.7rem; border-radius: var(--sb-radius, 8px);
  font-weight: 500; font-size: 0.95rem;
}
.sb-drop-toggle:hover, .sb-menu-toggle:hover { background: var(--sb-hairline, #eadfce); }
.sb-drop-menu, .sb-menu-list {
  position: absolute; top: calc(100% + 6px); right: 0; min-width: 190px;
  background: var(--sb-panel, #fffdf8); border: 1px solid var(--sb-panel-border, #e3d9c6);
  border-radius: var(--sb-radius, 8px); padding: 0.4rem;
  box-shadow: 0 12px 32px rgba(0,0,0,0.14);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity 0.14s ease, transform 0.14s ease, visibility 0.14s;
}
.sb-drop-menu { left: 0; right: auto; }
.sb-drop:hover .sb-drop-menu, .sb-drop:focus-within .sb-drop-menu, .sb-drop.open .sb-drop-menu,
.sb-menu:hover .sb-menu-list, .sb-menu:focus-within .sb-menu-list, .sb-menu.open .sb-menu-list {
  opacity: 1; visibility: visible; transform: translateY(0);
}
.sb-drop-menu a, .sb-menu-list a {
  display: block; padding: 0.5rem 0.65rem; border-radius: calc(var(--sb-radius, 8px) - 3px);
  color: var(--sb-text); font-size: 0.92rem;
}
.sb-drop-menu a:hover, .sb-menu-list a:hover { background: var(--sb-hairline, #eadfce); text-decoration: none; }

/* Notification bell */
.sb-bell {
  position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%; color: var(--sb-text);
}
.sb-bell:hover { background: var(--sb-hairline, #eadfce); }
.sb-bell-badge {
  position: absolute; top: 3px; right: 2px; min-width: 17px; height: 17px; padding: 0 4px;
  display: flex; align-items: center; justify-content: center;
  background: var(--sb-accent, #b5652c); color: #fff; font-size: 0.68rem; font-weight: 700;
  border-radius: 9px; line-height: 1;
}

/* Mode toggle */
.sb-mode-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 50%; color: var(--sb-text);
}
.sb-mode-toggle:hover { background: var(--sb-hairline, #eadfce); }

.sb-nav-toggle {
  display: none; margin-left: auto; font-size: 1.4rem; line-height: 1;
  width: 42px; height: 42px; border-radius: var(--sb-radius, 8px); color: var(--sb-text);
}
.sb-nav-toggle:hover { background: var(--sb-hairline, #eadfce); }

/* ── Footer ────────────────────────────────────────────────────────────────── */
.sb-footer {
  flex-shrink: 0; margin-top: 3rem; padding-block: 1.5rem;
  border-top: 1px solid var(--sb-hairline, #eadfce);
  background: var(--sb-panel, #fffdf8); color: var(--sb-subtle, #6f6555); font-size: 0.85rem;
}
.sb-footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.sb-footer-links { display: flex; gap: 1rem; }
.sb-footer-links a { color: var(--sb-subtle, #6f6555); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  background: var(--sb-btn-bg, #8a4b1f); color: var(--sb-btn-text, #fff);
  padding: 0.6rem 1.1rem; border-radius: var(--sb-radius, 8px);
  font-weight: 600; font-size: 0.95rem; line-height: 1.2; white-space: nowrap;
  border: 1px solid transparent; transition: filter 0.14s ease, transform 0.04s ease;
}
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-secondary {
  background: var(--sb-panel, #fffdf8); color: var(--sb-text, #2b2620);
  border-color: var(--sb-panel-border, #e3d9c6);
}
.btn-secondary:hover { background: var(--sb-hairline, #eadfce); filter: none; }
.btn-danger { background: #c0392b; color: #fff; }
.btn-ghost { background: transparent; color: var(--sb-text); border-color: transparent; }
.btn-ghost:hover { background: var(--sb-hairline, #eadfce); filter: none; }
.btn-small { padding: 0.4rem 0.75rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.sb-field { margin-bottom: 1.1rem; }
.sb-field label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 0.35rem; color: var(--sb-heading, #1a1611); }
.sb-hint { margin: 0.35rem 0 0; font-size: 0.82rem; color: var(--sb-subtle, #6f6555); }
input[type=text], input[type=email], input[type=password], input[type=search],
input[type=url], input[type=number], input[type=date], textarea, select {
  width: 100%; padding: 0.6rem 0.75rem;
  background: var(--sb-bg, #fff); color: var(--sb-text, #2b2620);
  border: 1px solid var(--sb-panel-border, #e3d9c6); border-radius: var(--sb-radius, 8px);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
textarea { min-height: 8rem; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--sb-accent, #b5652c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--sb-accent, #b5652c) 22%, transparent);
}
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-position: calc(100% - 18px) calc(50% - 2px), calc(100% - 13px) calc(50% - 2px); background-size: 5px 5px; background-repeat: no-repeat; padding-right: 2.2rem; }
.sb-checkbox { display: flex; align-items: center; gap: 0.5rem; font-size: 0.95rem; }
.sb-checkbox input { width: auto; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.sb-card {
  background: var(--sb-panel, #fffdf8); border: 1px solid var(--sb-panel-border, #e3d9c6);
  border-radius: var(--sb-radius, 8px); padding: 1.5rem;
}
.sb-auth-card { max-width: 440px; margin-inline: auto; }
.sb-card h1 { margin-bottom: 0.5rem; }
.sb-grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* Song list card (used by home/favourites — engine + community reuse these). */
.sb-songcard {
  display: block; background: var(--sb-panel, #fffdf8);
  border: 1px solid var(--sb-panel-border, #e3d9c6); border-radius: var(--sb-radius, 8px);
  padding: 0.85rem 1rem; transition: border-color 0.14s ease, transform 0.06s ease;
}
.sb-songcard:hover { border-color: var(--sb-accent, #b5652c); text-decoration: none; transform: translateY(-1px); }
.sb-songcard .sb-song-title { font-weight: 700; color: var(--sb-heading, #1a1611); }
.sb-songcard .sb-song-artist { color: var(--sb-subtle, #6f6555); font-size: 0.9rem; }

/* ── Tables ────────────────────────────────────────────────────────────────── */
.sb-table-wrap { overflow-x: auto; }
.sb-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.sb-table th, .sb-table td { padding: 0.65rem 0.8rem; text-align: left; border-bottom: 1px solid var(--sb-hairline, #eadfce); vertical-align: middle; }
.sb-table th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--sb-subtle, #6f6555); font-weight: 700; }
.sb-table tbody tr:hover { background: color-mix(in srgb, var(--sb-hairline, #eadfce) 55%, transparent); }

/* ── Badges + pills ────────────────────────────────────────────────────────── */
.sb-badge {
  display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.15rem 0.5rem;
  background: var(--sb-hairline, #eadfce); color: var(--sb-text, #2b2620);
  border-radius: 999px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em;
}
.sb-pill { display: inline-flex; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.sb-pill.pending { background: #fff3cd; color: #7a5b00; }
.sb-pill.accepted, .sb-pill.approved { background: #d4edda; color: #1a5c2c; }
.sb-pill.rejected { background: #f8d7da; color: #842029; }

/* ── Toolbar ───────────────────────────────────────────────────────────────── */
.sb-toolbar {
  display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap;
  padding: 0.6rem 0.85rem; background: var(--sb-panel, #fffdf8);
  border: 1px solid var(--sb-panel-border, #e3d9c6); border-radius: var(--sb-radius, 8px);
}
.sb-toolbar-group { display: flex; align-items: center; gap: 0.35rem; }
.sb-toolbar .sb-spacer { flex: 1 1 auto; }

/* Stepper (used by transpose / font-size controls) */
.sb-stepper { display: inline-flex; align-items: center; border: 1px solid var(--sb-panel-border, #e3d9c6); border-radius: var(--sb-radius, 8px); overflow: hidden; }
.sb-stepper button { padding: 0.35rem 0.7rem; font-weight: 700; color: var(--sb-text); }
.sb-stepper button:hover { background: var(--sb-hairline, #eadfce); }
.sb-stepper .sb-stepper-value { padding: 0.35rem 0.75rem; min-width: 3ch; text-align: center; border-inline: 1px solid var(--sb-panel-border, #e3d9c6); font-variant-numeric: tabular-nums; }

/* Segmented control */
.sb-segmented { display: inline-flex; border: 1px solid var(--sb-panel-border, #e3d9c6); border-radius: var(--sb-radius, 8px); overflow: hidden; }
.sb-segmented button { padding: 0.4rem 0.75rem; font-size: 0.85rem; color: var(--sb-text); }
.sb-segmented button + button { border-left: 1px solid var(--sb-panel-border, #e3d9c6); }
.sb-segmented button[aria-pressed="true"], .sb-segmented button.active { background: var(--sb-btn-bg, #8a4b1f); color: var(--sb-btn-text, #fff); }

/* ── Drawer / slide-over ───────────────────────────────────────────────────── */
.sb-drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 90;
  opacity: 0; visibility: hidden; transition: opacity 0.2s ease, visibility 0.2s;
}
.sb-drawer-backdrop.open { opacity: 1; visibility: visible; }
.sb-drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(400px, 90vw); z-index: 91;
  background: var(--sb-panel, #fffdf8); border-left: 1px solid var(--sb-panel-border, #e3d9c6);
  box-shadow: -12px 0 40px rgba(0,0,0,0.18); padding: 1.25rem;
  transform: translateX(100%); transition: transform 0.24s cubic-bezier(.4,0,.2,1);
  overflow-y: auto; display: flex; flex-direction: column;
}
.sb-drawer.open { transform: translateX(0); }
.sb-drawer.sb-drawer-left { right: auto; left: 0; border-left: none; border-right: 1px solid var(--sb-panel-border, #e3d9c6); box-shadow: 12px 0 40px rgba(0,0,0,0.18); transform: translateX(-100%); }
.sb-drawer.sb-drawer-left.open { transform: translateX(0); }
.sb-drawer-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.sb-drawer-close { font-size: 1.5rem; line-height: 1; width: 36px; height: 36px; border-radius: var(--sb-radius, 8px); color: var(--sb-text); }
.sb-drawer-close:hover { background: var(--sb-hairline, #eadfce); }

/* ── Popover ───────────────────────────────────────────────────────────────── */
.sb-popover {
  position: absolute; z-index: 80; background: var(--sb-panel, #fffdf8);
  border: 1px solid var(--sb-panel-border, #e3d9c6); border-radius: var(--sb-radius, 8px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.16); padding: 1rem;
}

/* ── Flash notices ─────────────────────────────────────────────────────────── */
.sb-notice {
  padding: 0.75rem 1rem; border-radius: var(--sb-radius, 8px); margin-bottom: 1rem;
  border: 1px solid var(--sb-panel-border, #e3d9c6); background: var(--sb-panel, #fffdf8);
  font-size: 0.92rem;
}
.sb-notice-ok { background: #e8f5ec; border-color: #b7dfc4; color: #1a5c2c; }
.sb-notice-error { background: #fdecea; border-color: #f5c2bd; color: #842029; }

/* ── Pagination ────────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 0.3rem; flex-wrap: wrap; align-items: center; margin-top: 1.5rem; }
.page-link {
  display: inline-flex; align-items: center; justify-content: center; min-width: 38px; height: 38px; padding: 0 0.6rem;
  border: 1px solid var(--sb-panel-border, #e3d9c6); border-radius: var(--sb-radius, 8px);
  color: var(--sb-text); font-size: 0.9rem; font-variant-numeric: tabular-nums;
}
.page-link:hover { background: var(--sb-hairline, #eadfce); text-decoration: none; }
.page-link.current { background: var(--sb-btn-bg, #8a4b1f); color: var(--sb-btn-text, #fff); border-color: transparent; }

/* ── Search box ────────────────────────────────────────────────────────────── */
.sb-search { position: relative; }
.sb-search input { padding-left: 2.4rem; }
.sb-search::before { content: "⌕"; position: absolute; left: 0.8rem; top: 50%; transform: translateY(-50%); color: var(--sb-subtle, #6f6555); font-size: 1.1rem; }

/* ── Confirm / alert modal (public/js/confirm-modal.js) ────────────────────── */
.cfm-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200;
  display: flex; align-items: flex-start; justify-content: center; padding: 16vh 1rem 1rem;
}
.cfm-box {
  background: var(--sb-panel, #fffdf8); border: 1px solid var(--sb-panel-border, #e3d9c6);
  border-radius: var(--sb-radius, 8px); width: 100%; max-width: 430px; padding: 1.25rem 1.35rem;
  box-shadow: 0 18px 50px rgba(0,0,0,0.3);
}
.cfm-title { font-weight: 700; font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--sb-heading, #1a1611); }
.cfm-msg { margin: 0 0 1.25rem; color: var(--sb-text, #2b2620); line-height: 1.55; }
.cfm-actions { display: flex; gap: 0.6rem; justify-content: flex-end; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  h1 { font-size: 1.6rem; }
  .sb-nav-toggle { display: inline-flex; }
  .sb-nav {
    position: absolute; top: 100%; left: 0; right: 0; margin: 0;
    flex-direction: column; align-items: stretch; gap: 0.15rem; padding: 0.75rem;
    background: var(--sb-panel, #fffdf8); border-bottom: 1px solid var(--sb-panel-border, #e3d9c6);
    box-shadow: 0 12px 24px rgba(0,0,0,0.12);
    display: none;
  }
  .sb-header.sb-nav-open .sb-nav { display: flex; }
  .sb-nav-actions { margin: 0.4rem 0 0; justify-content: flex-start; }
  .sb-drop, .sb-menu { width: 100%; }
  .sb-drop-menu, .sb-menu-list {
    position: static; opacity: 1; visibility: visible; transform: none; box-shadow: none;
    border: none; border-left: 2px solid var(--sb-hairline, #eadfce); border-radius: 0; margin-left: 0.5rem;
    display: none;
  }
  .sb-drop.open .sb-drop-menu, .sb-menu.open .sb-menu-list { display: block; }
  .sb-footer-inner { flex-direction: column; align-items: flex-start; }
}

/* Print: hide site chrome; the song sheet owns the page (see song.css). */
@media print {
  .sb-header, .sb-footer, .sb-toolbar, .sb-skip { display: none !important; }
  body.sb-body { background: #fff; color: #000; }
}
