/* ============ CSS VARIABLES & RESET ============ */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --bg-card: #1c2128;
  --bg-hover: #262c36;
  --border: #30363d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;
  --danger: #f85149;
  --danger-hover: #ff6b63;
  --success: #3fb950;
  --warning: #d29922;
  --tag-bg: #1f3a5f;
  --tag-text: #58a6ff;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
}

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

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

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ============ SCROLLBAR ============ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--text-muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* ============ INPUTS ============ */
.input, .select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.input:focus, .select:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-muted); }

/* ============ LOGIN PAGE ============ */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-card h1 {
  font-size: 24px;
  margin-bottom: 8px;
  text-align: center;
}

.login-card .subtitle {
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 32px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group .input {
  width: 100%;
}

.login-card .btn-primary {
  width: 100%;
  padding: 10px;
  font-size: 15px;
  margin-top: 8px;
}

.error-msg {
  background: rgba(248, 81, 73, 0.1);
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.error-msg.show { display: block; }

/* ============ TOP BAR ============ */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topbar-brand {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-right: 16px;
  white-space: nowrap;
}

.topbar-search {
  flex: 1;
  max-width: 400px;
}

.topbar-search .input { width: 100%; }

.topbar-filters {
  display: flex;
  gap: 8px;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  margin-left: auto;
}

/* ============ NAV LINKS ============ */
.nav-links {
  display: flex;
  gap: 4px;
}

.nav-links a {
  padding: 6px 12px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.nav-links a:hover, .nav-links a.active {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ============ MAIN CONTENT ============ */
.main-content {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
}

/* ============ SECTION HEADERS ============ */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.section-header h2 {
  font-size: 20px;
  font-weight: 600;
}

/* ============ RECOMMENDATIONS ROW ============ */
.rec-row {
  margin-bottom: 32px;
}

.rec-scroll {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 8px;
  scroll-snap-type: x mandatory;
}

.rec-scroll .card {
  min-width: 220px;
  max-width: 220px;
  scroll-snap-align: start;
}

/* ============ MEDIA GRID ============ */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* ============ CARD ============ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: var(--shadow);
}

.card-thumb {
  aspect-ratio: 16 / 9;
  background: var(--bg-tertiary);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.card-placeholder {
  font-size: 32px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.card-body {
  padding: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-category {
  font-size: 11px;
  color: var(--warning);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  background: var(--tag-bg);
  color: var(--tag-text);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}

.card-actions {
  display: flex;
  gap: 4px;
  padding: 0 12px 12px;
}

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

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

.modal-header h3 { font-size: 16px; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius);
  line-height: 1;
}

.modal-close:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.modal-body { padding: 20px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

/* ============ PLAYBACK MODAL ============ */
.playback-modal .modal {
  max-width: 90%;
  width: 90%;
}

.playback-video {
  width: 100%;
  max-height: 80vh;
  background: #000;
  display: block;
}

.playback-audio-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  background: var(--bg-tertiary);
}

.playback-audio-wrap audio {
  width: 100%;
  max-width: 500px;
}

.playback-iframe {
  width: 100%;
  height: 75vh;
  border: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.playback-fallback {
  padding: 24px;
  text-align: center;
  color: var(--text-secondary);
}

.playback-fallback a {
  display: inline-block;
  margin-top: 12px;
}

/* ============ TAG EDITOR PAGE ============ */
.two-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.column-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.column-panel h2 {
  font-size: 18px;
  margin-bottom: 16px;
}

.add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.add-form .input { flex: 1; }

.item-list { list-style: none; }

.item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.item-row:last-child { border-bottom: none; }

.item-name {
  flex: 1;
  font-size: 14px;
}

.item-name input {
  background: var(--bg-tertiary);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: var(--radius);
  font-size: 14px;
  width: 100%;
}

.item-count {
  color: var(--text-muted);
  font-size: 12px;
}

/* ============ HISTORY PAGE ============ */
.history-list { list-style: none; }

.history-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  transition: background 0.15s;
}

.history-item:hover { background: var(--bg-hover); }

.history-thumb {
  width: 120px;
  min-width: 120px;
  aspect-ratio: 16 / 9;
  background: var(--bg-tertiary);
  background-size: cover;
  background-position: center;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
}

.history-info { flex: 1; }

.history-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.history-time {
  font-size: 13px;
  color: var(--text-muted);
}

.history-actions { display: flex; gap: 8px; }

/* ============ EMPTY STATE ============ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state h3 {
  font-size: 18px;
  margin-bottom: 8px;
  color: var(--text-primary);
}

/* ============ LOAD MORE ============ */
.load-more-container {
  text-align: center;
  padding: 24px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    padding: 12px 16px;
    gap: 8px;
  }
  .topbar-search { max-width: 100%; order: 10; width: 100%; }
  .topbar-filters { order: 11; width: 100%; }
  .topbar-filters .select { flex: 1; }
  .main-content { padding: 16px; }
  .two-columns { grid-template-columns: 1fr; }
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .history-item { flex-direction: column; align-items: flex-start; }
  .history-thumb { width: 100%; }
  .playback-modal .modal { max-width: 100%; width: 100%; border-radius: 0; }
  .playback-iframe { height: 60vh; }
}

@media (max-width: 480px) {
  .media-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .nav-links a { padding: 6px 8px; font-size: 12px; }
}
