/* ===== Colores (claro / oscuro automático) =====
   Toda la paleta está aquí: para cambiar el aspecto basta con tocar estas variables. */
:root {
  /* Paleta «Pizarra y azul» */
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #17202b;
  --muted: #5b6878;
  --line: #d9dee5;
  --brand: #2a5db0;        /* color de acento: botones principales, pestañas activas */
  --brand-text: #ffffff;   /* texto sobre el acento */
  --brand-ink: #2a5db0;    /* acento usado como texto (sección activa) */
  --top-bg: #1e2935;       /* barra superior */
  --top-text: #f3f5f8;
  --danger: #c62828;
  --ok: #2e7d32;
  --warn: #b26a00;  --warn-bg: #fff4d6;  --warn-text: #7a4b00;
  --st-pend-bg: #e3f2fd; --st-pend: #0d47a1;
  --st-curso-bg: #fff3cd; --st-curso: #7a5a00;
  --st-fin-bg: #e8f5e9;  --st-fin: #1b5e20;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.06);
  --radius: 12px;
  --toque: 48px;           /* altura mínima de botones: cómoda con guantes */
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161c;
    --card: #1a2129;
    --text: #e8edf2;
    --muted: #98a4b3;
    --line: #2c3641;
    --brand: #6b9be0; --brand-text: #0e1620; --brand-ink: #8fb3ea;
    --top-bg: #18202a; --top-text: #e8edf2;
    --warn: #e0a93e; --warn-bg: #3a2c10; --warn-text: #ffd58a;
    --st-pend-bg: #1c2d42; --st-pend: #9cc3f0;
    --st-curso-bg: #3a2f12; --st-curso: #f0cf7a;
    --st-fin-bg: #1b3220;  --st-fin: #9bd3a2;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Barra superior ===== */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--top-bg); color: var(--top-text);
}
.topbar h1 { font-size: 1.2rem; font-weight: 650; letter-spacing: .01em; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  border: 0; background: transparent; color: inherit;
  font-size: 1.5rem; line-height: 1; padding: 4px 8px; cursor: pointer; border-radius: 8px;
  min-width: 44px; min-height: 44px;
}
.red { width: 10px; height: 10px; border-radius: 50%; background: var(--ok); }
.red.sin { background: var(--muted); }

/* ===== Contenido ===== */
main {
  flex: 1; width: 100%; max-width: 860px; margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
  outline: none;
}

/* ===== Barra inferior ===== */
.bottombar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; justify-content: space-around;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottombar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; min-height: 58px; font-size: .78rem; color: var(--muted); text-decoration: none;
  border-top: 3px solid transparent;
}
.bottombar a .ico { font-size: 1.3rem; filter: grayscale(1); opacity: .7; }
.bottombar a.activa { color: var(--brand-ink); font-weight: 700; border-top-color: var(--brand); }
.bottombar a.activa .ico { filter: none; opacity: 1; }

/* En ordenador: barra lateral en vez de inferior */
@media (min-width: 900px) {
  body { padding-left: 96px; }
  .bottombar { top: 0; right: auto; width: 96px; flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--line); padding-top: 72px; }
  .bottombar a { flex: 0; padding: 14px 4px; border-top: 0; border-left: 3px solid transparent; }
  .bottombar a.activa { border-left-color: var(--brand); }
  main { padding-bottom: 40px; }
  .fab { bottom: 32px !important; }
}

/* ===== Elementos ===== */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
}
.card h2 { font-size: 1rem; margin: 0 0 10px; }
a.card { display: block; color: inherit; text-decoration: none; }
a.card:active { transform: scale(.99); }
.fila { display: flex; align-items: center; gap: 8px; }
.fila.entre { justify-content: space-between; }
.crece { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.peq { font-size: .85rem; }
.titulo-obra { font-weight: 600; font-size: 1.05rem; margin: 0 0 4px; overflow-wrap: anywhere; }
.vacio { text-align: center; padding: 40px 16px; color: var(--muted); }
.vacio .grande { font-size: 3rem; }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: .75rem; font-weight: 600;
  white-space: nowrap; border: 1px solid transparent;
}
.badge.pendiente   { background: var(--st-pend-bg); color: var(--st-pend); }
.badge.en_curso    { background: var(--st-curso-bg); color: var(--st-curso); }
.badge.terminada   { background: var(--st-fin-bg); color: var(--st-fin); }

