/* =========================================================
   Concurs FP/001/2026 · Cercador de places
   Estils generals (escriptori i mòbil)
   ========================================================= */
:root {
  --blau: #17345c;
  --blau-2: #24508c;
  --blau-clar: #e8eef7;
  --corall: #ff7a59;
  --verd: #1f8a5b;
  --vermell: #c62828;
  --vermell-clar: #fde8e8;
  --groc-clar: #fff6db;
  --gris: #5c6573;
  --gris-clar: #f3f5f8;
  --vora: #d9dee6;
  --text: #1b2330;
  --fons: #f6f8fb;
  --radi: 12px;
  --ombra: 0 2px 10px rgba(23, 52, 92, .08);
  --alt-capcalera: 108px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--fons);
}
a { color: var(--blau-2); }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; color: var(--blau); }
h3 { margin: 0 0 .5rem; }
.amagat { display: none !important; }
.nota { font-size: .85rem; color: var(--gris); margin: .4rem 0; }

/* ---------- Capçalera i menú ---------- */
.capcalera {
  position: sticky; top: 0; z-index: 50;
  background: var(--blau); color: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  padding-top: env(safe-area-inset-top);
}
.capcalera-int {
  max-width: 1600px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: .55rem 1rem; gap: 1rem;
}
.titol { display: flex; align-items: center; gap: .6rem; }
.titol img { border-radius: 8px; }
.titol strong { display: block; font-size: 1.05rem; }
.titol span { display: block; font-size: .8rem; opacity: .8; }
.menu {
  max-width: 1600px; margin: 0 auto;
  display: flex; gap: .25rem; padding: 0 .75rem;
}
.tab {
  appearance: none; border: 0; background: transparent; color: #cfdaf0;
  font: inherit; font-weight: 600; padding: .6rem 1rem; cursor: pointer;
  border-bottom: 3px solid transparent; display: flex; align-items: center; gap: .4rem;
}
.tab:hover { color: #fff; }
.tab.actiu { color: #fff; border-bottom-color: var(--corall); }
.badge {
  display: inline-block; min-width: 1.5em; padding: 0 .4em; border-radius: 999px;
  background: var(--corall); color: #fff; font-size: .75rem; text-align: center; margin-left: .2rem;
}

main { max-width: 1600px; margin: 0 auto; padding: 1rem; }
.panell { display: none; }
.panell.actiu { display: block; }

/* ---------- Botons ---------- */
.btn {
  appearance: none; border: 1px solid var(--blau-2); background: var(--blau-2); color: #fff;
  font: inherit; font-weight: 600; padding: .5rem .9rem; border-radius: 8px; cursor: pointer;
  display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap;
  text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn-clar { background: #fff; color: var(--blau-2); }
.capcalera .btn-clar { border-color: #fff; }
.btn-perill { background: #fff; color: var(--vermell); border-color: var(--vermell); }
.btn-petit { padding: .3rem .65rem; font-size: .85rem; }

/* ---------- Targetes / informació ---------- */
.avis {
  background: var(--groc-clar); border: 1px solid #f1d27a; border-radius: var(--radi);
  padding: .75rem 1rem; margin-bottom: 1rem;
}
.avis.petit { font-size: .9rem; }
.graella-info { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; }
.targeta {
  background: #fff; border: 1px solid var(--vora); border-radius: var(--radi);
  padding: 1rem 1.1rem; box-shadow: var(--ombra);
}
.targeta ul, .targeta ol { padding-left: 1.2rem; margin: .3rem 0; }
.targeta li { margin: .25rem 0; }
.targeta.destacada { border-left: 5px solid var(--corall); }
.linia-temps { list-style: none; padding: 0 !important; }
.linia-temps li { display: grid; grid-template-columns: 9.5rem 1fr; gap: .6rem; padding: .35rem 0; border-bottom: 1px dashed var(--vora); }
.linia-temps .data { font-weight: 700; color: var(--blau); }
.llegenda { display: grid; grid-template-columns: 4.5rem 1fr; gap: .3rem .6rem; margin: 0; }
.llegenda dt { font-weight: 700; color: var(--blau); }
.llegenda dd { margin: 0; }

.xip {
  display: inline-block; font-size: .7rem; font-weight: 700; padding: .05rem .4rem;
  border-radius: 6px; line-height: 1.4; vertical-align: middle; letter-spacing: .02em;
}
.xip-v { background: #dff3e8; color: var(--verd); }
.xip-r { background: #fdebd6; color: #a35200; }
.xip-a4 { background: #efe3fb; color: #6a2ca0; }
.xip-atc { background: #e2ecfb; color: var(--blau-2); }
.xip-ds { background: var(--vermell-clar); color: var(--vermell); }

/* ---------- Mèrits ---------- */
.merits-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1rem; align-items: start; }
.taula-scroll { overflow-x: auto; }
.barem { width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radi); overflow: hidden; box-shadow: var(--ombra); }
.barem th, .barem td { padding: .5rem .7rem; border-bottom: 1px solid var(--vora); text-align: left; vertical-align: top; }
.barem thead th { background: var(--blau); color: #fff; }
.barem .grup td { background: var(--blau-clar); font-weight: 700; color: var(--blau); }
.barem .expl td { font-size: .85rem; color: var(--gris); background: #fbfcfe; }
.barem .max { text-align: center; font-weight: 700; color: var(--blau); vertical-align: middle; }
.barem tfoot td { font-weight: 700; background: var(--blau); color: #fff; }
.barem tfoot .max { color: #fff; }

.calculadora { position: sticky; top: calc(var(--alt-capcalera) + 1rem); max-height: calc(100vh - var(--alt-capcalera) - 2rem); overflow-y: auto; }
.calculadora fieldset { border: 1px solid var(--vora); border-radius: 10px; margin: 0 0 .7rem; padding: .5rem .75rem .7rem; }
.calculadora legend { font-weight: 700; color: var(--blau); padding: 0 .3rem; display: flex; gap: .5rem; align-items: center; }
.calculadora .sub { background: var(--blau-clar); border-radius: 999px; padding: 0 .55rem; font-size: .85rem; }
.calculadora label { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin: .35rem 0; font-size: .9rem; }
.calculadora label.check { justify-content: flex-start; }
.calculadora input[type=number], .calculadora input[type=text], .calculadora select {
  font: inherit; padding: .3rem .45rem; border: 1px solid var(--vora); border-radius: 6px; background: #fff; max-width: 60%;
}
.calculadora input[type=number] { width: 6rem; text-align: right; }
.curs { display: grid; grid-template-columns: 1fr 5.5rem 2rem; grid-template-areas: "nom nom nom" "hores tipus treu"; gap: .3rem; margin-bottom: .5rem; padding-bottom: .5rem; border-bottom: 1px dashed var(--vora); align-items: center; }
.curs [data-curs="n"] { grid-area: nom; }
.curs [data-curs="h"] { grid-area: tipus; }
.curs [data-curs="t"] { grid-area: hores; }
.curs button { grid-area: treu; }
.calculadora .curs input, .calculadora .curs select { font: inherit; font-size: .88rem; padding: .3rem .4rem; border: 1px solid var(--vora); border-radius: 6px; min-width: 0; width: 100%; max-width: none; text-align: left; }
.curs button { border: 0; background: transparent; color: var(--vermell); cursor: pointer; font-size: 1rem; }
.total { border-top: 2px solid var(--blau); padding-top: .6rem; }
.total div { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.total-gran { font-size: 1.25rem; color: var(--blau); margin-top: .3rem; }
.total-gran b { font-size: 1.6rem; color: var(--corall); }

/* ---------- Cercador ---------- */
.cercador {
  position: sticky; top: var(--alt-capcalera); z-index: 20; background: var(--fons);
  padding: .25rem 0 .5rem;
}
.cerca-caixa { position: relative; }
.cerca-caixa .lupa { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); font-size: 1.1rem; }
#cerca {
  width: 100%; font: inherit; font-size: 1.1rem; padding: .85rem 2.8rem .85rem 2.7rem;
  border: 2px solid var(--blau-2); border-radius: 12px; background: #fff; box-shadow: var(--ombra);
}
#cerca:focus { outline: 3px solid rgba(255,122,89,.35); }
#cerca::-webkit-search-cancel-button { display: none; }
.cerca-x {
  border: 0; background: transparent; cursor: pointer; font-size: 1.05rem; color: var(--gris);
  padding: .3rem .5rem;
}
.cerca-caixa .cerca-x { position: absolute; right: .5rem; top: 50%; transform: translateY(-50%); }
.cerca-opcions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .55rem; }
.segment { display: inline-flex; border: 1px solid var(--blau-2); border-radius: 8px; overflow: hidden; }
.segment button { border: 0; background: #fff; color: var(--blau-2); font: inherit; font-weight: 600; padding: .35rem .8rem; cursor: pointer; font-size: .9rem; }
.segment button + button { border-left: 1px solid var(--blau-2); }
.segment button.actiu { background: var(--blau-2); color: #fff; }
.xips-filtres { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.xips-filtres:empty { display: none; }
.xip-filtre {
  background: var(--blau-clar); color: var(--blau); border: 1px solid #c9d6ea; border-radius: 999px;
  padding: .15rem .3rem .15rem .7rem; font-size: .82rem; display: inline-flex; align-items: center; gap: .25rem; max-width: 100%;
}
.xip-filtre span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60vw; }
.xip-filtre button { border: 0; background: transparent; cursor: pointer; color: var(--blau); font-weight: 700; }
.resum { font-size: .9rem; color: var(--gris); margin-top: .45rem; }
.resum b { color: var(--text); }
.filtres-mobil { display: none; }
.mobil-only { display: none; }

/* ---------- Taula de places ---------- */
.taula-places-wrap { background: #fff; border: 1px solid var(--vora); border-radius: var(--radi); box-shadow: var(--ombra); overflow: auto; max-height: calc(100vh - var(--alt-capcalera) - 190px); }
.taula-tria + * , #tab-tria .taula-places-wrap { max-height: none; }
.taula-places { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .85rem; }
.taula-places th, .taula-places td { padding: .4rem .5rem; border-bottom: 1px solid var(--vora); text-align: left; vertical-align: top; }
.taula-places thead th {
  position: sticky; top: 0; z-index: 3; background: var(--blau); color: #fff; white-space: nowrap; font-weight: 600;
}
.th-int { display: flex; align-items: center; gap: .25rem; }
.th-ordena { cursor: pointer; user-select: none; }
.th-ordena .fletxa { opacity: .6; font-size: .75rem; }
.btn-filtre {
  border: 1px solid rgba(255,255,255,.4); background: transparent; color: #fff; border-radius: 5px;
  cursor: pointer; font-size: .7rem; padding: 0 .3rem; line-height: 1.5;
}
.btn-filtre.actiu { background: var(--corall); border-color: var(--corall); }
.taula-places tbody tr:nth-child(even) td { background: #fafbfd; }
.taula-places tbody tr:hover td { background: #eef4ff; }
.taula-places tbody tr.triada td { background: #fff8e6; }
.taula-places tbody tr.duplicada td { background: var(--vermell-clar); }
.col-ordre { position: sticky; right: 0; z-index: 2; background: inherit; box-shadow: -3px 0 6px rgba(0,0,0,.06); text-align: center !important; }
.taula-places thead th.col-ordre { z-index: 4; background: var(--corall); }
.taula-places tbody td.col-ordre { background: #fff; }
.taula-places tbody tr.triada td.col-ordre { background: #fff1c9; }
.taula-places tbody tr.duplicada td.col-ordre { background: #f9cfcf; }
.c-placa { white-space: nowrap; font-weight: 700; }
.c-num { text-align: right; white-space: nowrap; }
.c-curt { text-align: center; }
.inp-ordre {
  width: 4.2rem; font: inherit; font-weight: 700; font-size: 1rem; text-align: center;
  padding: .3rem .2rem; border: 2px solid var(--vora); border-radius: 8px; background: #fff;
}
.inp-ordre:focus { border-color: var(--corall); outline: none; }
.triada .inp-ordre { border-color: #e9b949; }
.duplicada .inp-ordre { border-color: var(--vermell); color: var(--vermell); }
.sentinella { height: 1px; }
.mes-files { text-align: center; padding: .8rem; color: var(--gris); }
.buit { background: #fff; border: 1px dashed var(--vora); border-radius: var(--radi); padding: 2rem; text-align: center; color: var(--gris); margin-top: 1rem; }
.cap-res td { text-align: center; padding: 2rem !important; color: var(--gris); }
mark { background: #ffe58a; padding: 0; border-radius: 2px; }

/* ---------- La meva tria ---------- */
.tria-barra { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: .8rem; margin-bottom: .8rem; }
.tria-barra .botons { display: flex; flex-wrap: wrap; gap: .4rem; }
.avis-tria { border-radius: 10px; padding: .6rem .9rem; margin-bottom: .6rem; font-size: .9rem; }
.avis-tria.error { background: var(--vermell-clar); border: 1px solid #f3b4b4; color: #8a1c1c; }
.avis-tria.info { background: var(--blau-clar); border: 1px solid #c9d6ea; }
.mou { display: inline-flex; flex-direction: column; vertical-align: middle; margin-left: .2rem; }
.mou button, .treu { border: 1px solid var(--vora); background: #fff; cursor: pointer; font-size: .65rem; line-height: 1; padding: .15rem .3rem; color: var(--blau-2); }
.mou button:first-child { border-radius: 5px 5px 0 0; }
.mou button:last-child { border-radius: 0 0 5px 5px; border-top: 0; }
.treu { border-radius: 5px; color: var(--vermell); margin-left: .2rem; font-size: .8rem; vertical-align: middle; }
.ordre-cel { white-space: nowrap; }
.c-punts { font-weight: 700; color: var(--blau); white-space: nowrap; text-align: right; }

/* ---------- Popover de filtres ---------- */
.vel { position: fixed; inset: 0; background: rgba(10, 20, 40, .25); z-index: 90; }
.popover {
  position: fixed; z-index: 100; background: #fff; border-radius: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.25);
  width: 340px; max-width: calc(100vw - 1rem); max-height: min(520px, calc(100vh - 2rem));
  display: flex; flex-direction: column; padding: .7rem; gap: .5rem;
}
.popover-cap { display: flex; justify-content: space-between; align-items: center; }
#pop-cerca { font: inherit; padding: .45rem .6rem; border: 1px solid var(--vora); border-radius: 8px; width: 100%; }
.pop-accions, .pop-peu { display: flex; gap: .4rem; justify-content: space-between; }
.pop-llista { overflow-y: auto; border: 1px solid var(--vora); border-radius: 8px; padding: .25rem; flex: 1; min-height: 120px; }
.pop-llista label { display: flex; gap: .45rem; align-items: flex-start; padding: .25rem .35rem; border-radius: 6px; cursor: pointer; font-size: .88rem; }
.pop-llista label:hover { background: var(--gris-clar); }
.pop-llista .compte { margin-left: auto; color: var(--gris); font-size: .78rem; padding-left: .4rem; }

/* ---------- Diàleg i toast ---------- */
.dialeg { position: fixed; inset: 0; background: rgba(10, 20, 40, .45); z-index: 200; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.dialeg-caixa { background: #fff; border-radius: 14px; max-width: 460px; width: 100%; padding: 1.2rem 1.3rem; box-shadow: 0 20px 50px rgba(0,0,0,.3); border-top: 6px solid var(--corall); }
.dialeg-botons { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%) translateY(150%);
  background: var(--text); color: #fff; padding: .6rem 1rem; border-radius: 10px; z-index: 300;
  transition: transform .25s ease, opacity .25s ease; max-width: 90vw; font-size: .9rem; pointer-events: none;
  opacity: 0; visibility: hidden;
}
.toast.visible { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

.peu { text-align: center; color: var(--gris); font-size: .8rem; padding: 1.5rem 1rem 2rem; }

/* =========================================================
   MÒBIL
   ========================================================= */
@media (max-width: 900px) {
  .merits-layout { grid-template-columns: 1fr; }
  .calculadora { position: static; max-height: none; }
}

@media (max-width: 800px) {
  :root { --alt-capcalera: 54px; }
  body { font-size: 15px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .capcalera-int { padding: .45rem .8rem; }
  .titol span { display: none; }
  /* Menú inferior tipus app */
  .menu {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: #fff;
    border-top: 1px solid var(--vora); padding: 0 0 env(safe-area-inset-bottom); gap: 0;
    box-shadow: 0 -2px 10px rgba(0,0,0,.08);
  }
  .tab {
    flex: 1; flex-direction: column; gap: 0; color: var(--gris); font-size: .72rem; padding: .45rem .2rem .5rem;
    border-bottom: 0; border-top: 3px solid transparent; position: relative;
  }
  .tab .ico { font-size: 1.25rem; }
  .tab.actiu { color: var(--blau); border-top-color: var(--corall); border-bottom: 0; }
  .tab .badge { position: absolute; top: .2rem; left: 55%; }
  main { padding: .6rem; }
  .graella-info { grid-template-columns: 1fr; }
  .linia-temps li { grid-template-columns: 1fr; gap: 0; }

  .mobil-only { display: inline-flex; }
  .filtres-mobil.obert { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
  .filtres-mobil .btn-filtre-m {
    border: 1px solid var(--blau-2); background: #fff; color: var(--blau-2); border-radius: 999px;
    padding: .25rem .7rem; font: inherit; font-size: .82rem; cursor: pointer;
  }
  .filtres-mobil .btn-filtre-m.actiu { background: var(--corall); border-color: var(--corall); color: #fff; }
  #cerca { font-size: 1rem; padding: .7rem 2.6rem .7rem 2.5rem; }
  .cercador { position: static; }
  .salt-calc { width: 100%; justify-content: center; margin-bottom: .7rem; }
  .calculadora { scroll-margin-top: 70px; }

  /* Taula -> targetes */
  .taula-places-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; max-height: none; }
  .taula-places thead { display: none; }
  .taula-places, .taula-places tbody { display: block; }
  .taula-places tbody tr {
    display: flex; flex-wrap: wrap; align-items: baseline; position: relative;
    background: #fff; border: 1px solid var(--vora); border-radius: 12px; margin-bottom: .55rem;
    padding: .6rem 5.6rem .6rem .75rem; box-shadow: var(--ombra); min-height: 6.2rem;
  }
  .taula-places tbody tr.triada { border-color: #e9b949; background: #fffaf0; }
  .taula-places tbody tr.duplicada { border-color: var(--vermell); background: var(--vermell-clar); }
  .taula-places tbody tr td, .taula-places tbody tr:nth-child(even) td, .taula-places tbody tr:hover td,
  .taula-places tbody tr.triada td, .taula-places tbody tr.duplicada td { background: transparent; }
  .taula-places td { display: block; flex: 1 1 100%; border: 0; padding: .05rem 0; font-size: .86rem; order: 10; }
  .taula-places td[data-l]::before { content: attr(data-l) ": "; color: var(--gris); font-size: .76rem; }
  .taula-places td.k-placa { order: 1; font-size: 1.02rem; }
  .taula-places td.k-loc { order: 2; font-weight: 700; color: var(--blau); font-size: .98rem; }
  .taula-places td.k-unitat { order: 3; }
  .taula-places td.k-centre { order: 4; }
  .taula-places td.k-nom { order: 5; }
  .taula-places td.k-unitat::before, .taula-places td.k-centre::before { content: none !important; }
  .taula-places td.k-centre { color: var(--gris); }
  .taula-places td.c-mini { flex: 0 0 auto; order: 6; margin-right: .75rem; font-size: .82rem; }
  .taula-places td.k-dept { order: 8; font-size: .78rem; color: var(--gris); }
  .taula-places td.k-dept::before { content: none !important; }
  .taula-places td.c-punts { order: 7; flex: 0 0 auto; }
  .taula-places td.col-ordre, .taula-places td.c-ordre-l {
    position: absolute; top: .55rem; right: .6rem; box-shadow: none; padding: 0;
    background: transparent !important; display: flex; flex-direction: column; align-items: center; gap: .2rem; width: auto;
  }
  .taula-places td.col-ordre::before { content: "Ordre"; font-size: .7rem; color: var(--gris); font-weight: 700; }
  .inp-ordre { width: 4.4rem; font-size: 1.15rem; padding: .45rem .2rem; }
  .cap-res { display: block !important; padding: 1rem !important; min-height: 0 !important; }
  .cap-res td { display: block; }
  .taula-tria td.c-ordre-l { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; width: 5rem; }
  .taula-tria td.c-ordre-l .mou { flex-direction: row; margin: 0; }
  .taula-tria td.c-ordre-l .mou button { border-radius: 5px !important; border-top: 1px solid var(--vora) !important; font-size: .8rem; padding: .25rem .45rem; }
  .tria-barra .botons .btn { flex: 1 1 auto; justify-content: center; }
  .popover { left: .5rem !important; right: .5rem; top: auto !important; bottom: calc(70px + env(safe-area-inset-bottom)); width: auto; max-width: none; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

@media print {
  .capcalera, .cercador, .tria-barra .botons, .peu, .menu { display: none !important; }
}
