:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --radius: 12px;
  --radius-sm: 8px;
  --topbar-h: 52px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--topbar-h);
  background: var(--primary);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  box-shadow: 0 2px 8px rgba(79,70,229,.3);
}
.topbar-logo {
  color: #fff; font-size: 1.1rem; font-weight: 700; letter-spacing: -.3px;
}
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.topbar-link {
  color: rgba(255,255,255,.85); font-size: .85rem; padding: 5px 10px;
  border-radius: 6px; transition: background .15s;
}
.topbar-link:hover, .topbar-link.active { background: rgba(255,255,255,.15); color: #fff; }

/* ── Layout ──────────────────────────────────────────────── */
.main { min-height: calc(100vh - var(--topbar-h)); }
.page { max-width: 640px; margin: 0 auto; padding: 0 0 80px; }

/* ── Hero (landing) ──────────────────────────────────────── */
.hero {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center;
  padding: 80px 24px 60px;
  max-width: 480px; margin: 0 auto;
}
.hero-icon { font-size: 3.5rem; margin-bottom: 12px; }
.hero-title { font-size: 2rem; font-weight: 800; letter-spacing: -.5px; color: var(--text); }
.hero-sub { color: var(--text-muted); margin-top: 6px; margin-bottom: 36px; font-size: 1rem; }
.hero-buttons { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 280px; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: .9rem; font-weight: 600; cursor: pointer;
  border: 2px solid transparent; transition: all .15s; white-space: nowrap;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-light); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.btn-lg { padding: 14px 28px; font-size: 1rem; border-radius: var(--radius); }
.btn-sm { padding: 6px 12px; font-size: .8rem; }
.btn-full { width: 100%; }
.btn-icon {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: .85rem; padding: 4px 8px;
  border-radius: 6px; transition: background .1s;
}
.btn-icon:hover { background: var(--border); color: var(--text); }
.btn-icon:disabled { opacity: .35; cursor: default; }

/* ── Search bar ──────────────────────────────────────────── */
.search-bar { background: var(--bg); padding: 12px 16px 8px; }
.sticky-top { position: sticky; top: var(--topbar-h); z-index: 50; }
.search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 0 12px;
  box-shadow: var(--shadow);
}
.search-wrap:focus-within { border-color: var(--primary); }
.search-icon { font-size: .9rem; color: var(--text-muted); flex-shrink: 0; }
.search-wrap input {
  flex: 1; border: none; outline: none; background: none;
  padding: 10px 0; font-size: 1rem; color: var(--text);
}
.search-clear {
  color: var(--text-muted); cursor: pointer; padding: 4px;
  border: none; background: none; font-size: .9rem;
}
.search-clear:hover { color: var(--text); }

/* ── Results info ────────────────────────────────────────── */
.results-info {
  padding: 6px 16px 4px;
  font-size: .8rem; color: var(--text-muted);
}

