/* ==========================================================================
   Panel de administración · mismo lenguaje visual que el sitio público
   ========================================================================== */

:root {
  --green-800: #18583A;
  --green-700: #1F6B43;
  --green-600: #2A8250;
  --green-brand: #2E8B57;
  --green-500: #3CB371;
  --green-200: #C5E8D4;
  --green-100: #E3F4EA;
  --green-50: #F1FAF5;
  --sky-50: #F2FAFD;
  --sky-100: #E3F3F9;
  --sky-200: #B0E0E6;
  --sky-300: #ADD8E6;
  --sky-400: #87CEEB;
  --sky-ink: #1E5670;
  --ink: #333333;
  --ink-soft: #5A646C;
  --line: #DDE5E9;
  --bg-soft: #F8F9FA;
  --danger: #A32626;
  --danger-bg: #FBEAEA;
  --warn-ink: #7A4B00;
  --warn-bg: #FFF4DB;
  --radius: 12px;
  --radius-sm: 8px;
  --side-w: 268px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Public Sans', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 1rem; line-height: 1.55; color: var(--ink); background: var(--bg-soft);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, ul, ol { margin-top: 0; }
a { color: var(--green-700); }
:focus-visible { outline: 3px solid var(--sky-400); outline-offset: 2px; border-radius: 4px; }
code { padding: 1px 6px; border-radius: 6px; background: var(--sky-100); color: var(--sky-ink); font-size: .9em; word-break: break-word; }
pre.code { overflow-x: auto; padding: 14px; border-radius: var(--radius); background: #333; color: #fff; font-size: .85rem; white-space: pre-wrap; }
.icon { width: 20px; height: 20px; flex: none; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .7rem 1.1rem; border: 1.5px solid transparent; border-radius: var(--radius);
  font: inherit; font-size: .95rem; font-weight: 600; line-height: 1.2; text-decoration: none; cursor: pointer;
  transition: background-color .2s, color .2s, border-color .2s, transform .2s;
}
.btn .icon { width: 18px; height: 18px; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--green-600); color: #fff; }
.btn--primary:hover { background: var(--green-700); }
.btn--ghost { border-color: var(--line); background: #fff; color: var(--ink); }
.btn--ghost:hover { border-color: var(--green-brand); background: var(--green-50); color: var(--green-700); }
.btn--danger { border-color: #E9C4C4; background: #fff; color: var(--danger); }
.btn--danger:hover:not([disabled]) { border-color: var(--danger); background: var(--danger-bg); }
.btn--small { padding: .45rem .8rem; font-size: .88rem; }
.btn--block { display: flex; width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--ink); cursor: pointer;
  transition: border-color .2s, color .2s;
}
.icon-btn .icon { width: 18px; height: 18px; }
.icon-btn:hover:not([disabled]) { border-color: var(--green-brand); color: var(--green-700); }
.icon-btn[disabled] { opacity: .35; cursor: not-allowed; }

/* ---------- Estructura ---------- */
.shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; align-self: start; display: flex; flex-direction: column; gap: 6px;
  height: 100vh; padding: 18px 14px; overflow-y: auto;
  border-right: 1px solid var(--line); background: #fff;
}
.side__brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 16px; color: var(--ink); text-decoration: none; }
.side__brand svg { width: 40px; height: 40px; flex: none; }
.side__brand span { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.side__brand strong { overflow: hidden; font-size: 1.05rem; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.side__brand small { color: var(--ink-soft); font-size: .76rem; }
.side__nav { display: flex; flex-direction: column; gap: 2px; }
.side__heading { margin: 16px 12px 4px; color: var(--ink-soft); font-size: .8rem; font-weight: 700; }
.side__link {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--ink);
  font: inherit; font-size: .95rem; font-weight: 500; text-align: left; text-decoration: none; cursor: pointer;
  transition: background-color .2s, color .2s;
}
.side__link .icon { width: 20px; height: 20px; color: var(--ink-soft); }
.side__link:hover { background: var(--sky-100); }
.side__link.is-active { background: var(--green-50); color: var(--green-700); font-weight: 700; }
.side__link.is-active .icon { color: var(--green-brand); }
.side__foot { margin: auto 0 0; padding-top: 14px; border-top: 1px solid var(--line); }
.side__user { margin: 0 0 6px; padding: 0 12px; color: var(--ink-soft); font-size: .85rem; }

.main { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 40; display: none; align-items: center; gap: 12px;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .95);
}
.menu-btn { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; color: var(--ink); cursor: pointer; }
.topbar__title { font-weight: 700; }
.content { max-width: 1060px; padding: clamp(20px, 4vw, 40px); }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-title { margin: 0 0 4px; font-size: 1.75rem; font-weight: 800; line-height: 1.15; letter-spacing: -.02em; }
.page-intro { max-width: 64ch; margin: 0; color: var(--ink-soft); }
.section-title { margin: 32px 0 12px; font-size: 1.1rem; font-weight: 700; }

.alert { margin-bottom: 18px; padding: 12px 16px; border: 1px solid transparent; border-radius: var(--radius); font-size: .95rem; }
.alert ul { margin: 6px 0 0; padding-left: 1.2rem; }
.alert--ok { border-color: var(--green-200); background: var(--green-50); color: var(--green-800); }
.alert--err { border-color: #E9C4C4; background: var(--danger-bg); color: #7C1D1D; }
.alert--warn { border-color: #F0D9A0; background: var(--warn-bg); color: var(--warn-ink); }

.card { padding: 24px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }

/* ---------- Tablas y listas ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th { padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--sky-50); color: var(--ink-soft); font-size: .85rem; font-weight: 700; text-align: left; white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--sky-50); }
.table .th-actions { text-align: right; }
.cell-actions { text-align: right; white-space: nowrap; }
.cell-actions > * { display: inline-flex; margin: 2px 0 2px 6px; vertical-align: middle; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; background: #EEF1F3; color: var(--ink-soft); font-size: .8rem; font-weight: 700; }
.badge--ok { background: var(--green-100); color: var(--green-800); }
.badge--warn { background: var(--warn-bg); color: var(--warn-ink); }
.empty { padding: 36px 24px; border: 1.5px dashed var(--line); border-radius: var(--radius); background: #fff; color: var(--ink-soft); text-align: center; }
.empty p { margin-bottom: 14px; }

/* ---------- Formularios ---------- */
.form.card { max-width: 760px; }
.form__group { margin: 28px 0 14px; padding-top: 22px; border-top: 1px solid var(--line); font-size: 1.05rem; font-weight: 700; }
.form__group:first-of-type { margin-top: 0; padding-top: 0; border-top: 0; }
.field { margin-bottom: 20px; }
.field__label { display: block; margin-bottom: 6px; font-size: .95rem; font-weight: 600; }
.field__sub { display: block; margin: 14px 0 6px; color: var(--ink-soft); font-size: .88rem; font-weight: 600; }
.req { color: var(--danger); }
.input {
  display: block; width: 100%; padding: .7rem .9rem; border: 1.5px solid #CBD6DC; border-radius: var(--radius);
  background: #fff; color: var(--ink); font: inherit; font-size: .98rem;
  transition: border-color .2s, box-shadow .2s;
}
.input:focus { border-color: var(--green-brand); box-shadow: 0 0 0 3px rgba(60, 179, 113, .22); outline: 0; }
textarea.input { min-height: 90px; resize: vertical; }
.input--code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
input[type="file"].input { padding: .55rem .7rem; background: var(--sky-50); }
.field__help { margin: 6px 0 0; color: var(--ink-soft); font-size: .88rem; }
.field__error { display: flex; align-items: center; gap: 6px; margin: 6px 0 0; color: var(--danger); font-size: .9rem; font-weight: 600; }
.field__error .icon { width: 16px; height: 16px; }
.has-error .input { border-color: var(--danger); }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--green-600); }
.check--small { margin-top: 6px; color: var(--ink-soft); font-size: .88rem; font-weight: 500; }
.form__actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }

