:root {
  --bg: var(--color-bg);
  --bg-alt: var(--color-surface);
  --text: var(--color-text);
  --muted: var(--color-text-muted);
  --card: var(--color-surface);
  --border: var(--color-border);
  --primary: var(--color-primary);
  --primary-dark: var(--color-primary-strong);
  --ghost: var(--color-ghost);
  --shadow: var(--shadow-md);
  font-family: var(--font-sans);
  color: var(--color-text);
  background-color: var(--color-bg);
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(160% 120% at 12% 8%, #e2eaff, #f5f7fb 42%, #f5f7fb);
}

a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
}

a:hover {
  text-decoration: underline;
}

.page {
  background: transparent;
}

.admin-page {
  background: linear-gradient(120deg, #f8faff 0%, #eef3ff 50%, #f5f7fb 100%);
}

.hero {
  background: linear-gradient(160deg, #ffffff 0%, #f0f4ff 45%, #eef3ff 100%);
  color: var(--text);
  padding: 0.5rem 0 2rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.04);
}

.hero.minimal {
  padding-bottom: 1rem;
}

.nav-bar {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(15, 23, 42, 0.05);
}

.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  width: min(1100px, 92vw);
  margin: 0 auto;
  padding: 0.6rem 0.25rem;
}

.mini-nav {
  width: min(1100px, 92vw);
  margin: 0 auto;
  padding: 0.75rem 0.25rem 0;
}

.nav-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.initial-hidden {
  visibility: hidden;
}

.initial-hidden.ready {
  visibility: visible;
}

.nav-actions.profile-visible .primary,
.nav-actions.profile-visible .ghost {
  display: none;
}

/* Oculta CTA cuando hay sesión (nuevas clases btn) */
.nav-actions.profile-visible .btn-primary,
.nav-actions.profile-visible .btn-ghost {
  display: none;
}

.nav-links {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  font-weight: 600;
}

.nav-links a {
  color: var(--text);
  padding: 0.35rem 0.55rem;
  border-radius: 10px;
  text-decoration: none;
}

.nav-links a[aria-current="page"] {
  background: #eef2f7;
}

.logo {
  font-weight: 800;
  letter-spacing: 0.02em;
  font-size: 1.05rem;
}

.brand {
  text-decoration: none;
  color: var(--text);
}

.prominent {
  font-size: 1.2rem;
}

.container {
  width: min(1100px, 92vw);
  margin: 0 auto;
  padding: 2.5rem 0 3rem;
}

.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #0f172a, #1e293b);
  color: #e2e8f0;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  box-shadow: 8px 0 32px rgba(0, 0, 0, 0.08);
}

.brand-block {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.logo-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
}

.brand-title {
  font-weight: 800;
  font-size: 1.05rem;
}

