/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #1a1a2e;
  --surface:  #16213e;
  --border:   #0f3460;
  --accent:   #e94560;
  --accent2:  #533483;
  --text:     #eaeaea;
  --muted:    #8892a4;
  --radius:   6px;
  --font:     'Segoe UI', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ───────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: .75rem 1.25rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .75rem;
}

header h1 { font-size: 1.4rem; white-space: nowrap; }

#header-actions {
  display: flex;
  gap: .6rem;
  align-items: center;
  flex-shrink: 0;
  margin-left: auto; /* right-aligns on same line; left-fills when alone on a row */
}



#filter-search {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: .3rem .6rem;
  font-size: .85rem;
  min-width: 0;
}

#btn-unlock        { background: transparent; border: 1px solid var(--border); color: var(--muted); }
#btn-add-tune      { background: #166534; color: #86efac; border: 1px solid #15803d; }
#btn-clear-filters { background: transparent; border: 1px solid var(--border); color: var(--muted); font-size: .8rem; }

#app-footer {
  padding: .4rem 1.25rem;
  text-align: center;
  font-size: .8rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

/* ── Column header filters ────────────────────────────────── */
th[data-filter] {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

th[data-filter]::after {
  content: ' ▾';
  font-size: .7em;
  opacity: .5;
}

th[data-filter].filter-active::after {
  content: ' ▾';
  opacity: 1;
}

th[data-filter].filter-active {
  color: var(--text);
}

th[data-filter].filter-active::before {
  content: '● ';
  color: var(--accent);
  font-size: .6em;
  vertical-align: middle;
}

/* ── Filter popover ───────────────────────────────────────── */
#filter-popover {
  position: fixed;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem .75rem;
  min-width: 160px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

#filter-popover-inner select,
#filter-popover-inner input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: .3rem .5rem;
  font-size: .85rem;
  width: 100%;
}

.popover-checkbox-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .25rem 0;
  font-size: .875rem;
  cursor: pointer;
}

.popover-checkbox-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.popover-clear {
  margin-top: .5rem;
  font-size: .75rem;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.popover-clear:hover { color: var(--text); }

/* Short/full column header label swap (see responsive section) */
.col-short { display: none; }

/* Dim pill for inactive mobile status indicators */
.pill-dim { background: rgba(255,255,255,.06); color: var(--muted); }

/* Mobile card row — hidden on desktop, shown in responsive block */
.mobile-row { display: none; }

/* Tooltip for truncated mobile text */
#mob-tooltip {
  position: fixed;
  z-index: 200;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .35rem .65rem;
  font-size: .8rem;
  max-width: 80vw;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  pointer-events: none;
  color: var(--text);
}

/* ── Buttons ──────────────────────────────────────────────── */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  padding: .35rem .75rem;
  font-size: .85rem;
  background: var(--accent2);
  color: var(--text);
  transition: opacity .15s;
}
button:hover { opacity: .85; }

/* ── Table ────────────────────────────────────────────────── */
main {
  flex: 1;
  overflow-x: auto;
  padding: 1rem 1.25rem;
  min-width: 0; /* required for overflow-x: auto to work inside a flex container */
}

#tune-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

#tune-table th,
#tune-table td {
  padding: .5rem .75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

#tune-table thead th {
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
  user-select: none;
}

#tune-table thead th[data-col] { cursor: pointer; }
#tune-table thead th[data-col]:hover { color: var(--text); }

.sort-indicator::after { content: ''; margin-left: .3em; }
th.sort-asc  .sort-indicator::after { content: '▲'; }
th.sort-desc .sort-indicator::after { content: '▼'; }

#tune-table tbody tr:nth-child(even) { background: rgba(255,255,255,.025); }
#tune-table tbody tr:hover           { background: rgba(255,255,255,.055); }

