/* DeCA — estilos (tema oscuro por defecto, claro opcional) */
:root, [data-theme="dark"] {
  --bg: #0f1822; --bg-2: #14202e; --card: #1a2838; --borde: #2b3d52;
  --texto: #e6edf5; --muted: #8fa3b8; --primario: #3b82f6; --primario-texto: #fff;
  --ok: #22c55e; --ok-bg: #0f2e1d; --error: #f87171; --error-bg: #3a1618;
  --aviso-bg: #3a2e10; --input: #0f1822; --sombra: 0 2px 8px rgba(0,0,0,.35);
}
[data-theme="light"] {
  --bg: #f3f5f8; --bg-2: #1f3a5f; --card: #ffffff; --borde: #d5dde6;
  --texto: #1b2733; --muted: #5f6f80; --primario: #1f5fbf; --primario-texto: #fff;
  --ok: #15803d; --ok-bg: #e6f6ec; --error: #b91c1c; --error-bg: #fdecec;
  --aviso-bg: #fff6dc; --input: #fff; --sombra: 0 1px 4px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--texto); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primario); }
h1 { font-size: 1.35rem; margin: 0 0 .25rem; }
h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 .4rem; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .hidden { display: none !important; }
.pre { white-space: pre-wrap; }

/* ---- Barra superior y menú */
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .5rem;
  background: var(--bg-2); color: #fff; padding: .55rem .75rem; padding-top: calc(.55rem + env(safe-area-inset-top)); }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { font-weight: 400; opacity: .7; font-size: .8rem; margin-left: .35rem; }
.brand { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.brand-logo { display: inline-flex; align-items: center; background: #fff; border-radius: 8px; padding: 3px 8px; height: 38px; max-width: 190px; flex-shrink: 1; min-width: 0; }
.brand-logo img { max-height: 32px; max-width: 100%; object-fit: contain; display: block; }
.brand .brand-deca { margin-left: 0; font-weight: 700; letter-spacing: .02em; }
.icon-btn { background: transparent; border: 0; color: #fff; font-size: 1.35rem; width: 2.4rem; height: 2.4rem; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: rgba(255,255,255,.1); }

.sidebar { position: fixed; top: 0; bottom: 0; left: 0; width: 250px; z-index: 40; background: var(--card);
  border-right: 1px solid var(--borde); padding: 1rem .75rem; overflow-y: auto; transform: translateX(-100%);
  transition: transform .2s ease; display: flex; flex-direction: column; gap: 2px; }
.sidebar.abierto { transform: none; box-shadow: var(--sombra); }
.sidebar a, .nav-logout, .nav-install { display: block; padding: .6rem .75rem; border-radius: 8px; color: var(--texto);
  text-decoration: none; background: none; border: 0; text-align: left; width: 100%; font: inherit; cursor: pointer; }
.sidebar a:hover, .nav-logout:hover, .nav-install:hover { background: var(--bg); }
.sidebar a.active { background: var(--primario); color: var(--primario-texto); }
.nav-install { color: var(--primario); font-weight: 600; }
.nav-user { font-weight: 600; padding: .25rem .75rem .75rem; border-bottom: 1px solid var(--borde); margin-bottom: .25rem; }
.nav-user span { display: block; font-weight: 400; color: var(--muted); font-size: .85rem; }
.nav-section { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: .8rem .75rem .25rem; }
.nav-version { margin-top: auto; padding: .75rem; font-size: .75rem; color: var(--muted); }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 35; display: none; }
.overlay.visible { display: block; }

.main { padding: 1rem .9rem 6rem; max-width: 1100px; margin: 0 auto; }
.main-solo { padding-top: 2rem; }

@media (min-width: 900px) {
  .sidebar { transform: none; top: 0; padding-top: 4.2rem; z-index: 20; }
  #menu-toggle, .overlay { display: none !important; }
  .main { margin-left: 250px; padding: 1.5rem 2rem 3rem; max-width: none; }
  .main-solo { margin-left: auto; }
  .fab { display: none; }
}

/* ---- Componentes */
.card { background: var(--card); border: 1px solid var(--borde); border-radius: 12px; padding: 1rem; box-shadow: var(--sombra); margin-bottom: .9rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; margin-bottom: 1rem; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .6rem 1rem; min-height: 44px;
  border-radius: 10px; border: 1px solid var(--borde); background: var(--card); color: var(--texto); text-decoration: none;
  font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { filter: brightness(1.1); }
.btn-primary { background: var(--primario); border-color: var(--primario); color: var(--primario-texto); }
.btn-peligro { border-color: var(--error); color: var(--error); }
.btn-block { width: 100%; }
.btn-grande { font-size: 1.05rem; padding: .8rem 1.4rem; }
.btn:disabled { opacity: .6; }
.inline { display: inline; }
.fab { position: fixed; right: 1rem; bottom: calc(1rem + env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 50%;
  background: var(--primario); color: #fff; font-size: 2rem; display: flex; align-items: center; justify-content: center;
  text-decoration: none; box-shadow: 0 4px 14px rgba(0,0,0,.4); z-index: 25; }
@media (max-width: 899px) { .hide-mobile { display: none; } }
@media (min-width: 900px) { .fab { display: none; } }

.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: .75rem; border: 1px solid transparent; }
.flash-ok { background: var(--ok-bg); border-color: var(--ok); }
.flash-error { background: var(--error-bg); border-color: var(--error); }
.flash-info { background: var(--card); border-color: var(--borde); }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--borde); color: var(--muted); }
.badge-verde { color: var(--ok); border-color: var(--ok); }
.badge-rojo { color: var(--error); border-color: var(--error); }

/* ---- Formularios */
label { display: block; margin-bottom: .75rem; font-size: .88rem; color: var(--muted); }
input, select, textarea { display: block; width: 100%; margin-top: .25rem; padding: .65rem .7rem; font: inherit; font-size: 16px;
  color: var(--texto); background: var(--input); border: 1px solid var(--borde); border-radius: 8px; min-height: 44px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primario); outline-offset: 0; border-color: var(--primario); }
input[type=checkbox] { display: inline; width: auto; min-height: 0; margin: 0 .5rem 0 0; transform: scale(1.25); }
label.check { display: flex; align-items: center; color: var(--texto); }
.aviso { background: var(--aviso-bg); padding: .75rem; border-radius: 8px; }
fieldset { margin: 0 0 .9rem; min-width: 0; }
legend { font-weight: 700; padding: 0 .35rem; color: var(--texto); }
fieldset.card legend { float: left; width: 100%; padding: 0; margin-bottom: .6rem; }
fieldset.card legend + * { clear: both; }
details summary { cursor: pointer; margin-bottom: .5rem; }
.fila-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-narrow { max-width: 560px; }
.zona-peligro { margin-top: 1rem; }
.deca-form { max-width: 720px; }
.barra-guardar { position: sticky; bottom: 0; padding: .75rem 0 calc(.75rem + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); }
.grid-2 { display: grid; gap: 1rem; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; } .span-full { grid-column: 1 / -1; } }
.logo-preview { max-width: 220px; max-height: 90px; background: #fff; padding: .4rem; border-radius: 6px; display: block; margin-bottom: .5rem; }

/* Buscador AJAX */
.buscador { position: relative; }
.buscador-resultados { list-style: none; margin: -.5rem 0 .75rem; padding: 0; position: absolute; left: 0; right: 0; top: 100%;
  background: var(--card); border: 1px solid var(--borde); border-radius: 8px; box-shadow: var(--sombra); z-index: 10; max-height: 300px; overflow-y: auto; }
.buscador-resultados li { padding: .65rem .8rem; cursor: pointer; border-bottom: 1px solid var(--borde); }
.buscador-resultados li:hover { background: var(--bg); }
.buscador-resultados li strong { display: block; }
.buscador-resultados li span { font-size: .82rem; color: var(--muted); }
.buscador-resultados li.vacio { color: var(--muted); cursor: default; }

/* ---- Listado de DeCA */
.filtros { padding: .75rem 1rem; }
.filtros summary { font-weight: 600; margin: 0; }
.filtros-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; margin-top: .75rem; }
.filtros-grid .span-2 { grid-column: 1 / -1; }
.filtros-grid > * { min-width: 0; }
.filtros-grid input, .filtros-grid select { width: 100%; min-width: 0; }
.filtros-botones { grid-column: 1 / -1; display: flex; gap: .5rem; }
@media (min-width: 900px) { .filtros-grid { grid-template-columns: 2fr 1fr 1fr 1fr 1fr; align-items: end; } .filtros-grid .span-2 { grid-column: auto; } }
.lista-decas { display: grid; gap: .6rem; }
@media (min-width: 900px) { .lista-decas { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); } }
.deca-card { display: block; background: var(--card); border: 1px solid var(--borde); border-left: 4px solid var(--primario);
  border-radius: 10px; padding: .75rem .9rem; color: var(--texto); text-decoration: none; }
