/* ═══ CSS Variables ════════════════════════════════════════════════════════ */
:root {
  --bg-body:         #0d0d14;
  --bg-surface:      #13131e;
  --bg-card:         #191926;
  --bg-card-hover:   #1e1e2e;
  --bg-input:        #1a1a28;
  --bg-form:         #111119;

  --border:          #252538;
  --border-focus:    #7c3aed;

  --text-primary:    #e8e8f4;
  --text-secondary:  #9090b0;
  --text-muted:      #55556a;

  --accent:          #7c3aed;
  --accent-hover:    #6d28d9;
  --accent-light:    #a78bfa;

  --danger:          #ef4444;
  --danger-hover:    #dc2626;
  --danger-bg:       rgba(239, 68, 68, 0.12);

  --success:         #22c55e;
  --success-bg:      rgba(34, 197, 94, 0.12);
  --warning:         #f59e0b;

  --status-watching: #3b82f6;
  --status-completed:#22c55e;
  --status-planned:  #f59e0b;
  --status-dropped:  #ef4444;

  --radius:          14px;
  --radius-sm:       8px;
  --radius-xs:       5px;

  --shadow-card:     0 2px 20px rgba(0, 0, 0, 0.5);
  --shadow-form:     0 8px 40px rgba(0, 0, 0, 0.6);

  --transition:      0.2s ease;
  --font:            -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ═══ Reset & Base ═════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background-color: var(--bg-body);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

img { display: block; max-width: 100%; }

button { cursor: pointer; font-family: inherit; }

input, select, textarea {
  font-family: inherit;
  font-size: 0.95rem;
}

/* ═══ Utility ══════════════════════════════════════════════════════════════ */
.hidden { display: none !important; }

/* ═══ Buttons ══════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.55rem 1.2rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  transition: background var(--transition), transform var(--transition), opacity var(--transition);
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-input);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-sm {
  padding: 0.35rem 0.8rem;
  font-size: 0.82rem;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
}
.btn-icon:hover { color: var(--text-primary); background: var(--bg-input); }

.btn-edit {
  background: rgba(124, 58, 237, 0.15);
  color: var(--accent-light);
  border: 1px solid rgba(124, 58, 237, 0.3);
}
.btn-edit:hover {
  background: rgba(124, 58, 237, 0.25);
}

.btn-delete {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-delete:hover {
  background: rgba(239, 68, 68, 0.22);
}

/* ═══ Header ═══════════════════════════════════════════════════════════════ */
.header {
  background: linear-gradient(135deg, #1a0a3e 0%, #0d0d14 60%);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.header-title {
  font-size: clamp(1.4rem, 4vw, 1.9rem);
  font-weight: 800;
  background: linear-gradient(90deg, #a78bfa, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.header-subtitle {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ═══ Form Panel ════════════════════════════════════════════════════════════ */
.form-panel {
  background: var(--bg-form);
  border-bottom: 1px solid var(--border);
  padding: 1.5rem;
  animation: slideDown 0.22s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.form-container {
  max-width: 900px;
  margin: 0 auto;
}

.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
}

.form-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

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

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group--full {
  grid-column: 1 / -1;
}

label {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.3px;
}

.required { color: var(--accent-light); }
.label-hint { font-weight: 400; color: var(--text-muted); }

input[type="text"],
input[type="url"],
input[type="number"],
input[type="search"],
select,
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.55rem 0.75rem;
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

input::placeholder,
textarea::placeholder { color: var(--text-muted); }

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.18);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239090b0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 2rem;
}

textarea { resize: vertical; min-height: 80px; }

.form-error {
  background: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-top: 1rem;
  color: #fca5a5;
  font-size: 0.88rem;
  line-height: 1.7;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
  flex-wrap: wrap;
}

/* ═══ Controls ══════════════════════════════════════════════════════════════ */
.controls {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 81px;
  z-index: 90;
}

.controls-inner {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.search-wrapper {
  position: relative;
  flex: 1 1 220px;
  min-width: 180px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 1.1rem;
  pointer-events: none;
}

.search-input {
  padding-left: 2rem;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  flex: 2 1 400px;
}

.control-select,
.control-input {
  flex: 1 1 150px;
  min-width: 130px;
}

/* ═══ Main / Grid ═══════════════════════════════════════════════════════════ */
.main {
  flex: 1;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

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

/* ═══ Cards ═════════════════════════════════════════════════════════════════ */
.series-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  box-shadow: var(--shadow-card);
}

.series-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.6);
  border-color: rgba(124, 58, 237, 0.35);
}

/* Image */
.card-image-wrapper {
  position: relative;
  aspect-ratio: 2 / 3;
  overflow: hidden;
  background: var(--bg-surface);
  flex-shrink: 0;
}

.card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s ease;
}

