@font-face {
  font-family: "rub";
  src: url("/assets/fonts/lato/Gilroy-Light.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
}
@font-face {
  font-family: "rub";
  src: url("/assets/fonts/lato/Gilroy-Regular.ttf") format("truetype");
  font-weight: bold;
  font-style: normal;
}

:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e2e4e9;
  --text: #1c1e26;
  --muted: #6b7080;
  --accent: #4056c7;
  --accent-soft: #eef0fb;
  --danger: #c0392b;
  --key-bg: #fdf0d5;
  --key-text: #8a5a00;
  --card: #fafbfc;
  --input-bg: #ffffff;
  --hdr-bg: #eef0fb;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 24, 40, .08);
}

body.dark {
  --bg: #131520;
  --panel: #1d212b;
  --border: #2f3342;
  --text: #e7e9f0;
  --muted: #98a0b3;
  --accent: #8b9cf5;
  --accent-soft: #262b3d;
  --danger: #e07b6d;
  --key-bg: #3b3115;
  --key-text: #ecc76f;
  --card: #252936;
  --input-bg: #171a23;
  --hdr-bg: #2a3050;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
body.dark .btn.danger { border-color: #5a3833; }
body.dark .btn.danger:hover { background: #33231f; }
body.dark .save-status.saved { color: #7ec98a; }
body.dark .modal-backdrop { background: rgba(0, 0, 0, .55); }

* { box-sizing: border-box; }

html, body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

/* ---------- шапка ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.save-status { font-size: 13px; color: var(--muted); }
.save-status.saved { color: #2e7d32; }

/* ---------- раскладка ---------- */
.layout {
  display: flex;
  gap: 16px;
  padding: 16px;
  align-items: flex-start;
}
.services {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
  min-width: 0;
}
.pool {
  width: 320px;
  flex-shrink: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  position: sticky;
  top: 62px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
}
.pool-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.pool-head h2 { margin: 0; font-size: 15px; }
.search {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 14px;
  background: var(--input-bg);
  color: var(--text);
}
.sort-select {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  background: var(--input-bg);
  color: var(--text);
}
.pool-list { overflow-y: auto; flex: 1; min-height: 120px; }

/* ---------- служение ---------- */
.service {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  display: flex;
  flex-direction: column;
}
.service-name {
  font-size: 15px;
  font-weight: 700;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 6px;
  margin: -4px -6px 6px;
  width: calc(100% + 12px);
  background: transparent;
  color: var(--text);
  font-family: inherit;
}
.service-name:hover:not([readonly]) { border-color: var(--border); }
.service-head { display: flex; align-items: center; gap: 2px; margin-bottom: 6px; }
.service-head .service-name { flex: 1; width: auto; margin: -4px 0; }
.svc-handle {
  cursor: grab;
  color: var(--muted);
  font-size: 16px;
  padding: 2px 4px;
  flex-shrink: 0;
  user-select: none;
}
.svc-handle:hover { color: var(--accent); }
.svc-del { flex-shrink: 0; font-size: 14px; }
.svc-del:hover { color: var(--danger); }
.add-service {
  min-height: 90px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
}
.add-service:hover { border-color: var(--accent); color: var(--accent); }
.service.dragging { opacity: .4; }
.service.drag-over-svc { outline: 2px dashed var(--accent); outline-offset: 2px; }
.service-name:focus { border-color: var(--accent); outline: none; background: var(--input-bg); }

.team {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
  margin-bottom: 10px;
  padding: 8px;
  background: var(--accent-soft);
  border-radius: 8px;
}
.team-slot { display: flex; align-items: center; gap: 6px; min-width: 0; }
.team-slot .slot-icon { flex-shrink: 0; width: 20px; text-align: center; font-size: 13px; }
.team-slot .slot-label {
  font-size: 12px;
  color: var(--muted);
  width: 72px;
  flex-shrink: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.team-slot select {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  padding: 3px 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--text);
}
.team-slot .slot-value { font-size: 13px; font-weight: 600; }

.service-songs { min-height: 60px; border-radius: 8px; }
.dropzone.drag-over { outline: 2px dashed var(--accent); outline-offset: 2px; background: var(--accent-soft); }

/* ---------- песня ---------- */
.song {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  margin-bottom: 6px;
  cursor: grab;
}
.song.dragging { opacity: .4; }
.song .num { color: var(--muted); font-size: 13px; width: 16px; text-align: right; flex-shrink: 0; }
.song .song-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.song .mp3-mark { font-size: 12px; flex-shrink: 0; }
.song .lead-badge {
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
  white-space: nowrap;
}
.song .key-badge {
  background: var(--key-bg);
  color: var(--key-text);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  flex-shrink: 0;
}
.song .btn-info {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 15px;
  color: var(--muted);
  padding: 2px 4px;
  flex-shrink: 0;
}
.song .btn-info:hover { color: var(--accent); }
.empty-hint { color: var(--muted); font-size: 13px; text-align: center; padding: 14px 6px; }

/* ---------- кнопки ---------- */
.btn {
  font-family: inherit;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  padding: 6px 12px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); color: #fff; }
.btn.danger { color: var(--danger); border-color: #e6c4bf; }
.btn.danger:hover { background: #fdf1ef; }
.btn.ghost { background: transparent; }
.btn.icon { border: none; background: none; font-size: 16px; padding: 4px 8px; color: var(--muted); }
.btn.icon:hover { color: var(--text); }

/* ---------- модалка ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 40, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--panel);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(20,24,40,.25);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 0;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 12px 16px; display: flex; flex-direction: column; gap: 10px; }
.modal-body label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.modal-body input, .modal-body select {
  font-family: inherit;
  font-size: 14px;
  background: var(--input-bg);
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
.modal-body input:focus, .modal-body select:focus { border-color: var(--accent); outline: none; }
.player { width: 100%; margin-top: 2px; }
.player.hidden-player { display: none; }
.link-open { font-size: 13px; color: var(--accent); text-decoration: none; margin-top: -4px; }
.link-open:hover { text-decoration: underline; }
.modal-foot {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 16px 16px;
}

.backup-section { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.backup-section h4 { margin: 0; font-size: 14px; }
.backup-section .hint { margin: 0; font-size: 13px; color: var(--muted); }
.check-row { flex-direction: row !important; align-items: center; gap: 6px; font-size: 14px !important; color: var(--text) !important; }
.backup-hr { border: none; border-top: 1px solid var(--border); margin: 6px 0; width: 100%; }

.people-list { list-style: none; margin: 0; padding: 0; }
.people-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px;
  border-bottom: 1px solid var(--border);
}
.people-add { display: flex; gap: 8px; margin-top: 10px; }
.people-add input { flex: 1; }

/* ---------- раскрытие песни в режиме просмотра ---------- */
.song .chev {
  color: var(--muted);
  font-size: 12px;
  flex-shrink: 0;
  transition: transform .15s;
}
.song.open .chev { transform: rotate(180deg); }
.song.open {
  border-radius: 8px 8px 0 0;
  margin-bottom: 0;
  background: var(--input-bg);
}
.song-details {
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 8px 8px;
  background: var(--input-bg);
  padding: 8px 10px 10px;
  margin-bottom: 6px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.detail-note { font-size: 13px; color: var(--muted); }

/* ---------- редактор текста песни ---------- */
.body-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.body-label { font-size: 13px; color: var(--muted); }
.parse-status { font-size: 12px; color: var(--accent); min-height: 14px; }
.url-row { display: flex; gap: 8px; }
.url-row input { flex: 1; min-width: 0; }
.url-row button { flex-shrink: 0; }
.mp3-variants { display: flex; flex-direction: column; gap: 6px; }
.mp3-variants:empty { display: none; }
.mp3-variant {
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#f-body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
  background: var(--input-bg);
  line-height: 1.4;
  white-space: pre;
  overflow-x: auto;
  min-height: 220px;
  resize: vertical;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
}
#f-body:focus { border-color: var(--accent); outline: none; }

/* ---------- просмотр текста песни ---------- */
.viewer { display: flex; flex-direction: column; gap: 8px; }
.viewer-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.seg {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.seg button {
  border: none;
  background: var(--input-bg);
  padding: 6px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent); color: #fff; }
.transpose { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.transpose .tr-label { font-size: 13px; color: var(--muted); }
.transpose select {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--text);
}
.acc-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--input-bg);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  color: var(--accent);
  flex-shrink: 0;
}
.fontsize { display: flex; align-items: center; gap: 4px; }
.fontsize button {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}
.song-text {
  font-family: "rub", Arial, Helvetica, sans-serif;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  padding: 4px 0;
}
.song-text .line { min-height: 1.4em; }
.song-text .line.chord { color: var(--accent); font-weight: 700; }
.song-text .line.hdr {
  font-weight: 700;
  margin-top: 6px;
  background: var(--hdr-bg);
  border-radius: 6px;
  padding: 2px 8px;
  margin-left: -8px;
  margin-right: -8px;
}

/* ---------- режим просмотра (мобильный) ---------- */
body.readonly .edit-only { display: none !important; }
body.readonly .song { cursor: pointer; gap: 4px; padding: 7px 5px; }
body.readonly .services,
body.readonly .service { min-width: 0; max-width: 100%; }
body.readonly .song-details .link-open { word-break: break-all; }
body.readonly .song-details audio { max-width: 100%; }
body.readonly .layout { display: block; padding: 10px; }
body.readonly .services { grid-template-columns: 1fr; gap: 10px; }
.service-name-view {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 8px;
}
body.readonly .team { grid-template-columns: 1fr 1fr; gap: 3px 10px; padding: 7px 9px; }
body.readonly .team-slot { gap: 4px; }
body.readonly .team-slot .slot-label { width: auto; font-size: 11px; }
body.readonly .team-slot .slot-value {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.readonly .empty-hint { display: none; }

@media (max-width: 900px) {
  .layout { flex-direction: column-reverse; }
  .pool { width: 100%; position: static; max-height: 300px; }
  .services { grid-template-columns: 1fr; }
}

/* ---------- переключатель режима ---------- */
.mode-switch { text-align: center; padding: 20px 0 28px; }
.mode-switch a { color: var(--muted); font-size: 13px; text-decoration: underline; }

/* перечёркнутая иконка = чего-то не хватает у песни */
.mp3-mark.miss { position: relative; opacity: .65; }
.mp3-mark.miss::after {
  content: '';
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  border-top: 2px solid var(--danger);
  transform: rotate(-45deg);
}

/* ---------- мультитреки ---------- */
@media (pointer: coarse) { .pc-only { display: none !important; } }
.mt-buttons { display: flex; flex-direction: column; gap: 6px; margin: 4px 0; }
.mt-btn, .mt-row-link {
  display: block;
  text-decoration: none;
  font-size: 13px;
  text-align: left;
  border-left: 4px solid var(--border);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mt-row-link {
  flex: 1;
  min-width: 0;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 6px 10px;
}
/* значок 🎛 в списках: рамка цвета категории мультитрека */
.mt-mark {
  border: 1.5px solid var(--border);
  border-radius: 6px;
  padding: 0 3px;
  line-height: 1.3;
}
.mt-mark.mt-green { border-color: #2ea043; }
.mt-mark.mt-red { border-color: #d73a49; }
.mt-mark.mt-yellow { border-color: #d4a72c; }
.mt-mark.mt-blue { border-color: #4c7bd9; }

.mt-green { border-left-color: #2ea043 !important; }
.mt-red { border-left-color: #d73a49 !important; }
.mt-yellow { border-left-color: #d4a72c !important; }
.mt-blue { border-left-color: #4c7bd9 !important; }
.mt-list { display: flex; flex-direction: column; gap: 6px; }
.mt-row { display: flex; align-items: center; gap: 4px; }
.mt-add { display: flex; gap: 6px; }
.mt-add select { flex: 1; min-width: 0; }
.mt-page-link { color: var(--muted); font-size: 13px; text-decoration: underline; }

/* ---------- режим выступления ---------- */
.perf-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.perf-overlay.hidden { display: none; }
body.perf-open { overflow: hidden; }
.perf-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.perf-head .btn.icon { font-size: 20px; padding: 6px 10px; }
.perf-head .btn.icon:disabled { opacity: .3; }
.perf-title-wrap { flex: 1; min-width: 0; }
.perf-title-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
}
.perf-title-row span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perf-pos { color: var(--muted); font-size: 13px; font-weight: 400; flex-shrink: 0; }
.perf-sub { color: var(--muted); font-size: 12px; }
.perf-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px 40px;
  -webkit-overflow-scrolling: touch;
}
.perf-body .player { width: 100%; margin-bottom: 8px; }
.perf-btn { width: 100%; margin: 2px 0; }
.bpm-badge {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 5px;
  flex-shrink: 0;
}

/* ---------- офлайн-блок ---------- */
body:not(.readonly) .view-only { display: none !important; }
.offline-box {
  margin: 0 auto 16px;
  max-width: 420px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.offline-status, .offline-progress { font-size: 13px; color: var(--muted); }
.offline-progress:empty { display: none; }

/* ---------- редактирование: убрать песню из события, добавить песню ---------- */
.song-del {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 5px;
  flex-shrink: 0;
}
.song-del:hover { color: var(--danger); }
.svc-actions { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.svc-actions .btn { width: 100%; }
.copy-songs-btn { color: var(--muted); }

/* стрелки порядка — только там, где нет мыши (drag&drop недоступен) */
.song-move { display: none; flex-shrink: 0; }
.song-move button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 4px;
}
@media (pointer: coarse) {
  body:not(.readonly) .song-move { display: inline-flex; }
}

/* ---------- выбор песен для события ---------- */
.picker-body { padding-top: 10px; }
.picker-list { max-height: 62vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.picker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
}
.picker-row:last-child { border-bottom: none; }
.picker-row:hover { background: var(--input-bg); }
.picker-row.in { background: rgba(46, 160, 67, .10); }
.picker-check { width: 16px; flex-shrink: 0; color: #2ea043; font-weight: 700; }
.picker-title { flex: 1; min-width: 0; }
.picker-note { color: var(--muted); font-size: 12px; flex-shrink: 0; }

/* ---------- мобильное редактирование ---------- */
@media (max-width: 700px) {
  body:not(.readonly) .topbar { flex-wrap: wrap; gap: 6px; }
  body:not(.readonly) .layout { padding: 10px; gap: 12px; }
  body:not(.readonly) .song { padding: 9px 6px; }
  body:not(.readonly) .btn-info,
  body:not(.readonly) .song-del { font-size: 16px; padding: 4px 7px; }
  body:not(.readonly) .modal { max-width: none; }
  .picker-list { max-height: 55vh; }
}