.deca-card.hoy { border-left-color: var(--ok); }
.deca-card.anulado { border-left-color: var(--error); opacity: .7; }
.deca-card-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: .2rem; }
.deca-card-cargador { font-weight: 600; }
.deca-card-ruta { color: var(--muted); font-size: .9rem; }
.deca-card-meta { display: flex; gap: .9rem; font-size: .82rem; color: var(--muted); margin-top: .3rem; flex-wrap: wrap; }
.vacio { text-align: center; color: var(--muted); }
.paginacion { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; gap: .5rem; }

/* ---- Ficha */
.acciones { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.ficha { display: grid; gap: 0; }
@media (min-width: 900px) { .ficha { grid-template-columns: 1fr 1fr; gap: 0 1rem; } }
.ficha p { margin: 0; }

/* ---- Tablas (se convierten en fichas en móvil) */
.buscar-simple { display: flex; gap: .5rem; margin-bottom: .9rem; max-width: 520px; }
.buscar-simple input { margin: 0; }
.tabla-wrap { padding: 0; overflow: hidden; }
.tabla { width: 100%; border-collapse: collapse; }
.tabla th, .tabla td { padding: .65rem .8rem; text-align: left; border-bottom: 1px solid var(--borde); }
.tabla th { font-size: .78rem; text-transform: uppercase; color: var(--muted); background: var(--bg); }
.tabla tr.inactivo td { opacity: .5; }
@media (max-width: 700px) {
  .tabla thead { display: none; }
  .tabla tr { display: block; border-bottom: 1px solid var(--borde); padding: .5rem .2rem; }
  .tabla td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .2rem .8rem; }
  .tabla td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; }
}

