/* GesGat Lite — Estils principals */

:root {
    --color-primari:    #6b7c2e;
    --color-primari-f:  #556324;
    --color-perill:     #dc2626;
    --color-ok:         #16a34a;
    --color-avis:       #d97706;
    --color-info:       #0891b2;
    --color-fons:       #f8fafc;
    --color-superficia: #ffffff;
    --color-vora:       #e2e8f0;
    --color-text:       #1e293b;
    --color-text-suau:  #64748b;
    --font:             'Segoe UI', system-ui, sans-serif;
    --radi:             6px;
    --ombra:            0 1px 3px rgba(0,0,0,.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--font);
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-fons);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.hidden { display: none !important; }

/* ── Login ── */
#pantalla-login {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: linear-gradient(135deg, #2c3a10 0%, #6b7c2e 100%);
}
.login-caixa {
    background: white;
    border-radius: 12px;
    padding: 2.5rem 2rem;
    width: 360px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.login-caixa h1 { font-size: 1.5rem; color: var(--color-primari); margin-bottom: .25rem; font-weight: 700; }
.login-caixa p  { color: var(--color-text-suau); margin-bottom: 1.5rem; font-size: .9rem; }

/* ── App shell ── */
#pantalla-app { display: flex; flex-direction: column; height: 100vh; }

/* ── Capçalera ── */
.capçalera {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .4rem 1rem;
    background: var(--color-primari);
    color: white;
    flex-shrink: 0;
}
.capçalera h1 { font-size: 1rem; font-weight: 700; white-space: nowrap; }
.info-usuari {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.3;
}
.info-ajuntament { font-size: .8rem; font-weight: 600; opacity: .95; }
.info-nom-usuari  { font-size: .75rem; opacity: .75; }
.separador-cap { flex: 1; }
.capçalera select {
    font-size: .85rem;
    padding: .25rem .4rem;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    width: auto;
}
.btn-logout { background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.3); color: white; padding: .3rem .75rem; border-radius: var(--radi); cursor: pointer; font-size: .85rem; white-space: nowrap; }
.btn-logout:hover { background: rgba(255,255,255,.25); }
.btn-pwd { padding: .3rem .45rem; }

/* ── Cos: nav lateral + contingut ── */
.cos-app { display: flex; flex: 1; overflow: hidden; }

/* ── Nav lateral ── */
.nav-lateral {
    width: 180px;
    background: var(--color-superficia);
    border-right: 1px solid var(--color-vora);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}
