:root {
  --bg: #0f0f14;
  --card: #1a1a24;
  --border: #2a2a3a;
  --text: #e8e8f0;
  --muted: #8888a0;
  --primary: #7c6cf0;
  --accent: #f06292;
  --ok: #4caf87;
  --warn: #ffb74d;
  --err: #ef5350;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 2rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, #151520, #1a1028);
}

.brand { display: flex; gap: 1rem; align-items: center; }
.logo { font-size: 2rem; }
.brand h1 { font-size: 1.4rem; font-weight: 700; }
.brand p { color: var(--muted); font-size: 0.85rem; }

.status-bar {
  display: flex; gap: 1rem; flex-wrap: wrap;
  font-size: 0.8rem;
}
.badge {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
}
.badge.ok { border-color: var(--ok); color: var(--ok); }
.badge.err { border-color: var(--err); color: var(--err); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.25rem;
  padding: 1.5rem 2rem 3rem;
  max-width: 1400px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}
.card.wide { grid-column: 1 / -1; }
.card h2 { font-size: 1rem; margin-bottom: 0.75rem; color: #c8c8e0; }
.hint { color: var(--muted); font-size: 0.82rem; margin-bottom: 0.75rem; }

.row { display: flex; gap: 0.5rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.mt { margin-top: 0.75rem; }

input, select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.9rem;
  flex: 1;
  min-width: 0;
}

.btn {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
  white-space: nowrap;
  transition: 0.15s;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn.sm { padding: 0.3rem 0.6rem; font-size: 0.78rem; }

.list { display: flex; flex-direction: column; gap: 0.6rem; margin-top: 0.75rem; }

.item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
}
.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.item-title { font-weight: 600; font-size: 0.92rem; }
.item-meta { color: var(--muted); font-size: 0.78rem; margin-top: 0.25rem; }
.item-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; margin-top: 0.5rem; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.form-grid label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; color: var(--muted); }
.form-grid .check { flex-direction: row; align-items: center; gap: 0.5rem; }

.block-label { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.75rem; font-size: 0.82rem; color: var(--muted); }
.block-label textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: inherit;
  resize: vertical;
  min-height: 100px;
}
.file-btn { position: relative; overflow: hidden; cursor: pointer; display: inline-flex; align-items: center; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photos-box { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; min-height: 40px; }
.photo-thumb {
  position: relative; width: 88px; border: 2px solid var(--border); border-radius: 8px;
  overflow: hidden; cursor: pointer; background: #000;
}
.photo-thumb.selected { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.photo-thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.photo-thumb .del {
  position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,0.7); color: #fff;
  border: none; border-radius: 4px; font-size: 0.65rem; padding: 2px 5px; cursor: pointer;
}

.log {
  background: #0a0a10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.75rem;
  font-family: 'Consolas', monospace;
  color: #a0a0c0;
  max-height: 120px;
  overflow-y: auto;
  margin-top: 0.75rem;
  white-space: pre-wrap;
}
.log.tall { max-height: 240px; }

.gen-preview {
  margin-top: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #0a0a10;
}
.gen-preview.hidden { display: none; }
.gen-preview img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  background: #000;
}
.gen-preview .hint { padding: 0.5rem 0.75rem; margin: 0; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.gallery-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s;
}
.gallery-item:hover, .gallery-item.active { border-color: var(--primary); }
.gallery-item img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  display: block;
  background: #000;
}
.gallery-item .cap {
  padding: 0.45rem 0.6rem;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  padding: 0.75rem 1.25rem;
  background: var(--card);
  border: 1px solid var(--primary);
  border-radius: 8px;
  display: none;
  z-index: 99;
  max-width: 360px;
  font-size: 0.88rem;
}
#toast.show { display: block; animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.modal-panel-lg { max-width: 720px; }

