:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #242830;
  --border: #2d3139;
  --text: #e8eaed;
  --text-dim: #9aa0a6;
  --accent: #f5c518; /* IMDb yellow */
  --accent-dim: #c99e10;
  --danger: #ef5350;
  --success: #4caf50;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 20px;
}

header { text-align: center; margin-bottom: 32px; }
header h1 { font-size: 2.5rem; margin-bottom: 4px; }
.subtitle { color: var(--text-dim); font-size: 0.95rem; }

/* Search */
.search-box { position: relative; max-width: 600px; margin: 0 auto 24px; }
#search-input {
  width: 100%;
  padding: 14px 18px;
  font-size: 1rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  transition: border 0.15s;
}
#search-input:focus { border-color: var(--accent); }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 400px;
  overflow-y: auto;
  z-index: 10;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.search-results.hidden { display: none; }

.search-result {
  display: flex;
  gap: 12px;
  padding: 10px 12px;
  cursor: pointer;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.search-result:last-child { border-bottom: none; }
.search-result:hover { background: var(--surface-2); }
.search-result img {
  width: 40px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface-2);
  flex-shrink: 0;
}
.search-result .info { flex: 1; min-width: 0; }
.search-result .title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-result .year { color: var(--text-dim); font-size: 0.85rem; }
.search-result.loading, .search-result.empty {
  cursor: default;
  color: var(--text-dim);
  justify-content: center;
  padding: 14px;
}

/* Filters */
.filters {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.filter-btn {
  background: var(--surface);
  color: var(--text-dim);
  border: 1px solid var(--border);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn:hover { color: var(--text); }
.filter-btn.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
.count { margin-left: auto; color: var(--text-dim); font-size: 0.9rem; }

/* Movie grid */
.movies-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.movie-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: transform 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
}
.movie-card:hover { transform: translateY(-3px); border-color: var(--accent-dim); }

.movie-card.watched { opacity: 0.6; }
.movie-card.watched .poster::after {
  content: "✓ Watched";
  position: absolute;
  top: 10px;
  right: 10px;
  background: var(--success);
  color: #fff;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}

.poster {
  position: relative;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.poster img { width: 100%; height: 100%; object-fit: cover; display: block; }
.poster .no-poster { color: var(--text-dim); font-size: 0.85rem; }

.movie-info { padding: 12px; flex: 1; display: flex; flex-direction: column; }
.movie-title { font-size: 1rem; font-weight: 600; margin-bottom: 4px; line-height: 1.3; }
.movie-meta { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 4px; }
.movie-rating { color: var(--accent); font-size: 0.85rem; margin-bottom: 8px; }
.movie-director { color: var(--text-dim); font-size: 0.8rem; margin-bottom: 12px; }

.movie-actions {
  margin-top: auto;
  display: flex;
  gap: 6px;
}
.action-btn {
  flex: 1;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
}
.action-btn:hover { background: var(--border); }
.action-btn.delete:hover { background: var(--danger); border-color: var(--danger); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-state.hidden { display: none; }
.empty-state p { margin-bottom: 4px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  padding: 12px 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 100;
}
.toast.show { opacity: 1; }

@media (max-width: 600px) {
  header h1 { font-size: 2rem; }
  .movies-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .movie-info { padding: 10px; }
}

/* --- View toggle --- */
.view-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px;
  margin-left: 4px;
}
.view-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 5px 10px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.view-btn:hover { color: var(--text); }
.view-btn.active {
  background: var(--accent);
  color: #000;
}

/* --- List view (table) --- */
.movies-list { width: 100%; }
.movies-list.hidden, .movies-grid.hidden { display: none; }

.movies-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.movies-table thead {
  background: var(--surface-2);
}

.movies-table th {
  text-align: left;
  padding: 12px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.movies-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}
.movies-table th.sortable:hover { color: var(--text); }

.sort-arrow {
  display: inline-block;
  margin-left: 4px;
  opacity: 0.4;
  font-size: 0.85em;
}
.movies-table th.sort-asc .sort-arrow::after { content: "▲"; opacity: 1; }
.movies-table th.sort-desc .sort-arrow::after { content: "▼"; opacity: 1; }
.movies-table th.sort-asc, .movies-table th.sort-desc { color: var(--accent); }

.movies-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  vertical-align: middle;
}
.movies-table tbody tr:last-child td { border-bottom: none; }
.movies-table tbody tr:hover { background: var(--surface-2); }
.movies-table tbody tr.watched { opacity: 0.55; }

.col-poster { width: 50px; padding-right: 0 !important; }
.movies-table td.col-poster { padding-right: 0; }
.movies-table .poster-thumb {
  width: 40px;
  height: 60px;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface-2);
  display: block;
}
.movies-table .poster-thumb-empty {
  width: 40px;
  height: 60px;
  background: var(--surface-2);
  border-radius: 4px;
}

.movies-table .title-cell {
  font-weight: 500;
  color: var(--text);
}
.movies-table .rating-cell { color: var(--accent); white-space: nowrap; }
.movies-table .status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.movies-table .status-pill.watched {
  background: rgba(76, 175, 80, 0.15);
  color: var(--success);
  border-color: rgba(76, 175, 80, 0.3);
}
.movies-table .row-actions {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
}
.movies-table .row-actions .action-btn {
  padding: 4px 10px;
  font-size: 0.78rem;
}

@media (max-width: 700px) {
  .col-hide-sm { display: none; }
  .movies-table th, .movies-table td { padding: 8px 10px; font-size: 0.85rem; }
}

/* --- Title links (grid + list) --- */
a.movie-title {
  display: block;
  color: var(--text);
  text-decoration: none;
  transition: color 0.15s;
}
a.movie-title:hover { color: var(--accent); }

.movies-table a.movie-link {
  color: var(--text);
  text-decoration: none;
  transition: color 0.15s;
}
.movies-table a.movie-link:hover { color: var(--accent); text-decoration: underline; }
