:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --chord-color: #d97706;
  --chord-hover: #b45309;
  --radius: 0.5rem;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  color-scheme: light;
}

[data-theme="dark"] {
  --primary: #38bdf8;
  --primary-hover: #7dd3fc;
  --primary-light: #162438;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --bg-main: #0b0f19;
  --bg-card: #151e2e;
  --border: #243044;
  --chord-color: #38bdf8;
  --chord-hover: #7dd3fc;
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.5);
  color-scheme: dark;
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

body, header.site-header, footer.site-footer, .card, .song-toolbar, .song-section-card, .form-control, .btn-outline, .section-preview-panel, .arrangement-builder, .arrangement-dropzone {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* Header & Navigation */
header.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
}

.nav-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 4rem;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  background: var(--primary);
  color: white;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  flex-shrink: 0;
}

[data-theme="dark"] .brand-icon {
  background: #0284c7;
  color: #ffffff;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  list-style: none;
}

.nav-links a {
  color: var(--text-muted);
  font-weight: 500;
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  transition: all 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--primary);
  background: var(--primary-light);
  text-decoration: none;
}

/* Theme Toggle Button */
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  cursor: pointer;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
  transition: all 0.2s ease;
  user-select: none;
}

.theme-toggle-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  transform: scale(1.05);
}

.theme-toggle-btn:active {
  transform: scale(0.95);
}

/* Light mode default: show moon, hide sun */
.theme-toggle-btn .icon-sun {
  display: none;
}
.theme-toggle-btn .icon-moon {
  display: inline-block;
}

/* Dark mode: show sun, hide moon */
[data-theme="dark"] .theme-toggle-btn .icon-sun {
  display: inline-block;
}
[data-theme="dark"] .theme-toggle-btn .icon-moon {
  display: none;
}

/* Main Content Area */
main {
  flex: 1;
  padding: 2rem 0;
}

/* Badges & Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
}

.badge-primary {
  background: var(--primary-light);
  color: var(--primary);
  border-color: #bfdbfe;
}

[data-theme="dark"] .badge-primary {
  border-color: #0369a1;
}

.badge-amber {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}

[data-theme="dark"] .badge-amber {
  background: #451a03;
  color: #fde68a;
  border-color: #78350f;
}

.badge-purple {
  background: #f3e8ff;
  color: #6b21a8;
  border-color: #e9d5ff;
}

[data-theme="dark"] .badge-purple {
  background: #3b0764;
  color: #e9d5ff;
  border-color: #581c87;
}

.badge-blue {
  background: #dbeafe;
  color: #1e40af;
  border-color: #bfdbfe;
}

[data-theme="dark"] .badge-blue {
  background: #172554;
  color: #93c5fd;
  border-color: #1e40af;
}

.badge-gray {
  background: #f1f5f9;
  color: #475569;
  border-color: #cbd5e1;
}

[data-theme="dark"] .badge-gray {
  background: #1e293b;
  color: #cbd5e1;
  border-color: #334155;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease-in-out;
  text-decoration: none !important;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

[data-theme="dark"] .btn-primary {
  background: #0284c7;
  color: #ffffff;
}

[data-theme="dark"] .btn-primary:hover {
  background: #0369a1;
}

.btn-outline {
  background: var(--bg-card);
  border-color: var(--border);
  color: var(--text-main);
}

.btn-outline:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-sm {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

.btn-xs {
  padding: 0.15rem 0.45rem;
  font-size: 0.75rem;
}

.btn-group {
  display: inline-flex;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.btn-group .btn {
  border-radius: 0;
  border: none;
  border-right: 1px solid var(--border);
}

.btn-group .btn:last-child {
  border-right: none;
}

/* Cards & Layout */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-header {
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Flash Messages */
.alert {
  padding: 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  border: 1px solid transparent;
}

.alert-success {
  background: #ecfdf5;
  color: #065f46;
  border-color: #a7f3d0;
}

[data-theme="dark"] .alert-success {
  background: #064e3b;
  color: #a7f3d0;
  border-color: #047857;
}

.alert-danger {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

[data-theme="dark"] .alert-danger {
  background: #450a0a;
  color: #fca5a5;
  border-color: #991b1b;
}

.alert-warning {
  background: #fffbeb;
  color: #92400e;
  border-color: #fde68a;
}

[data-theme="dark"] .alert-warning {
  background: #451a03;
  color: #fde68a;
  border-color: #78350f;
}

/* Music & Song Styles */
.song-view {
  max-width: 800px;
  margin: 0 auto;
}

.song-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-card);
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  position: sticky;
  top: 4.5rem;
  z-index: 30;
}

.song-section-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
  padding: 1.25rem;
  position: relative;
  transition: border-color 0.2s;
}

.song-section-card:hover {
  border-color: var(--primary);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px dashed var(--border);
}

.section-copy-btn {
  opacity: 0.5;
  transition: opacity 0.2s;
}

