:root {
  --bg: #141414;
  --surface: #1f1f1f;
  --surface2: #2a2a2a;
  --border: #333;
  --text: #e9e9e9;
  --muted: #9a9a9a;
  --accent: #ffc600;
  --accent-text: #141414;
  --chord: #ffc600;
  --header: #7fb8ff;
  --danger: #ff6b6b;
  --mono: "Roboto Mono", Consolas, "Courier New", monospace;
}
:root[data-theme="light"] {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface2: #efefec;
  --border: #dddcd7;
  --text: #1c1c1c;
  --muted: #6b6b6b;
  --accent: #1a73e8;
  --accent-text: #fff;
  --chord: #0b5cc4;
  --header: #b4520a;
  --danger: #c62828;
}

/* Bootstrap 5.3 bridge: point its theme variables at ours so components/utilities match */
:root, [data-bs-theme] {
  --bs-body-bg: var(--bg);
  --bs-body-color: var(--text);
  --bs-secondary-bg: var(--surface2);
  --bs-tertiary-bg: var(--surface);
  --bs-secondary-color: var(--muted);
  --bs-border-color: var(--border);
  --bs-emphasis-color: var(--text);
  --bs-code-color: inherit;
  --bs-link-color: var(--accent);
  --bs-primary: var(--accent);
  --bs-danger: var(--danger);
  scroll-behavior: auto; /* Bootstrap's smooth scrolling fights the auto-scroll in song view */
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
h1, h2 { font-weight: 700; line-height: 1.3; }
p { margin: 10px 0; } /* Bootstrap reboot zeroes the top margin */
code { font-family: var(--mono); font-size: .9em; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; font-size: 17px; white-space: nowrap; }
.topbar nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar nav a { text-decoration: none; padding: 6px 10px; border-radius: 6px; color: var(--muted); white-space: nowrap; }
.topbar nav a.active { color: var(--text); background: var(--surface2); }

main { max-width: 1000px; margin: 0 auto; padding: 16px; }

/* ---------- controls ---------- */
/* .btn is styled through Bootstrap's --bs-btn-* variables; variants only swap color/bg/border */
.btn {
  --bs-btn-padding-x: 12px; --bs-btn-padding-y: 7px; --bs-btn-border-radius: 7px;
  --bs-btn-font-size: inherit; --bs-btn-font-weight: inherit; --bs-btn-line-height: inherit;
  --bs-btn-color: var(--text); --bs-btn-bg: var(--surface2); --bs-btn-border-color: var(--border);
  --bs-btn-hover-color: var(--bs-btn-color); --bs-btn-hover-bg: var(--bs-btn-bg); --bs-btn-hover-border-color: var(--muted);
  --bs-btn-active-color: var(--bs-btn-color); --bs-btn-active-bg: var(--bs-btn-bg); --bs-btn-active-border-color: var(--muted);
  --bs-btn-disabled-color: var(--bs-btn-color); --bs-btn-disabled-bg: var(--bs-btn-bg); --bs-btn-disabled-border-color: var(--bs-btn-border-color);
  --bs-btn-disabled-opacity: .4;
  --bs-btn-focus-box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--accent) 35%, transparent);
  display: inline-flex; align-items: center; gap: 6px; justify-content: center; white-space: nowrap;
}
.btn.primary, .btn.on { --bs-btn-color: var(--accent-text); --bs-btn-bg: var(--accent); --bs-btn-border-color: var(--accent); --bs-btn-hover-border-color: var(--accent); --bs-btn-active-border-color: var(--accent); }
.btn.primary { font-weight: 600; }
.btn.danger { --bs-btn-color: var(--danger); }
.btn.sm { --bs-btn-padding-x: 9px; --bs-btn-padding-y: 4px; --bs-btn-font-size: 13px; }
.icon-btn { background: none; border: 1px solid var(--border); border-radius: 7px; padding: 5px 9px; cursor: pointer; }

input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--surface); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

.cb-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 18px; margin: 0; }

