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

:root {
  --bg: #1a1a2e;
  --panel: #16213e;
  --surface: #0f3460;
  --accent: #e94560;
  --accent2: #533483;
  --text: #eaeaea;
  --muted: #8892a4;
  --border: #2a3a5a;
  --success: #2ecc71;
  --radius: 6px;
  --font: system-ui, -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ── Nav ── */
.app-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 48px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  text-decoration: none;
}
.nav-links { display: flex; gap: 1.25rem; }
.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color 0.15s;
}
.nav-links a:hover { color: var(--text); }
.nav-user { display: flex; align-items: center; gap: 0.75rem; font-size: 0.875rem; color: var(--muted); }

/* ── Two-panel layout ── */
main { padding: 0; }

.two-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 48px);
}

.panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid var(--border);
}
.panel:last-child { border-right: none; }

.panel-header {
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-shrink: 0;
}
.panel-header h2 { font-size: 0.9rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

.panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}

/* turbo-frame must stretch to fill panel so scroll works */
turbo-frame {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ── Standard page layout ── */
.page-layout {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem;
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}
.page-header h1 { font-size: 1.4rem; }

/* ── Forms ── */
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], textarea, select {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.4rem 0.6rem;
  font-size: 0.875rem;
  font-family: var(--font);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 60px; }

label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.25rem; }
.field { margin-bottom: 0.75rem; }

.search-bar {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex: 1;
}
.search-bar input { flex: 1; }

.christmas-toggle {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  font-size: 1.1rem;
  opacity: 0.3;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.christmas-toggle:has(input:checked) { opacity: 1; }
.christmas-toggle input { display: none; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font);
  font-weight: 500;
  text-decoration: none;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--text); }
.btn-muted { background: var(--border); color: var(--muted); }
.btn-danger { background: #c0392b; color: #fff; }
.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.75rem; }

/* ── Song search results ── */
.song-list { list-style: none; }
.song-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  gap: 0.5rem;
}
.song-item:hover { background: var(--panel); }
.song-item + .song-item { border-top: 1px solid var(--border); }

.song-title { font-weight: 500; flex: 1; }
.song-refs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.ref-badge {
  background: var(--surface);
  color: var(--text);
  padding: 0.15rem 0.45rem;
  border-radius: 3px;
  font-size: 0.72rem;
  font-family: monospace;
  white-space: nowrap;
}
.ref-badge.rb { background: #1a3a5c; }
.ref-badge.ja { background: #3a1a5c; }

.song-meta { color: var(--muted); font-size: 0.75rem; }

.play-count-badge {
  background: #1a6b3a;
  color: #a8f0c0;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
  min-width: 1.4rem;
  text-align: center;
  white-space: nowrap;
}

/* ── Session cards ── */
.session-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  background: var(--panel);
  overflow: hidden;
}
.session-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  gap: 0.5rem;
}
.session-card-header::-webkit-details-marker { display: none; }
.session-card-header::before {
  content: "▶";
  font-size: 0.6rem;
  color: var(--muted);
  transition: transform 0.15s;
  flex-shrink: 0;
}
.session-card[open] > .session-card-header::before { transform: rotate(90deg); }
.session-card-header:hover { background: var(--surface); }
.session-card-date { font-weight: 600; font-size: 0.9rem; flex: 1; }
.session-card-count {
  color: var(--muted);
  font-size: 0.78rem;
  background: var(--border);
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  white-space: nowrap;
}
.session-card-delete {
  margin-left: auto;
  flex-shrink: 0;
}
.session-card-body {
  border-top: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
}

/* ── Session detail layout ── */
.session-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0.75rem 0.5rem;
  flex-shrink: 0;
}

/* ── Session panel ── */
.session-list { list-style: none; }
.session-item {
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.session-date { font-weight: 600; font-size: 0.9rem; }
.session-count { color: var(--muted); font-size: 0.8rem; }

.session-songs-list { list-style: none; }
.session-song-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border);
}
.session-song-item:last-child { border-bottom: none; }
.song-number { color: var(--muted); font-size: 0.75rem; min-width: 1.5rem; text-align: right; }
.session-song-title { flex: 1; font-weight: 500; }
.session-song-suggester { color: var(--muted); font-size: 0.75rem; }
.suggester-select { width: auto; min-width: 80px; font-size: 0.75rem; padding: 0.15rem 0.4rem; border-radius: 3px; }

/* ── Add-song form ── */
.add-song-area {
  border-top: 1px solid var(--border);
  padding: 0.75rem;
  background: var(--panel);
  flex-shrink: 0;
}
.add-song-area h3 { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.5rem; text-transform: uppercase; letter-spacing: 0.05em; }

/* ── Session players ── */
.session-players-section {
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}
.session-players-list {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}
.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.2rem 0.6rem 0.2rem 0.75rem;
  font-size: 0.8rem;
  color: var(--text);
}
.chip-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
  padding: 0;
  display: inline-flex;
  align-items: center;
}
.chip-remove:hover { color: var(--accent); }
.player-select-inline {
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 20px;
  color: var(--muted);
  padding: 0.2rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
}
.player-select-inline:focus { outline: none; border-color: var(--accent); color: var(--text); }

.search-results-inline { margin-top: 0.5rem; }
.search-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0.5rem;
  border-radius: var(--radius);
  gap: 0.5rem;
}
.search-result-row:hover { background: var(--surface); }

/* ── Song detail ── */
.song-detail h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.refs-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.75rem 0;
}
.play-history { margin-top: 1rem; }
.play-history h3 { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.5rem; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; padding: 0.5rem 0.75rem; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--panel); }

/* ── Misc ── */
.notice { background: var(--surface); border-left: 3px solid var(--success); padding: 0.6rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.875rem; }
.empty-state { color: var(--muted); text-align: center; padding: 2rem; font-size: 0.9rem; }
.tag-christmas { background: #8b0000; color: #ffd700; padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.7rem; }
.tag-suggested { background: var(--accent2); color: #fff; padding: 0.1rem 0.4rem; border-radius: 3px; font-size: 0.7rem; }

a { color: var(--text); }
a:hover { color: var(--accent); }

.inline-form { display: inline; }

/* ── Login page ── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 48px);
  padding: 2rem 1rem;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.5rem;
  width: 100%;
  max-width: 380px;
}
.login-brand {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
  margin-bottom: 0.25rem;
}
.login-sub {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 1.5rem;
}
.login-alert {
  background: rgba(201, 57, 57, 0.15);
  border: 1px solid #c0392b;
  color: #e07070;
  border-radius: var(--radius);
  padding: 0.6rem 0.75rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}
.login-submit {
  width: 100%;
  justify-content: center;
  padding: 0.6rem;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}
.login-footer {
  text-align: center;
  margin-top: 1.25rem;
  font-size: 0.8rem;
}
.login-footer a { color: var(--muted); }
.login-footer a:hover { color: var(--text); }