/* Truncating spans for Name + Source columns */
.cell-trunc {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cell-name-content   { max-width: min(14vw, 200px); }
.cell-source-content { max-width: min(11vw, 160px); }
.cell-inst-content   { max-width: min(11vw, 130px); }
.cell-tuning-content { max-width: min(9vw,  110px); }

.pill {
  display: inline-block;
  padding: .15rem .45rem;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}
.pill-yes  { background: #1e4d2b; color: #6fcf97; }
.pill-no   { background: #4d1e1e; color: #eb5757; }
.pill-warn     { background: #4d3a1e; color: #f2c94c; }
.pill-to-learn { background: #2a1a4e; color: #c4b5fd; }

.action-btn {
  background: transparent;
  border: 1px solid var(--border);
  padding: .2rem .5rem;
  font-size: .75rem;
  margin-right: .25rem;
}

#empty-msg { color: var(--muted); text-align: center; padding: 2rem; }

/* ── Modal ────────────────────────────────────────────────── */
dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 560px;
  width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
}

dialog::backdrop { background: rgba(0,0,0,.65); }

dialog h2 { margin-bottom: 1rem; }
dialog h3 { font-size: .95rem; margin: .75rem 0 .4rem; color: var(--muted); }

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem;
  margin-bottom: .75rem;
}

fieldset legend {
  padding: 0 .35rem;
  font-size: .85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: .4rem;
}

fieldset label {
  display: grid;
  grid-template-columns: 120px 1fr;
  align-items: center;
  gap: .4rem;
  margin-bottom: .4rem;
  font-size: .85rem;
}

fieldset input[type="checkbox"] { justify-self: start; }

fieldset input[type="text"],
fieldset input[type="date"],
fieldset select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: .3rem .5rem;
  font-size: .85rem;
  width: 100%;
}

.autocomplete-row {
  display: flex;
  gap: .4rem;
  align-items: center;
}

.autocomplete-row input  { flex: 1; }
.quick-add-btn { flex-shrink: 0; padding: .3rem .6rem; font-size: .85rem; background: var(--accent2); }

/* collapse instrument fieldset when checkbox unchecked */
fieldset .fs-body { display: none; }
fieldset.active .fs-body { display: contents; }

.note-row, .ref-row {
  display: flex;
  gap: .4rem;
  margin-bottom: .4rem;
  align-items: flex-start;
}

.note-row input, .ref-row input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: .3rem .5rem;
  font-size: .85rem;
}

.remove-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: .2rem .45rem;
  font-size: .75rem;
}

.btn-danger { background: var(--accent); }

.modal-error { color: #eb5757; font-size: .82rem; margin: .3rem 0 0; }

.note-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .3rem 0;
  border-bottom: 1px solid var(--border);
}
.note-row:last-child { border-bottom: none; }
.note-text { flex: 1; font-size: .875rem; white-space: pre-wrap; word-break: break-word; }
.note-edit-controls { display: flex; gap: .25rem; }

.btn-edit-row { background: transparent; border: none; font-size: 1rem; padding: .2rem .3rem; }

#btn-delete-tune { background: #4d1e1e; color: #eb5757; border: 1px solid #eb5757; margin-right: auto; }

.modal-actions {
  display: flex;
  gap: .6rem;
  justify-content: flex-end;
  margin-top: 1rem;
}
.status-radios {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.radio-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .85rem;
  font-weight: normal;
  cursor: pointer;
}
.radio-row input[type="radio"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  flex-shrink: 0;
}

#btn-save-tune { background: var(--accent); }
#btn-cancel    { background: transparent; border: 1px solid var(--border); }

#notes-modal {
  max-width: 700px;
  height: 70vh;
  max-height: 85vh;
}

#note-editor-modal {
  max-width: 700px;
  height: 90vh;
  max-height: 95vh;
}
#note-editor-modal[open] {
  display: flex;
  flex-direction: column;
}

#note-editor-ta {
  flex: 1;
  min-height: 0;
  display: block;
  width: 100%;
  resize: vertical;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: .5rem .65rem;
  font-size: .875rem;
  font-family: var(--font);
  line-height: 1.5;
  margin-bottom: .5rem;
}
#note-editor-ta:focus {
  outline: 2px solid var(--accent2);
  outline-offset: -1px;
}

/* ── Detail modal ─────────────────────────────────────────── */
#detail-content h2 { margin-bottom: .75rem; }
#detail-content table { width: 100%; border-collapse: collapse; font-size: .85rem; }
#detail-content td { padding: .3rem .5rem; border-bottom: 1px solid var(--border); }
#detail-content td:first-child { color: var(--muted); width: 120px; }
#detail-content h3 { margin: 1rem 0 .4rem; font-size: .9rem; color: var(--muted); }

