:root {
  --bg: #12141c;
  --panel: #1b1e2b;
  --accent: #1db954;
  --text: #f2f3f5;
  --muted: #9aa0ab;
  --border: #2a2e3f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans Thai", sans-serif;
  background: linear-gradient(180deg, #1a1230, var(--bg) 40%);
  color: var(--text);
  min-height: 100vh;
}

.hero {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
}

.hero h1 { margin: 0 0 0.5rem; font-size: 1.8rem; }
.hero p { margin: 0; color: var(--muted); }

.container {
  max-width: 1000px;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 800px) {
  .container { grid-template-columns: 1fr; }
}

.search-panel, .playlist-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}

#search-form {
  display: flex;
  gap: 0.5rem;
}

#search-input {
  flex: 1;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1119;
  color: var(--text);
  font-size: 1rem;
}

button {
  cursor: pointer;
  font-family: inherit;
}

#search-form button {
  padding: 0.7rem 1.2rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #06210f;
  font-weight: 600;
}

.quick-tags {
  margin-top: 0.85rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.tag {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  font-size: 0.82rem;
}

.tag:hover { border-color: var(--accent); color: var(--accent); }

.status {
  min-height: 1.2rem;
  margin: 0.7rem 0 0.3rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.status.error { color: #ff6b6b; }

.track-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 520px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.track {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem;
  border-radius: 8px;
  background: #0f1119;
  border: 1px solid var(--border);
}

.track img {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
  background: #2a2e3f;
  flex-shrink: 0;
}

.track-info { flex: 1; min-width: 0; }
.track-info .name {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.track-info .artist {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.icon-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 0.9rem;
}
.icon-btn:hover { border-color: var(--accent); }

.add-btn {
  border: none;
  background: var(--accent);
  color: #06210f;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.8rem;
}

.remove-btn {
  border: none;
  background: transparent;
  color: #ff6b6b;
  font-size: 1.1rem;
  padding: 0.2rem 0.4rem;
}

.added-by {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 0.15rem;
}

.locked-label {
  font-size: 0.9rem;
  padding: 0.2rem 0.4rem;
  opacity: 0.6;
  cursor: default;
}

.playlist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.playlist-header h2 { margin: 0; font-size: 1.15rem; }

.ghost-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  font-size: 0.8rem;
}
.ghost-btn:hover { color: #ff6b6b; border-color: #ff6b6b; }

.hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: 0.5rem 0 0.75rem;
}

.playlist { min-height: 120px; counter-reset: track-num; }

.playlist .track {
  cursor: grab;
}
.playlist .track.dragging { opacity: 0.5; }

.playlist-footer {
  margin-top: 0.75rem;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
}

.empty-msg {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  padding: 1rem 0;
}

/* --- แถบผู้ใช้ (user bar) --- */
.user-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.user-bar #user-email {
  color: var(--muted);
  margin-right: auto;
}

.user-bar a {
  color: var(--text);
  text-decoration: none;
}

.user-bar a:hover { color: var(--accent); }

/* --- หน้าเข้าสู่ระบบ --- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
}

.auth-card h1 {
  margin: 0 0 0.3rem;
  font-size: 1.4rem;
  text-align: center;
}

.auth-card h2 {
  margin: 0 0 0.3rem;
  font-size: 1.15rem;
}

.auth-hint {
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
  margin: 0 0 1.5rem;
}

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.auth-card input {
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1119;
  color: var(--text);
  font-size: 0.95rem;
}

.auth-card button {
  padding: 0.7rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #06210f;
  font-weight: 600;
  font-size: 0.95rem;
}

.auth-error {
  color: #ff6b6b;
  font-size: 0.82rem;
  min-height: 1rem;
}

.auth-note {
  margin: 1.25rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.auth-note code {
  background: #0f1119;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.1rem 0.35rem;
}

/* --- หน้าแอดมิน --- */
.admin-container {
  display: block;
  max-width: 1000px;
}

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  white-space: nowrap;
}

.user-table th, .user-table td {
  text-align: left;
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--border);
}

.user-table th {
  color: var(--muted);
  font-weight: 600;
}

.user-actions {
  display: flex;
  gap: 0.4rem;
}

.ghost-btn.danger:hover { color: #ff6b6b; border-color: #ff6b6b; }

.admin-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.admin-section h2 { margin: 0 0 0.4rem; font-size: 1.1rem; }

.spotify-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.device-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.device-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.7rem;
  border-radius: 8px;
  background: #0f1119;
  border: 1px solid var(--border);
}

/* --- ตารางเวลา + คำนวณเวลาลิสต์เพลง --- */
.schedule-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.schedule-controls label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.schedule-controls input {
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f1119;
  color: var(--text);
  font-size: 0.85rem;
}

.time-progress {
  margin-top: 0.75rem;
}

.time-progress-bar {
  height: 8px;
  border-radius: 999px;
  background: #0f1119;
  border: 1px solid var(--border);
  overflow: hidden;
}

.time-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

.time-progress-fill.over { background: #ff6b6b; }

.time-progress-label {
  margin-top: 0.4rem;
  font-size: 0.78rem;
  color: var(--muted);
}
