:root {
  --bg: #0b0f17;
  --surface: #141b27;
  --surface-2: #1d2738;
  --text: #e7edf5;
  --muted: #8a98ad;
  --accent: #3ea6ff;
  --emby: #52b54b;       /* Emby green — the priority source */
  --danger: #ff5c6c;
  --radius: 12px;
}

* { box-sizing: border-box; }

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

/* Top bar / nav -------------------------------------------------------------*/
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 15, 23, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid #1f2a3a;
  padding: env(safe-area-inset-top) 12px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.brand { font-size: 20px; font-weight: 700; padding: 12px 4px 0; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 8px; }
.tab {
  flex: 0 0 auto;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 15px;
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.tab.active { background: var(--surface-2); color: var(--text); }

/* Layout --------------------------------------------------------------------*/
main { padding: 16px; max-width: 1200px; margin: 0 auto; padding-bottom: 64px; }
.view-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.view-head h1 { font-size: 22px; margin: 0; }
.hidden { display: none !important; }
.status, .empty { color: var(--muted); padding: 8px 0; }

input[type="search"], input[type="text"], input[type="password"], select, textarea {
  background: var(--surface);
  border: 1px solid #28344a;
  color: var(--text);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 16px; /* >=16px prevents iOS zoom-on-focus */
  width: 100%;
}
textarea { resize: vertical; line-height: 1.5; font-family: inherit; }
select { width: auto; }

.view-head input[type="search"] { max-width: 420px; }

/* Card grid -----------------------------------------------------------------*/
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}
.poster {
  aspect-ratio: 2 / 3;
  background: var(--surface-2) center/cover no-repeat;
  display: block;
  cursor: zoom-in;
}
.card.expanded { outline: 2px solid var(--accent); outline-offset: 0; }
.card.expanded .poster { cursor: zoom-out; }
.poster.placeholder { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; text-align: center; padding: 8px; }
.card-body { padding: 10px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-title { font-size: 14px; font-weight: 600; line-height: 1.25; }
.card-year { color: var(--muted); font-size: 12px; }

.badges { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.badge-emby { background: var(--emby); color: #06210a; }
.badge-watched { background: var(--surface-2); color: var(--muted); }
.provider-logos { display: flex; flex-wrap: wrap; gap: 4px; }
.provider-logos img { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; }
.provider-none { color: var(--muted); font-size: 11px; }
.provider-other { color: var(--accent); font-size: 11px; font-weight: 600; }

/* Expandable detail panel ---------------------------------------------------*/
.detail-panel {
  grid-column: 1 / -1;
  background: var(--surface);
  border: 1px solid #28344a;
  border-radius: var(--radius);
  overflow: hidden;
  animation: dp-in 0.18s ease;
}
@keyframes dp-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.dp-loading { padding: 28px; color: var(--muted); text-align: center; }
.dp-inner { display: flex; gap: 18px; padding: 18px; }
.dp-poster {
  flex: 0 0 160px;
  aspect-ratio: 2 / 3;
  border-radius: 10px;
  background: var(--surface-2) center/cover no-repeat;
}
.dp-info { flex: 1; min-width: 0; position: relative; }
.dp-close {
  position: absolute; top: -4px; right: -4px;
  background: transparent; border: none; color: var(--muted);
  font-size: 18px; line-height: 1; padding: 6px 8px; cursor: pointer;
}
.dp-close:hover { color: var(--text); }
.dp-title { margin: 0 36px 6px 0; font-size: 22px; }
.dp-meta { color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 14px; }
.dp-rating { color: #ffce4d; font-weight: 600; }
.dp-dot { color: #3a475c; }
.dp-tagline { color: var(--muted); font-style: italic; margin: 8px 0; }
.dp-genres { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { background: var(--surface-2); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.dp-overview { line-height: 1.55; margin: 10px 0; }
.dp-line { font-size: 13px; color: var(--muted); margin: 4px 0; }
.dp-label {
  color: var(--muted); font-weight: 700; text-transform: uppercase;
  font-size: 11px; letter-spacing: 0.04em; margin-right: 8px;
}
.dp-avail { margin: 12px 0 0; }
.dp-avail-row { display: flex; align-items: center; gap: 6px; margin: 6px 0; flex-wrap: wrap; }
.dp-avail-row img { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; }
.dp-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.dp-actions .btn { flex: 0 0 auto; padding: 9px 18px; font-size: 14px; }
@media (max-width: 560px) {
  .dp-inner { flex-direction: column; }
  .dp-poster { flex-basis: auto; width: 120px; }
}

.card-actions { display: flex; gap: 6px; margin-top: auto; flex-wrap: wrap; }
.btn {
  flex: 1 1 auto;
  border: 1px solid #2b3a52;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: #04243f; border-color: var(--accent); font-weight: 600; }
.btn-emby { background: var(--emby); color: #06210a; border-color: var(--emby); font-weight: 600; }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; }
.btn[disabled] { opacity: .55; cursor: default; }

/* Typeahead (quick add) -----------------------------------------------------*/
.quick-add { position: relative; flex: 1 1 280px; max-width: 460px; }
.typeahead {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--surface);
  border: 1px solid #28344a;
  border-radius: 10px;
  max-height: 60vh;
  overflow-y: auto;
  z-index: 15;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.ta-row { display: flex; gap: 10px; padding: 8px 10px; align-items: center; cursor: pointer; border-bottom: 1px solid #1c2636; }
.ta-row:last-child { border-bottom: none; }
.ta-row:hover { background: var(--surface-2); }
.ta-thumb { width: 38px; height: 57px; border-radius: 5px; object-fit: cover; background: var(--surface-2); flex: 0 0 auto; }
.ta-meta { flex: 1; min-width: 0; }
.ta-title { font-size: 14px; font-weight: 600; }
.ta-sub { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }

/* Settings ------------------------------------------------------------------*/
.settings { display: grid; gap: 16px; max-width: 520px; }
.settings label { display: grid; gap: 6px; font-weight: 600; font-size: 14px; }
.settings small { color: var(--muted); font-weight: 400; }
.settings .opt { color: var(--muted); font-weight: 400; }
.settings button { background: var(--accent); color: #04243f; border: none; border-radius: 10px; padding: 12px; font-size: 16px; font-weight: 700; cursor: pointer; }
.health { margin-top: 20px; max-width: 520px; display: grid; gap: 8px; }
.health .row { background: var(--surface); border-radius: 10px; padding: 12px; display: flex; justify-content: space-between; gap: 12px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--emby); } .dot.bad { background: var(--danger); } .dot.off { background: var(--muted); }

/* Import a list -------------------------------------------------------------*/
.import-hint { color: var(--muted); margin: 0 0 12px; font-size: 14px; }
.import-hint code { background: var(--surface-2); padding: 1px 6px; border-radius: 5px; font-size: 13px; }
.btn-lg {
  border: 1px solid #2b3a52; background: var(--surface-2); color: var(--text);
  border-radius: 10px; padding: 11px 20px; font-size: 15px; cursor: pointer;
}
.btn-lg.btn-primary { background: var(--accent); color: #04243f; border-color: var(--accent); font-weight: 700; }
.btn-lg[disabled] { opacity: .55; cursor: default; }
.import-bar { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.import-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 6px; font-size: 13px; }
.import-summary span { background: var(--surface); border: 1px solid #28344a; border-radius: 999px; padding: 4px 12px; }
.import-summary .imp-ok { color: var(--emby); border-color: var(--emby); }
.import-summary .imp-bad { color: var(--danger); }
.import-results { display: grid; gap: 8px; margin-top: 12px; }
.imp-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid #28344a; border-radius: 10px;
  padding: 8px 12px; cursor: pointer;
}
.imp-row input { width: 18px; height: 18px; flex: 0 0 auto; accent-color: var(--accent); cursor: pointer; }
.imp-thumb { width: 34px; height: 51px; border-radius: 5px; object-fit: cover; background: var(--surface-2); flex: 0 0 auto; }
.imp-body { flex: 1; min-width: 0; }
.imp-query { font-size: 13px; color: var(--muted); }
.imp-match { font-size: 15px; font-weight: 600; }
.imp-match.imp-none { color: var(--danger); font-weight: 500; }
.imp-year { color: var(--muted); font-weight: 400; font-size: 13px; }
.imp-pick { width: 100%; max-width: 480px; margin-top: 2px; padding: 7px 10px; font-size: 14px; }
.imp-review { color: var(--accent); }
.imp-meta { display: flex; align-items: center; gap: 8px; margin-top: 3px; flex-wrap: wrap; }
.imp-src { font-size: 12px; color: var(--accent); }
.imp-flag { font-size: 12px; color: var(--muted); }
.imp-done { font-size: 12px; color: var(--emby); font-weight: 600; }
.imp-row.imp-duplicate, .imp-row.imp-notfound, .imp-row.imp-empty { opacity: .72; }
.imp-row.imp-added { border-color: var(--emby); }
.import-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* More button + toast -------------------------------------------------------*/
.more { display: block; margin: 20px auto 0; background: var(--surface-2); color: var(--text); border: 1px solid #2b3a52; border-radius: 10px; padding: 10px 22px; cursor: pointer; }
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid #2b3a52;
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  z-index: 50;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.spinner { color: var(--muted); }