/* ── Song list ───────────────────────────────────────────── */
.song-list { list-style: none; padding: 0 12px; }
.song-card {
  background: var(--surface); border-radius: var(--radius-sm);
  margin-bottom: 6px; box-shadow: var(--shadow);
  transition: transform .1s, box-shadow .1s;
}
.song-card:active { transform: scale(.99); }
.song-card-link {
  display: flex; align-items: center; padding: 14px 14px 14px 16px;
  gap: 8px; min-height: 56px;
}
.song-card-body { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.song-title { font-weight: 600; font-size: .95rem; color: var(--text); }
.song-author { font-size: .8rem; color: var(--text-muted); }
.song-arrow { color: var(--text-light); font-size: 1.3rem; font-weight: 300; }

/* ── Song detail ─────────────────────────────────────────── */
.song-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  position: sticky; top: var(--topbar-h); z-index: 40;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.song-header-actions { display: flex; align-items: center; gap: 6px; }
.back-btn {
  color: var(--primary); font-size: .9rem; font-weight: 600;
  border: none; background: none; cursor: pointer; padding: 4px 0;
}
.song-meta { padding: 20px 20px 8px; }
.song-detail-title { font-size: 1.6rem; font-weight: 800; letter-spacing: -.4px; line-height: 1.2; }
.song-detail-author { color: var(--text-muted); margin-top: 4px; font-size: .9rem; }

.lyrics { padding: 12px 20px 40px; }
.lyric-section {
  white-space: pre-wrap; line-height: 1.8; font-size: 1.125rem;
  color: var(--text); padding: 12px 0;
  border-bottom: 1px dashed var(--border);
}
.lyric-section:last-child { border-bottom: none; }

/* ── Dropdown ────────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  list-style: none; min-width: 180px; z-index: 200;
  overflow: hidden;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  display: block; width: 100%; text-align: left; padding: 10px 14px;
  background: none; border: none; cursor: pointer; font-size: .9rem;
  color: var(--text); transition: background .1s;
}
.dropdown-item:hover { background: var(--primary-light); color: var(--primary); }
.dropdown-item:disabled { color: var(--text-muted); cursor: default; }

/* ── Login / form page ───────────────────────────────────── */
.form-page { display: flex; justify-content: center; align-items: flex-start; padding: 40px 16px; }
.form-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 32px 28px;
  width: 100%; max-width: 360px;
}
.form-title { font-size: 1.4rem; font-weight: 800; }
.form-sub { color: var(--text-muted); font-size: .875rem; margin-top: 4px; margin-bottom: 24px; }
.username-display {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 12px;
}
.username-label { font-size: .75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.username-value { font-weight: 700; color: var(--text); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.field input {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 1rem; color: var(--text);
  background: var(--surface); outline: none; transition: border-color .15s;
}
.field input:focus { border-color: var(--primary); }
.form-error {
  background: #fef2f2; color: var(--danger); border: 1px solid #fecaca;
  border-radius: var(--radius-sm); padding: 8px 12px;
  font-size: .85rem; margin-bottom: 12px;
}
.form-divider { text-align: center; color: var(--text-muted); font-size: .8rem; margin: 14px 0; }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
  display: flex; border-bottom: 2px solid var(--border);
  padding: 0 16px; background: var(--bg);
  position: sticky; top: var(--topbar-h); z-index: 50;
}
.tab {
  padding: 14px 16px; font-size: .9rem; font-weight: 600;
  color: var(--text-muted); border: none; background: none; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Setlist manager ─────────────────────────────────────── */
.setlist-toolbar { padding: 14px 16px 8px; }
.create-setlist-form {
  margin: 0 16px 8px; padding: 14px; background: var(--surface);
  border: 1.5px solid var(--primary); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.create-setlist-form input {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); font-size: 1rem; outline: none; margin-bottom: 10px;
}
.create-setlist-form input:focus { border-color: var(--primary); }
.create-form-actions { display: flex; gap: 8px; }

.setlist-item {
  margin: 0 12px 6px; background: var(--surface);
  border-radius: var(--radius-sm); box-shadow: var(--shadow); overflow: hidden;
}
.setlist-item-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 14px 16px; gap: 10px;
}
.setlist-item-info { flex: 1; min-width: 0; }
.setlist-name { display: block; font-weight: 700; font-size: .95rem; }
.setlist-meta { font-size: .78rem; color: var(--text-muted); }
.setlist-item-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Setlist editor ──────────────────────────────────────── */
.editor-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky; top: calc(var(--topbar-h) + 50px); z-index: 40;
}
.editor-title-input {
  flex: 1; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px 10px; font-size: .95rem; font-weight: 700; outline: none;
}
.editor-title-input:focus { border-color: var(--primary); }
.editor-body {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  min-height: 400px;
}
@media (max-width: 520px) {
  .editor-body { grid-template-columns: 1fr; }
}
.editor-search { border-right: 1px solid var(--border); }
.editor-section-label {
  font-size: .75rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px;
  padding: 10px 16px 4px;
}
.add-song-item .song-card-link { padding-right: 8px; }
.add-song-item { display: flex; align-items: center; }
.add-song-item .song-card-link { flex: 1; }
.add-song-item .add-song-btn { margin-right: 10px; flex-shrink: 0; }
#editor-song-results { padding-bottom: 0; }
#editor-song-results .song-card { margin-bottom: 4px; }

.setlist-order-list { list-style: none; padding: 0 12px; }
.order-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border-radius: var(--radius-sm);
  margin-bottom: 4px; padding: 10px 10px 10px 12px;
  box-shadow: var(--shadow);
}
.order-num {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: .7rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.order-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.order-controls { display: flex; gap: 2px; flex-shrink: 0; }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--text-muted); }
.empty-hint { font-size: .85rem; color: var(--text-light); margin-top: 6px; }
.empty-hint code {
  background: var(--bg); border: 1px solid var(--border);
  padding: 1px 5px; border-radius: 4px; font-size: .8rem;
}

/* ── Manage Songs Tab ────────────────────────────────────── */
.upload-zone {
  margin: 16px 12px 8px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
.upload-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-light);
}
.upload-zone-inner {
  display: flex; flex-direction: column; align-items: center;
  padding: 28px 20px 20px; text-align: center;
}
.upload-icon { font-size: 2rem; margin-bottom: 8px; }
.upload-text { font-size: .95rem; color: var(--text-muted); }
.upload-hint-text { font-size: .78rem; color: var(--text-light); margin-top: 4px; }
.upload-browse {
  color: var(--primary); font-weight: 600; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px;
}
.upload-feedback {
  margin: 0 16px 14px; padding: 9px 14px;
  border-radius: var(--radius-sm); font-size: .85rem; font-weight: 500;
}
.upload-feedback-info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.upload-feedback-success { background: #f0fdf4; color: #15803d; border: 1px solid #bbf7d0; }
.upload-feedback-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }

.manage-header {
  padding: 6px 16px 4px;
  font-size: .8rem; color: var(--text-muted);
}

.manage-item {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 10px;
  margin: 0 12px 6px; padding: 14px 14px 14px 16px;
  background: var(--surface); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.manage-item-body { flex: 1; min-width: 0; }
.manage-item-view { display: flex; flex-direction: column; gap: 2px; }
.manage-item-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.manage-item-actions { display: flex; gap: 6px; flex-shrink: 0; padding-top: 2px; }

.manage-item-edit { padding-top: 2px; }
.edit-input {
  width: 100%; padding: 8px 10px; border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm); font-size: .95rem; font-weight: 600;
  color: var(--text); outline: none; margin-bottom: 8px;
}
.edit-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.badge-edited {
  display: inline-block;
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  background: #fef9c3; color: #a16207;
  border: 1px solid #fde68a; border-radius: 4px;
  padding: 1px 6px; line-height: 1.6;
}

@media (max-width: 480px) {
  .manage-item { flex-direction: column; }
  .manage-item-actions { width: 100%; justify-content: flex-end; }
}
