/* ============================================================
   Agos — Stremio-inspired streaming UI
   Dark theme with purple accent, clean typography
   ============================================================ */

:root {
  --bg: #0b0d10;
  --bg-2: #12141a;
  --bg-3: #1a1d27;
  --surface: #1a1d27;
  --surface-2: #222633;
  --border: #2a2f3e;
  --text: #e8eaf0;
  --text-dim: #8a90a0;
  --accent: #6c5ce7;
  --accent-2: #fd79a8;
  --accent-3: #00cec9;
  --green: #00e676;
  --red: #ff5252;
  --yellow: #ffd740;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea { font-family: inherit; }

.app { display: flex; height: 100vh; overflow: hidden; }

/* ── LOADING OVERLAY ─────────────────────────── */
#loading-overlay {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--bg); z-index: 9999;
}
#loading-overlay .spinner-track {
  width: 56px; height: 56px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
#loading-overlay .spinner-fill {
  width: 100%; height: 100%; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--green);
  animation: spin 1.2s linear infinite reverse;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-overlay p { margin-top: 16px; color: var(--text-dim); font-size: 14px; }

/* ── SIDEBAR ─────────────────────────────────── */
.sidebar {
  width: 260px; min-width: 260px;
  background: var(--bg-2);
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 12px;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 26px; }
.logo-text { font-size: 20px; font-weight: 700; letter-spacing: -0.5px; }
.icon-btn {
  font-size: 18px; color: var(--text-dim);
  padding: 4px 8px; border-radius: 6px;
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; margin-bottom: 16px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 500;
  text-align: left; transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--bg-3); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { font-size: 18px; width: 24px; text-align: center; }

.sidebar-section { margin-bottom: 16px; }
.sidebar-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.sidebar-section-header h3 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 1px;
  color: var(--text-dim); font-weight: 600;
}
.ghost-btn {
  font-size: 12px; color: var(--accent);
  padding: 4px 10px; border-radius: 6px; font-weight: 600;
}
.ghost-btn:hover { background: var(--bg-3); }

.addon-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.addon-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--bg-3); color: var(--text);
  font-size: 13px; transition: background 0.15s;
}
.addon-item:hover { background: var(--bg-2); }
.addon-item .addon-name { flex: 1; font-weight: 500; }
.addon-item .addon-status {
  font-size: 11px; padding: 3px 8px; border-radius: 20px;
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px;
}
.addon-status-ok { background: rgba(0,230,118,0.15); color: var(--green); }
.addon-status-loading { background: rgba(255,215,64,0.15); color: var(--yellow); }
.addon-status-error { background: rgba(255,82,82,0.15); color: var(--red); }
.addon-item .addon-icon {
  width: 36px; height: 36px; border-radius: 6px;
  object-fit: cover; display: block;
}
.addon-item .delete-addon {
  color: var(--text-dim); font-size: 16px; padding: 2px 6px;
}
.addon-item .delete-addon:hover { color: var(--red); background: rgba(255,82,82,0.1); }

.empty-state {
  text-align: center; padding: 16px;
  color: var(--text-dim); font-size: 13px;
  border: 1px dashed var(--border); border-radius: var(--radius-sm);
  display: none;
}
.empty-state.visible { display: block; }
.empty-state p { margin: 0 0 4px 0; }
.empty-state .dim { font-size: 12px; }

.lib-tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.lib-tab {
  padding: 5px 12px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
  color: var(--text-dim);
  transition: background 0.15s, color 0.15s;
}
.lib-tab:hover { background: var(--bg-3); color: var(--text); }
.lib-tab.active { background: var(--bg-3); color: var(--accent); }

.library-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.library-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
  transition: background 0.12s;
}
.library-item:hover { background: var(--bg-3); }
.library-item .lib-poster {
  width: 44px; height: 60px; border-radius: 4px;
  object-fit: cover; flex-shrink: 0;
}
.library-item .lib-info { flex: 1; min-width: 0; }
.library-item .lib-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.library-item .lib-year { font-size: 12px; color: var(--text-dim); }
.library-item .lib-check {
  font-size: 16px; opacity: 0; color: var(--green);
}
.library-item:hover .lib-check { opacity: 1; }