/* ---------- lists ---------- */
.list { margin-top: 14px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px;
  border-top: 1px solid var(--border); text-decoration: none;
}
.list-item:first-child { border-top: 0; }
a.list-item:hover, .list-item.clickable:hover { background: var(--surface2); cursor: pointer; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .num { width: 22px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.key-badge {
  font-family: var(--mono); font-weight: 700; font-size: 13px; color: var(--chord);
  border: 1px solid var(--border); border-radius: 6px; padding: 2px 7px; white-space: nowrap;
}
.row-actions { display: flex; gap: 4px; flex-shrink: 0; }
.row-btn {
  background: none; border: 1px solid transparent; border-radius: 6px; color: var(--muted);
  width: 30px; height: 30px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1; cursor: pointer; padding: 0;
}
.row-btn:hover { border-color: var(--border); color: var(--text); background: var(--surface); }
.row-btn.danger:hover { color: var(--danger); border-color: var(--danger); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- activity log ---------- */
.activity-filters { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; margin-top: 12px; }
.list-item.activity { align-items: flex-start; }
.activity .a-icon { width: 24px; text-align: center; flex: 0 0 auto; }
.activity .a-user { font-weight: 700; }
.activity.bad .title { color: var(--danger); }
.activity .a-when { font-size: 12px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
@media (max-width: 640px) {
  .activity-filters { grid-template-columns: 1fr 1fr; }
  .activity-filters #aq { grid-column: 1 / -1; }
}

/* ---------- song view ---------- */
.song-head { margin-bottom: 10px; }
.song-head .artist { color: var(--muted); }
.toolbar {
  position: sticky; top: 53px; z-index: 10;
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  padding: 8px; margin: 0 -8px 12px; background: var(--bg); border-bottom: 1px solid var(--border);
}
.group { display: inline-flex; align-items: center; gap: 4px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.group .btn { border: 0; background: none; padding: 5px 9px; }
.group .btn.on { background: var(--accent); }
.group .val { min-width: 64px; text-align: center; font-family: var(--mono); font-weight: 700; color: var(--chord); font-size: 14px; }
.group .lbl { font-size: 12px; color: var(--muted); padding-left: 6px; }
.meta { font-size: 13px; margin-bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.meta:empty { display: none; }
.chip {
  display: inline-flex; align-items: baseline; gap: 4px; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
.chip .lbl { color: var(--muted); }
.chip b { font-family: var(--mono); color: var(--chord); }
.chip b a { font-family: system-ui, sans-serif; color: var(--text); font-weight: 600; }
.chip.add { color: var(--muted); text-decoration: none; border-style: dashed; }
.chip.add:hover { color: var(--text); border-color: var(--muted); }

.sheet {
  font-family: var(--mono); white-space: pre; overflow-x: auto;
  padding: 4px 0 40vh; line-height: 1.35;
}
.sheet .ln { min-height: 1.35em; }
.sheet .chd { color: var(--chord); font-weight: 700; }
.sheet .chd .ch { cursor: pointer; }
.sheet .chd .ch:hover { text-decoration: underline; }
.sheet .hdr { color: var(--header); font-weight: 700; margin-top: .6em; font-family: system-ui, sans-serif; }
.sheet .tab { color: var(--muted); }

.diagrams { display: flex; gap: 10px; overflow-x: auto; padding: 4px 0 12px; margin-bottom: 8px; border-bottom: 1px dashed var(--border); }
.diagram { flex: 0 0 auto; text-align: center; }
.diagram .name { font-family: var(--mono); font-weight: 700; color: var(--chord); font-size: 14px; }
.diagram svg { display: block; }
.diagram svg .ln { stroke: var(--muted); }
.diagram svg .nut { stroke: var(--text); }
.diagram svg .dot { fill: var(--text); }
.diagram svg text { fill: var(--muted); font: 10px system-ui, sans-serif; }

.setlist-nav { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 10px; font-size: 14px; }

/* ---------- editor ---------- */
.form-grid { display: grid; grid-template-columns: 2fr 2fr 1fr 1fr 1fr 1fr; gap: 10px; margin: 14px 0; }
textarea.content { font-family: var(--mono); min-height: 55vh; line-height: 1.35; white-space: pre; overflow-wrap: normal; overflow-x: auto; resize: vertical; tab-size: 4; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0; }
.hint code { font-family: var(--mono); background: var(--surface2); padding: 1px 4px; border-radius: 4px; }
.preview { margin-top: 14px; border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--surface); }
.preview .sheet { padding-bottom: 8px; }

/* ---------- modal & toast ---------- */
.cb-modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px; }
.cb-modal { width: 100%; max-width: 480px; max-height: 80vh; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.cb-modal h2 { margin-bottom: 12px; }
.cb-modal .list { max-height: 45vh; overflow: auto; }
/* ---------- SweetAlert2 theming ---------- */
.swal2-popup { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 12px; }
.swal2-title, .swal2-html-container { color: var(--text); }
/* .swal2-popup prefix outranks our global input[type=text] { width: 100% }, which overflowed the popup */
.swal2-popup .swal2-input {
  width: auto; margin: 1em 2em 3px; padding: 8px 12px; height: auto; border-radius: 7px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); font-size: 15px;
}
/* Fields we put in the dialog's html (Add user, Reset password) get one fixed width so they line up */
.swal2-html-container .swal2-input { width: 260px; max-width: calc(100% - 4em); }
.swal2-popup .swal2-input::placeholder { color: var(--muted); }
.swal2-input:focus { border-color: var(--accent); box-shadow: none; }
.swal2-styled.swal2-confirm { background: var(--accent); color: var(--accent-text); }
.swal2-styled.swal2-cancel { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.swal2-validation-message { background: var(--surface2); color: var(--text); }
.swal2-popup.swal2-toast { box-shadow: 0 4px 16px rgba(0,0,0,.35); }
.swal2-timer-progress-bar { background: var(--accent); }

/* ---------- account menu ---------- */
.topbar .dropdown-menu { --bs-dropdown-bg: var(--surface); --bs-dropdown-border-color: var(--border); --bs-dropdown-link-color: var(--text);
  --bs-dropdown-link-hover-bg: var(--surface2); --bs-dropdown-link-hover-color: var(--text); --bs-dropdown-link-active-bg: var(--surface2);
  --bs-dropdown-link-active-color: var(--text); --bs-dropdown-divider-bg: var(--border); }
.topbar .dropdown-item-text { font-size: 13px; }

/* ---------- login ---------- */
.auth-card {
  max-width: 380px; margin: 10vh auto 0; padding: 22px; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.auth-card .brand { margin-bottom: 14px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card label { margin-top: 12px; }
.auth-card .btn { margin-top: 18px; }
.auth-error { margin-top: 10px; padding: 8px 10px; border-radius: 7px; color: var(--danger); border: 1px solid var(--danger); font-size: 14px; }

.auth-notice { margin-top: 10px; padding: 8px 10px; border-radius: 7px; border: 1px solid var(--accent); font-size: 14px; }
.auth-error ul { margin: 0; padding-left: 18px; }

/* ---------- setup ---------- */
.auth-card.wide { max-width: 560px; margin-top: 6vh; }
.setup-step { display: flex; align-items: center; gap: 8px; margin: 20px 0 4px; font-size: 16px; }
.setup-step span {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); font-size: 12px;
}
.setup-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.setup-row.host { grid-template-columns: 1fr 110px; }
.setup-row > div { display: flex; flex-direction: column; min-width: 0; }
.auth-card .hint { margin: 4px 0 0; }
.pw-field { position: relative; }
.pw-field input { padding-right: 58px; }
.pw-field button {
  position: absolute; top: 50%; right: 6px; transform: translateY(-50%);
  padding: 3px 8px; border: 0; border-radius: 5px; background: var(--surface2); color: var(--muted); font-size: 12px; cursor: pointer;
}
.pw-field button:hover { color: var(--text); }
/* inside SweetAlert dialogs the wrapper takes the input's margins so the button stays centered on the input */
.swal2-popup .pw-field { width: 260px; max-width: calc(100% - 4em); margin: 1em auto 3px; }
.swal2-popup .pw-field .swal2-input { margin: 0; width: 100%; max-width: none; padding-right: 58px; }
/* Temporary-password box: monospace so look-alike characters are easy to tell apart, room for the Copy button */
.swal2-popup .pw-copy .swal2-input { padding-right: 96px; font-family: ui-monospace, Consolas, monospace; font-size: 17px; letter-spacing: 1px; }
@media (max-width: 640px) {
  .setup-row:not(.host) { grid-template-columns: 1fr; }
  main { padding: 12px; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .topbar .brand { font-size: 15px; }
  .toolbar { top: 49px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .hide-sm { display: none; }
}

/* ---------- install page ---------- */
.auth-foot { text-align: center; margin-top: 14px; font-size: 14px; }
.auth-foot a { color: var(--muted); }
.install-page { max-width: 720px; padding-top: 28px; }
.install-page h1 { margin-bottom: 2px; }
.install-icon { border-radius: 12px; flex: 0 0 auto; border: 1px solid var(--border); }
.install-page > .cb-row:first-child { flex-wrap: nowrap; align-items: center; }
.install-tabs { margin: 18px 0 6px; flex-wrap: wrap; }
.install-page section h2 { font-size: 16px; margin: 18px 0 8px; }
.install-page ol { padding-left: 22px; margin: 0; }
.install-page li { margin-bottom: 8px; }
.install-page .kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 4px;
  border: 1px solid var(--border); border-radius: 5px; background: var(--surface2); font-size: 13px; vertical-align: -3px;
}
.install-now {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; padding: 10px 12px;
  border: 1px solid var(--accent); border-radius: 8px;
}
.install-now span { flex: 1; }
.install-note { margin-top: 22px; font-size: 13px; }
