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

:root {
  /* Match panel design system exactly */
  --primary:        #282828;
  --primary-hover:  #3d3d3d;
  --bg:             #f2f4f6;
  --card:           #ffffff;
  --text:           #282828;
  --sub:            #6b7684;
  --border:         #e5e8eb;
  --danger:         #f04452;
  --success:        #22a35a;
  --warning-bg:     #fff8e6;
  --warning-text:   #b07c00;
  --warning-border: #f5d580;
  --success-bg:     #eaf7ee;
  --success-border: #b3e6c5;
  --accent:         #282828;

  --spring:      cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --shadow:      0 8px 32px rgba(0,0,0,.08);
  --shadow-sm:   0 4px 16px rgba(0,0,0,.06);
  --radius-lg:   20px;
  --radius-md:   16px;
  --radius-sm:   12px;
  --sidebar-w:   248px;
  --font:        'Noto Sans KR', 'Pretendard', system-ui, sans-serif;
}

html { font-size: 15px; }
body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }

/* ── Auth page ─────────────────────────────────────────────────────────────── */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px; margin: 1.5rem;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 2.5rem 2rem; box-shadow: var(--shadow);
}
.auth-logo { text-align: center; margin-bottom: 2rem; }
.auth-logo-icon { font-size: 2.8rem; margin-bottom: .6rem; }
.auth-title { font-size: 1.5rem; font-weight: 800; color: var(--text); }
.auth-subtitle { color: var(--sub); font-size: .9rem; margin-top: .25rem; font-weight: 500; }
.auth-form { display: flex; flex-direction: column; gap: 1.1rem; }
.auth-error {
  background: #fef2f2; border: 1px solid #fecaca;
  color: var(--danger); border-radius: var(--radius-sm); padding: .65rem 1rem;
  font-size: .88rem; font-weight: 600;
}

/* ── Fields ────────────────────────────────────────────────────────────────── */
.field-group { display: flex; flex-direction: column; gap: .4rem; }
.field-label { font-size: .82rem; font-weight: 700; color: var(--sub); text-transform: uppercase; letter-spacing: .04em; }
.field-input-wrap { position: relative; }
.field-input {
  width: 100%; background: var(--bg); border: none;
  color: var(--text); border-radius: var(--radius-sm); padding: .75rem 1rem;
  font-size: .95rem; font-family: var(--font); transition: outline .2s var(--ease-smooth);
  outline: 2px solid transparent; appearance: none;
}
.field-input:focus { outline: 2px solid rgba(40,40,40,.22); }
.field-input::placeholder { color: #b0b8c1; }
.field-input-wrap .field-input { padding-right: 2.8rem; }
.field-eye {
  position: absolute; right: .8rem; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--sub); cursor: pointer; line-height: 0; padding: .2rem;
}
.field-eye:hover { color: var(--text); }