/* ── MAIN ────────────────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg-2); flex-shrink: 0;
}
.topbar-left { flex: 1; max-width: 640px; }
.search-wrap { flex: 1; position: relative; }
.search-input {
  width: 100%; padding: 12px 16px 12px 44px;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg-3); color: var(--text); font-size: 15px;
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input::placeholder { color: var(--text-dim); }
.search-input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(108,92,231,0.15);
}
.search-btn {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%); color: var(--text-dim); pointer-events: none;
}
.search-btn svg { width: 18px; height: 18px; }

.topbar-spacer { flex: 1; }
.topbar-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--text-dim);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--green);
}
.status-text { letter-spacing: 0.3px; }

.cat-header {
  padding: 12px 20px; display: flex; align-items: center;
  gap: 10px; flex-shrink: 0;
}
.cat-header h2 { font-size: 22px; letter-spacing: -0.5px; }
.cat-count { font-size: 13px; color: var(--text-dim); }

.content {
  flex: 1; overflow-y: auto; padding: 20px;
}
.content::-webkit-scrollbar { width: 8px; }
.content::-webkit-scrollbar-track { background: var(--bg); }
.content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── LOADING / ERROR / EMPTY ───────────────── */
.loading, .error {
  display: flex; flex-direction: column;
  align-items: center; gap: 12px;
  padding: 80px 20px; color: var(--text-dim); text-align: center;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.error { gap: 10px; }
.error svg { width: 36px; height: 36px; color: var(--red); }
.error p { font-size: 14px; }

.empty-grid { display: none; flex-direction: column; align-items: center; gap: 10px; padding: 80px 20px; }
.empty-grid.visible { display: flex; }
.empty-glyph { font-size: 48px; }
.empty-grid p { font-size: 15px; color: var(--text-dim); }

/* ── GRID ────────────────────────────────────── */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
}
.grid-item {
  position: relative; border-radius: var(--radius);
  overflow: hidden; background: var(--bg-2); cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, filter 0.2s;
}
.grid-item:hover {
  transform: translateY(-4px); box-shadow: var(--shadow); filter: brightness(1.05);
}
.grid-item .poster {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block;
}
.grid-item .overlay {
  position: absolute; inset: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 60%);
  display: flex; flex-direction: column; justify-content: flex-end; padding: 12px;
  opacity: 0; transition: opacity 0.15s;
}
.grid-item:hover .overlay { opacity: 1; }
.grid-item .overlay .title {
  font-size: 14px; font-weight: 600; color: #fff; margin-bottom: 4px;
}
.grid-item .overlay .year {
  font-size: 12px; color: rgba(255,255,255,0.85);
}
.grid-item .overlay .type {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
  color: rgba(255,255,255,0.7); margin-top: 4px;
}

/* Badges */
.badge {
  position: absolute; top: 8px; right: 8px;
  padding: 4px 10px; border-radius: 20px;
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-watched { background: rgba(0,230,118,0.2); color: var(--green); }
.badge-starred { background: rgba(255,215,64,0.2); color: var(--yellow); }

/* ── NO ADDONS BANNER ────────────────────────── */
.no-addons-banner {
  display: none; align-items: center; justify-content: center;
  gap: 12px; padding: 14px;
  border-top: 1px solid var(--border); background: var(--bg-2);
  font-size: 13px; color: var(--yellow);
}
.no-addons-banner.visible { display: flex; }

/* ── MODAL ───────────────────────────────────── */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.7); z-index: 100;
  align-items: center; justify-content: center;
  backdrop-filter: blur(6px);
}
.modal-backdrop.visible { display: flex; }

.modal {
  width: 920px; max-width: 96vw; max-height: 94vh;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; overflow: hidden;
  animation: popIn 0.18s ease-out;
}
@keyframes popIn {
  from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); }
}

.modal-side {
  width: 240px; background: var(--bg-3);
  display: flex; flex-direction: column;
  align-items: center; padding: 16px;
}
.modal-side img {
  width: 100%; aspect-ratio: 2/3; object-fit: cover;
  border-radius: var(--radius-sm);
}
.modal-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.modal-tags span {
  padding: 4px 12px; border-radius: 20px;
  font-size: 12px; font-weight: 600;
}
.modal-tags .tag-genre { background: var(--bg-3); color: var(--text-dim); }
.modal-tags .tag-rating { background: rgba(108,92,231,0.15); color: var(--accent); }

.modal-body { flex: 1; padding: 24px; overflow-y: auto; }
.modal-body h2 { font-size: 26px; letter-spacing: -0.5px; margin-bottom: 8px; }
.detail-meta {
  display: flex; flex-wrap: wrap; gap: 16px;
  color: var(--text-dim); font-size: 14px; margin-bottom: 12px;
}
.detail-meta .meta-item { display: flex; align-items: center; gap: 6px; }
.detail-summary {
  color: var(--text-dim); font-size: 14px; line-height: 1.7; margin-bottom: 16px;
}

.modal-actions {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px;
}
.btn {
  padding: 10px 18px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 600; transition: background 0.15s, opacity 0.15s;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: #5b4bd7; }
.btn.green { background: var(--green); color: #000; }
.btn.green:hover { background: #00c853; }
.btn.yellow { background: var(--yellow); color: #000; }
.btn.yellow:hover { background: #ffb32b; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn .badge-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); display: inline-block; margin-right: 6px; vertical-align: middle;
}

.streams {
  display: flex; flex-direction: column; gap: 8px; margin-top: 8px;
}
.stream-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: var(--radius-sm); background: var(--bg-3);
}
.stream-item .stream-name { font-weight: 600; flex: 1; }
.stream-item .stream-provider { font-size: 12px; color: var(--text-dim); }
.stream-item .stream-quality { font-size: 12px; color: var(--text-dim); }

.modal-header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; letter-spacing: -0.3px; }
.addon-modal .modal-body { padding: 16px; }
.addon-modal form { display: flex; flex-direction: column; gap: 12px; }
.addon-modal input {
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-3);
  color: var(--text); font-size: 14px;
}
.addon-modal input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px rgba(108,92,231,0.15); }
.addon-modal .url {
  background: var(--bg-3); padding: 2px 6px;
  border-radius: 4px; font-size: 12px; color: var(--accent);
}

/* ── RESPONSIVE ─────────────────────────────── */
@media (max-width: 820px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 200;
    transform: translateX(-100%); transition: transform 0.25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .main { width: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .modal { flex-direction: column; }
  .modal-side { width: 100%; }
  .modal-side img { aspect-ratio: 16/9; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .search-wrap { order: 2; flex-basis: 100%; }
  .topbar-spacer { display: none; }
  .cat-header { padding: 10px 12px; }
  .content { padding: 12px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
}
