/* Replanteo EM · estilo móvil-primero · colores corporativos Vibracom */
:root {
    --primary: #0056ac;        /* azul Vibracom (muestreado del logo oficial) */
    --primary-dark: #003d7d;
    --primary-light: #e6effa;
    --green: #2e7d32;          /* verde de éxito (pasos hechos, finalizados) */
    --green-dark: #1b5e20;
    --green-light: #e8f5e9;
    --amber: #f9a825;
    --blue: #0056ac;
    --red: #c62828;
    --bg: #f4f6f8;
    --card: #ffffff;
    --text: #1b2026;
    --muted: #6b7480;
    --border: #dde3ea;
    --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
    line-height: 1.45;
}

/* Barra superior */
.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--primary);
    color: #fff;
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top));
}
/* El logo oficial es azul sobre transparente: en la barra azul va dentro de una pastilla blanca */
.topbar .logo-chip {
    background: #fff;
    border-radius: 8px;
    padding: 4px 8px;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
}
.topbar .logo-chip img { height: 15px; width: auto; display: block; }
.topbar h1 {
    font-size: 18px;
    margin: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.topbar .back {
    color: #fff;
    text-decoration: none;
    font-size: 24px;
    line-height: 1;
    padding: 4px 8px;
    margin-left: -8px;
}
.topbar .logo { width: 28px; height: 28px; }
.admin-link {
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    border: 1px solid rgba(255,255,255,.5);
    border-radius: 20px;
    padding: 4px 12px;
}

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px 16px calc(40px + env(safe-area-inset-bottom));
}

/* Targetes */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 12px;
}
a.card { display: block; text-decoration: none; color: inherit; }
a.card:active { background: var(--primary-light); }
.info-card, .time-card { font-size: 15px; }
.time-card { display: flex; flex-wrap: wrap; gap: 4px 16px; }

.group-title {
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin: 20px 0 8px;
}
.group-title .count {
    background: var(--border);
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 12px;
}

.inst-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.inst-head strong { flex: 1; }
.inst-head h2 { margin: 0; font-size: 18px; }
.inst-loc { font-size: 14px; margin-top: 4px; }
.inst-meta { font-size: 13px; color: var(--muted); margin-top: 6px; }

