/* ============================================================
   TV Tracker — Dark moderno stile Netflix
   ============================================================ */

:root {
  --bg:            #0b0d13;
  --bg-elevated:   #141823;
  --bg-card:       #1a1f2e;
  --bg-card-hover: #20263731;
  --border:        #2a3142;
  --border-strong: #3a4358;
  --text:          #e8ebf0;
  --text-dim:      #9aa3b4;
  --text-faint:    #5b6477;
  --accent:        #e50914;   /* rosso Netflix */
  --accent-hover:  #ff1f2a;
  --accent-2:      #6366f1;   /* viola acceso */
  --towatch:       #f5a623;   /* giallo/arancio */
  --watching:      #2ecc71;   /* verde */
  --watched:       #2c89e8;   /* azzurro */
  --star:          #f5c518;
  --radius:        12px;
  --radius-sm:     8px;
  --shadow:        0 8px 30px rgba(0,0,0,.45);
  --shadow-sm:      0 2px 10px rgba(0,0,0,.35);
  --transition:    .18s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }

/* ============================================================
   HEADER
   ============================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(180deg, rgba(11,13,19,.98) 0%, rgba(11,13,19,.92) 100%);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1600px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 8px;
  font-size: 14px;
  color: #fff;
  transform: translateY(-1px);
}
.brand h1 {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -.5px;
}

.search-wrap {
  flex: 1;
  min-width: 280px;
  display: flex;
  gap: 8px;
}
.search-wrap input {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  transition: var(--transition);
}
.search-wrap input:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(99,102,241,.18);
}
.search-wrap input::placeholder { color: var(--text-faint); }

.header-nav { display: flex; gap: 8px; }

/* ============================================================
   BOTTONI
   ============================================================ */
.btn {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  transition: var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-card-hover); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-elevated); }

/* ============================================================
   RISULTATI RICERCA
   ============================================================ */