#btn-detail-close {
  margin-top: 1rem;
  background: transparent;
  border: 1px solid var(--border);
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 600px) {
  /* Fixed viewport so header and footer stay put while main scrolls */
  body { height: 100dvh; overflow: hidden; }
  main { overflow-y: auto; }

  /* Search drops to its own full-width row */
  #filter-search           { order: 3; flex-basis: 100%; }
  /* Actions fill remaining space; each button gets an equal share; ☰ stays natural size */
  #header-actions          { flex: 1; margin-left: 0; }
  #header-actions > button { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; }
  #btn-bulk-edit           { flex: none; }

  /* Table: block layout so the card has a concrete width to truncate against */
  #tune-table,
  #tune-table tbody,
  #tune-table tr  { display: block; width: 100%; }
  #tune-table thead { display: none; }
  #tune-table tr  { border-bottom: 1px solid var(--border); }
  #tune-table td:not(.mobile-row) { display: none; }
  .mobile-row     { display: block; padding: .45rem .6rem; }

  /* Line 1: Name (Source) … [Call][Rev][Lrn] */
  .mob-line1 {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .4rem;
  }
  .mob-name-wrap {
    display: flex;
    align-items: baseline;
    gap: .25rem;
    flex: 1;
    min-width: 0;
  }
  .mob-name {
    font-weight: 600;
    font-size: .82rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 0;
    min-width: 1.5rem;
  }
  .mob-source {
    font-size: .75rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 0 1 auto;
    min-width: 1.5rem;
  }
  .mob-status { display: flex; gap: .2rem; align-items: center; flex-shrink: 0; }
  .mob-pill   { font-size: .7rem; padding: .1rem .4rem; }

  /* Line 2: Instrument (Tuning) · Key [actions] */
  .mob-line2 {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .4rem;
    margin-top: .25rem;
  }
  .mob-meta {
    font-size: .72rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
  }
  .mob-actions { display: flex; gap: .2rem; flex-shrink: 0; }

  /* Modals: fullscreen — !important beats any ID-specific desktop size rules */
  dialog {
    position: fixed !important;
    inset: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    border: none !important;
    margin: 0 !important;
  }
}

/* ── Bulk edit popover ────────────────────────────────────── */
#bulk-edit-popover {
  position: fixed;
  z-index: 100;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .4rem;
  min-width: 200px;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  flex-direction: column;
  gap: .2rem;
}
#bulk-edit-popover:not([hidden]) { display: flex; }

#bulk-edit-popover button {
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: .4rem .65rem;
  border-radius: var(--radius);
  font-size: .875rem;
}

#bulk-edit-popover button:hover { background: rgba(255,255,255,.08); opacity: 1; }

#btn-bulk-edit { background: transparent; border: 1px solid var(--border); color: var(--text); font-size: 1rem; padding: .3rem .65rem; }
#btn-call      { background: #1b4332; color: #74c69d; border: 1px solid #2d6a4f; font-weight: 600; }
#btn-review    { background: #3d2e10; color: #f2c94c; border: 1px solid #4d3a1e; font-weight: 600; }
#btn-learn     { background: #2a1a4e; color: #c4b5fd; border: 1px solid #3d2562; font-weight: 600; }

/* ── Call modal ───────────────────────────────────────────── */
#call-modal {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  border: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
}
#call-modal[open] {
  display: flex;
  flex-direction: column;
}

#call-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

#call-title { flex: 1; margin: 0; font-size: 1.5rem; }

#call-back,
#call-close {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 1rem;
  padding: .45rem .85rem;
}

#call-options {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
}

.call-option-btn {
  display: block;
  width: 100%;
  padding: 1.1rem 1.25rem;
  font-size: 1.15rem;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  margin-bottom: .5rem;
  cursor: pointer;
}
.call-option-btn:hover,
.call-option-btn:active { background: rgba(255,255,255,.08); opacity: 1; }

.call-all-btn {
  background: var(--accent2);
  margin-bottom: .85rem;
  font-weight: 600;
}

/* ── Bulk refs modal ──────────────────────────────────────── */
#bulk-refs-modal { max-width: 760px; }

#bulk-refs-controls {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}

#bulk-refs-controls input,
#bulk-refs-controls select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: .3rem .5rem;
  font-size: .85rem;
}

