* { box-sizing: border-box; }

:root {
  --color-primary: #5c1a35;      /* maroon del escudo */
  --color-primary-dark: #3f1225;
  --color-accent: #d4af37;       /* dorado del escudo */
  --color-header-bg: #12161f;    /* azul marino casi negro */
  --color-header-text: #d4af37;
  --color-bg: #f5f5f6;
  --color-surface: #ffffff;
  --color-text: #1a1a1a;
  --color-muted: #777;
  --color-border: #e5e5e5;
  --color-hover: #f5f7ff;
  --font-scale: 1;
}

body.dark-theme {
  --color-bg: #14171c;
  --color-surface: #1e2229;
  --color-text: #e9e9ea;
  --color-muted: #a2a8b2;
  --color-border: #2b3038;
  --color-hover: #262c36;
  --color-header-bg: #0a0c10;
}

body.high-contrast {
  --color-primary: #7a0f3b;
  --color-accent: #ffd700;
  --color-border: #000000;
}
body.high-contrast.dark-theme {
  --color-bg: #000000;
  --color-surface: #000000;
  --color-text: #ffffff;
  --color-border: #ffffff;
}

body {
  font-family: -apple-system, Segoe UI, Roboto, sans-serif;
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: calc(14px * var(--font-scale));
  transition: background 0.2s, color 0.2s;
}

.page {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

/* Encabezado */
.topbar {
  position: relative;
  background-color: var(--color-header-bg);
  background-image:
    linear-gradient(rgba(6, 10, 20, 0.94), rgba(6, 10, 20, 0.96)),
    url('banner.jpg');
  background-size: cover;
  background-position: center 30%;
  color: var(--color-header-text);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 20px 20px 18px;
  gap: 10px;
  border-bottom: 3px solid var(--color-accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}

.topbar-side { min-width: 0; }

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  justify-self: center;
  text-align: center;
  cursor: pointer;
}

.brand-logo {
  height: 56px;
  width: 56px;
  filter: drop-shadow(0 1px 4px rgba(0, 0, 0, 0.5));
}

.brand-text {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.brand-text h1 {
  font-size: 26px;
  margin: 0;
  color: var(--color-accent);
  font-family: Georgia, 'Times New Roman', serif;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

.brand-subtitle {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: #d8dce2;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-self: end;
}

@media (max-width: 640px) {
  .topbar { grid-template-columns: 1fr; justify-items: center; }
  .topbar-side { display: none; }
}

.icon-btn {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--color-accent);
  color: var(--color-header-text);
  width: 36px;
  height: 36px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.a11y-wrapper { position: relative; }

.a11y-modal-content { max-width: 420px; height: auto; max-height: 90vh; }
.a11y-modal-header { background: var(--color-header-bg); color: var(--color-accent); }
.a11y-modal-header button { background: rgba(255,255,255,0.1); color: var(--color-header-text); border: none; }
.a11y-modal-body { padding: 18px; }

.a11y-section-label {
  font-size: 11px;
  letter-spacing: 0.5px;
  color: var(--color-muted);
  font-weight: 600;
  margin-bottom: 8px;
}

.font-size-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 18px;
}

.font-size-btn {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 12px 0;
  margin: 0;
  cursor: pointer;
}

.font-size-btn.active {
  background: var(--color-header-bg);
  color: var(--color-accent);
  border-color: var(--color-header-bg);
}

.a11y-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--color-bg);
  border-radius: 10px;
  margin-bottom: 10px;
}

.a11y-toggle-row strong { font-size: 13px; display: block; }
.a11y-toggle-row p { font-size: 12px; color: var(--color-muted); margin: 2px 0 0; }

.a11y-reset-btn {
  width: 100%;
  margin-top: 6px;
  text-align: center;
}

body.reduce-motion,
body.reduce-motion * {
  transition: none !important;
  animation: none !important;
}

.switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--color-border);
  border-radius: 20px;
  transition: 0.2s;
}

.switch-slider::before {
  content: "";
  position: absolute;
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}