select.field-input { cursor: pointer; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary); color: #fff;
  border: none; border-radius: var(--radius-sm);
  padding: .8rem 1.4rem; font-size: .92rem; font-weight: 700; font-family: var(--font);
  cursor: pointer; transition: all .2s var(--spring);
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:active:not(:disabled) { transform: scale(.97); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg); color: var(--text); border: none;
  border-radius: var(--radius-sm); padding: .75rem 1.2rem; font-size: .88rem;
  font-weight: 700; font-family: var(--font); cursor: pointer;
  transition: all .2s var(--spring);
  display: inline-flex; align-items: center; gap: .45rem;
}
.btn-secondary:hover:not(:disabled) { background: #e5e8eb; }

.btn-danger {
  background: #fef2f2; color: var(--danger); border: 1px solid #fecaca;
  border-radius: var(--radius-sm); padding: .65rem 1rem; font-size: .88rem;
  font-weight: 700; font-family: var(--font); cursor: pointer;
  transition: all .2s; display: inline-flex; align-items: center; gap: .4rem;
}
.btn-danger:hover:not(:disabled) { background: #fee2e2; }

.btn-ghost {
  background: none; color: var(--sub); border: none;
  border-radius: var(--radius-sm); padding: .55rem .85rem; font-size: .88rem;
  font-family: var(--font); cursor: pointer; transition: all .2s;
  display: inline-flex; align-items: center; gap: .4rem;
}
.btn-ghost:hover { color: var(--text); background: var(--bg); }

.btn-success {
  background: var(--success-bg); color: var(--success); border: 1.5px solid var(--success-border);
  border-radius: var(--radius-sm); padding: .7rem 1.2rem; font-size: .88rem;
  font-weight: 700; font-family: var(--font); cursor: pointer;
  transition: all .2s; display: inline-flex; align-items: center; gap: .5rem;
}
.btn-success:hover:not(:disabled) { background: #d3f0dc; }
.btn-success:disabled { opacity: .45; cursor: not-allowed; }

.btn-warning {
  background: var(--warning-bg); color: var(--warning-text); border: 1.5px solid var(--warning-border);
  border-radius: var(--radius-sm); padding: .7rem 1.2rem; font-size: .88rem;
  font-weight: 700; font-family: var(--font); cursor: pointer;
  transition: all .2s; display: inline-flex; align-items: center; gap: .5rem;
}
.btn-warning:hover:not(:disabled) { background: #fdefc3; }
.btn-warning:disabled { opacity: .45; cursor: not-allowed; }

.btn-lg { padding: .88rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-sm { padding: .45rem .85rem; font-size: .82rem; }
.btn-icon { width: 36px; height: 36px; padding: 0; justify-content: center; border-radius: var(--radius-sm); }

/* ── Spinner ───────────────────────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.35);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .65s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── App layout ────────────────────────────────────────────────────────────── */
.app-layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); min-height: 100vh; background: var(--card);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  padding: 16px 12px; flex-shrink: 0; position: sticky; top: 0; height: 100vh;
  overflow-y: auto; gap: 12px;
}
.sidebar-brand { padding: 4px 8px 8px; }
.sidebar-logo { font-size: 1.6rem; }
.sidebar-name { font-size: 1.1rem; font-weight: 800; margin-top: .25rem; }
.sidebar-sub { font-size: .75rem; color: var(--sub); margin-top: .15rem; font-weight: 500; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: .65rem; padding: .65rem .85rem;
  border-radius: var(--radius-sm); color: var(--sub); font-size: .9rem; font-weight: 700;
  cursor: pointer; border: none; background: none; font-family: var(--font);
  text-align: left; transition: all .2s var(--spring); text-decoration: none;
}
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--bg); color: var(--text); }
.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer { border-top: 1px solid var(--border); padding-top: 12px; }
.sidebar-user { font-size: .78rem; color: var(--sub); padding: .25rem .5rem; font-weight: 600; }
.sidebar-user strong { color: var(--text); }

/* ── Sync section ──────────────────────────────────────────────────────────── */
.sync-section {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 14px;
}
.sync-title {
  font-size: .75rem; font-weight: 800; color: var(--sub);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px;
}
.sync-btns { display: flex; flex-direction: column; gap: 6px; }
.sync-status { font-size: .75rem; color: var(--sub); margin-top: 8px; text-align: center; font-weight: 600; min-height: 16px; }
.sync-status.ok  { color: var(--success); }
.sync-status.err { color: var(--danger); }

/* ── Main area ─────────────────────────────────────────────────────────────── */
.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: .9rem 1.5rem; display: flex; align-items: center; gap: .75rem;
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 1.05rem; font-weight: 800; flex: 1; }
.topbar-badge {
  background: var(--bg); color: var(--sub); font-size: .78rem;
  font-weight: 700; border-radius: 20px; padding: .2rem .8rem;
}

.content { padding: 1.25rem 1.5rem; flex: 1; }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card); border-radius: var(--radius-lg);
  padding: 1.25rem; margin-bottom: 1rem;
  box-shadow: 0 4px 24px rgba(0,0,0,.07);
}
.card-title { font-size: .95rem; font-weight: 800; margin-bottom: 1rem; color: var(--text); }