/* Mapa d'instal·lacions */
.map-wrap {
    position: relative;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    margin-bottom: 14px;
    background: var(--card);
}
#map { height: 240px; }
.map-wrap.fullscreen {
    position: fixed;
    inset: 0;
    z-index: 40;
    border-radius: 0;
    border: none;
    margin: 0;
}
.map-wrap.fullscreen #map { height: 100%; }
.map-fs-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 1px 5px rgba(0,0,0,.35);
    font-size: 20px;
    cursor: pointer;
}
.map-legend {
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 1000;
    display: flex;
    gap: 10px;
    background: rgba(255,255,255,.92);
    border-radius: 10px;
    padding: 5px 10px;
    font-size: 12px;
}
.map-legend span { display: inline-flex; align-items: center; gap: 4px; }
.dot-mini {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.dot-pendent { background: var(--amber); }
.dot-en_curs { background: var(--blue); }
.dot-finalitzada { background: var(--green); }
/* Pin del mapa amb l'ordre de treball */
.pin {
    transform-origin: 50% 100%;
    filter: drop-shadow(0 2px 3px rgba(0,0,0,.4));
}
.pin-highlight { z-index: 1000 !important; }
.pin-highlight .pin {
    animation: pin-bounce .7s ease 3;
    filter: drop-shadow(0 3px 6px rgba(0,0,0,.5));
}
.pin-highlight .pin path { fill: var(--red); }
@keyframes pin-bounce {
    0%, 100% { transform: translateY(0) scale(1.15); }
    40%      { transform: translateY(-16px) scale(1.15); }
    60%      { transform: translateY(-16px) scale(1.15); }
}

/* Número d'ordre a les targetes i al popup */
.inst-num {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
}
.inst-num-pendent { background: var(--amber); }
.inst-num-en_curs { background: var(--blue); }

.map-popup { display: flex; flex-direction: column; gap: 6px; min-width: 180px; }
.map-popup .badge { align-self: flex-start; }
.map-popup-btns { display: flex; gap: 8px; margin-top: 2px; }
.map-popup-btns .btn { padding: 8px 12px; font-size: 14px; }
/* El CSS de Leaflet pinta els enllaços de blau; als botons del popup mana el color propi */
.leaflet-container .map-popup a.btn-primary { color: #fff; }
.leaflet-container .map-popup a.btn-secondary { color: var(--primary-dark); }

/* Filtres ràpids per estat */
.filter-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-bottom: 4px;
}
.filter-chips::-webkit-scrollbar { display: none; }
.chip {
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    border: 1.5px solid var(--border);
    border-radius: 20px;
    background: var(--card);
    color: var(--muted);
    padding: 7px 14px;
    white-space: nowrap;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.chip.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.chip-n { opacity: .75; font-weight: 400; }

/* Accions de la targeta («Al mapa», «Com arribar») */
.inst-card { cursor: pointer; }
.card-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.btn-route, .btn-showmap {
    padding: 9px 14px;
    font-size: 14px;
    align-self: flex-start;
}

/* Insígnies d'estat */
.badge {
    font-size: 12px;
    font-weight: 600;
    border-radius: 20px;
    padding: 3px 10px;
    white-space: nowrap;
}
.badge-pendent { background: #fff8e1; color: #8d6e00; }
.badge-en_curs { background: #e3f2fd; color: var(--blue); }
.badge-finalitzada { background: var(--green-light); color: var(--green-dark); }

/* Barra de progrés */
.sticky-progress {
    position: sticky;
    top: calc(48px + env(safe-area-inset-top));
    z-index: 15;
    background: var(--bg);
    padding: 10px 16px 6px;
    max-width: 640px;
    margin: 0 auto;
}
.progress {
    height: 10px;
    background: var(--border);
    border-radius: 6px;
    overflow: hidden;
    margin-top: 8px;
}
.sticky-progress .progress { margin-top: 0; }
.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 6px;
    transition: width .3s ease;
}
.progress-label { font-size: 13px; color: var(--muted); margin-top: 4px; text-align: center; }

/* Llista de tasques */
.tasks { list-style: none; margin: 0; padding: 0; }
.task {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 10px;
    overflow: hidden;
}
.task.done { background: var(--green-light); border-color: #c5e1c6; }
.task-main {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 16px;
}
/* Tic d'estat: s'encén sol quan tots els camps del pas estan omplerts */
.task-tick {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: 2px solid var(--border);
    color: transparent;
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .2s, border-color .2s;
}
.task.done .task-tick {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}
.task-num {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--border);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 1px;
}
.task.done .task-num { background: var(--green); color: #fff; }
.task-label { flex: 1; }
.task.done .task-label { color: var(--green-dark); }

.task-fields {
    border-top: 1px dashed var(--border);
    padding: 12px 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Camps */
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field-input, input[type=text], input[type=password], input[type=date], input[type=number], textarea, select {
    font: inherit;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    width: 100%;
}
.field-input:focus, input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); border-color: var(--primary); }
.gps-row { display: flex; gap: 8px; }
.gps-row .field-input { flex: 1; }

/* Llistes d'opcions (una opció o diverses) */
.opt-list {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.opt {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 12px;
    background: #fff;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.opt + .opt { border-top: 1px solid var(--border); }
.opt input {
    width: 22px;
    height: 22px;
    accent-color: var(--primary);
    flex-shrink: 0;
    margin: 0;
}
.opt:has(input:checked) { background: var(--primary-light); }
.opt span { font-size: 15px; }

/* Llistes Sí/No (una resposta per línia) */
.yn-list {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.yn-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    background: #fff;
}
.yn-item + .yn-item { border-top: 1px solid var(--border); }
.yn-text { font-size: 15px; flex: 1; }
.yn-btns { display: flex; gap: 6px; flex-shrink: 0; }
.yn-opt { position: relative; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.yn-opt input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.yn-opt span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 46px;
    padding: 7px 12px;
    border-radius: 20px;
    border: 1.5px solid var(--border);
    font-size: 14px;
    font-weight: 600;
    color: var(--muted);
    background: #fff;
}
.yn-opt input:checked + span {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}
.yn-opt.yn-no input:checked + span {
    background: var(--red);
    border-color: var(--red);
}

/* Botons */
.btn {
    font: inherit;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    padding: 12px 18px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    -webkit-tap-highlight-color: transparent;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-primary:disabled { background: #b3c2d4; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--primary-dark); border: 1.5px solid var(--primary); }
.btn-danger { background: #fff; color: var(--red); border: 1.5px solid var(--red); }
.btn-big { width: 100%; padding: 16px; font-size: 17px; margin-top: 8px; }

/* Notes de veu */
.audio-box { display: flex; flex-direction: column; gap: 8px; }
.audio-list { display: flex; flex-direction: column; gap: 6px; }
.audio-list audio, .audio-player { width: 100%; max-width: 360px; display: block; margin-top: 4px; }
.audio-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.rec-btn.recording {
    color: var(--red);
    border-color: var(--red);
    animation: rec-pulse 1.2s ease infinite;
}
@keyframes rec-pulse {
    0%, 100% { background: #fff; }
    50%      { background: #ffebee; }
}

/* Fotos */
.photo-box { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.photo-thumb { max-width: 100%; max-height: 260px; border-radius: 10px; border: 1px solid var(--border); }
.photo-thumb-small { max-height: 90px; border-radius: 8px; vertical-align: middle; }

/* Parts del muntatge (una pantalla per part) */
body.has-stepnav .container {
    padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
.step-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 0 14px;
}
.step-icon { font-size: 32px; line-height: 1; }
.step-head > div { flex: 1; }
.step-part {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}
.step-title { margin: 2px 0 0; font-size: 20px; }
.step-count {
    font-size: 13px;
    font-weight: 700;
    background: var(--border);
    color: var(--muted);
    border-radius: 20px;
    padding: 4px 12px;
    white-space: nowrap;
}

/* Barra de navegació entre parts */
.stepnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 640px;
    margin: 0 auto;
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.stepnav-btn { min-width: 108px; padding: 12px 10px; }
.stepnav-btn:disabled { opacity: .4; cursor: not-allowed; }
.stepnav-dots {
    flex: 1;
    display: flex;
    justify-content: center;
    gap: 7px;
    flex-wrap: wrap;
}
.dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: none;
    padding: 0;
    background: var(--border);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.dot.complete { background: #8cb4dc; }
.dot.active {
    background: var(--primary);
    transform: scale(1.35);
}
.dot:disabled { cursor: default; opacity: .55; }

/* Fotos de referència del pas */
.ref-photos { padding: 0 16px 12px; }
.ref-photos-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 6px;
}
.ref-strip {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.ref-strip::-webkit-scrollbar { display: none; }
.ref-thumb {
    height: 110px;
    border-radius: 10px;
    border: 1px solid var(--border);
    flex-shrink: 0;
    cursor: zoom-in;
}

/* Visor de foto ampliada */
.lightbox[hidden] { display: none; }
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 60;
    background: rgba(10, 15, 10, .92);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    cursor: zoom-out;
}
.lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 10px;
}
.lightbox-close {
    position: absolute;
    top: calc(12px + env(safe-area-inset-top));
    right: 16px;
    background: rgba(255,255,255,.15);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 18px;
    cursor: pointer;
}
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,.18);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 46px;
    height: 46px;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    padding: 0 0 4px;
}
.lightbox-prev { left: 10px; }
.lightbox-next { right: 10px; }
.lightbox-counter {
    position: absolute;
    bottom: calc(16px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    background: rgba(0,0,0,.45);
    border-radius: 12px;
    padding: 4px 12px;
}

/* Zona de finalització */
.finish-zone { margin-top: 20px; }
.finished-card { text-align: center; background: var(--green-light); border-color: #c5e1c6; }

/* Pantalla d'inici (overlay) */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 30, 20, .55);
    backdrop-filter: blur(3px);
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.overlay-card {
    background: #fff;
    border-radius: 18px;
    padding: 24px 20px;
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.overlay-card h2 { margin: 0; text-align: center; }
.logo-big { width: 56px; height: 56px; margin: 0 auto; }
.overlay[hidden] { display: none; }
.overlay-card { max-height: 85vh; overflow-y: auto; }

/* Passos de la guia per desbloquejar la ubicació */
.gps-steps {
    margin: 0;
    padding-left: 22px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 15px;
}

/* Admin */
.import-example {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 12px;
    overflow-x: auto;
    margin: 10px 0;
}
input[type=file] {
    font: inherit;
    padding: 10px;
    border: 1px dashed var(--border);
    border-radius: 10px;
    background: #fff;
    width: 100%;
}
.admin-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.danger-zone {
    margin-top: 28px;
    padding-top: 16px;
    border-top: 1px dashed var(--border);
    display: flex;
    justify-content: center;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table td { padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.admin-table tr:last-child td { border-bottom: none; }
.col-check { width: 30px; font-size: 16px; }
.data-line { font-size: 13px; color: var(--muted); margin-top: 3px; }
.data-line a { color: var(--blue); }

/* Diversos */
.muted { color: var(--muted); font-size: 14px; }
.center { text-align: center; }
.error { color: var(--red); font-weight: 600; }
.empty {
    text-align: center;
    color: var(--muted);
    padding: 40px 16px;
}
.empty a { color: var(--primary-dark); }

/* Toast */
#toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(20px);
    background: #263226;
    color: #fff;
    padding: 12px 18px;
    border-radius: 12px;
    font-size: 15px;
    max-width: 90vw;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    z-index: 100;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
