:root {
  --ink: #15231f;
  --muted: #66746f;
  --paper: #f8f4ec;
  --surface: #fffdf8;
  --line: #ded5c5;
  --green: #255b4d;
  --green-2: #3f7b67;
  --gold: #c8983d;
  --rose: #9f4d4e;
  --blue: #315f7c;
  --shadow: 0 18px 55px rgba(35, 38, 34, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(140deg, rgba(37, 91, 77, 0.13), transparent 36%),
    linear-gradient(320deg, rgba(200, 152, 61, 0.16), transparent 42%),
    var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea { font: inherit; }

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 26px 32px 18px;
  background: rgba(255, 253, 248, 0.88);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--gold);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(26px, 3vw, 42px); font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
h2 { margin-bottom: 6px; font-size: 24px; }
h3 { margin-bottom: 14px; font-size: 18px; }
p { color: var(--muted); }

.tabs {
  display: flex;
  gap: 8px;
  padding: 4px;
  background: #eee5d6;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.tab, button {
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--ink);
  background: transparent;
  cursor: pointer;
  font-weight: 750;
}

.tab.is-active, button[type="submit"], .mini.primary {
  color: white;
  background: var(--green);
}

main { padding: 26px 32px 48px; }
.view { display: none; }
.view.is-active { display: block; }

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.search, .select-label {
  display: grid;
  gap: 6px;
  min-width: 260px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--ink);
  background: var(--surface);
}

.matrix-shell {
  overflow: auto;
  max-height: calc(100vh - 190px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.matrix {
  width: 100%;
  min-width: 1180px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.matrix th, .matrix td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  vertical-align: top;
  background: var(--surface);
}

.matrix th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #efe5d6;
  text-align: left;
  font-size: 12px;
}

.matrix .piece-head, .matrix .piece-cell {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 220px;
  max-width: 260px;
  background: #f6efe3;
}

.matrix .piece-head { z-index: 4; }
.composer { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; font-weight: 500; }

.cell-tags { display: flex; flex-wrap: wrap; gap: 4px; min-width: 108px; }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  border-radius: 999px;
  padding: 4px 7px;
  color: #10231e;
  background: #e8eadc;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.1;
}
.tag.part { background: #d9eadf; color: #174738; }
.tag.instrument { background: #f0e2bd; color: #614713; }
.tag .remove { padding: 0; color: inherit; background: transparent; line-height: 1; }
.comment-dot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 22px;
  border-radius: 999px;
  border: 0;
  color: white;
  background: var(--rose);
  cursor: pointer;
  padding: 0;
}
.comment-dot svg {
  width: 14px;
  height: 14px;
  stroke-width: 2.4;
}
.comment-popover {
  position: fixed;
  z-index: 30;
  max-width: min(320px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  color: var(--ink);
  background: white;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
}

.performer-sticky {
  position: sticky;
  top: 104px;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: -4px 0 16px;
  border: 1px solid rgba(37, 91, 77, 0.28);
  border-radius: 8px;
  padding: 12px 14px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 12px 34px rgba(35, 38, 34, 0.12);
  backdrop-filter: blur(18px);
}

.performer-current {
  min-width: 0;
}

.performer-current .eyebrow {
  display: block;
  margin-bottom: 3px;
}

.performer-current strong {
  display: block;
  overflow: hidden;
  color: var(--green);
  font-size: 22px;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.performer-current small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-weight: 650;
}

.performer-actions {
  display: flex;
  align-items: end;
  gap: 10px;
}

.performer-switcher {
  min-width: 280px;
}
#performer-save-all[hidden],
#piece-save-all[hidden] {
  display: none;
}
#performer-save-all:disabled,
#piece-save-all:disabled {
  cursor: wait;
  opacity: 0.68;
}


.piece-list {
  display: grid;
  gap: 12px;
}

.piece-editor, .panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 10px 28px rgba(35, 38, 34, 0.08);
}

.piece-editor {
  display: grid;
  grid-template-columns: minmax(180px, 1.2fr) minmax(240px, 1.5fr) minmax(240px, 1.5fr);
  gap: 18px;
}

.piece-title { margin: 0 0 3px; font-weight: 850; }
.performer-readonly {
  grid-template-columns: minmax(180px, 1.2fr) minmax(170px, 0.9fr) minmax(220px, 1.2fr);
}
.performer-comment-block {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.performer-comment {
  margin-bottom: 0;
  color: var(--ink);
}
.empty-state {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}
.part-strip, .chip-options { display: flex; flex-wrap: wrap; gap: 8px; }
.choice-chip, .part-check-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 10px;
  background: #fbf7ef;
}
.part-check-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  color: #174738;
  background: #d9eadf;
  font-size: 12px;
  font-weight: 750;
  line-height: 1.1;
  white-space: nowrap;
}
.part-check-chip input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  opacity: 0;
}
.part-check-chip:not(:has(input:checked)) {
  color: var(--muted);
  background: #fbf7ef;
}
.part-check-chip:has(input:checked) {
  border-color: rgba(37, 91, 77, 0.64);
  background: #d9eadf;
}
.compact-chip-options {
  gap: 4px;
}
.choice-chip.is-selected {
  border-color: var(--green);
  color: white;
  background: var(--green);
}

.token-box {
  min-height: 44px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px;
  background: var(--surface);
  position: relative;
}