.song-section-card:hover .section-copy-btn {
  opacity: 1;
}

/* Chord Rendering Grid / Flex */
.song-section-text {
  font-family: inherit;
  font-size: var(--song-font-size, 1.05rem);
  line-height: 1.7;
}

.chord-line {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 0.4rem;
}

.chord-line.plain-line {
  display: block;
}

.chord-empty-line {
  height: 0.9rem;
}

.chord-token-pair {
  display: inline-flex;
  flex-direction: column;
  vertical-align: bottom;
  white-space: pre;
}

.chord {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-weight: 700;
  font-size: 0.85em;
  color: var(--chord-color);
  line-height: 1.1;
  min-height: 1.1em;
  user-select: none;
  letter-spacing: 0.02em;
}

[data-theme="dark"] .chord {
  color: #38bdf8;
  text-shadow: 0 0 1px rgba(56, 189, 248, 0.35);
}

.chord-empty {
  visibility: hidden;
}

.lyrics {
  color: var(--text-main);
  line-height: 1.35;
}

/* Hide Chords Mode */
.hide-chords .chord {
  display: none !important;
}

.hide-chords .chord-line {
  margin-bottom: 0.2rem;
}

/* Song Arrangements */
.arrangement-flow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin: 1rem 0;
}

.arrangement-item {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.75rem;
  background: var(--primary-light);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
}

/* Search input */
.search-box {
  position: relative;
  width: 100%;
  margin-bottom: 1.25rem;
}

.search-box input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.5rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text-main);
  outline: none;
  box-shadow: var(--shadow);
}

.search-box input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

[data-theme="dark"] .search-box input:focus {
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.search-icon {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* Table styles */
.table-responsive {
  overflow-x: auto;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

table.data-table th,
table.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

table.data-table th {
  background: var(--bg-card);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-muted);
}

table.data-table tr:hover td {
  background: var(--primary-light);
}

/* Form Styles */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-weight: 500;
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  padding: 0.6rem 0.85rem;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  background: var(--bg-card);
  color: var(--text-main);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

[data-theme="dark"] .form-control:focus {
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.form-control option {
  background-color: var(--bg-card);
  color: var(--text-main);
}

/* Footer */
footer.site-footer {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  margin-top: auto;
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
}

/* Split Section Editor (Desktop side-by-side view) */
.section-editor-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
  align-items: stretch;
}

@media (min-width: 900px) {
  .section-editor-split {
    grid-template-columns: 1fr 1fr;
  }
}

.section-editor-left {
  display: flex;
  flex-direction: column;
}

.section-editor-right {
  display: flex;
  flex-direction: column;
}

.section-preview-panel {
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  min-height: 180px;
  flex: 1;
  overflow-y: auto;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] .section-preview-panel {
  background: #090d16;
  border-color: var(--border);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.4);
}

.section-preview-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Arrangement Visual Drag & Drop Builder */
.arrangement-builder {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

[data-theme="dark"] .arrangement-builder {
  background: #111827;
  border-color: var(--border);
}

.arrangement-dropzone {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  min-height: 56px;
  background: var(--bg-main);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  transition: all 0.2s ease;
}

[data-theme="dark"] .arrangement-dropzone {
  background: #090d16;
  border-color: #334155;
}

.arrangement-dropzone.dragover-zone {
  border-color: var(--primary);
  background: var(--primary-light);
  border-style: solid;
}

.arrangement-empty-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
  user-select: none;
}

.arrangement-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: grab;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.arrangement-chip:active {
  cursor: grabbing;
}

.arrangement-chip.dragging {
  opacity: 0.35;
  transform: scale(0.95);
}

.arrangement-chip.drag-over-left {
  border-left: 3px solid var(--primary) !important;
  box-shadow: -3px 0 0 rgba(37, 99, 235, 0.3);
}

.arrangement-chip.drag-over-right {
  border-right: 3px solid var(--primary) !important;
  box-shadow: 3px 0 0 rgba(37, 99, 235, 0.3);
}

.arrangement-chip .drag-handle {
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: grab;
  line-height: 1;
}

.arrangement-chip .chip-label {
  white-space: nowrap;
}

.arrangement-chip .chip-remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 0.1rem;
  font-size: 1.15rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s;
}

.arrangement-chip .chip-remove-btn:hover {
  color: #ef4444;
}

/* Palette styles */
.arrangement-palette-box {
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
}

.arrangement-palette-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px dashed var(--border);
  background: var(--bg-card);
  color: var(--text-main);
  transition: all 0.15s ease;
  user-select: none;
}

.arrangement-palette-item:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
  transform: translateY(-1px);
}

