:root {
  --bg: #080a0d;
  --panel: #11141a;
  --panel-alt: #171c25;
  --border: #222834;
  --border-strong: #323a4a;
  --text: #f1f5f9;
  --muted: #8a94a6;
  --accent: #e11d2e;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #38bdf8;
  --radius: 0px;
}

* {
  box-sizing: border-box;
  border-radius: 0 !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
code { background: rgba(255,255,255,0.08); padding: 2px 6px; border-radius: 5px; font-size: 12px; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.login-brand h1 { margin: 0; font-size: 20px; }
.login-brand p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.brand-icon {
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
}

.back-site-link {
  text-align: center;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
}

/* Layout */
.admin-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #0e121b;
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.sidebar-sub {
  font-size: 12px;
  color: var(--muted);
}

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

.nav-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: #cbd5e1;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-item.active {
  background: rgba(225, 29, 46, 0.14);
  border-left: 3px solid var(--accent);
  color: #fff;
  font-weight: 700;
}

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

.admin-main {
  padding: 26px 30px 60px;
  max-width: 1280px;
  width: 100%;
}

.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-head h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
}

/* Panels & KPI */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.panel h3 {
  margin: 0 0 14px;
  font-size: 16px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.kpi-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 28px;
  font-weight: 800;
  margin-top: 6px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.two-col-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
  gap: 18px;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.field, .field-full {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-full {
  grid-column: 1 / -1;
}

label {
  font-size: 13px;
  font-weight: 600;
  color: #d1d5db;
}

input[type="text"],
input[type="password"],
input[type="url"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--border-strong);
  background: #0d111a;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  font-weight: 500;
}

.checkbox-label input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.mode-box {
  padding: 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px dashed var(--border-strong);
}

.toolbar {
  margin-bottom: 14px;
  max-width: 340px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: 9px;
  border: none;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s, background 0.15s;
}

.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 7px; }

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

.btn-ghost {
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.12); }

.btn-danger-soft {
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.25);
}
.btn-danger-soft:hover { background: rgba(239, 68, 68, 0.25); }

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-weight: 600;
}

.movie-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 220px;
}

.movie-cell img {
  width: 44px;
  height: 64px;
  object-fit: cover;
  background: #080a0f;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.badge-purple { background: rgba(99, 102, 241, 0.22); color: #a5b4fc; }

/* Quick Add Movie/Series Panel */
.quick-add-panel {
  margin-bottom: 18px;
  border-left: 3px solid var(--accent);
}

.quick-add-grid {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.poster-dropzone {
  position: relative;
  width: 150px;
  aspect-ratio: 2 / 3;
  background: #0b0e14;
  border: 2px dashed var(--border-strong);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s;
}

.poster-dropzone:hover,
.poster-dropzone.dragover {
  border-color: var(--accent);
  background: rgba(225, 29, 46, 0.08);
}

.poster-dropzone img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.poster-dropzone-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.poster-dropzone-icon {
  font-size: 26px;
  line-height: 1;
}

.poster-dropzone-change {
  position: absolute;
  inset: auto 0 0 0;
  padding: 6px 8px;
  background: rgba(8, 10, 13, 0.88);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.type-toggle {
  display: inline-flex;
  border: 1px solid var(--border-strong);
  background: #0b0e14;
}

.type-toggle-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.type-toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

.toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar-row input[type="search"] {
  max-width: 320px;
}

.filter-pills {
  display: flex;
  gap: 6px;
}

.filter-pill {
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

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

.extra-details {
  grid-column: 1 / -1;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  padding: 10px 14px;
}

.extra-details summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  user-select: none;
}

.extra-details[open] summary {
  color: var(--text);
  margin-bottom: 14px;
}

/* Episodes Manager inside Modal */
.episodes-list-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
  max-height: 280px;
  overflow-y: auto;
}

.episode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: #0d111a;
  border: 1px solid var(--border);
}

.episode-row-info {
  min-width: 0;
}

.episode-row-title {
  font-weight: 700;
  font-size: 13px;
}

.episode-row-sub {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 380px;
}

.episode-add-box {
  padding: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-strong);
}

@media (max-width: 680px) {
  .quick-add-grid {
    grid-template-columns: 1fr;
  }
  .poster-dropzone {
    width: 130px;
  }
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.badge-green { background: rgba(34, 197, 94, 0.16); color: #86efac; }
.badge-gray { background: rgba(156, 163, 175, 0.16); color: #d1d5db; }
.badge-amber { background: rgba(245, 158, 11, 0.16); color: #fcd34d; }
.badge-blue { background: rgba(56, 189, 248, 0.16); color: #7dd3fc; }

.actions-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

/* Upload controls */
.upload-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

.upload-inline input[type="text"],
.upload-inline input[type="url"] {
  flex: 1;
}

.upload-progress {
  margin-top: 6px;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.upload-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #f59e0b, #22c55e);
  transition: width 0.15s;
}

.preview-img {
  max-height: 110px;
  border-radius: 8px;
  margin-top: 8px;
  border: 1px solid var(--border);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-dialog {
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-head h3 { margin: 0; font-size: 17px; }

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.alert-error {
  padding: 10px 12px;
  border-radius: 9px;
  background: rgba(239, 68, 68, 0.16);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 13px;
}

.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 200;
  background: #1e293b;
  border: 1px solid var(--border-strong);
  color: #fff;
  padding: 11px 18px;
  border-radius: 10px;
  font-weight: 600;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

@media (max-width: 860px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
  }
  .admin-main {
    padding: 18px 14px 48px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .two-col-grid {
    grid-template-columns: 1fr;
  }
}
