/* ═══════════════════════════════════════════════════════════════════════════
   styles.css — Giao diện 3 tầng tối giản (Top / Middle / Bottom) & Ma trận 2×2
   ═══════════════════════════════════════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* ── 1. Ma Trận 4 Giao Diện: [Default | CLI] × [Dark | White] ── */
body[data-theme="default-dark"] {
  --bg: #0c0e13;
  --surface: #13161f;
  --surface-2: #1c202d;
  --fg: #eef1f7;
  --muted: #828ba0;
  --border: #242938;
  --accent: #eef1f7;
  --accent-fg: #0c0e13;
  --ok: #22c55e;
  --radius-lg: 14px;
  --radius-sm: 8px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body[data-theme="default-light"] {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #ebebea;
  --fg: #14161a;
  --muted: #6c717d;
  --border: #e1e2e6;
  --accent: #14161a;
  --accent-fg: #ffffff;
  --ok: #16a34a;
  --radius-lg: 14px;
  --radius-sm: 8px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body[data-theme="cli-dark"] {
  --bg: #07090b;
  --surface: #0d1115;
  --surface-2: #151c22;
  --fg: #d7f5e8;
  --muted: #658a7b;
  --border: #1f302a;
  --accent: #34d399;
  --accent-fg: #06120c;
  --ok: #34d399;
  --radius-lg: 4px;
  --radius-sm: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

body[data-theme="cli-light"] {
  --bg: #f2f1eb;
  --surface: #faf9f5;
  --surface-2: #e5e3da;
  --fg: #181917;
  --muted: #696a62;
  --border: #cecdc3;
  --accent: #181917;
  --accent-fg: #faf9f5;
  --ok: #15803d;
  --radius-lg: 4px;
  --radius-sm: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.4;
}

body {
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none !important;
}

button, input, select {
  font: inherit;
  color: inherit;
}

svg.ico {
  width: 17px;
  height: 17px;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  flex-shrink: 0;
  display: block;
}

svg.ico.spin {
  animation: spin360 1s linear infinite;
}

@keyframes spin360 {
  to { transform: rotate(360deg); }
}

.ico-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ico-slot.muted, .muted-text {
  color: var(--muted);
}

/* ── 2. TẦNG TOP ── */
.app-top {
  height: 48px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  z-index: 20;
}

.brand-btn {
  background: transparent;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
}
.brand-btn:hover {
  background: var(--surface-2);
}

.brand-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}
.status-dot.offline {
  background: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Nút dùng chung ── */
.icon-btn {
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms ease, opacity 120ms ease;
}
.icon-btn.bordered {
  border: 1px solid var(--border);
}
.icon-btn:hover {
  background: var(--surface-2);
}
.icon-btn.is-active {
  background: var(--accent);
  color: var(--accent-fg);
}
.icon-btn.is-cached {
  color: var(--ok);
}
.icon-btn.is-dim, .icon-btn:disabled {
  opacity: 0.32;
  cursor: default;
}

.mini-btn {
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 120ms ease;
}
.mini-btn:hover {
  background: var(--surface-2);
}
.mini-btn.is-primary, .mini-btn.is-active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 500;
}
.mini-btn.full-w {
  width: 100%;
  text-align: center;
}
.mini-btn.text-left {
  text-align: left;
}

/* ── 3. TẦNG MIDDLE ── */
.app-middle {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}

#visCanvas {
  width: 100%;
  height: 100%;
  display: block;
}

.cli-bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  height: 34px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  z-index: 10;
}
.cli-prompt {
  color: var(--muted);
}
.cli-bar input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
}
.cli-notice {
  color: var(--muted);
  font-size: 12px;
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Panel Full-Middle (Thư viện & Playlist) ── */
.middle-full-panel {
  position: absolute;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  z-index: 15;
}

.lib-header, .sheet-header {
  min-height: 44px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.sheet-header {
  font-size: 13px;
  color: var(--muted);
}

.seg-group {
  display: inline-flex;
  padding: 2px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  gap: 2px;
  flex-shrink: 0;
}
.seg-btn {
  border: none;
  background: transparent;
  padding: 4px 10px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.seg-btn.is-active {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 500;
}

.lib-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  max-width: 280px;
  min-width: 0;
}

.search-box {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 6px;
}
.search-box input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  font-size: 12.5px;
}

.lib-right-btns {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Cột lọc Ca sĩ dọc A → Z + Danh sách Bài ── */
.lib-tracks-layout {
  flex: 1;
  min-height: 0;
  display: flex;
}

.az-sidebar {
  width: 124px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
@media (max-width: 480px) {
  .az-sidebar {
    width: 98px;
  }
}

.az-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.az-item:hover {
  background: var(--surface-2);
}
.az-item.is-active {
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 500;
}

.lib-track-list, .playlist-rows, .lib-artist-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 16px;
}

.lib-track-row, .playlist-row, .lib-artist-row {
  min-height: 42px;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lib-track-row.is-playing .lib-title,
.playlist-row.is-playing .pl-title {
  font-weight: 600;
}

/* Bài ẩn nằm ở cuối cùng danh sách, mờ đi */
.lib-track-row.is-archived,
.lib-artist-row.is-archived {
  opacity: 0.45;
}

.lib-track-main, .pl-main {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  padding: 4px 0;
}

.lib-idx, .pl-idx {
  color: var(--muted);
  font-size: 12px;
  margin-right: 6px;
}

.lib-artist-tag, .pl-artist {
  color: var(--muted);
  font-size: 12.5px;
  margin-left: 6px;
}

.lib-track-actions, .artist-row-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

/* ── Quản lý Ca sĩ & Kéo thả ── */
.lib-artists-layout, .lib-config-layout {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.lib-artists-hint {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

.lib-artist-row.drag-over {
  border-top: 2px solid var(--accent);
}
.lib-artist-row.is-dragging {
  opacity: 0.35;
}

.artist-check-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.artist-check-wrap input[type="checkbox"] {
  width: 15px;
  height: 15px;
  cursor: pointer;
  accent-color: var(--accent);
}
.artist-order-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lib-artist-row.is-archived .artist-order-name {
  text-decoration: line-through;
}
.artist-meta-count {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.drag-handle {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  cursor: grab;
  touch-action: none;
}
.drag-handle:active {
  cursor: grabbing;
}

/* ── Form Cấu hình tìm kiếm Ca sĩ ── */
.cfg-form-box {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 12.5px;
}
.cfg-head, .cfg-footer, .row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cfg-footer {
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.cfg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 560px) {
  .cfg-grid {
    grid-template-columns: 1fr;
  }
}
.cfg-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cfg-field span, .cfg-subhead, .field-caption {
  font-size: 12px;
  color: var(--muted);
}
.cfg-field input, .cfg-add-source-row input, .cfg-add-source-row select {
  height: 34px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.cfg-sources-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cfg-sources-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cfg-source-item {
  padding: 7px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.cfg-source-info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.cfg-source-badge {
  padding: 2px 6px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-size: 11.5px;
}
.cfg-source-q {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 280px;
}
.cfg-source-stat, .cfg-hint {
  color: var(--muted);
  font-size: 12px;
}
.cfg-source-btns {
  display: flex;
  align-items: center;
  gap: 4px;
}
.cfg-add-source-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.cfg-add-source-row input {
  flex: 1;
  min-width: 160px;
}

/* ── Hộp thoại Confirm thoát Thư viện ── */
.confirm-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 40;
}
.confirm-card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.confirm-title {
  font-weight: 600;
  font-size: 14px;
}
.confirm-desc {
  font-size: 12.5px;
  color: var(--muted);
}
.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  padding-top: 4px;
}

/* ── 4. SETTING POPOVER (Chữ rõ ràng + 4 Sub-menus) ── */
.setting-popover {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 310px;
  max-width: calc(100vw - 20px);
  max-height: calc(100% - 20px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  z-index: 30;
  font-size: 13px;
}

.setting-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.setting-title {
  font-weight: 600;
}
.back-btn {
  border: none;
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: var(--radius-sm);
}
.back-btn:hover {
  background: var(--surface-2);
}

.setting-root-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.setting-nav-item {
  width: 100%;
  border: none;
  background: transparent;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  cursor: pointer;
}
.setting-nav-item:hover {
  background: var(--surface-2);
}
.nav-label {
  font-weight: 500;
}
.nav-summary {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.nav-arrow {
  color: var(--muted);
}

.setting-sub {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.setting-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.setting-block input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.theme-card {
  padding: 9px 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  cursor: pointer;
  text-align: left;
}
.theme-card strong {
  font-size: 12.5px;
  font-weight: 600;
}
.theme-card span {
  font-size: 11.5px;
  opacity: 0.72;
}
.theme-card.is-active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.storage-card {
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.storage-card.row-between {
  flex-direction: row;
}

.limit-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.limit-input-wrap input {
  width: 72px;
  height: 30px;
  padding: 0 8px;
  text-align: right;
  font-weight: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

.empty-note {
  padding: 36px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ── 5. TẦNG BOTTOM (Player tối giản thuần Icon) ── */
.app-bottom {
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 20;
}

.progress-track {
  height: 5px;
  width: 100%;
  background: var(--surface-2);
  cursor: pointer;
  position: relative;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 140ms linear;
}

.bottom-bar {
  height: 56px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.now-playing {
  flex: 1;
  min-width: 0;
}
.np-title {
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.np-artist {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.transport-cluster {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.play-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
body[data-theme^="cli-"] .play-btn {
  border-radius: var(--radius-sm);
}

.v-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  margin: 0 4px;
}