/* Specific colors by block type (Light theme) */
.chip-type-verse {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.chip-type-chorus {
  background: #fef3c7;
  border-color: #fde68a;
  color: #92400e;
}

.chip-type-bridge {
  background: #f3e8ff;
  border-color: #e9d5ff;
  color: #6d28d9;
}

.chip-type-pre_chorus {
  background: #ccfbf1;
  border-color: #99f6e4;
  color: #0f766e;
}

.chip-type-intro,
.chip-type-outro {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #334155;
}

.chip-type-coda {
  background: #fdf2f8;
  border-color: #fbcfe8;
  color: #be185d;
}

.chip-type-other {
  background: #f8fafc;
  border-color: #e2e8f0;
  color: #475569;
}

/* Specific colors by block type (Dark theme) */
[data-theme="dark"] .chip-type-verse {
  background: #172554;
  border-color: #1d4ed8;
  color: #93c5fd;
}

[data-theme="dark"] .chip-type-chorus {
  background: #451a03;
  border-color: #b45309;
  color: #fde68a;
}

[data-theme="dark"] .chip-type-bridge {
  background: #3b0764;
  border-color: #7e22ce;
  color: #e9d5ff;
}

[data-theme="dark"] .chip-type-pre_chorus {
  background: #042f2e;
  border-color: #0f766e;
  color: #99f6e4;
}

[data-theme="dark"] .chip-type-intro,
[data-theme="dark"] .chip-type-outro {
  background: #1e293b;
  border-color: #334155;
  color: #cbd5e1;
}

[data-theme="dark"] .chip-type-coda {
  background: #500724;
  border-color: #9d174d;
  color: #fbcfe8;
}

[data-theme="dark"] .chip-type-other {
  background: #1e293b;
  border-color: #334155;
  color: #94a3b8;
}

/* Dark mode admin styling adjustments */
[data-theme="dark"] .chord-helper-toolbar {
  background: #0b0f19 !important;
  border-color: var(--border) !important;
}

[data-theme="dark"] .chord-helper-toolbar span {
  color: var(--text-muted) !important;
}

[data-theme="dark"] .card[style*="background: #f8fafc"],
[data-theme="dark"] div[style*="background: #f8fafc"] {
  background: #0f172a !important;
  border-color: var(--border) !important;
}

[data-theme="dark"] .card[style*="background: #f0f9ff"] {
  background: #0c2138 !important;
  border-color: #1e40af !important;
}

[data-theme="dark"] .card[style*="background: #fdfcfe"] {
  background: #151e2e !important;
  border-color: var(--border) !important;
}

[data-theme="dark"] h4[style*="color: #334155"] {
  color: #cbd5e1 !important;
}

[data-theme="dark"] h3[style*="color: #1e3a8a"] {
  color: #93c5fd !important;
}

[data-theme="dark"] p[style*="color: #3b82f6"] {
  color: #60a5fa !important;
}

[data-theme="dark"] span[style*="color: #cbd5e1"] {
  color: #475569 !important;
}

[data-theme="dark"] [style*="border-color: #f59e0b"] {
  border-color: #d97706 !important;
  color: #fbbf24 !important;
  background: rgba(217, 119, 6, 0.12) !important;
}

[data-theme="dark"] [style*="border-color: #f59e0b"]:hover {
  background: rgba(217, 119, 6, 0.25) !important;
  color: #fde68a !important;
}

[data-theme="dark"] [style*="border-color: #8b5cf6"] {
  border-color: #7c3aed !important;
  color: #c4b5fd !important;
  background: rgba(124, 58, 237, 0.12) !important;
}

[data-theme="dark"] [style*="border-color: #8b5cf6"]:hover {
  background: rgba(124, 58, 237, 0.25) !important;
}

[data-theme="dark"] [style*="border-color: #14b8a6"] {
  border-color: #0d9488 !important;
  color: #5eead4 !important;
  background: rgba(13, 148, 136, 0.12) !important;
}

[data-theme="dark"] [style*="border-color: #14b8a6"]:hover {
  background: rgba(13, 148, 136, 0.25) !important;
}

[data-theme="dark"] [style*="border-color: #fca5a5"] {
  border-color: #991b1b !important;
  color: #fca5a5 !important;
  background: rgba(239, 68, 68, 0.12) !important;
}

[data-theme="dark"] [style*="border-color: #fca5a5"]:hover {
  background: rgba(239, 68, 68, 0.25) !important;
}

/* Auto Number Toggle */
.auto-number-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-main);
  transition: all 0.15s ease;
}

.auto-number-toggle:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

.auto-number-toggle input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Mobile Responsiveness */
@media (max-width: 640px) {
  .nav-bar {
    gap: 0.5rem;
  }
  .brand-title {
    font-size: 1.05rem;
  }
  .nav-links {
    gap: 0.35rem;
  }
  .nav-links a {
    padding: 0.3rem 0.5rem;
    font-size: 0.85rem;
  }
  .theme-toggle-btn {
    width: 2rem;
    height: 2rem;
    font-size: 1rem;
  }
}