/* ── Stats ─────────────────────────────────────────────────────────────────── */
.stats-row { display: flex; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.stat-card {
  flex: 1; min-width: 130px; background: var(--card);
  border-radius: var(--radius-lg); padding: 1.1rem 1.25rem;
  box-shadow: 0 4px 24px rgba(0,0,0,.07);
}
.stat-label { font-size: .72rem; color: var(--sub); font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 2rem; font-weight: 800; margin-top: .2rem; }
.stat-sub { font-size: .78rem; color: var(--sub); margin-top: .1rem; font-weight: 500; }

/* ── Add tabs ──────────────────────────────────────────────────────────────── */
.add-tabs { display: flex; gap: .4rem; margin-bottom: 1rem; flex-wrap: wrap; }
.add-tab {
  padding: .45rem 1.1rem; border-radius: 20px; font-size: .85rem; font-weight: 700;
  cursor: pointer; border: 1.5px solid var(--border); background: none;
  color: var(--sub); font-family: var(--font); transition: all .2s var(--spring);
}
.add-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.add-tab:hover:not(.active) { background: var(--bg); color: var(--text); }

/* ── Search row ────────────────────────────────────────────────────────────── */
.search-row { display: flex; gap: .6rem; }
.search-row .field-input { flex: 1; margin-bottom: 0; }

/* ── Playlist ──────────────────────────────────────────────────────────────── */
.playlist-toolbar { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.playlist-toolbar-right { margin-left: auto; display: flex; gap: .5rem; align-items: center; }

.playlist-list { list-style: none; display: flex; flex-direction: column; gap: .5rem; }

.playlist-item {
  display: flex; align-items: center; gap: .75rem;
  background: var(--card); border-radius: var(--radius-md);
  padding: .75rem 1rem; box-shadow: var(--shadow-sm);
  transition: box-shadow .2s var(--spring);
}
.playlist-item:hover { box-shadow: 0 8px 28px rgba(0,0,0,.1); }
.playlist-item.dragging { opacity: .4; }
.playlist-item.drag-over { box-shadow: 0 0 0 2px var(--primary); }

.drag-handle { color: var(--sub); cursor: grab; padding: .2rem; font-size: 1.1rem; }
.drag-handle:active { cursor: grabbing; }
.song-thumb {
  width: 52px; height: 38px; object-fit: cover; border-radius: 8px;
  background: var(--bg); flex-shrink: 0;
}
.song-thumb-placeholder {
  width: 52px; height: 38px; border-radius: 8px; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  color: var(--sub); font-size: 1.1rem; flex-shrink: 0;
}
.song-info { flex: 1; min-width: 0; }
.song-title { font-size: .9rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.song-meta { font-size: .75rem; color: var(--sub); margin-top: .15rem; font-weight: 500; }
.song-type {
  font-size: .7rem; font-weight: 800; border-radius: 4px; padding: .1rem .45rem;
  text-transform: uppercase; letter-spacing: .04em;
}
.song-type.youtube { background: #fef2f2; color: #e53e3e; }
.song-type.local   { background: var(--success-bg); color: var(--success); }
.song-actions { display: flex; gap: .3rem; flex-shrink: 0; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--sub); }
.empty-state-icon { font-size: 2.5rem; margin-bottom: .8rem; }
.empty-state-text { font-size: .95rem; font-weight: 600; }

/* ── Search results ────────────────────────────────────────────────────────── */
.results-list { list-style: none; display: flex; flex-direction: column; gap: .4rem; margin-top: .75rem; }
.result-item {
  display: flex; align-items: center; gap: .75rem; padding: .65rem 1rem;
  background: var(--bg); border-radius: var(--radius-sm);
  transition: background .15s;
}
.result-item:hover { background: #e8eaed; }

/* ── Settings ──────────────────────────────────────────────────────────────── */
.settings-grid { display: flex; flex-direction: column; gap: 0; }
.setting-row {
  display: flex; align-items: center; gap: 1rem; padding: .85rem 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: none; }
.setting-info { flex: 1; }
.setting-label { font-size: .9rem; font-weight: 700; }
.setting-desc { font-size: .78rem; color: var(--sub); margin-top: .2rem; }
.setting-control { flex-shrink: 0; }

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 44px; height: 26px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #d1d5db; border-radius: 26px; transition: background .2s;
}
.toggle-slider::before {
  content: ''; position: absolute; width: 20px; height: 20px; border-radius: 50%;
  background: #fff; left: 3px; top: 3px; transition: transform .2s var(--spring);
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.3); backdrop-filter: blur(4px);
  z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card); border-radius: var(--radius-lg);
  padding: 1.75rem; width: 100%; max-width: 480px; box-shadow: var(--shadow);
  animation: modalIn .18s var(--ease-smooth);
}
@keyframes modalIn { from { opacity: 0; transform: scale(.96); } }
.modal-title { font-size: 1.05rem; font-weight: 800; margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.5rem; }

/* ── Toast ─────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 2000;
  display: flex; flex-direction: column; gap: .5rem; pointer-events: none;
}
.toast {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .75rem 1.1rem; font-size: .88rem;
  box-shadow: var(--shadow); animation: toastIn .2s var(--ease-smooth);
  display: flex; align-items: center; gap: .6rem; pointer-events: auto;
  min-width: 220px; max-width: 340px; font-weight: 600;
}
.toast.success { border-color: var(--success-border); }
.toast.error   { border-color: #fecaca; }
.toast.info    { border-color: var(--border); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* ── Progress ──────────────────────────────────────────────────────────────── */
.progress-wrap { background: var(--bg); border-radius: 4px; height: 4px; overflow: hidden; margin: .5rem 0; }
.progress-bar  { height: 100%; background: var(--primary); width: 0; transition: width .3s; border-radius: 4px; }

/* ── Misc ──────────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
.hint { font-size: .8rem; color: var(--sub); margin-top: .4rem; font-weight: 500; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b0b8c1; }

/* Responsive */
@media (max-width: 720px) {
  :root { --sidebar-w: 210px; }
  .stats-row { flex-direction: column; }
}
@media (max-width: 560px) {
  .app-layout { flex-direction: column; }
  .sidebar { width: 100%; min-height: auto; height: auto; position: static; }
}