/* === Full-window schedule modal === */
.modal-fullscreen {
  padding: 0;
  align-items: stretch;
  justify-content: stretch;
}
.modal-panel.modal-full {
  width: 100%;
  max-width: none;
  height: 100vh;
  max-height: 100vh;
  border-radius: 0;
  border: none;
  display: flex;
  flex-direction: column;
}
.modal-head-full {
  padding: 1rem 1.5rem;
  flex-shrink: 0;
  background: linear-gradient(180deg, rgba(99,102,241,0.08) 0%, transparent 100%);
}
.modal-head-full h3 { font-size: 1.35rem; margin: 0 0 0.2rem; }
.modal-subtitle { margin: 0; font-size: 0.82rem; color: var(--muted); }
.schedule-form-full {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}
.schedule-layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  gap: 0;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.schedule-fields-panel {
  padding: 1.25rem 1.5rem;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: rgba(0,0,0,0.15);
}
.schedule-playlist-panel {
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1.5rem;
  min-height: 0;
  overflow: hidden;
}
.panel-section-title {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 700;
  color: #e0e0f0;
  letter-spacing: 0.02em;
}
.field-block {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.85rem;
}
.field-label { font-size: 0.88rem; font-weight: 600; color: #d8d8ec; }
.field-hint { font-size: 0.72rem; color: var(--muted); line-height: 1.35; margin-bottom: 0.15rem; }
.field-block input,
.field-block select,
.field-block textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
}
.field-block textarea { resize: vertical; min-height: 72px; }
.field-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.field-check {
  margin-top: 0.5rem;
  padding: 0.65rem 0.75rem;
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.25);
  border-radius: 8px;
  flex-direction: row !important;
  align-items: flex-start;
  gap: 0.55rem !important;
  cursor: pointer;
}
.field-check span { font-size: 0.82rem; color: #c8c8e0; line-height: 1.4; }

.playlist-section { margin-top: 0; }
.playlist-section-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; margin-bottom: 0.65rem; flex-shrink: 0;
}
.playlist-section-head .panel-section-title { margin-bottom: 0.2rem; }
.playlist-count {
  font-size: 1.1rem; font-weight: 700; color: var(--primary);
  background: rgba(99,102,241,0.15); padding: 0.35rem 0.75rem;
  border-radius: 999px; white-space: nowrap; flex-shrink: 0;
}
.playlist-search-wrap {
  flex: 0 0 auto;
  margin-bottom: 0.65rem;
  max-width: 360px;
}
.playlist-search {
  display: block;
  width: 100%;
  max-width: 360px;
  margin: 0;
  padding: 0.4rem 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
  line-height: 1.35;
  height: 2.15rem;
  min-height: 0;
  flex: none !important;
  box-sizing: border-box;
}
.playlist-search::-webkit-search-cancel-button {
  cursor: pointer;
}
.playlist-picker-full {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}
.playlist-picker-full .playlist-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.playlist-scroll-full {
  flex: 1;
  min-height: 120px;
  max-height: none;
}
.playlist-foot-hint {
  margin: 0.65rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  flex-shrink: 0;
}
.modal-foot-full {
  flex-shrink: 0;
  padding: 0.85rem 1.5rem;
  background: rgba(0,0,0,0.35);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.modal-foot-hint { font-size: 0.78rem; color: var(--muted); }
.modal-foot-actions { display: flex; gap: 0.5rem; }

body.modal-open { overflow: hidden; }

.playlist-col-title { font-size: 0.8rem; font-weight: 600; color: #b0b0c8; margin-bottom: 0.35rem; flex-shrink: 0; }
.playlist-scroll {
  overflow-y: auto; border: 1px solid var(--border); border-radius: 8px;
  background: rgba(0,0,0,0.2);
}
.playlist-track {
  display: flex; align-items: center; justify-content: space-between; gap: 0.35rem;
  padding: 0.45rem 0.6rem; font-size: 0.8rem; border-bottom: 1px solid rgba(255,255,255,0.04);
  cursor: pointer;
}
.playlist-track:hover { background: rgba(99,102,241,0.12); }
.playlist-track.selected-side { cursor: default; }
.playlist-track .track-name { flex: 1; word-break: break-all; line-height: 1.25; }
.playlist-track .track-btn {
  flex-shrink: 0; border: none; border-radius: 4px; padding: 0.2rem 0.5rem;
  font-size: 0.72rem; cursor: pointer; font-weight: 600;
}
.playlist-track .track-btn.add { background: rgba(76,175,135,0.2); color: var(--ok); }
.playlist-track .track-btn.remove { background: rgba(239,83,80,0.2); color: var(--err); }

@media (max-width: 900px) {
  .schedule-layout { grid-template-columns: 1fr; overflow-y: auto; }
  .schedule-fields-panel { border-right: none; border-bottom: 1px solid var(--border); max-height: 45vh; }
  .schedule-playlist-panel { min-height: 50vh; }
  .field-row-2 { grid-template-columns: 1fr; }
  .playlist-picker-full { min-height: 280px; }
}

@media (max-width: 600px) {
  header { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .grid { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .autodj-header { flex-direction: column; align-items: stretch; }
  .autodj-toolbar { flex-direction: column; align-items: stretch; }
  .autodj-toolbar-settings { flex-wrap: wrap; }
  .form-grid-modal { grid-template-columns: 1fr; }
  .form-grid-modal label.span-2 { grid-column: 1; }
  .playlist-picker-full { grid-template-columns: 1fr; }
}

/* === AutoDJ-style schedule === */
.autodj-section { padding: 1.25rem 1.5rem; }
.autodj-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.autodj-title { font-size: 1.5rem; font-weight: 700; margin: 0 0 0.25rem; color: #e8e8f0; }
.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  border-color: #6366f1; color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; gap: 0.4rem;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-icon { font-size: 1.1rem; line-height: 1; }

.autodj-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
  padding: 0.75rem; background: rgba(0,0,0,0.25); border: 1px solid var(--border);
  border-radius: 10px; margin-bottom: 1.25rem;
}
.autodj-toolbar-settings {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.65rem;
  margin-left: auto; font-size: 0.78rem; color: var(--muted);
}
.autodj-toolbar-settings label { display: flex; align-items: center; gap: 0.35rem; }
.check-inline { cursor: pointer; }
.time-sm, .num-sm {
  width: auto; min-width: 0; padding: 0.25rem 0.4rem; font-size: 0.78rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; color: var(--text);
}
.num-sm { width: 3rem; }

.autodj-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.autodj-empty {
  grid-column: 1 / -1; text-align: center; padding: 2.5rem 1rem;
  border: 1px dashed var(--border); border-radius: 12px; color: var(--muted);
}
.autodj-empty h3 { font-size: 1.1rem; color: #c8c8e0; margin-bottom: 0.5rem; }

.adj-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  display: flex; flex-direction: column; overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.adj-card:hover { border-color: rgba(99, 102, 241, 0.45); box-shadow: 0 4px 20px rgba(0,0,0,0.25); }
.adj-card-body { padding: 1rem 1rem 0.75rem; flex: 1; }
.adj-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; }
.adj-card-title { font-size: 1rem; font-weight: 700; line-height: 1.3; margin: 0; }
.adj-status {
  display: inline-flex; align-items: center; gap: 0.35rem;
  font-size: 0.68rem; font-weight: 600; padding: 0.2rem 0.55rem;
  border-radius: 999px; white-space: nowrap; flex-shrink: 0;
}
.adj-status.on { background: rgba(76, 175, 135, 0.15); color: var(--ok); }
.adj-status.off { background: rgba(136, 136, 160, 0.15); color: var(--muted); }
.adj-status.err { background: rgba(239, 83, 80, 0.15); color: var(--err); }
.adj-status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.adj-meta { font-size: 0.8rem; color: var(--muted); margin-top: 0.5rem; line-height: 1.45; }
.adj-meta strong { color: #b8b8d0; font-weight: 600; }
.adj-foot {
  border-top: 1px solid var(--border); padding: 0.65rem 1rem;
  display: flex; justify-content: space-between; align-items: center; gap: 0.5rem;
  font-size: 0.78rem; color: var(--muted);
}
.adj-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.adj-actions .btn { padding: 0.35rem 0.55rem; }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-backdrop.hidden { display: none; }
.modal-panel {
  background: #1a1a24; border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: 16px; width: 100%; max-width: 560px; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: 0 24px 48px rgba(0,0,0,0.5);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 1.25rem; }
.modal-close {
  background: none; border: none; color: var(--muted); font-size: 1.75rem;
  line-height: 1; cursor: pointer; padding: 0 0.25rem;
}
.modal-close:hover { color: #fff; }
.modal-body { padding: 1.25rem; overflow-y: auto; }
.form-grid-modal {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem;
}
.form-grid-modal label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.82rem; color: var(--muted); }
.form-grid-modal label.span-2 { grid-column: 1 / -1; }
.form-grid-modal input, .form-grid-modal select, .form-grid-modal textarea {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 0.55rem 0.65rem; border-radius: 8px; font-size: 0.9rem; font-family: inherit;
}
.form-grid-modal textarea { resize: vertical; min-height: 60px; }
.time-row { display: flex; align-items: center; gap: 0.35rem; }
.time-row input { width: 4rem; text-align: center; }
.check-block { flex-direction: row !important; align-items: center; gap: 0.5rem !important; cursor: pointer; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 0.5rem;
  padding-top: 1rem; margin-top: 0.5rem; border-top: 1px solid var(--border);
}

/* Music gallery */
.music-gallery-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 0.75rem;
}
.music-gallery-head h2 { margin: 0 0 0.25rem; }
.music-list {
  display: flex; flex-direction: column; gap: 0.45rem;
  max-height: 320px; overflow-y: auto;
}
.music-item {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.55rem 0.75rem; background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px;
}
.music-item:hover { border-color: rgba(99, 102, 241, 0.4); }
.music-item .name { flex: 1; font-size: 0.88rem; word-break: break-all; }
.music-item .meta { font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.music-item .play-btn {
  background: rgba(76, 175, 135, 0.15); color: var(--ok);
  border: 1px solid rgba(76, 175, 135, 0.3); border-radius: 6px;
  padding: 0.3rem 0.55rem; cursor: pointer; font-size: 0.75rem;
}
.music-item .play-btn:hover { background: rgba(76, 175, 135, 0.25); }
.folder-btn { width: 100%; margin-top: 0.25rem; justify-content: center; }
.upload-progress {
  position: relative; margin-top: 0.75rem;
  background: rgba(0,0,0,0.35); border-radius: 999px; height: 1.1rem; overflow: hidden;
}
.upload-progress.hidden { display: none; }
.upload-progress-bar { width: 100%; height: 100%; }
.upload-progress-fill {
  height: 100%; width: 0; background: linear-gradient(90deg, #6366f1, #4f46e5);
  transition: width 0.2s ease;
}
.upload-progress-text {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 0.68rem; font-weight: 700; color: #fff;
}
.music-preview-bar {
  margin-top: 0.75rem; padding: 0.5rem 0.75rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}
.music-preview-bar.hidden { display: none; }
.shared-folder-hint { margin: 0.25rem 0 0.75rem; font-size: 0.78rem; }
.shared-folder-hint code { font-size: 0.72rem; color: #a8a8d0; }
