/* ── Reset básico ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ── Paleta de variables (tema claro por defecto) ────────────────── */
:root {
  --bg: #f5f6f8;
  --bg-elevated: #ffffff;
  --border: #e0e2e7;
  --text: #1b1d22;
  --text-muted: #6b7280;
  --accent: #3a6ff7;
  --accent-hover: #2f5cd6;
  --danger: #d1453a;
  --success: #2a9d5c;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.06), 0 4px 12px rgba(20, 20, 30, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --bg-elevated: #1d2025;
    --border: #2a2d34;
    --text: #eceef1;
    --text-muted: #9aa0aa;
    --accent: #5b8cff;
    --accent-hover: #7ba0ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --bg-elevated: #1d2025;
  --border: #2a2d34;
  --text: #eceef1;
  --text-muted: #9aa0aa;
  --accent: #5b8cff;
  --accent-hover: #7ba0ff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
}

:root[data-theme="light"] {
  --bg: #f5f6f8;
  --bg-elevated: #ffffff;
  --border: #e0e2e7;
  --text: #1b1d22;
  --text-muted: #6b7280;
  --accent: #3a6ff7;
  --accent-hover: #2f5cd6;
  --shadow: 0 1px 2px rgba(20, 20, 30, 0.06), 0 4px 12px rgba(20, 20, 30, 0.04);
}

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

/* ── Topbar ────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .logo { font-weight: 700; font-size: 1.25rem; color: var(--accent); }
.topbar nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topbar nav a { color: var(--text-muted); font-size: 0.9rem; }
.topbar nav a:hover { color: var(--text); }
#theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 2rem;
  height: 2rem;
  cursor: pointer;
}

/* ── Layout general ────────────────────────────────────────────── */
.page { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.layout { display: grid; grid-template-columns: 240px 1fr; gap: 1.5rem; }

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

/* ── Sidebar / búsqueda ───────────────────────────────────────── */
.sidebar {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  align-self: start;
}
.search-form { display: flex; flex-direction: column; gap: 0.5rem; position: relative; margin-bottom: 1.25rem; }
.search-form input[type="text"] {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.search-form button {
  padding: 0.5rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.search-form button:hover { background: var(--accent-hover); }

.tag-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.tag-list li { display: flex; justify-content: space-between; align-items: center; font-size: 0.85rem; }
.tag-list .count { color: var(--text-muted); font-size: 0.75rem; }
.tag-list .muted { color: var(--text-muted); }

/* ── Sugerencias de autocompletado ────────────────────────────── */
.suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  z-index: 20;
}
.suggestion-item { padding: 0.5rem 0.65rem; cursor: pointer; font-size: 0.85rem; }
.suggestion-item:hover, .suggestion-item.active { background: var(--bg); }

/* ── Grid de posts ────────────────────────────────────────────── */
.results-meta { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 0.75rem; }
.post-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
}
.post-thumb {
  position: relative;
  display: block;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  aspect-ratio: 1 / 1;
}
.post-thumb img { width: 100%; height: 100%; object-fit: cover; }
.post-thumb .score {
  position: absolute;
  bottom: 0.4rem;
  right: 0.4rem;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}
.badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.post-thumb .badge { position: absolute; top: 0.4rem; left: 0.4rem; }
.rating-safe { background: #2a9d5c; color: #fff; }
.rating-questionable { background: #e0a82e; color: #26210a; }
.rating-explicit { background: #d1453a; color: #fff; }

.empty { color: var(--text-muted); padding: 2rem 0; text-align: center; grid-column: 1 / -1; }

/* ── Paginación ───────────────────────────────────────────────── */
.pagination { display: flex; justify-content: space-between; margin-top: 1.5rem; }
.pagination a {
  padding: 0.5rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
}
.pagination a:hover { border-color: var(--accent); color: var(--accent); }

/* ── Vista de post ────────────────────────────────────────────── */
.post-view { display: grid; grid-template-columns: 1fr 300px; gap: 1.5rem; }
@media (max-width: 800px) { .post-view { grid-template-columns: 1fr; } }
.post-media {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.post-media img { border-radius: 6px; max-height: 80vh; }
.post-info {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  align-self: start;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.post-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; }
.post-actions button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}
.post-actions button:hover { background: var(--accent-hover); }

/* ── Formularios ──────────────────────────────────────────────── */
.upload-form, .auth-form, .settings-form {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: relative;
}
.upload-form label, .auth-form label, .settings-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.upload-form input, .upload-form select, .upload-form textarea,
.auth-form input,
.settings-form input, .settings-form select, .settings-form textarea {
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.checkbox-label { flex-direction: row !important; align-items: center; gap: 0.5rem !important; }
.upload-form button, .auth-form button, .settings-form button {
  padding: 0.6rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}
.upload-form button:hover, .auth-form button:hover, .settings-form button:hover { background: var(--accent-hover); }

.error { color: var(--danger); }
.success { color: var(--success); }
.hint { color: var(--text-muted); font-size: 0.85rem; max-width: 640px; }

/* ── Admin: pool de tags del importador ──────────────────────── */
.inline-form {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0 1.5rem;
}
.inline-form input {
  flex: 1;
  max-width: 320px;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
}
.inline-form button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.admin-table tr.muted { color: var(--text-muted); }
.admin-table tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: 0.5rem; }
.row-actions form { display: inline; }
.row-actions button {
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
}
.row-actions button.danger { color: var(--danger); border-color: var(--danger); }
.row-actions button:hover { border-color: var(--accent); }

/* ── Footer ───────────────────────────────────────────────────── */
.bottombar {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 1.5rem;
  border-top: 1px solid var(--border);
}
