:root {
  --ground: #f4f6f6;
  --surface: #fff;
  --surface-2: #eef2f2;
  --ink: #17201f;
  --ink-soft: #46534f;
  --ink-mute: #78888a;
  --line: #dbe3e2;
  --accent: #0f6d63;
  --accent-ink: #0b4f48;
  --accent-soft: #e2efec;
  --danger: #a5352f;
  --danger-soft: #fbeceb;
  --warn: #b4622a;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0e1615; --surface: #151f1e; --surface-2: #1b2726;
    --ink: #e6edeb; --ink-soft: #b7c5c2; --ink-mute: #869491;
    --line: #283634;
    --accent: #4fb0a1; --accent-ink: #7fccbf; --accent-soft: #16302c;
    --danger: #e07a72; --danger-soft: #2b1a19;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-ink); }
.mono { font-family: var(--mono); font-size: .88em; font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.trunc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt { margin-top: 12px; }
.inline { display: inline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }

/* topbar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 22px; height: 54px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: -.02em; text-decoration: none; color: var(--ink); }
.brand span { color: var(--accent); }
.topbar nav { display: flex; gap: 4px; margin-right: auto; }
.topbar nav a {
  padding: 6px 11px; border-radius: var(--radius); text-decoration: none;
  color: var(--ink-soft); font-size: 14px;
}
.topbar nav a:hover { background: var(--surface-2); }
.topbar nav a.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.who { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--ink-mute); }
.who small {
  display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--accent);
}

/* layout */
.wrap { max-width: 1060px; margin: 0 auto; padding: 28px 22px 80px; }
.wrap.narrow { max-width: 640px; }
.pagehead { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
h1 { font-size: 24px; letter-spacing: -.02em; margin: 0 auto 0 0; }
h1 small, h2 small { font-size: 13px; font-weight: 400; color: var(--ink-mute); margin-left: 6px; }
h2 { font-size: 15px; margin: 0 0 12px; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 18px;
}
.card.center { text-align: center; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }

/* forms */
label { display: block; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
label em { font-style: normal; font-weight: 400; color: var(--ink-mute); margin-left: 6px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=search], textarea, select {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px;
  font: inherit; color: var(--ink); background: var(--ground);
  border: 1px solid var(--line); border-radius: var(--radius);
}
input[type=file] { margin-top: 6px; font-size: 13px; width: 100%; }
textarea { resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
/* Las dos arcadas del caso nuevo, una debajo de la otra: el nombre del archivo no cabe a medias. */
.arches { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.hint { font-size: 13px; color: var(--ink-mute); margin: 0 0 14px; }

button, .btn {
  font: inherit; font-size: 14px; padding: 8px 15px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--radius); text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { border-color: var(--ink-mute); }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.primary:hover { filter: brightness(1.08); border-color: var(--accent); }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Acción destructiva pero reversible: contorno en vez de bloque sólido, para
   que no compita visualmente con "Eliminar caso". */
button.outline-danger {
  background: none; border: 1px solid var(--danger); color: var(--danger);
  font-weight: 600;
}
button.outline-danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
/* Se cualifican con button para igualar la especificidad de button.danger,
   que si no pinta un fondo rojo debajo de un texto rojo y lo hace ilegible. */
button.link, .link {
  background: none; border: 0; padding: 2px 6px;
  color: var(--accent-ink); font-size: 13px; text-decoration: underline;
  text-underline-offset: 2px;
}
button.link:hover, .link:hover { border: 0; color: var(--ink); }
button.link.danger, .link.danger { background: none; color: var(--danger); }

/* Encabezado de una columna de fechas: alterna hora local / UTC (ui.js).
   Hereda la tipografía del th; la etiqueta dice qué hora se ve. */
button.ts-toggle {
  font: inherit; color: inherit; background: none; border: 0; padding: 0;
  cursor: pointer; white-space: nowrap; text-align: left; text-transform: inherit; letter-spacing: inherit;
}
button.ts-toggle:hover { border: 0; color: var(--accent-ink); text-decoration: underline dotted; text-underline-offset: 3px; }
.tz {
  display: inline-block; margin-left: 4px; padding: 1px 5px; border-radius: 4px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-soft); font-weight: 600;
}

/* alerts */
.alert { padding: 11px 14px; border-radius: var(--radius); margin: 0 0 16px; font-size: 14px; }
.alert p { margin: 0 0 6px; }
.alert p:last-child { margin: 0; }
.alert.error { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.alert.ok { background: var(--accent-soft); color: var(--accent-ink); border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); }
.alert.info { background: var(--surface-2); color: var(--ink-soft); border: 1px solid var(--line); }

/* table */
.grid { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; overflow: hidden; }
.grid th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--ink-mute); background: var(--surface-2); padding: 9px 13px; border-bottom: 1px solid var(--line);
}
.grid td { padding: 10px 13px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid.tight td, .grid.tight th { padding: 7px 12px; }
.grid tr.muted td { opacity: .55; }
.grid .na { color: var(--ink-mute); }

.pill {
  display: inline-block; padding: 2px 9px; border-radius: 100px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
  background: var(--surface-2); color: var(--ink-mute);
}
.pill.ready, .pill.admin { background: var(--accent-soft); color: var(--accent-ink); }
.pill.failed { background: var(--danger-soft); color: var(--danger); }
.pill.processing { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }

.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { margin-top: 0; }
.pager { display: flex; gap: 4px; margin-top: 16px; }
.pager a { padding: 5px 11px; border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none; color: var(--ink-soft); }
.pager a.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.empty { color: var(--ink-mute); padding: 34px; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

.copyrow { display: flex; gap: 8px; align-items: center; }
.copyrow input { margin-top: 0; font-family: var(--mono); font-size: 13px; }
.pwform { display: flex; gap: 6px; margin-top: 6px; }
.pwform input { margin-top: 0; }
details summary { cursor: pointer; list-style: none; }
.code {
  background: var(--surface-2); border: 1px solid var(--line); border-left: 2px solid var(--accent);
  border-radius: var(--radius); padding: 12px 14px; overflow-x: auto;
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6; margin: 0 0 12px;
}

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 360px; }
.auth h1 { font-size: 22px; margin: 0 0 2px; }
.auth h1 span { color: var(--accent); }
.auth .sub { color: var(--ink-mute); font-size: 13px; margin: 0 0 20px; }
.auth button { width: 100%; }

@media (max-width: 640px) {
  .two { grid-template-columns: 1fr; }
  .topbar { gap: 12px; padding: 0 14px; }
  .topbar nav a { padding: 5px 8px; }
  .who span { display: none; }
}

/* ---------- login sin etiquetas ---------- */
.login h1 { margin-bottom: 20px; }
.login label { margin: 0 0 12px; }
.login label input[type=text],
.login label input[type=password] { margin: 6px 0 0; }
.login button { margin-top: 4px; }

/* ---------- campo de archivo ---------- */
.field { margin-bottom: 14px; }
.fieldlabel {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); margin-bottom: 5px;
}
.filefield {
  position: relative; display: flex; align-items: center; gap: 10px;
  margin: 0; padding: 5px; cursor: pointer;
  background: var(--ground); border: 1px solid var(--line); border-radius: var(--radius);
}
.filefield:hover { border-color: var(--ink-mute); }
.filefield:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.filefield input[type=file] {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; margin: 0;
}
.filebtn {
  flex: 0 0 auto; padding: 6px 12px; font-size: 13px; font-weight: 600;
  color: var(--ink-soft); background: var(--surface);
  border: 1px solid var(--line); border-radius: 4px;
}
.filename {
  font-size: 13px; color: var(--ink-mute); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.filefield.has .filename { color: var(--ink); }
.filefield.has .filebtn { color: var(--accent-ink); border-color: var(--accent); }
button[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- subnavegacion de administracion ---------- */
.subnav { background: var(--surface); border-bottom: 1px solid var(--line); }
.subnav-inner {
  max-width: 1060px; margin: 0 auto; padding: 0 22px;
  display: flex; gap: 2px;
}
.subnav a {
  padding: 10px 13px; font-size: 13.5px; color: var(--ink-mute);
  text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subnav a:hover { color: var(--ink); }
.subnav a.on { color: var(--accent-ink); border-bottom-color: var(--accent); font-weight: 600; }

/* ---------- personalizacion ---------- */
.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
.colorfield {
  display: block; width: 100%; height: 38px; margin-top: 5px; padding: 3px;
  background: var(--ground); border: 1px solid var(--line);
  border-radius: var(--radius); cursor: pointer;
}
.colorfield::-webkit-color-swatch-wrapper { padding: 0; }
.colorfield::-webkit-color-swatch { border: 0; border-radius: 3px; }
input[type=number] {
  display: block; width: 100%; margin-top: 5px; padding: 9px 11px;
  font: inherit; color: var(--ink); background: var(--ground);
  border: 1px solid var(--line); border-radius: var(--radius);
}
/* Vista previa del fondo del visor: los dos temas, lado a lado. */
.bg-image-only[hidden] { display: none; }
.bglive { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 14px; }
.bglive figure { margin: 0; }
.bglive-box {
  position: relative; aspect-ratio: 16 / 10; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--radius);
}
.bglive-box img { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
.bglive-box img[hidden] { display: none; }
.bglive figcaption { margin-top: 6px; font-size: 13px; opacity: .75; }
.actions { display: flex; gap: 10px; margin-bottom: 24px; }
.login h1 { display: none; }

@media (max-width: 640px) {
  .three { grid-template-columns: 1fr; }
  .subnav-inner { padding: 0 14px; overflow-x: auto; }
}
.inlinehint { margin-left: 10px; display: inline; }

/* ---------- modal de confirmacion ---------- */
.modal {
  width: min(420px, calc(100vw - 32px));
  padding: 22px 24px 18px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .35);
}
.modal::backdrop { background: rgba(6, 10, 10, .58); backdrop-filter: blur(2px); }
.modal h3 { margin: 0 0 8px; font-size: 17px; letter-spacing: -.01em; }
.modal p { margin: 0 0 20px; font-size: 14.5px; color: var(--ink-soft); line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; }
.modal-actions button { min-width: 104px; }

/* ---------- 404 ---------- */
.notfound { min-height: 100vh; display: grid; place-items: center; }
.notfound h1 {
  margin: 0; font-family: var(--mono); font-size: clamp(72px, 16vw, 160px);
  font-weight: 600; letter-spacing: .06em; color: var(--ink-mute);
}

/* ---------- sliders y numeros ---------- */
/* Sin flechitas: los giros se escriben. */
input.nospin { -moz-appearance: textfield; appearance: textfield; }
input.nospin::-webkit-outer-spin-button,
input.nospin::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.range-field { display: flex; align-items: flex-end; gap: 14px; }
.range-field label { flex: 1; }
.range-field input[type=range] { display: block; width: 100%; margin-top: 10px; accent-color: var(--accent); }
.range-field output {
  min-width: 84px; margin-bottom: 14px; text-align: right;
  font-family: var(--mono); font-size: 13px; color: var(--accent);
}

/* Pie de todas las paginas. En las que ocupan el alto de la pantalla
   (ingresar, 404), queda fijo abajo. */
.site-foot {
  padding: 22px 16px 26px; text-align: center;
  font-size: 12px; color: var(--ink-mute); letter-spacing: .02em;
}
body:has(.auth) .site-foot, body:has(.notfound) .site-foot { position: fixed; left: 0; right: 0; bottom: 0; }