.nav-logos {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: .5rem;
    padding: .85rem .75rem .75rem;
    border-bottom: 1px solid var(--color-vora);
}
.nav-logos .logo-meitat {
    max-width: 68px;
    max-height: 52px;
    width: auto;
    height: auto;
    object-fit: contain;
}
.btn-llicencia-lite {
    display: block;
    width: 100%;
    text-align: center;
    font-size: .72rem;
    padding: .3rem .5rem;
    background: #f8fafc;
    border: none;
    border-bottom: 1px solid var(--color-vora);
    color: var(--color-text-suau);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.btn-llicencia-lite:hover { background: #f1f5f9; }
.nav-btn {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .65rem 1rem;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--color-text);
    font-size: .9rem;
    text-align: left;
    border-left: 3px solid transparent;
    transition: background .15s;
}
.nav-btn:hover  { background: #f1f5f9; }
.nav-btn.actiu  { background: #f3f5ec; color: var(--color-primari); border-left-color: var(--color-primari); font-weight: 600; }
.nav-icona { width: 1.25rem; height: 1.25rem; flex-shrink: 0; }

/* ── Contingut principal ── */
.contingut { flex: 1; overflow-y: auto; padding: 1.25rem; }

/* ── Capçalera de mòdul ── */
.modul-header {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: 1rem;
}
.modul-header h2 { font-size: 1.2rem; white-space: nowrap; margin-right: .4rem; flex-shrink: 0; }
.modul-filtres { display: contents; }
/* Evita que input/select s'expandeixin a width:100% dins el header */
.modul-header input[type=text],
.modul-header input[type=date],
.modul-header select { width: auto; min-width: 130px; flex-shrink: 1; }
/* TomSelect dins el header del mòdul */
.modul-header .ts-wrapper { width: auto; min-width: 130px; flex-shrink: 1; }

/* Checkbox de filtre (inline, al header del mòdul) */
.check-filtre {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .875rem;
    cursor: pointer;
    white-space: nowrap;
    color: var(--color-text);
}
.check-filtre input[type=checkbox] {
    width: auto;
    cursor: pointer;
    accent-color: var(--color-primari);
}

/* ── Formularis ── */
.form-grup { margin-bottom: 1rem; }
.form-grup label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .3rem; color: var(--color-text-suau); }
input[type=text], input[type=email], input[type=password], input[type=date],
input[type=number], select, textarea {
    width: 100%;
    padding: .5rem .75rem;
    border: 1px solid var(--color-vora);
    border-radius: var(--radi);
    font-size: .9rem;
    font-family: var(--font);
    background: white;
    color: var(--color-text);
    transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primari);
    box-shadow: 0 0 0 2px rgba(107,124,46,.15);
}
textarea { min-height: 80px; resize: vertical; }

/* ── Botons ── */
.btn, button[type=submit], button[type=button]:not(.btn-geo):not(.btn-tancar):not(.btn-llicencia-lite) {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem 1rem;
    border: none;
    border-radius: var(--radi);
    cursor: pointer;
    font-size: .875rem;
    font-family: var(--font);
    font-weight: 500;
    transition: background .15s;
    background: var(--color-primari);
    color: white;
}
.btn:hover, button[type=submit]:hover, button[type=button]:not(.btn-geo):not(.btn-tancar):not(.btn-llicencia-lite):hover { background: var(--color-primari-f); }
.btn-secundari, button[type=button].btn-secundari {
    background: var(--color-superficia);
    color: var(--color-text);
    border: 1px solid var(--color-vora);
}
.btn-secundari:hover, button[type=button].btn-secundari:hover { background: #f1f5f9; }
.btn-perill { background: var(--color-perill); }
.btn-perill:hover { background: #b91c1c; }
.btn-taula { background: #f1f5f9; color: var(--color-text); border: 1px solid var(--color-vora); padding: .25rem .6rem; font-size: .8rem; border-radius: 4px; }
.btn-taula:hover { background: #e2e8f0; }
.btn-taula.btn-perill { background: #fee2e2; color: var(--color-perill); border-color: #fecaca; }
.btn-taula.btn-perill:hover { background: #fecaca; }

/* ── Taules ── */
.taula-contenidor { background: white; border-radius: var(--radi); border: 1px solid var(--color-vora); overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
thead { background: #f8fafc; }
th { padding: .6rem 1rem; text-align: left; font-size: .8rem; font-weight: 600; color: var(--color-text-suau); text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--color-vora); }
td { padding: .65rem 1rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }
.accions { white-space: nowrap; display: flex; gap: .3rem; }
.buit { text-align: center; color: var(--color-text-suau); padding: 2rem !important; }
.taula-peu { padding: .5rem 1rem; font-size: .85rem; color: var(--color-text-suau); border-top: 1px solid var(--color-vora); background: #f8fafc; }
.taula-peu-pag { display: flex; justify-content: space-between; align-items: center; }
.pag-botons { display: flex; gap: .3rem; }

/* ── Badges ── */
.badge { display: inline-block; padding: .2rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-activa,  .badge-actiu  { background: #dcfce7; color: #166534; }
.badge-inactiva { background: #fef9c3; color: #854d0e; }
.badge-arxivada, .badge-arxivat { background: #f1f5f9; color: #64748b; }
.badge-mort     { background: #fee2e2; color: #991b1b; }
.badge-adoptat  { background: #dbeafe; color: #1e40af; }

/* ── Modals ── */
.modal-fons {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    display: flex; align-items: center; justify-content: center;
    z-index: 1100; padding: 1rem;
}
.modal-caixa {
    background: white; border-radius: 10px; padding: 1.5rem;
    width: 100%; max-width: 520px; max-height: 90vh;
    overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,.2);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.modal-header h3 { font-size: 1.1rem; }
/* Només el botó × (sense classe .btn) rep la tipografia gran */
.btn-tancar:not(.btn) { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--color-text-suau); padding: 0 .25rem; }
.btn-tancar:not(.btn):hover { color: var(--color-text); }
.modal-accions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; padding-top: 1rem; border-top: 1px solid var(--color-vora); }

/* ── Fotos ── */
.foto-miniatura { width: 40px; height: 40px; object-fit: cover; border-radius: 50%; }
.foto-preview { max-width: 200px; max-height: 150px; border-radius: var(--radi); object-fit: cover; margin-top: .5rem; }

/* ── Incidències — badges d'estat ── */
.badge-inc-oberta    { background: #fee2e2; color: #991b1b; }
.badge-inc-en_proces { background: #fef9c3; color: #854d0e; }
.badge-inc-resolta   { background: #dcfce7; color: #166534; }
.badge-inc-arxivada  { background: #f1f5f9; color: #64748b; }

/* ── Voluntaris — checkboxes de colònies ── */
.colonies-checkbox-list {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    max-height: 160px;
    overflow-y: auto;
    border: 1px solid var(--color-vora);
    border-radius: var(--radi);
    padding: .5rem .75rem;
    background: #f8fafc;
}
.checkbox-colonia {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .875rem;
    cursor: pointer;
    padding: .15rem 0;
}
.checkbox-colonia input[type=checkbox] { width: auto; cursor: pointer; }

.text-suau { color: var(--color-text-suau); font-size: .85rem; }

/* ── Semàfor CER ── */
.badge-cer {
    display: inline-block;
    padding: .15rem .45rem;
    border-radius: 99px;
    font-size: .75rem;
    font-weight: 700;
    color: white;
}
.badge-cer-buit { background: #e2e8f0; color: var(--color-text-suau); }

/* ── Configuració: tabs ── */
.conf-tabs-header {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--color-vora);
    margin-bottom: 1.25rem;
}
.conf-tab-btn {
    padding: .6rem 1.25rem;
    border: none;
    background: none;
    font-size: .9rem;
    font-weight: 500;
    color: var(--color-text-suau);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    border-radius: 0;
}
.conf-tab-btn:hover  { color: var(--color-text); background: #f8fafc; }
.conf-tab-btn.actiu  { color: var(--color-primari); border-bottom-color: var(--color-primari); font-weight: 600; }
.conf-tab-contingut  { /* visible per defecte */ }

.conf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.25rem;
}
.conf-bloc {
    background: white;
    border: 1px solid var(--color-vora);
    border-radius: var(--radi);
    padding: 1.25rem;
}
.conf-bloc h3 { font-size: .95rem; margin-bottom: 1rem; color: var(--color-text); }
.conf-check-label {
    display: flex;
    align-items: flex-start;
    gap: .5rem;
    font-size: .9rem;
    cursor: pointer;
    line-height: 1.4;
}
.conf-check-label input[type=checkbox] {
    width: auto;
    margin-top: .15rem;
    flex-shrink: 0;
    cursor: pointer;
    accent-color: var(--color-primari);
}
.conf-logo-preview {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--color-vora);
    border-radius: var(--radi);
    padding: .5rem;
    margin-bottom: .4rem;
}

/* ── Pantalla bloqueig ── */
.bloqueig-caixa {
    background: white;
    border-radius: 12px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 480px;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0,0,0,.3);
}
.bloqueig-caixa h2 { color: var(--color-perill); margin-bottom: 1rem; }
.bloqueig-caixa p  { color: #444; margin-bottom: 1rem; }
.bloqueig-caixa textarea {
    width: 100%; margin-bottom: .75rem;
    font-family: monospace; font-size: .85rem;
}
.bloqueig-caixa button { width: 100%; margin-bottom: .5rem; }
.btn-link { background: none !important; color: var(--color-text-suau) !important; text-decoration: underline; font-size: .85rem; }

/* ── Mapa ── */
#mapa-leaflet { height: calc(100vh - 140px); border-radius: var(--radi); }

.btn-popup {
    margin-top: .4rem; padding: .3rem .65rem;
    background: var(--color-primari); color: white;
    border: none; border-radius: 4px; cursor: pointer; font-size: .8rem;
}
.btn-popup-perill { background: #ef4444; }
.btn-popup-perill:hover { background: #dc2626; }

/* Botó de geolocalització als formularis */
/* button.btn-geo té més especificitat que button[type=button] */
button.btn-geo {
    width: 34px; height: 34px; flex-shrink: 0;
    background: white; color: #555;
    border: 1px solid var(--color-vora);
    border-radius: var(--radi); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background .15s;
}
button.btn-geo:hover { background: #f0fdf4; border-color: var(--color-primari); }

/* Botó de geolocalització al mapa Leaflet */
.mapa-btn-geo {
    width: 34px !important; height: 34px !important;
    display: flex !important; align-items: center; justify-content: center;
    cursor: pointer; background: white;
}
.mapa-btn-geo:hover { background: #f0fdf4 !important; }

/* Llegenda del mapa */
.mapa-llegenda {
    background: white;
    border-radius: var(--radi);
    padding: .6rem .75rem;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    border: 1px solid var(--color-vora);
    min-width: 170px;
    font-size: .82rem;
    color: var(--color-text);
}
.mapa-llegenda-cap {
    display: flex; justify-content: space-between; align-items: center;
    cursor: pointer; gap: .75rem;
}
.mapa-llegenda-cap:hover { opacity: .8; }
.llegenda-subtitol {
    font-size: .75rem; font-weight: 600; color: var(--color-text-suau);
    text-transform: uppercase; letter-spacing: .03em; margin-bottom: 5px;
}
.llegenda-fila {
    display: flex; align-items: center; gap: 6px;
    margin-bottom: 4px; font-size: .82rem;
}
.llegenda-icona     { width: 20px; height: 20px; flex-shrink: 0; }
.llegenda-icona-sm  { width: 16px; height: 16px; flex-shrink: 0; }

/* ── Informes ── */
.inf-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.inf-kpi-card { background: white; border-radius: 10px; padding: 1.1rem 1.25rem; border: 1px solid var(--color-vora); display: flex; align-items: center; gap: 1rem; box-shadow: var(--ombra); }
.inf-kpi-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: white; flex-shrink: 0; padding: 8px; }
.inf-kpi-label { margin: 0; font-size: .78rem; color: var(--color-text-suau); text-transform: uppercase; letter-spacing: .4px; }
.inf-kpi-valor { margin: 4px 0 0; font-size: 1.75rem; font-weight: 700; color: var(--color-text); }
.inf-seccio { background: white; border-radius: 10px; padding: 1.25rem 1.5rem; border: 1px solid var(--color-vora); margin-bottom: 1.25rem; box-shadow: var(--ombra); }
.inf-seccio h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 1rem; color: var(--color-primari); border-bottom: 2px solid #f1f5f9; padding-bottom: .6rem; font-size: 1rem; }
.inf-seccio h3 svg { width: 20px; height: 20px; flex-shrink: 0; }
.inf-grup-titol { color: var(--color-text-suau); margin: 0 0 .75rem; border-bottom: 1px dashed var(--color-vora); padding-bottom: .4rem; font-size: .875rem; text-transform: uppercase; letter-spacing: .4px; }
.inf-accions { display: flex; flex-direction: column; gap: .5rem; }
.inf-btn-accio { background: #f8fafc; border: 1px solid var(--color-vora); padding: .65rem .9rem; border-radius: var(--radi); text-align: left; cursor: pointer; transition: all .15s; display: flex; align-items: center; gap: .75rem; color: var(--color-text); font-size: .875rem; font-weight: 500; width: 100%; }
.inf-btn-accio svg { width: 18px; height: 18px; flex-shrink: 0; }
.inf-btn-accio:hover { background: var(--color-primari); color: white; border-color: var(--color-primari); }
.inf-btn-accio:hover span { color: white !important; }
.inf-toolbar { display: flex; justify-content: space-between; background: white; padding: .75rem 1rem; border-radius: var(--radi); box-shadow: var(--ombra); margin-bottom: 1.25rem; border: 1px solid var(--color-vora); position: sticky; top: 0; z-index: 10; }
.inf-full-a4 { background: white; max-width: 900px; margin: 0 auto; padding: 2.5rem; box-shadow: 0 4px 20px rgba(0,0,0,.1); border-radius: 4px; min-height: 60vh; }
@media print {
    body > *:not(#pantalla-informes) { display: none !important; }
    #pantalla-informes { display: block !important; overflow: visible !important; }
    #inf-dashboard, .inf-toolbar, .nav-lateral, .capçalera { display: none !important; }
    .inf-full-a4 { box-shadow: none; max-width: 100%; padding: 0; margin: 0; }
}

/* ── Toasts ── */
#toast-contenidor { position: fixed; top: 1rem; right: 1rem; z-index: 9999; display: flex; flex-direction: column; gap: .5rem; }
.toast {
    padding: .75rem 1.1rem; border-radius: var(--radi);
    font-size: .875rem; font-weight: 500; max-width: 360px;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    opacity: 0; transform: translateX(20px);
    transition: opacity .25s, transform .25s;
}
.toast-visible { opacity: 1; transform: translateX(0); }
.toast-ok    { background: #dcfce7; color: #166534; border-left: 4px solid var(--color-ok); }
.toast-error { background: #fee2e2; color: #991b1b; border-left: 4px solid var(--color-perill); }
.toast-avis  { background: #fef9c3; color: #854d0e; border-left: 4px solid var(--color-avis); }
.toast-info  { background: #e0f2fe; color: #0c4a6e; border-left: 4px solid var(--color-info); }

/* ── TomSelect — adaptat al color primari ── */
.ts-control, .ts-dropdown {
    border-color: var(--color-vora) !important;
    border-radius: var(--radi) !important;
    font-family: var(--font) !important;
    font-size: .9rem !important;
}
.ts-wrapper.focus .ts-control {
    border-color: var(--color-primari) !important;
    box-shadow: 0 0 0 2px rgba(107,124,46,.15) !important;
    outline: none !important;
}
.ts-dropdown-content .option.selected,
.ts-dropdown-content .option:hover,
.ts-dropdown-content .option.active {
    background: var(--verde-fondo) !important;
    color: var(--color-primari) !important;
}
.ts-dropdown { box-shadow: 0 4px 12px rgba(0,0,0,.1) !important; }
.ts-control { min-height: 36px !important; }

/* ══════════════════ MÒBIL ══════════════════ */
@media (max-width: 700px) {

    /* Capçalera — compactar */
    .capçalera { padding: .3rem .6rem; gap: .5rem; }
    .capçalera h1 { font-size: .85rem; }
    .info-usuari { display: none; }   /* Nom ajuntament/usuari ocult en mòbil */
    .capçalera select { min-width: 44px; font-size: .78rem; padding: .2rem; }
    .btn-logout { padding: .25rem .5rem; font-size: .78rem; }

    /* Nav lateral — només icones */
    .nav-lateral { width: 48px; }
    .nav-logos { padding: .4rem .2rem; }
    .nav-logos .logo-meitat { max-width: 32px; max-height: 28px; }
    .btn-llicencia-lite { font-size: .6rem; padding: .15rem; }
    .nav-btn { padding: .55rem 0; justify-content: center; }
    .nav-btn .nav-label { display: none; }
    .nav-icona { width: 1.15rem; height: 1.15rem; }

    /* Contingut — ocupar tot l'ample restant */
    .contingut { padding: .75rem .5rem; }

    /* Capçalera mòdul — scroll horitzontal si no hi cap */
    .modul-header { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: .25rem; }
    .modul-header h2 { font-size: 1rem; }
    .modul-header input[type=text],
    .modul-header input[type=date],
    .modul-header select { min-width: 100px; }

    /* Pestanyes configuració — scroll horitzontal */
    .conf-tabs-header { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .conf-tab-btn { white-space: nowrap; font-size: .82rem; padding: .55rem .9rem; }

    /* Taules — scroll horitzontal ja aplicat a .taula-contenidor */
    table { min-width: 500px; }  /* Força scroll en taules amples */

    /* Formularis de 2 columnes → 1 columna */
    [style*="grid-template-columns:1fr 1fr"],
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    /* Modals — ocupar quasi tota la pantalla */
    .modal-caixa { padding: 1rem; max-height: 92vh; max-width: 100%; border-radius: 10px 10px 0 0; }
    .modal-fons { align-items: flex-end; }

    /* Mapa */
    #mapa-leaflet { height: calc(100vh - 160px); border-radius: 0; }

    /* Gràfic configuració */
    .conf-grid { grid-template-columns: 1fr; }

    /* Toasts — ample complet en mòbil */
    #toast-contenidor { left: .5rem; right: .5rem; }
    .toast { max-width: 100%; }
}

@media (max-width: 400px) {
    .nav-lateral { width: 40px; }
    .nav-btn { padding: .45rem 0; }
}