.series-card:hover .card-image { transform: scale(1.04); }

.card-image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 2.5rem;
  background: linear-gradient(135deg, #13131e, #191926);
}

.card-image-placeholder small {
  font-size: 0.75rem;
  letter-spacing: 0.5px;
}

/* Badge */
.card-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: #fff;
}

.status-watching  { background: var(--status-watching); }
.status-completed { background: var(--status-completed); }
.status-planned   { background: var(--status-planned); color: #111; }
.status-dropped   { background: var(--status-dropped); }

/* Card Body */
.card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0.9rem;
  flex: 1;
}

.card-title {
  font-size: 0.97rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-year {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.card-genre {
  font-size: 0.78rem;
  color: var(--accent-light);
  font-weight: 600;
  letter-spacing: 0.3px;
}

.card-rating {
  font-size: 0.85rem;
  color: var(--warning);
  font-weight: 600;
}

.card-description {
  font-size: 0.8rem;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.card-actions .btn { flex: 1; justify-content: center; }

/* ═══ Status / Empty / Loading ══════════════════════════════════════════════ */
.status-message {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

.status-message.error {
  color: #fca5a5;
  background: var(--danger-bg);
  border: 1px solid rgba(239, 68, 68, 0.25);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.empty-state { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.empty-icon  { font-size: 3.5rem; }
.empty-title { font-size: 1.2rem; font-weight: 700; color: var(--text-primary); }
.empty-subtitle { font-size: 0.9rem; color: var(--text-muted); }

/* Spinner */
.spinner-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ Pagination ════════════════════════════════════════════════════════════ */
.pagination {
  margin-top: 2.5rem;
  display: flex;
  justify-content: center;
}

.pagination-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
}

.pagination-info {
  font-size: 0.88rem;
  color: var(--text-secondary);
  min-width: 110px;
  text-align: center;
}

.btn-pagination {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-pagination:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-light); }
.btn-pagination:disabled { opacity: 0.35; cursor: not-allowed; }

/* ═══ Toast Notifications ═══════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1.1rem;
  font-size: 0.88rem;
  color: var(--text-primary);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateX(20px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: 320px;
  pointer-events: auto;
}

.toast.toast-visible { opacity: 1; transform: translateX(0); }

.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-error   { border-left: 4px solid var(--danger); }

/* ═══ Footer ════════════════════════════════════════════════════════════════ */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
  margin-top: auto;
}

/* ═══ Responsive ════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .header-inner { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .controls { top: 0; position: relative; }
  .controls-inner { flex-direction: column; }
  .search-wrapper, .filter-row { width: 100%; flex: unset; }
  .filter-row { flex-direction: column; }
  .control-select, .control-input { width: 100%; flex: unset; }
  .series-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
  .main { padding: 1.25rem 1rem; }
}

@media (max-width: 480px) {
  .series-grid { grid-template-columns: 1fr 1fr; }
  .card-body { padding: 0.7rem; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 360px) {
  .series-grid { grid-template-columns: 1fr; }
}