.token-box input {
  flex: 1;
  min-width: 135px;
  border: 0;
  padding: 6px;
  background: transparent;
}

.suggestions {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  right: 0;
  z-index: 5;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
  box-shadow: var(--shadow);
}
.suggestions button {
  display: block;
  width: 100%;
  border-radius: 0;
  text-align: left;
  background: white;
}
.suggestions button:hover { background: #f3ead9; }

.editor-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: start;
}

.mini {
  border: 1px solid var(--line);
  background: #f6efe3;
  padding: 8px 10px;
}

.admin-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.admin-nav {
  position: sticky;
  top: 104px;
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 253, 248, 0.94);
  box-shadow: 0 10px 28px rgba(35, 38, 34, 0.08);
}

.admin-nav-item {
  width: 100%;
  border-radius: 6px;
  padding: 10px 12px;
  text-align: left;
  background: transparent;
}

.admin-nav-item.is-active {
  color: white;
  background: var(--green);
}

.admin-panels {
  min-width: 0;
}

.admin-panel {
  display: none;
}

.admin-panel.is-active {
  display: block;
}
.admin-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.admin-section-head h3 {
  margin-bottom: 0;
}
.admin-add-form {
  margin-bottom: 16px;
  border: 1px solid rgba(37, 91, 77, 0.24);
  border-radius: 8px;
  padding: 12px;
  background: #fbf7ef;
}
.admin-add-form[hidden] {
  display: none;
}

.stack { display: grid; gap: 9px; }
.phone-field {
  display: block;
}
.phone-field .iti {
  width: 100%;
}
.phone-field input {
  min-width: 0;
  width: 100%;
}
.phone-field .iti__tel-input {
  padding-top: 11px;
  padding-bottom: 11px;
}
.phone-field .iti__country-list {
  border-color: var(--line);
  border-radius: 8px;
  box-shadow: 0 16px 38px rgba(35, 38, 34, 0.18);
}
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.check input { width: auto; }

.admin-list {
  display: grid;
  gap: 8px;
  margin-top: 16px;
  max-height: 470px;
  overflow: auto;
}
.admin-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.admin-row-static {
  grid-template-columns: 1fr auto auto;
}
.piece-admin-row,
.performer-admin-row,
.part-admin-row,
.instrument-admin-row {
  display: block;
}
.piece-row-summary,
.performer-row-summary,
.part-row-summary,
.instrument-row-summary {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 8px;
  align-items: center;
}
.performer-row-summary,
.instrument-row-summary {
  grid-template-columns: 1fr auto auto;
}
.piece-admin-row.is-expanded,
.performer-admin-row.is-expanded,
.part-admin-row.is-expanded,
.instrument-admin-row.is-expanded {
  border: 1px solid rgba(37, 91, 77, 0.26);
  border-radius: 8px;
  padding: 10px;
  background: #fbf7ef;
}
.row-chip-line {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}
.inline-piece-form,
.inline-admin-form {
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) minmax(150px, 1fr) 96px;
  gap: 10px;
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.inline-performer-form {
  grid-template-columns: minmax(180px, 1.2fr) minmax(180px, 1fr) minmax(240px, 1.2fr);
}
.inline-instrument-form {
  grid-template-columns: minmax(180px, 1.2fr) minmax(180px, 1fr) auto;
}
.inline-part-form {
  grid-template-columns: minmax(180px, 1.2fr) 110px auto;
}
.inline-piece-form label:not(.check),
.inline-admin-form label:not(.check) {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.inline-piece-form input,
.inline-piece-form textarea,
.inline-admin-form input,
.inline-admin-form textarea {
  text-transform: none;
}
.inline-phone-field {
  grid-template-columns: minmax(145px, 0.8fr) minmax(170px, 1.2fr);
}
.inline-notes,
.inline-parts,
.inline-form-actions {
  grid-column: 1 / -1;
}
.inline-parts {
  margin: 0;
  border: 0;
  padding: 0;
}
.inline-parts legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}
.inline-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.admin-row.is-dragging {
  opacity: 0.45;
}
.drag-handle {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #f6efe3;
  cursor: grab;
  font-size: 18px;
  line-height: 1;
}
.drag-handle:active {
  cursor: grabbing;
}
.admin-row strong { display: block; }
.admin-row small { color: var(--muted); }

#toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 320px;
  border-radius: 8px;
  padding: 12px 14px;
  color: white;
  background: var(--green);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: 0.2s ease;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 920px) {
  .topbar, .toolbar, .performer-sticky, .performer-actions { align-items: stretch; flex-direction: column; }
  .performer-sticky, .admin-nav { top: 154px; }
  main { padding: 18px; }
  .piece-editor, .admin-layout, .editor-actions, .inline-piece-form, .inline-admin-form, .inline-performer-form, .inline-part-form, .inline-instrument-form { grid-template-columns: 1fr; }
  .admin-nav { position: static; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .piece-row-summary, .performer-row-summary, .part-row-summary, .instrument-row-summary { grid-template-columns: auto 1fr; }
  .performer-row-summary, .instrument-row-summary { grid-template-columns: 1fr; }
  .piece-row-summary .mini, .performer-row-summary .mini, .part-row-summary .mini, .instrument-row-summary .mini { grid-column: span 1; }


  .search, .select-label, .performer-switcher { min-width: 0; }
}