.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 6px 14px; min-height: 40px; border-radius: 99px; font-size: .88rem; white-space: nowrap; cursor: pointer;
}
.chip.activa { background: var(--text); color: var(--bg); border-color: var(--text); }

input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
}
input:not([type=checkbox]):not([type=radio]):not([type=range]), select { min-height: var(--toque); }
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
label { display: block; font-size: .85rem; color: var(--muted); margin: 12px 0 4px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 600px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; padding: 11px 16px; min-height: var(--toque); border-radius: 10px; cursor: pointer; text-decoration: none;
}
.btn:active, .chip:active, .accion:active { filter: brightness(.94); }
.btn.prim { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
.btn.peligro { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.bloque { width: 100%; }
.btn.mini { padding: 6px 12px; min-height: 40px; font-size: .85rem; }
.botones { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

.fab {
  position: fixed; right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 11;
  background: var(--brand); color: var(--brand-text); border: 0; border-radius: 99px;
  padding: 14px 20px; font: inherit; font-weight: 700; box-shadow: 0 4px 12px rgba(0,0,0,.25);
  text-decoration: none;
}
@media (min-width: 900px) { .fab { right: calc(50% - 430px + 48px); } }

/* Recuento */
.contador { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.contador:last-child { border-bottom: 0; }
.contador .nombre { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.contador .cant {
  width: 64px; text-align: center; font-weight: 700; font-size: 1.05rem; padding: 8px 4px;
}
.contador button.pm {
  width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 1.3rem; font-weight: 700; cursor: pointer;
}
.contador button.quitar { border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 6px; }

.datos dt { font-size: .8rem; color: var(--muted); margin-top: 8px; }
.datos dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.datos dd a { color: inherit; }
.notas { white-space: pre-wrap; overflow-wrap: anywhere; }
.proximo { border-style: dashed; }

.aviso {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(140px + env(safe-area-inset-bottom)); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  max-width: calc(100% - 32px); box-shadow: 0 4px 12px rgba(0,0,0,.3);
}

/* ===== Cálculos ===== */
.calc-menu { display: flex; align-items: center; gap: 12px; }
.calc-menu .crece > span { display: block; }
.calc-menu .resumen { overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ico-calc { font-size: 1.8rem; width: 2.2rem; text-align: center; flex: none; }
#calculos-obra .card { box-shadow: none; background: var(--bg); margin: 8px 0 0; }
.subtitulo { font-size: 1rem; margin: 20px 0 10px; }
.ayuda { margin: 4px 0 0; }
.grid3, .grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
@media (min-width: 600px) { .grid3 { grid-template-columns: repeat(3, 1fr); } .grid4 { grid-template-columns: repeat(4, 1fr); } }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: .95rem; margin: 10px 14px 0 0; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--brand); }
.checks { display: grid; grid-template-columns: 1fr; }
@media (min-width: 600px) { .checks { grid-template-columns: 1fr 1fr; } }
.fila-calc { padding: 10px 0; border-bottom: 1px solid var(--line); }
.fila-calc label { margin-top: 8px; }
.fila-calc .fila.peq { flex-wrap: wrap; }
.fila-calc .quitar, .fila-calc + .quitar { border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 6px; }

.resultado { border: 2px solid var(--brand); }
.resultado.aviso-ko, .aviso-ko { border: 2px solid var(--danger); }
.cifras { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 8px; }
@media (min-width: 600px) { .cifras { grid-template-columns: repeat(4, 1fr); } }
.cifras > div { background: var(--bg); border-radius: 10px; padding: 10px; }
.cifras .etq { display: block; font-size: .75rem; color: var(--muted); }
.cifras .cifra { display: block; font-size: 1.35rem; font-weight: 700; }
.avisos { color: var(--danger); margin: 8px 0; padding-left: 20px; }
.ok { color: var(--ok); font-weight: 700; }
.ko { color: var(--danger); font-weight: 700; }
details.card summary { cursor: pointer; font-weight: 600; }
details.card[open] summary { margin-bottom: 10px; }
.tabla-scroll { overflow-x: auto; margin: 8px 0; }
.tabla { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tabla th, .tabla td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tabla th { font-size: .75rem; color: var(--muted); font-weight: 600; }
.tabla tfoot td { font-weight: 600; border-bottom: 0; }
.tabla tr.sel td { background: color-mix(in srgb, var(--brand) 22%, transparent); font-weight: 600; }
.tabla td:not(:first-child) { white-space: nowrap; }

/* ===== Materiales ===== */
.enlace { color: inherit; text-decoration: none; }
.acciones { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (min-width: 600px) { .acciones { grid-template-columns: repeat(5, 1fr); } }
.accion {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 76px; padding: 10px 6px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--text); font: inherit; font-size: .85rem; font-weight: 600;
  text-align: center; text-decoration: none; cursor: pointer; margin: 0;
}
.accion span { font-size: 1.6rem; line-height: 1; }
.accion:active { transform: scale(.98); }
.sub-panel { margin-top: 12px; padding: 12px; border-radius: 10px; background: var(--bg); }
.linea-calc { padding: 6px 0; border-bottom: 1px solid var(--line); }
.linea-calc input[type=number] { width: 90px; text-align: right; }
.dia h2 { margin: 0; }
.linea-mat { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.card > .linea-mat:last-child, .linea-mat:last-child { border-bottom: 0; }
a.card.linea-mat { padding: 12px 14px; border: 1px solid var(--line); }
.linea-mat .crece > span { display: block; overflow-wrap: anywhere; }
.nombre-mat { font-weight: 600; }
.cant-mat { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.cant-mat small { font-weight: 400; color: var(--muted); }
.mini-foto { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex: none; background: var(--bg); }
.mini-foto.grande { width: 64px; height: 64px; }
.mini-ico { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; background: var(--bg); border-radius: 8px; flex: none; }
.linea-resumen { padding: 4px 0; }
.pm {
  width: 44px; height: 44px; flex: none; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 1.3rem; font-weight: 700; cursor: pointer;
}
.cant-grande { text-align: center; font-weight: 700; font-size: 1.1rem; min-width: 0; }
.foto-form { width: 120px; height: 120px; object-fit: cover; border-radius: 10px; cursor: zoom-in; }
.ref-albaran img { width: 100%; max-height: 260px; object-fit: contain; background: var(--bg); border-radius: 8px; cursor: zoom-in; display: block; }
.ref-albaran p { margin: 6px 0 0; }

.escaner { padding: 10px; }
.visor-camara { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; }
.visor-camara video { width: 100%; height: 100%; object-fit: cover; display: block; }
.visor-camara .guia { position: absolute; left: 10%; right: 10%; top: 50%; height: 2px; background: #ff3b30; box-shadow: 0 0 8px #ff3b30; }
.estado-camara { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 10px; background: rgba(0,0,0,.6); color: #fff; font-size: .85rem; text-align: center; }
.estado-camara.error { background: rgba(160,20,20,.85); }

.visor { position: fixed; inset: 0; z-index: 50; background: #000; display: flex; flex-direction: column; }
.visor-barra { display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 8px) 12px 8px; color: #fff; }
.visor-foto { flex: 1; overflow: auto; display: flex; align-items: center; justify-content: center; }
.visor-foto img { max-width: 100%; max-height: 100%; object-fit: contain; }
.visor.ampliada .visor-foto { display: block; }
.visor.ampliada .visor-foto img { max-width: none; max-height: none; width: 250%; }
label.btn { margin: 0; }

/* Presupuesto (fotos y archivos del jefe) */
.docs { display: flex; flex-direction: column; gap: 8px; }
.doc { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.doc:last-child { border-bottom: 0; }
.doc-ver {
  width: 56px; height: 56px; flex: none; padding: 0; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); overflow: hidden; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.doc-ver img { width: 100%; height: 100%; object-fit: cover; }
.doc-ico { font-size: 1.8rem; }
.doc-info { min-width: 0; }
.doc-nombre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc .icon-btn { font-size: 1.15rem; color: var(--muted); }

/* Selector de tipo de trabajo (Obra / Avería / Mantenimiento) */
.etiqueta { display: block; font-size: .85rem; color: var(--muted); margin: 4px 0 6px; }
.segmentos { display: flex; gap: 6px; flex-wrap: wrap; }
.segmento { margin: 0; flex: 1 1 0; min-width: 0; position: relative; }
.segmento input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; pointer-events: none; }
.segmento span {
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
  padding: 8px 4px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); font-weight: 600; font-size: .82rem; cursor: pointer; height: 100%; line-height: 1.2;
}
.segmento span b { font-size: 1.3rem; font-weight: 400; line-height: 1.2; }
.segmento input:checked + span { background: var(--brand); border-color: var(--brand); color: var(--brand-text); }
.segmento input:focus-visible + span { outline: 2px solid var(--text); }
.distancia { font-weight: 700; color: var(--text); margin-bottom: 2px; }
#f-promotor { padding: 7px 10px; font-size: .9rem; }

/* Horas: fichaje en marcha */
.fichaje { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 8px; border-radius: 10px;
  background: color-mix(in srgb, var(--brand) 18%, transparent); }
.punto-rec { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); flex: none; animation: latido 1.6s ease-in-out infinite; }
@keyframes latido { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .punto-rec { animation: none; } }

/* Datos para el boletín */
.progreso { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 8px; }
.progreso span { display: block; height: 100%; background: var(--brand); }
.clave { color: var(--danger); font-weight: 700; }
.compacto label { margin-top: 6px; }
.grid3.compacto { grid-template-columns: repeat(3, 1fr); }
.con-otro [data-otro] { margin-top: 6px; }
.aviso-dato { margin: 4px 0 0; padding: 6px 8px; border-radius: 8px; font-size: .85rem; color: var(--warn-text); background: var(--warn-bg); border-left: 3px solid var(--warn); }
.con-aviso select, .con-aviso input { border-color: var(--warn); }
.avisos-resumen { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--warn-bg); color: var(--warn-text); font-size: .9rem; }
.avisos-resumen summary { cursor: pointer; font-weight: 600; }
.avisos-resumen ul { margin: 6px 0 0; padding-left: 18px; }
.grid4.compacto { grid-template-columns: repeat(4, 1fr); }
.compacto label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Recuentos: apartados (Alumbrado, Fuerza, Telecomunicaciones, Cuadro…) */
.apartado + .apartado { margin-top: 12px; }
.apartado-titulo { padding: 6px 8px; border-radius: 8px; background: color-mix(in srgb, var(--brand) 18%, transparent); }

/* Recuentos por pasos: pestañas de estancia y de apartado */
.pestanas { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 0 4px; }
.pestana { flex: 0 0 auto; border: 1px solid var(--line); background: transparent; color: inherit; border-radius: 999px; padding: 8px 12px; font: inherit; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.pestana .num { display: inline-block; min-width: 1.4em; margin-left: 4px; padding: 0 5px; border-radius: 999px; background: var(--line); font-size: .8rem; text-align: center; }
.pestana.activa { background: var(--brand); border-color: var(--brand); color: var(--brand-text); font-weight: 600; }
.pestana.activa .num { background: rgba(0,0,0,.15); }
.paso { display: inline-grid; place-items: center; width: 1.4em; height: 1.4em; border-radius: 50%; background: var(--brand); color: var(--brand-text); font-size: .75rem; font-weight: 700; }
.contador button.pm.cinco { width: 48px; font-size: 1rem; background: color-mix(in srgb, var(--brand) 22%, var(--bg)); }

/* Aviso de versión nueva */
.actualizar { position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 60;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; max-width: 560px; margin: 0 auto;
  padding: 10px 12px; border-radius: 12px; background: var(--card, #fff); color: var(--text, #111);
  border: 2px solid var(--brand); box-shadow: 0 4px 16px rgba(0,0,0,.25); font-size: .95rem; }
.actualizar[hidden] { display: none; }