.search-results {
  max-width: 1600px;
  margin: 20px auto 0;
  padding: 0 24px;
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-head h2 {
  font-size: 18px;
  font-weight: 700;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  flex-direction: column;
}
.result-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}
.result-card .card-poster {
  aspect-ratio: 2/3;
  background: linear-gradient(135deg, #1a1f2e, #0f1218);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 38px;
  overflow: hidden;
}
.result-card .card-poster img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.result-card .card-body {
  padding: 12px 14px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.result-card .card-title {
  font-size: 15px;
  font-weight: 700;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.result-card .card-sub {
  font-size: 12px;
  color: var(--text-dim);
}
.result-card .card-add {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--accent-2);
  font-weight: 600;
}
.result-card:hover .card-add { color: var(--text); }

/* ============================================================
   LISTE (3 colonne)
   ============================================================ */
.lists-container {
  flex: 1;
  max-width: 1600px;
  width: 100%;
  margin: 28px auto 0;
  padding: 0 24px 40px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  align-items: start;
}

.list-column {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 240px;
}
.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.list-head h2 {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.dot-towatch { background: var(--towatch); }
.dot-watching { background: var(--watching); }
.dot-watched  { background: var(--watched); }
.count {
  background: var(--bg-card);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.list-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-list {
  color: var(--text-faint);
  font-size: 13px;
  text-align: center;
  padding: 28px 12px;
  font-style: italic;
}

/* Card serie nelle liste */
.series-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  gap: 12px;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}
.series-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-card-hover);
  transform: translateX(2px);
}
.series-card .sc-poster {
  width: 48px; height: 70px;
  border-radius: 4px;
  flex-shrink: 0;
  background: linear-gradient(135deg, #232838, #11141c);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 20px;
  overflow: hidden;
}
.series-card .sc-poster img { width: 100%; height: 100%; object-fit: cover; }
.series-card .sc-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.series-card .sc-title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.series-card .sc-sub {
  font-size: 11px;
  color: var(--text-dim);
}
.series-card .sc-progress {
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 2px;
}
.series-card .sc-stars {
  color: var(--star);
  font-size: 12px;
  letter-spacing: 1px;
}
.series-card .sc-rating-empty { color: var(--text-faint); }
.series-card .sc-remove {
  position: absolute;
  top: 6px; right: 6px;
  width: 22px; height: 22px;
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 14px;
  cursor: pointer;
  border-radius: 4px;
  opacity: 0;
  transition: var(--transition);
}
.series-card:hover .sc-remove { opacity: 1; }
.series-card .sc-remove:hover { background: rgba(229,9,20,.18); color: var(--accent-hover); }

/* ============================================================
   MODAL GENERALE
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  max-width: 820px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  box-shadow: var(--shadow);
  position: relative;
  animation: slideUp .25s ease;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  transition: var(--transition);
  z-index: 5;
}
.modal-close:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Header serie nel modal */
.modal-series-head {
  display: flex;
  gap: 22px;
  margin-bottom: 24px;
}
.modal-poster {
  width: 160px; height: 240px;
  flex-shrink: 0;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #232838, #0f1218);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 52px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.modal-poster img { width: 100%; height: 100%; object-fit: cover; }

.modal-series-info { flex: 1; min-width: 0; }
.modal-series-info h2 {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 6px;
  letter-spacing: -.5px;
}
.modal-meta {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 10px;
}
.modal-genres {
  display: inline-block;
  font-size: 11px;
  color: var(--accent-2);
  margin-bottom: 12px;
  font-weight: 600;
}
.modal-summary {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 16px;
  max-height: 130px;
  overflow-y: auto;
}

/* Segmented control lista globale */
.modal-list-switch {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.modal-list-switch label { font-size: 13px; color: var(--text-dim); font-weight: 600; }
.segmented {
  display: flex;
  gap: 4px;
  background: var(--bg-card);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.seg {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  transition: var(--transition);
}
.seg:hover { color: var(--text); }
.seg.active { background: var(--accent); color: #fff; }
.seg.se-danger:hover { color: var(--accent-hover); }

/* Extra: stelle + note */
.modal-extra {
  display: flex;
  gap: 20px;
  padding: 18px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}
.extra-block { display: flex; flex-direction: column; gap: 8px; }
.extra-block.flex1 { flex: 1; }
.extra-block label {
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.stars { display: flex; gap: 4px; font-size: 26px; }
.star {
  color: var(--text-faint);
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}
.star:hover, .star.active { color: var(--star); transform: scale(1.12); }

#seriesNote, .manual-form input, .manual-form textarea {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
  transition: var(--transition);
}
#seriesNote:focus, .manual-form input:focus, .manual-form textarea:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(99,102,241,.16);
}

/* Tracking stagioni */
.modal-seasons h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 12px;
}
.seasons-list { display: flex; flex-direction: column; gap: 8px; }

.season-row {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.season-row .season-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.season-row .season-name { font-weight: 700; font-size: 14px; }
.season-row .season-meta { font-size: 11px; color: var(--text-dim); }

.season-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.season-state {
  display: flex;
  gap: 3px;
  background: var(--bg-elevated);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.season-state button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  transition: var(--transition);
}
.season-state button:hover { color: var(--text); }
.season-state button.s-towatch.active  { background: var(--towatch); color: #1a1300; }
.season-state button.s-watching.active  { background: var(--watching); color: #042411; }
.season-state button.s-watched.active   { background: var(--watched);  color: #fff; }

.episode-counter {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}
.episode-counter input {
  width: 56px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12px;
  text-align: center;
  font-family: inherit;
}
.episode-counter input:focus { outline: none; border-color: var(--accent-2); }

/* ============================================================
   MODAL STATISTICHE
   ============================================================ */
.modal-stats h2, .modal-manual h2 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 20px;
}
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stat-card .stat-value {
  font-size: 32px;
  font-weight: 800;
  color: var(--accent-2);
  letter-spacing: -1px;
}
.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.stat-card.accent .stat-value { color: var(--accent); }
.stat-card.green  .stat-value { color: var(--watching); }
.stat-card.blue   .stat-value { color: var(--watched); }
.stat-card.yellow .stat-value { color: var(--towatch); }

/* ============================================================
   MODAL AGGIUNTA MANUALE
   ============================================================ */
.manual-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.manual-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}
.manual-form label:nth-child(1),
.manual-form label:nth-child(4),
.manual-form label:nth-child(7) {
  grid-column: 1 / -1;
}
.manual-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 6px;
}
.manual-actions .hint { font-size: 11px; color: var(--text-faint); }

/* ============================================================
   TOAST + loading + error
   ============================================================ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: toastIn .25s ease;
}
.toast.error { border-color: var(--accent); }
.toast.success { border-color: var(--watching); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
  font-size: 14px;
}
.error {
  text-align: center;
  padding: 30px;
  color: var(--accent-hover);
  font-size: 14px;
}

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
  border-top: 1px solid var(--border);
  padding: 18px 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
}

/* ============================================================
   SCROLLBAR
   ============================================================ */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
  .lists-container { grid-template-columns: 1fr; }
  .list-column { min-height: 120px; }
}
@media (max-width: 640px) {
  .header-inner { padding: 12px 16px; gap: 12px; }
  .search-wrap { order: 3; width: 100%; }
  .header-nav { margin-left: auto; }
  .brand h1 { font-size: 18px; }
  .search-results, .lists-container { padding: 0 16px 30px; }
  .modal { padding: 20px 16px; }
  .modal-series-head { flex-direction: column; align-items: center; text-align: center; }
  .modal-poster { width: 130px; height: 195px; }
  .modal-extra { flex-direction: column; gap: 16px; }
  .manual-form { grid-template-columns: 1fr; }
  .grid-cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
