:root {
  --bg: #0d1015;
  --surface: #161b24;
  --elevated: #1e2531;
  --border: #262e3d;
  --accent: #ff6b2c;
  --accent-soft: rgba(255, 107, 44, 0.16);
  --text: #f3f5f8;
  --muted: #94a0b4;
  --green: #22c55e;
  --red: #ef4444;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.error-text {
  color: var(--red);
  margin-top: 12px;
  font-size: 0.9rem;
}

.center-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  text-align: center;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.brand-name {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.brand-tag {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
}

.btn-primary,
.btn-secondary,
.btn-ghost {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
}

.btn-ghost:hover {
  color: var(--text);
}

.full-width {
  width: 100%;
}

.app-shell {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100vh;
  height: 100dvh;
}

.app-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  min-height: 0;
}

.sidebar,
.content-area {
  overflow: auto;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  text-align: left;
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(255, 107, 44, 0.35);
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
  background: var(--elevated);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-meta {
  min-width: 0;
}

.user-name {
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.content-area {
  min-width: 0;
}

.content-inner {
  padding: 24px 28px;
  max-width: 1160px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0 0 4px 0;
  font-size: 1.5rem;
}

.target-selector {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

select,
input[type="email"],
input[type="text"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.9rem;
}

.search-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 20px;
}

.proxy-config {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.filter-chip {
  background: var(--elevated);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.proxy-config input {
  flex: 1;
  min-width: 220px;
}

.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.inline-form input {
  flex: 1;
  min-width: 200px;
}

.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.section-heading {
  margin: 22px 0 12px;
  font-size: 1.1rem;
}

.cards-grid,
.list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
  align-items: stretch;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  height: 100%;
  min-width: 0;
}

.card.active-device,
.card.is-now-playing,
.track-row.is-now-playing {
  border-color: var(--accent);
  background: var(--elevated);
  box-shadow: 0 0 0 1px rgba(255, 107, 44, 0.35);
}

.badge.live {
  background: rgba(255, 107, 44, 0.2);
  color: var(--accent);
}

.badge.paused {
  background: rgba(148, 160, 180, 0.2);
  color: var(--text);
}

.btn-fav {
  background: var(--elevated);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-fav.is-favorite {
  color: var(--accent);
  border-color: rgba(255, 107, 44, 0.5);
  background: var(--accent-soft);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.card-meta {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-weight: 600;
  font-size: 0.98rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-subtitle {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-actions {
  margin-top: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.card-actions > button {
  flex: 1;
}

.whitelist-share-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  padding: 4px 0;
}

.whitelist-share-toggle input[type="checkbox"] {
  accent-color: var(--accent, #ff6b2c);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

.artwork-wrap {
  width: 54px;
  height: 54px;
  border-radius: 12px;
  overflow: hidden;
  background: var(--elevated);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  font-weight: 800;
  font-size: 1.1rem;
  color: #fff;
}

.artwork-wrap.small {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  font-size: 0.95rem;
}

.artwork-wrap.large {
  width: 88px;
  height: 88px;
  border-radius: 16px;
  font-size: 1.8rem;
}

.artwork-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.16);
  color: var(--green);
  flex-shrink: 0;
}

.badge.idle {
  background: var(--elevated);
  color: var(--muted);
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

/* Dettaglio Playlist */
.playlist-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.playlist-hero {
  display: flex;
  align-items: center;
  gap: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  margin-bottom: 18px;
}

.playlist-hero h2 {
  margin: 0 0 6px;
}

.playlist-hero p {
  margin: 0;
}

.track-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.track-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.track-index {
  width: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  flex-shrink: 0;
}

.track-duration {
  color: var(--muted);
  font-size: 0.85rem;
  flex-shrink: 0;
}

/* Barra Controllo Remoto */
.remote-bar {
  background: var(--elevated);
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.remote-media {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.remote-info {
  min-width: 0;
  flex: 1;
}

.remote-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remote-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.icon-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
}

.remote-volume {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 96px;
  z-index: 60;
  background: var(--elevated);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 440px;
  max-height: 80vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

@media (max-width: 768px) {
  #playlist-tracks-list .track-row {
    flex-wrap: wrap;
  }
  .app-layout {
    display: block;
    overflow: auto;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar,
  .content-area {
    overflow: visible;
  }
  .nav-list {
    flex-direction: row;
    overflow-x: auto;
  }
  .content-inner {
    padding: 18px 16px;
  }
  .remote-bar {
    flex-wrap: wrap;
    padding: 10px 14px;
    gap: 10px;
  }
  .remote-media {
    flex: 1 1 100%;
  }
  .remote-volume {
    margin-left: auto;
  }
}

.sidebar-apk {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border-radius: 12px;
  background: var(--elevated);
  border: 1px solid var(--border);
}

.sidebar-apk-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-apk-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
}

.sidebar-apk-link {
  text-align: center;
  text-decoration: none;
  font-size: 0.85rem;
}

.badge-group {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  font-weight: 600;
  cursor: pointer;
  flex: 0 0 auto !important;
}

.btn-danger-ghost:hover {
  color: #f87171;
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(248, 113, 113, 0.08);
}