/* ---- Login */
.login-box { max-width: 380px; margin: 0 auto; text-align: center; }
.login-box .card { text-align: left; margin-top: 1rem; }
.login-logo { width: 84px; height: 84px; border-radius: 20px; }

/* ---- Estados DeCA, QR y versiones */
.badge.estado-emitido { color: var(--ok); border-color: var(--ok); }
.badge.estado-anulado { color: var(--error); border-color: var(--error); }
.badge.estado-sustituido { color: #d97706; border-color: #d97706; }
.qr-card { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.qr-img { width: 170px; height: 170px; background: #fff; border-radius: 8px; padding: 4px; image-rendering: pixelated; }
.url-publica { font-family: ui-monospace, Consolas, monospace; font-size: .78rem; word-break: break-all; color: var(--muted); }
.versiones { list-style: none; margin: 0; padding: 0; }
.versiones li { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; padding: .45rem 0; border-bottom: 1px solid var(--borde); }
.versiones li.actual a { font-weight: 700; }
h1 small { font-size: .8em; }
.asignar-form { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.asignar-form label { flex: 1; min-width: 200px; margin: 0; }
.asignar-form .span-full { flex-basis: 100%; margin: 0; }

/* ---- Páginas legales */
.legal { max-width: 820px; margin: 0 auto; line-height: 1.6; }
.legal h1 { margin-bottom: .2rem; }
.legal h2 { font-size: 1.05rem; margin: 1.4rem 0 .4rem; }
.legal ul, .legal ol { padding-left: 1.3rem; }
.legal li { margin-bottom: .35rem; }
.legal .tabla { margin: .6rem 0; font-size: .9rem; }
.legal-nav { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.legal-nav a { font-size: .82rem; padding: .25rem .6rem; border: 1px solid var(--borde); border-radius: 999px; color: var(--muted); text-decoration: none; }
.legal-nav a.active { color: var(--texto, inherit); border-color: currentColor; font-weight: 600; }
.legal-volver { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1.5rem; }
mark.pendiente { background: #fde68a; color: #7c2d12; padding: 0 .25rem; border-radius: 4px; }
.firmas { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-top: 2rem; }
.firma-linea { border-bottom: 1px solid var(--muted); height: 3.5rem; margin-bottom: .3rem; }
.pie-legal { display: flex; flex-wrap: wrap; justify-content: center; gap: .3rem 1rem; margin: 2rem 0 4.5rem; font-size: .8rem; }
.pie-legal a { color: var(--muted); text-decoration: none; }
.pie-legal a:hover { text-decoration: underline; }
@media print {
  .topbar, .sidebar, .overlay, .fab, .legal-nav, .legal-volver, .pie-legal, .flash { display: none !important; }
  body, .main, .legal { background: #fff !important; color: #000 !important; margin: 0 !important; padding: 0 !important; box-shadow: none !important; border: 0 !important; }
  .legal a { color: #000; }
  .legal .tabla th { background: #fff !important; color: #000 !important; }
  .legal h2 { color: #000 !important; }
}
@page { margin: 18mm 16mm; }

/* ---- Manual de uso */
a.icon-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn-ayuda { font-weight: 700; font-size: 1.05rem; width: 2rem; height: 2rem; border: 2px solid rgba(255,255,255,.75); border-radius: 50%; }
.btn-ayuda.active { background: rgba(255,255,255,.2); }
.ayuda { max-width: 820px; margin: 0 auto; line-height: 1.6; }
.ayuda h1 { margin-bottom: .2rem; }
.ayuda h2 { font-size: 1.12rem; margin: 0 0 .5rem; }
.ayuda h3 { font-size: .98rem; margin: .9rem 0 .3rem; }
.ayuda section { scroll-margin-top: 4.5rem; }
.ayuda ul, .ayuda ol { padding-left: 1.3rem; margin: .4rem 0; }
.ayuda li { margin-bottom: .35rem; }
.ayuda kbd { font-family: inherit; font-size: .85em; padding: .05rem .4rem; border: 1px solid var(--borde); border-bottom-width: 2px; border-radius: 5px; background: var(--bg); white-space: nowrap; }
.ayuda code { font-size: .9em; padding: .05rem .3rem; border-radius: 4px; background: var(--bg); }
.ayuda .tabla { margin: .5rem 0; font-size: .92rem; }
.ayuda-indice ol { columns: 2 240px; column-gap: 1.5rem; margin-top: .5rem; }
.ayuda-indice li { break-inside: avoid; }
.ayuda-indice li.sep { list-style: none; margin: .5rem 0 .2rem -1.3rem; font-weight: 700; color: var(--muted); font-size: .8rem; text-transform: uppercase; }
.ayuda-indice a { text-decoration: none; }
.ayuda-bloque { margin: 1.8rem 0 .7rem; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); border-bottom: 1px solid var(--borde); padding-bottom: .3rem; }
.ayuda .pasos li::marker { font-weight: 700; color: var(--primario); }
.ayuda .nota { border-left: 3px solid var(--primario); padding: .4rem .7rem; background: var(--bg); border-radius: 0 8px 8px 0; margin: .7rem 0 0; }
.ayuda .destacado { border-color: var(--primario); }
.tag-admin { display: inline-block; font-size: .72rem; font-weight: 700; padding: .05rem .45rem; border-radius: 999px; color: #b45309; border: 1px solid #d97706; vertical-align: middle; }
.definiciones dt { font-weight: 700; margin-top: .7rem; }
.definiciones dd { margin: .15rem 0 0 0; }
.ayuda details { border-top: 1px solid var(--borde); padding: .55rem 0; }
.ayuda details summary { cursor: pointer; font-weight: 600; }
.ayuda details p { margin: .4rem 0 0; }
.ayuda-pie { text-align: center; }
@media print {
  .ayuda-indice { display: none !important; }
  .ayuda section { break-inside: avoid; box-shadow: none !important; border: 1px solid #ccc !important; background: #fff !important; }
  .ayuda details { display: block; }
}
.capturas { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; align-items: flex-start; margin: .8rem 0; }
.captura { margin: .8rem auto; text-align: center; }
.capturas .captura { margin: 0; }
.captura a { display: block; }
.captura img { display: block; width: 100%; height: auto; border-radius: 10px; border: 1px solid var(--borde); box-shadow: var(--sombra); }
.captura figcaption { font-size: .8rem; color: var(--muted); margin-top: .35rem; line-height: 1.35; }
.captura-movil { width: 100%; max-width: 270px; }
.captura-escritorio { width: 100%; }
.captura-documento { width: 100%; max-width: 420px; }
.captura-documento img { background: #fff; }
.pasos .captura, .pasos .capturas { margin-top: .6rem; }
@media print { .captura { break-inside: avoid; } .captura-movil { max-width: 200px; } }