.switch input:checked + .switch-slider {
  background: var(--color-primary);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
}

/* Secciones */
section { margin-bottom: 20px; }

label {
  display: block;
  font-size: 13px;
  color: var(--color-muted);
  margin-bottom: 4px;
}

input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-size: 1em;
  background: var(--color-surface);
  color: var(--color-text);
}

button {
  padding: 10px 16px;
  border: none;
  border-radius: 8px;
  background: var(--color-primary);
  color: white;
  font-size: 0.95em;
  cursor: pointer;
  margin-top: 6px;
  margin-right: 6px;
}

button.secondary {
  background: var(--color-border);
  color: var(--color-text);
}

#search-section {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

#search-section input { flex: 1; min-width: 160px; }

#breadcrumb {
  font-size: 13px;
  color: var(--color-muted);
  padding: 8px 0;
}

#breadcrumb span { cursor: pointer; color: var(--color-primary); }
#breadcrumb span.current { color: var(--color-muted); cursor: default; }

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.view-toggle { display: flex; gap: 4px; }

.view-btn {
  background: var(--color-surface);
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  width: 32px;
  height: 32px;
  padding: 0;
  margin: 0;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.view-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.folder-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 12px;
  padding: 18px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 4px;
  cursor: pointer;
}

.folder-card:hover {
  border-color: var(--color-primary);
  background: var(--color-hover);
}

.folder-card-icon { font-size: 32px; }
.folder-card-name { font-size: 0.85em; word-break: break-word; }
.folder-card-meta { font-size: 0.75em; color: var(--color-muted); }

.results-summary {
  font-size: 0.85em;
  color: var(--color-muted);
  margin-bottom: 10px;
}

.results-section {
  margin-bottom: 18px;
}

.results-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8em;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: var(--color-primary);
  text-transform: uppercase;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--color-accent);
}

.results-section-count {
  font-weight: 400;
  color: var(--color-muted);
  text-transform: none;
  letter-spacing: 0;
}

.hidden { display: none; }

.hint { color: var(--color-muted); font-size: 1em; }

.item-list {
  list-style: none;
  padding: 0;
  margin: 0;
  background: var(--color-surface);
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--color-border);
}

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

.item-row:last-child { border-bottom: none; }
.item-row.clickable { cursor: pointer; }
.item-row.clickable:hover { background: var(--color-hover); }

.item-icon { width: 22px; font-size: 16px; }
.item-name { flex: 1; font-size: 1em; word-break: break-word; }

.site-badge {
  display: inline-block;
  font-size: 10px;
  color: var(--color-primary);
  background: var(--color-hover);
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 4px;
  vertical-align: middle;
}

.item-meta { font-size: 0.85em; color: var(--color-muted); white-space: nowrap; }

.item-actions { display: flex; gap: 6px; flex-shrink: 0; }

.mini-btn { padding: 5px 10px; font-size: 0.85em; margin: 0; border-radius: 6px; }

.error { color: #c0392b; font-size: 1em; }

#popular-section { display: flex; gap: 12px; flex-wrap: wrap; }

.popular-block {
  flex: 1;
  min-width: 220px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 12px 14px;
}

.popular-block h3 { font-size: 0.9em; margin: 0 0 8px; color: var(--color-text); }

.popular-list { list-style: none; margin: 0; padding: 0; }

.popular-list li {
  font-size: 0.9em;
  padding: 6px 0;
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.popular-list li:last-child { border-bottom: none; }
.popular-list li:hover { color: var(--color-primary); }
.popular-list .count { color: var(--color-muted); font-size: 0.8em; white-space: nowrap; }

/* Modal del visor */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: 10px;
  width: 100%;
  max-width: 900px;
  height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.95em;
  font-weight: 600;
}

.modal-header button { margin: 0; }
.modal-body { flex: 1; overflow: auto; padding: 0; }

.viewer-iframe { width: 100%; height: 100%; border: none; }

.text-preview {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9em;
  padding: 16px;
  margin: 0;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