#bulk-refs-controls input[type="search"] { flex: 1; min-width: 140px; }

#bulk-refs-list {
  max-height: 55vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: .5rem;
}

.bulk-tune-row {
  padding: .45rem .65rem;
  border-bottom: 1px solid var(--border);
}
.bulk-tune-row:last-child { border-bottom: none; }

.bulk-tune-main {
  display: flex;
  align-items: center;
  gap: .6rem;
}

.bulk-tune-name {
  font-weight: 600;
  font-size: .875rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bulk-tune-meta,
.bulk-tune-instruments {
  font-size: .8rem;
  color: var(--muted);
  white-space: nowrap;
}

.bulk-tune-refs { white-space: nowrap; }

.btn-bulk-add-ref { flex-shrink: 0; font-size: .75rem; padding: .2rem .5rem; }

.bulk-ref-form {
  display: flex;
  gap: .4rem;
  align-items: center;
  margin-top: .35rem;
  padding-top: .35rem;
  border-top: 1px solid var(--border);
}

.bulk-ref-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: .3rem .5rem;
  font-size: .85rem;
  flex: 1;
}

.bulk-ref-form .bulk-ref-site { max-width: 110px; flex: none; }

.btn-bulk-ref-save { background: var(--accent); flex-shrink: 0; font-size: .8rem; padding: .25rem .6rem; }

.bulk-refs-empty { color: var(--muted); text-align: center; padding: 1.5rem; font-size: .875rem; }

/* ── CSV upload modal ────────────────────────────────────────── */
#csv-format-details summary {
  cursor: pointer;
  font-size: .875rem;
  color: var(--muted);
  margin-bottom: .4rem;
  user-select: none;
}
#csv-format-details summary:hover { color: var(--text); }

.csv-format-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .8rem;
  margin-bottom: .6rem;
}
.csv-format-table th,
.csv-format-table td {
  padding: .3rem .5rem;
  border: 1px solid var(--border);
  text-align: left;
}
.csv-format-table th { background: var(--bg); color: var(--muted); font-weight: 600; }
.csv-format-table td:first-child { font-family: monospace; color: #74c69d; }
.csv-format-table td:nth-child(2) { text-align: center; color: var(--accent); font-weight: 600; }

.csv-format-note {
  font-size: .78rem;
  color: var(--muted);
  margin: 0;
}

#csv-upload-area {
  margin: 1rem 0 .75rem;
}

#csv-results {
  margin-top: .75rem;
  font-size: .875rem;
}
.csv-ok     { color: #6fcf97; margin: .3rem 0; }
.csv-error  { color: #eb5757; margin: .3rem 0; }
.csv-status { color: var(--muted); margin: .3rem 0; }
.csv-errors { color: var(--muted); margin: .3rem 0 .3rem 1.25rem; }
.csv-errors li { margin-bottom: .2rem; }

#btn-csv-import { background: var(--accent); }

/* ── Musician chips ──────────────────────────────────────────── */
.ref-musicians-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .35rem;
  width: 100%;
  margin-top: .3rem;
}

.ref-musician-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}

.musician-chip {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  background: var(--accent2);
  border-radius: 99px;
  padding: .15rem .45rem .15rem .55rem;
  font-size: .75rem;
  white-space: nowrap;
}

.chip-remove {
  background: transparent;
  border: none;
  color: inherit;
  padding: 0 .1rem;
  font-size: .65rem;
  line-height: 1;
  opacity: .7;
}
.chip-remove:hover { opacity: 1; }

/* Allow ref rows to wrap so the musician row sits on its own line */
.ref-row { flex-wrap: wrap; }

/* Same for bulk ref form */
.bulk-ref-form { flex-wrap: wrap; }
.bulk-ref-musicians-mount { width: 100%; }
.bulk-ref-musicians-mount .ref-musicians-row { margin-top: 0; }

/* ── References display modal ────────────────────────────────── */
.refs-modal-item {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
}
.refs-modal-item:last-child { border-bottom: none; }

.ref-link-anchor {
  color: var(--accent);
  font-size: .875rem;
  text-decoration: none;
}
.ref-link-anchor:hover { text-decoration: underline; }

.ref-meta {
  font-size: .8rem;
  color: var(--muted);
}

.ref-site-wrap { max-width: 160px; }