.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.icon-opt { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px; border-radius: var(--radius); text-align: center; cursor: pointer; }
.icon-opt input { position: absolute; opacity: 0; pointer-events: none; }
.icon-opt__box {
  display: grid; place-items: center; width: 46px; height: 46px; border: 1.5px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--ink-soft); transition: border-color .2s, background-color .2s, color .2s;
}
.icon-opt small { color: var(--ink-soft); font-size: .76rem; line-height: 1.2; }
.icon-opt:hover .icon-opt__box { border-color: var(--green-brand); color: var(--green-700); }
.icon-opt input:checked + .icon-opt__box { border-color: var(--green-600); background: var(--green-600); color: #fff; }
.icon-opt input:focus-visible + .icon-opt__box { outline: 3px solid var(--sky-400); outline-offset: 2px; }

.file-box { padding: 14px; border: 1.5px dashed #CBD6DC; border-radius: var(--radius); background: #fff; }
.file-current { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; padding: 10px; border-radius: var(--radius); background: var(--sky-50); }
.file-current a { font-weight: 600; word-break: break-all; }
.thumb { width: 64px; height: 48px; flex: none; border: 1px solid var(--line); border-radius: var(--radius-sm); object-fit: cover; }
.mini-icon { display: inline-grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 10px; background: var(--green-100); color: var(--green-brand); }
.mini-icon .icon { width: 18px; height: 18px; }
.mini-icon--lg { width: 48px; height: 48px; }
.mini-icon--lg .icon { width: 22px; height: 22px; }
.file-cell { display: flex; align-items: center; gap: 12px; }
.file-cell a { font-weight: 600; word-break: break-word; }

/* ---------- Resumen y archivos ---------- */
.todo { margin-bottom: 20px; border-color: #F0D9A0; background: #FFFBF0; }
.todo h2 { margin: 0 0 8px; font-size: 1.05rem; }
.todo ul { margin: 0; padding: 0; list-style: none; }
.todo__item { display: flex; gap: 10px; padding: 8px 0; }
.todo__item .icon { width: 20px; height: 20px; margin-top: 2px; color: #B7791F; }
.todo__item--info .icon { color: var(--sky-ink); }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.stat-card {
  display: flex; flex-direction: column; gap: 2px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; color: var(--ink-soft); text-decoration: none;
  transition: border-color .2s, box-shadow .2s, transform .2s;
}
.stat-card:hover { border-color: var(--green-brand); box-shadow: 0 14px 26px -20px rgba(31, 107, 67, .6); transform: translateY(-2px); }
.stat-card__icon { display: grid; place-items: center; width: 40px; height: 40px; margin-bottom: 10px; border-radius: 10px; background: var(--green-100); color: var(--green-brand); }
.stat-card strong { color: var(--green-brand); font-size: 2rem; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
.shortcuts { display: flex; flex-wrap: wrap; gap: 10px; }
.upload { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.upload .field { flex: 1 1 320px; margin: 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tab { padding: 8px 16px; border: 1.5px solid var(--line); border-radius: 999px; background: #fff; color: var(--ink); font-size: .92rem; font-weight: 600; text-decoration: none; }
.tab:hover { border-color: var(--green-brand); color: var(--green-700); }
.tab.is-active { border-color: var(--green-600); background: var(--green-600); color: #fff; }

/* ---------- Pantallas de acceso e instalador ---------- */
body.auth {
  display: grid; place-items: center; min-height: 100vh; margin: 0; padding: 24px 16px;
  background:
    radial-gradient(60% 50% at 85% 0%, var(--sky-200) 0%, transparent 70%),
    radial-gradient(50% 45% at 0% 100%, var(--green-100) 0%, transparent 70%),
    var(--sky-50);
}
.auth__card {
  width: min(100%, 520px); padding: clamp(24px, 5vw, 36px); border: 1px solid var(--line); border-radius: var(--radius);
  background: #fff; box-shadow: 0 30px 60px -40px rgba(30, 86, 112, .45);
}
.auth__brand { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.auth__mark { width: 46px; height: 46px; flex: none; }
.auth__brand h1 { margin: 0; font-size: 1.4rem; font-weight: 800; line-height: 1.2; letter-spacing: -.02em; }
.auth__brand p { margin: 2px 0 0; color: var(--ink-soft); font-size: .92rem; }
.auth__card p { margin-bottom: 14px; }
.auth__links { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin: 20px 0 0; font-size: .92rem; }
.auth .form__actions { margin-top: 22px; padding-top: 0; border-top: 0; }
.auth .field__help { margin-bottom: 14px; }
.steps { margin: 0 0 20px; padding-left: 1.3rem; }
.steps li { margin-bottom: 8px; }

/* ---------- Adaptación a pantallas ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .topbar { display: flex; }
  .side {
    position: fixed; inset: 0 auto 0 0; z-index: 60; width: min(86vw, 300px);
    transform: translateX(-102%); transition: transform .25s;
  }
  .side.is-open { transform: none; box-shadow: 0 0 0 100vmax rgba(20, 40, 50, .4); }
  .page-title { font-size: 1.5rem; }
}
@media (max-width: 700px) {
  /* Las tablas pasan a tarjetas para que Editar y Eliminar siempre se vean */
  .table-wrap { overflow: visible; border: 0; background: transparent; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table tr { margin-bottom: 12px; padding: 10px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
  .table tbody tr:hover { background: #fff; }
  .table td { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 6px 0; border: 0; text-align: right; }
  .table td::before { content: attr(data-label); flex: none; color: var(--ink-soft); font-size: .82rem; font-weight: 700; text-align: left; }
  .table td:first-child { display: block; font-weight: 700; text-align: left; }
  .table td:first-child::before { content: none; }
  .table td.cell-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--line); white-space: normal; }
  .table td.cell-actions::before { content: none; }
}
@media (max-width: 560px) {
  .card { padding: 18px; }
  .table th, .table td { padding: 10px 12px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; }
}
