:root {
  --bg: #15181e;
  --surface: #1e222b;
  --surface2: #272c38;
  --border: #33394a;
  --text: #dde3ed;
  --text-muted: #7a8296;
  --accent: #4c8de8;
  --accent-hover: #6ba0f0;
  --danger: #d95050;
  --success: #4aab77;
  --topbar-h: 54px;
  --libs-w: 230px;
  --service-w: 300px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

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

.hidden { display: none !important; }

/* ── Loading ── */
#loading {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 14px; color: var(--text-muted); font-size: 14px;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Setup ── */
#setup-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 40px;
  width: 100%; max-width: 420px;
  display: flex; flex-direction: column; gap: 12px;
}
.setup-logo {
  font-size: 22px; font-weight: 700;
  letter-spacing: -0.3px; margin-bottom: 4px;
}
.app-version {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
  margin-left: 4px;
}
.setup-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 8px; }
.setup-error { color: var(--danger); font-size: 12px; min-height: 16px; }
.setup-card label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.setup-help-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  margin-top: 2px;
}
.setup-help-link:hover { color: var(--accent-hover); }
.setup-card input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 13px;
  outline: none;
}
.setup-card input:focus { border-color: var(--accent); }

/* ── Buttons ── */
button {
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 9px 18px;
  border-radius: 6px;
  font-weight: 600;
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-link {
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  padding: 8px 10px;
  font-size: 12px;
  background: var(--surface2);
  white-space: nowrap;
}
.btn-link:hover { border-color: var(--accent); color: var(--accent-hover); }
.btn-icon {
  width: 34px; height: 34px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-muted);
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }
.btn-sm {
  width: 26px; height: 26px;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700;
  flex-shrink: 0;
}
.btn-add { color: var(--accent); }
.btn-add {
  width: auto;
  min-width: 58px;
  padding: 0 8px;
  font-size: 11px;
}
.btn-add:hover { background: var(--surface2); }
.btn-add.in-service { color: var(--text-muted); cursor: default; }
.btn-play { color: var(--text-muted); }
.btn-play:hover, .btn-play.playing { color: var(--accent); background: var(--surface2); }
.btn-remove { color: var(--text-muted); }
.btn-remove:hover { color: var(--danger); background: var(--surface2); }

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  gap: 12px; padding: 0 16px;
  flex-shrink: 0;
}
.topbar-logo {
  font-weight: 700; font-size: 15px;
  white-space: nowrap; margin-right: 4px;
}
.topbar-version {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 700;
  letter-spacing: .35px;
  vertical-align: middle;
}
.search-wrap {
  flex: 1; position: relative; max-width: 480px;
}
.search-wrap input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 36px 7px 12px;
  font-size: 13px;
  outline: none;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-count {
  position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%);
  font-size: 11px; color: var(--text-muted);
  pointer-events: none;
}
.topbar-actions {
  display: flex; align-items: center; gap: 8px; margin-left: auto;
}
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 7px 10px;
  font-size: 12px;
  font-family: inherit;
  outline: none; cursor: pointer;
  max-width: 180px;
}
select:focus { border-color: var(--accent); }

/* ── Main layout ── */
.main-layout {
  display: flex;
  height: calc(100vh - var(--topbar-h));
  overflow: hidden;
}

/* ── Panels ── */
.panel {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.panel-hd {
  padding: 10px 14px;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.badge {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px; font-weight: 700;
}

/* ── Libraries panel ── */
.panel-libs { width: var(--libs-w); flex-shrink: 0; }
.lib-list { overflow-y: auto; flex: 1; padding: 6px 0; }
.lib-list::-webkit-scrollbar { width: 4px; }
.lib-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.library-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 7px 14px;
  cursor: pointer; list-style: none;
  border-radius: 0;
  transition: background 0.1s;
  user-select: none;
}
.library-item::before {
  content: '';
  width: 12px; height: 12px;
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-right: 8px;
  flex-shrink: 0;
  transition: background 0.1s, border-color 0.1s;
}
.library-item:hover { background: var(--surface2); }
.library-item:hover::before { border-color: var(--accent); }
.library-item.active {
  background: var(--surface2);
  color: var(--accent);
}
.library-item.active::before {
  background: var(--accent);
  border-color: var(--accent);
}
.lib-name { flex: 1; font-size: 13px; }
.lib-count {
  font-size: 11px; color: var(--text-muted);
  background: var(--bg);
  border-radius: 8px; padding: 1px 6px;
  flex-shrink: 0;
}
.library-item.active .lib-count { color: var(--accent); }

/* ── Hymns panel ── */
.panel-hymns { flex: 1; min-width: 0; }
.hymn-list { overflow-y: auto; flex: 1; }
.hymn-list::-webkit-scrollbar { width: 4px; }
.hymn-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.hymn-item {
  display: flex; align-items: center;
  padding: 7px 12px;
  border-bottom: 1px solid var(--border);
  gap: 8px; list-style: none;
  transition: background 0.1s;
}
.hymn-item:hover { background: var(--surface2); }
.hymn-item.in-service { opacity: 0.5; }
.hymn-info {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}
.hymn-num {
  font-size: 10px; color: var(--text-muted);
  font-weight: 600;
}
.hymn-title {
  font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hymn-lib {
  font-size: 10px; color: var(--text-muted);
}
.hymn-actions {
  display: flex; gap: 4px; flex-shrink: 0;
}

/* ── Service panel ── */
.panel-service {
  width: var(--service-w); flex-shrink: 0;
  border-right: none;
}
.panel-subactions {
  padding: 10px 10px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.plan-grid {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 6px 8px;
  align-items: center;
  margin-bottom: 8px;
}
.plan-label {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2px;
}
.plan-input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 12px;
}
.btn-plan-save {
  width: 100%;
  margin-bottom: 8px;
  display: block;
  text-align: center;
}
.btn-open-operator {
  width: 100%;
  padding: 8px 12px;
  text-align: center;
}
.service-list { overflow-y: auto; flex: 1; padding: 4px 0; }
.service-list::-webkit-scrollbar { width: 4px; }
.service-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.service-item {
  display: flex; align-items: center;
  padding: 6px 10px; gap: 6px;
  border-bottom: 1px solid var(--border);
  list-style: none; cursor: grab;
  transition: background 0.1s;
  position: relative;
}
.service-item:hover { background: var(--surface2); }
.service-item.dragging { opacity: 0.4; }
.service-item.drag-over { border-top: 2px solid var(--accent); }
.service-order {
  font-size: 10px; color: var(--text-muted);
  width: 16px; text-align: center; flex-shrink: 0;
}
.drag-handle {
  color: var(--border); font-size: 12px;
  cursor: grab; flex-shrink: 0;
  user-select: none;
}
.service-hymn-info {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 1px;
}
.service-actions {
  display: flex; gap: 3px; flex-shrink: 0;
}

/* ── Empty states ── */
.empty-state {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); font-size: 12px;
  text-align: center; padding: 24px;
  line-height: 1.6;
}

/* ── Responsive ── */
@media (max-width: 700px) {
  :root { --libs-w: 0px; --service-w: 100vw; }
  .panel-libs { display: none; }
  .panel-hymns { display: none; }
  .panel-service { width: 100%; }
}
