/* ─── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --border: #e4e4e7;
  --text: #18181b;
  --text-muted: #71717a;
  --accent: #2563eb;
  --accent-bg: #eff6ff;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* ─── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.full-width { width: 100%; }
.danger { color: var(--danger) !important; }

/* ─── Buttons ───────────────────────────────────────────────────────────────── */
button { cursor: pointer; font-size: 14px; font-family: inherit; border: none; background: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-outline {
  background: transparent;
  color: var(--text);
  padding: 9px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: background 0.15s;
}
.btn-outline:hover { background: var(--bg); }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 18px;
  transition: background 0.12s, color 0.12s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ─── Form fields ───────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-muted); }

input[type="text"],
input[type="url"],
input[type="password"],
select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap input { padding-right: 40px; }
.input-wrap .btn-icon { position: absolute; right: 2px; }

.error-msg { font-size: 12px; color: var(--danger); }

/* ─── Dropdown ──────────────────────────────────────────────────────────────── */
.dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 100;
  min-width: 140px;
  overflow: hidden;
}
.dropdown button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  color: var(--text);
  transition: background 0.1s;
}
.dropdown button:hover { background: var(--bg); }
.dropdown hr { border: none; border-top: 1px solid var(--border); }

/* ─── Auth screen ───────────────────────────────────────────────────────────── */
#auth-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.brand { font-size: 24px; font-weight: 700; color: var(--accent); text-align: center; }
.brand-sub { font-size: 13px; color: var(--text-muted); text-align: center; margin-top: -14px; }
.feature-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: -8px;
}
.feature-list li {
  font-size: 13px;
  color: var(--text-muted);
  padding-left: 16px;
  position: relative;
  line-height: 1.4;
}
.feature-list li::before {
  content: '·';
  position: absolute;
  left: 4px;
  color: var(--accent);
  font-weight: 700;
}
.hint { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-bottom: 8px; }

.auth-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.auth-tab {
  flex: 1;
  padding: 9px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  transition: background 0.12s, color 0.12s;
}
.auth-tab.active { background: var(--accent); color: #fff; }
.auth-tab:not(.active):hover { background: var(--bg); }

.tab-panel { display: flex; flex-direction: column; gap: 12px; }

.key-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.key-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.key-card code {
  font-family: monospace;
  font-size: 13px;
  word-break: break-all;
  color: var(--text);
  line-height: 1.6;
}
.key-warning { font-size: 12px; color: var(--danger); line-height: 1.5; }

/* ─── App screen layout ─────────────────────────────────────────────────────── */
#app-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ─── Header ────────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
}
.header-left { display: flex; align-items: center; gap: 4px; }
.header-right { display: flex; align-items: center; gap: 4px; }
.app-title { font-size: 16px; font-weight: 600; }

#app-menu { top: 52px; right: 8px; }

/* ─── Search bar ────────────────────────────────────────────────────────────── */
#search-bar {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  gap: 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#search-input { flex: 1; }

/* ─── Playlist tabs ─────────────────────────────────────────────────────────── */
#playlist-tabs {
  display: flex;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  scrollbar-width: none;
}
#playlist-tabs::-webkit-scrollbar { display: none; }

.ptab-wrap {
  position: relative;
  display: flex;
  align-items: stretch;
  flex-shrink: 0;
}

.ptab {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  border-bottom: 2px solid transparent;
  transition: color 0.12s, border-color 0.12s;
}
.ptab:hover { color: var(--text); }
.ptab.active { color: var(--accent); border-bottom-color: var(--accent); }
.ptab-add { font-size: 20px; padding: 6px 14px; color: var(--text-muted); }
.ptab-add:hover { color: var(--accent); }

.ptab-dots {
  padding: 0 6px 0 2px;
  color: var(--text-muted);
  font-size: 14px;
  display: flex;
  align-items: center;
}
.ptab-dots:hover { color: var(--text); }

.ptab-dropdown { top: 100%; left: 0; min-width: 120px; }

/* ─── Main content / Station list ───────────────────────────────────────────── */
#main-content {
  flex: 1;
  overflow-y: auto;
  position: relative;
}

#station-list { padding: 4px 0; }

.station-item {
  display: flex;
  align-items: center;
  padding: 10px 10px 10px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.station-item:hover { background: #fafafa; }
.station-item.current { background: var(--accent-bg); }
.station-item.dragging { opacity: 0.4; }
.station-item.drag-over { border-top: 2px solid var(--accent); }

.drag-handle {
  color: var(--border);
  font-size: 20px;
  margin-right: 6px;
  cursor: grab;
  flex-shrink: 0;
  padding: 0 2px;
}
.drag-handle:hover { color: var(--text-muted); }

.station-play-area {
  width: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 10px;
  flex-shrink: 0;
  font-size: 15px;
  color: var(--text-muted);
}
.station-item.current .station-play-area { color: var(--accent); }

.playing-anim {
  display: flex;
  gap: 2px;
  align-items: flex-end;
  height: 16px;
}
.playing-anim span {
  display: block;
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  animation: bar 0.8s ease-in-out infinite alternate;
}
.playing-anim span:nth-child(2) { animation-delay: 0.15s; }
.playing-anim span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bar {
  from { height: 4px; }
  to   { height: 14px; }
}

.station-info { flex: 1; min-width: 0; }
.station-name {
  display: block;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.station-url {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.station-menu-wrap { position: relative; flex-shrink: 0; }
.station-dropdown { top: 100%; right: 0; min-width: 120px; }

/* ─── Empty state ───────────────────────────────────────────────────────────── */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 60px 24px;
  text-align: center;
}
.empty-icon { font-size: 48px; opacity: 0.3; }
#empty-text { font-size: 15px; color: var(--text-muted); }
#empty-sub { font-size: 13px; color: var(--text-muted); opacity: 0.7; }

/* ─── Player bar ────────────────────────────────────────────────────────────── */
#player-bar {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
}
.player-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.player-icon { font-size: 22px; flex-shrink: 0; }
.player-text { flex: 1; min-width: 0; }
#player-station-name {
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#player-status { font-size: 12px; margin-top: 1px; }
.player-controls { display: flex; gap: 2px; flex-shrink: 0; }
.player-btn { width: 40px; height: 40px; font-size: 18px; }

/* ─── FAB ───────────────────────────────────────────────────────────────────── */
#add-station-fab {
  position: fixed;
  bottom: 80px;
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(37,99,235,0.4);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.12s;
}
#add-station-fab:hover { background: var(--accent-hover); transform: scale(1.06); }

/* ─── Modals ────────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.16);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 4px; }

/* ─── Spinner ───────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Toast ─────────────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #18181b;
  color: #fff;
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 300;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: var(--shadow);
}

/* ─── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .auth-card { padding: 24px 18px; }
  .modal-card { padding: 20px 16px; }
}