.brand-sub {
  color: #cbd5e1;
  font-size: 0.9rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar-nav a {
  color: #e2e8f0;
  text-decoration: none;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  font-weight: 600;
}

.sidebar-nav a[aria-current="page"],
.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sidebar-footer {
  margin-top: auto;
}

.main {
  padding: 2rem;
  width: 100%;
  box-sizing: border-box;
}

.main > section {
  margin-bottom: 1.5rem;
}

.flow > * + * {
  margin-top: 2rem;
}

.hero-content {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.hero-content.container {
  padding-bottom: 1rem;
}

.hero-content.container.compact {
  padding-bottom: 0.5rem;
}

.eyebrow {
  letter-spacing: 0.15em;
  text-transform: uppercase;
  font-size: 0.8rem;
  opacity: 0.85;
  color: #1d4ed8;
  font-weight: 700;
}

.lead {
  font-size: 1.12rem;
  max-width: 680px;
  line-height: 1.55;
  color: #1f2937;
}

.grid {
  display: grid;
  gap: 1.5rem;
}

.grid.cols-3 {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

@media (min-width: 860px) {
  .upload-section {
    grid-template-columns: 2fr 1fr;
  }
  .access-section {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .results-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.85rem;
  box-shadow: var(--shadow);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-weight: 600;
}

.field input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f9fafb;
  color: var(--text);
}

.field input:focus {
  outline: 2px solid var(--primary);
  border-color: var(--primary);
}

.field input[type="file"] {
  padding: 0.4rem;
  background: transparent;
}

button {
  padding: 0.9rem 1.1rem;
  border: none;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  color: #ffffff;
  background: linear-gradient(140deg, var(--primary), var(--primary-dark));
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 10px 22px rgba(29, 78, 216, 0.32);
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  box-shadow: none;
}

button:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 26px rgba(37, 99, 235, 0.42);
}

.ghost {
  background: var(--ghost);
  color: var(--text);
  border-radius: 12px;
  padding: 0.55rem 1rem;
  border: 1px solid var(--border);
  box-shadow: none;
}

.primary {
  background: linear-gradient(140deg, #1d4ed8, #0f3cb5);
  color: #fff;
  padding: 0.65rem 1.2rem;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 700;
  display: inline-block;
  box-shadow: 0 10px 24px rgba(29, 78, 216, 0.18);
}

.muted {
  color: var(--muted);
  font-size: 0.95rem;
}

.small {
  font-size: 0.85rem;
}

.warning {
  color: #b45309;
  font-weight: 600;
}

.instructions-card ol {
  padding-left: 1.2rem;
  line-height: 1.4;
}

.file-details {
  padding: 0.75rem;
  border-radius: 12px;
  background: #f3f4f6;
  border: 1px dashed var(--border);
}

.file-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.queue-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.queue-item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  background: #f8fafc;
}

.queue-item[data-status="processing"] {
  border-color: var(--primary);
  background: rgba(29, 78, 216, 0.08);
}

.queue-item[data-status="error"] {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.queue-item[data-status="done"] {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.12);
}

.queue-item-main {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.queue-item-status {
  font-weight: 600;
  color: var(--text);
}

.status-panel {
  text-align: center;
}

.status {
  min-height: 1.5rem;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  background: #eef2f7;
  margin: 0 auto;
  width: fit-content;
}

.status[data-variant="loading"] {
  background: rgba(37, 99, 235, 0.12);
}

.status[data-variant="error"] {
  background: rgba(239, 68, 68, 0.14);
}

.status[data-variant="success"] {
  background: rgba(16, 185, 129, 0.16);
}

.result-card img {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  margin-top: 1rem;
}

.results-section {
  display: grid;
  gap: 1rem;
}

.results-list {
  display: grid;
  gap: 1.25rem;
}

.result-item {
  display: grid;
  gap: 0.85rem;
}

.result-item-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.result-item-title {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.result-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.result-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.result-item-body {
  display: grid;
  gap: 1rem;
}

.result-item-body img {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.result-item-message {
  margin: 0;
}

.result-item-error {
  color: #b91c1c;
  font-weight: 600;
}

.card-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}
.card-header.split {
  flex-wrap: wrap;
}
.command-card {
  background: linear-gradient(135deg, #ffffff 0%, #f5f7ff 100%);
}
.compact-grid {
  margin-top: 1rem;
}

.hidden {
  display: none;
}

.table-wrapper {
  max-height: 420px;
  overflow: auto;
  margin-top: 1rem;
}

.table-wrapper.small {
  max-height: 260px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

thead {
  position: sticky;
  top: 0;
  background: #f9fafb;
}

th,
td {
  text-align: left;
  padding: 0.45rem 0.35rem;
  border-bottom: 1px solid var(--border);
}

#no-metrics {
  text-align: center;
  margin-top: 0.5rem;
}

.actions {
  display: flex;
  gap: 0.5rem;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  background: linear-gradient(120deg, #f8fbff, #f0f4ff);
  flex-wrap: wrap;
  gap: 1rem;
}

.topbar-actions {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
}
.topbar > div:first-child {
  flex: 1;
}
.filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  align-items: end;
  max-width: 720px;
}

.stats-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.5rem;
}

.stat-card h2 {
  margin: 0.35rem 0 0;
}
.stat-card {
  background: linear-gradient(180deg, #ffffff, #f7f9ff);
}

.admin-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  background: radial-gradient(90% 60% at 20% 20%, rgba(37, 99, 235, 0.08), transparent), var(--bg);
}

.auth-card {
  width: min(480px, 100%);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.auth-card h1 {
  margin-top: 0;
}

.status-text {
  min-height: 1.2rem;
}

.password-helper {
  margin-top: 0.35rem;
}

.password-checklist {
  list-style: none;
  padding: 0;
  margin: 0.35rem 0 0;
  display: grid;
  gap: 0.35rem;
}

.password-checklist li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.55rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--ghost);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.password-checklist li::before {
  content: '•';
  font-size: 1rem;
  line-height: 1;
}

.password-checklist li[data-valid='true'] {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.35);
  color: #065f46;
}

.password-checklist li[data-valid='true']::before {
  content: '✓';
}

.password-checklist li[data-valid='false'] {
  background: rgba(239, 68, 68, 0.08);
  border-color: rgba(239, 68, 68, 0.35);
  color: #991b1b;
}

.highlight {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.hero-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.nav a {
  color: var(--text);
}

.nav .ghost {
  background: #f8fafc;
  border-color: var(--border);
  color: var(--text);
}

.nav .primary {
  background: linear-gradient(140deg, #1d4ed8, #0f3cb5);
  box-shadow: 0 10px 26px rgba(29, 78, 216, 0.22);
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(140deg, #1d4ed8, #0f3cb5);
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
  box-shadow: 0 10px 22px rgba(29, 78, 216, 0.2);
  padding: 0.35rem;
}

.avatar svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.6;
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0;
  margin: 0;
  list-style: none;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #eef2f7;
  color: var(--text);
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
}

.pill.warn {
  background: rgba(234, 179, 8, 0.16);
  border-color: rgba(234, 179, 8, 0.4);
}

.pill.success {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.4);
}

.pill.muted {
  background: #f8fafc;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem;
}

.setting-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-alt);
}

.setting-card input {
  min-width: 120px;
}

.pill.tiny,
.actions .tiny,
button.tiny {
  padding: 0.25rem 0.5rem;
  font-size: 0.85rem;
}

body.dark {
  --color-bg: #0f172a;
  --color-surface: #111827;
  --color-surface-alt: #0f172a;
  --color-border: #1f2937;
  --color-text: #e5e7eb;
  --color-text-muted: #9ca3af;
  --color-ghost: #1f2937;
  --bg: #0f172a;
  --bg-alt: #111827;
  --card: #111827;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --border: #1f2937;
  background: radial-gradient(120% 80% at 12% 8%, #0b1220, #0f172a 42%, #0f172a);
}

body.dark .card {
  box-shadow: none;
}

body.dark table thead {
  background: #111827;
}

body.dark .pill {
  background: #1f2937;
  border-color: #273044;
}

body.dark .pill.warn {
  background: rgba(234, 179, 8, 0.2);
}

body.dark .pill.success {
  background: rgba(16, 185, 129, 0.2);
}

.charts-grid {
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

.charts-grid canvas {
  width: 100%;
  height: 220px;
}

.chart-card {
  padding: 1.25rem;
}

.chart-card .card-header {
  margin-bottom: 0.35rem;
}

body .stat-card h2 {
  font-size: 1.6rem;
}

.stats-grid .card {
  height: 100%;
}

.export-chip-row {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
}

.export-footer {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .sidebar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }
  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .main {
    padding: 1.25rem;
  }
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }
  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }
}

.avatar-menu {
  position: relative;
}

.avatar-dropdown {
  position: absolute;
  top: 48px;
  right: 0;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 18px 36px rgba(15, 26, 44, 0.12);
  padding: 0.5rem 0;
  min-width: 160px;
  display: none;
  z-index: 10;
}

.avatar-dropdown a,
.avatar-dropdown button {
  width: 100%;
  display: block;
  padding: 0.6rem 1rem;
  background: transparent;
  border: none;
  text-align: left;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}

.avatar-dropdown a:hover,
.avatar-dropdown button:hover {
  background: #f1f5f9;
}

.avatar-dropdown.open {
  display: block;
}
