/* ===== Mapa Halloween ===== */
:root {
  --bg: #14101c; --bg2: #1e1829; --card: #261e34; --line: #3a2f4d;
  --text: #f3eefa; --muted: #b3a8c4; --orange: #ff7a1a; --orange-d: #e5600a;
  --green: #7bd88f; --red: #ef5a5a; --purple: #8b5cf6;
  --radius: 14px; --maxw: 720px;
  font-size: 16px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  font-family: 'Nunito', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45; -webkit-font-smoothing: antialiased;
  max-width: var(--maxw); margin: 0 auto; min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
}
a { color: var(--orange); }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- capçalera ---------- */
.hero { position: relative; padding: 22px 16px 10px; background: linear-gradient(180deg, #2a1f3a, var(--bg)); overflow: hidden; }
.hero h1 {
  font-family: 'Creepster', Georgia, cursive; font-weight: 400; font-size: 2.5rem; letter-spacing: 1px; line-height: 1;
  color: var(--orange); text-shadow: 0 0 18px rgba(255,122,26,.45), 0 2px 0 #000; position: relative; z-index: 1;
}
.hero-place { color: var(--muted); font-weight: 600; margin-top: 4px; position: relative; z-index: 1; }
.hero-moon {
  position: absolute; right: 16px; top: 12px; width: 64px; height: 64px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff6d6, #f6d58a 60%, #c99b45); box-shadow: 0 0 40px rgba(246,213,138,.35);
}

/* ---------- pestanyes ---------- */
.tabs {
  position: sticky; top: 0; z-index: 1500; display: flex; gap: 6px; padding: 8px 12px;
  background: rgba(20,16,28,.92); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.tab {
  flex: 1; text-align: center; padding: 10px 4px; border-radius: 999px; font-weight: 800; font-size: .95rem;
  color: var(--muted); text-decoration: none; background: var(--bg2); border: 1px solid var(--line); white-space: nowrap;
}
.tab[aria-selected="true"] { background: var(--orange); color: #1a0f05; border-color: var(--orange); }

.banner { margin: 8px 16px 0; background: linear-gradient(90deg, #4c1d95, #6d28d9); color: #fff; padding: 12px 14px; border-radius: var(--radius); font-weight: 700; text-align: center; }

/* ---------- vista Cases ---------- */
.view-cases { padding: 0 16px 8px; display: flex; flex-direction: column; gap: 12px; }
.lead { color: var(--muted); margin-top: 8px; }
.lead strong { color: var(--text); }
.houses-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 4px; }
.houses-head h2 { font-size: 1.05rem; white-space: nowrap; }
.houses-head #count { color: var(--orange); font-size: 1.35rem; }
.houses-head input { max-width: 150px; }
.house-list { list-style: none; display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; }
.house { display: flex; align-items: center; gap: 8px; background: var(--card); border-radius: 13px; padding: 4px 10px 4px 4px; border: 2px solid transparent; }
.house.is-mine { border-color: var(--green); }
.house-main { flex: 1; min-width: 0; display: flex; gap: 10px; align-items: center; text-align: left; background: none; border: 0; color: var(--text); padding: 8px; border-radius: 10px; }
.house-main:hover { background: rgba(255,255,255,.04); }
.house-ic { font-size: 1.35rem; flex: 0 0 auto; }
.house-txt { display: grid; min-width: 0; }
.house-txt small { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.house-txt .u { color: var(--green); text-decoration: underline; }
.house-go {
  flex: 0 0 auto; font-size: .8rem; font-weight: 800; color: var(--orange); border: 1px solid var(--orange);
  border-radius: 999px; padding: 6px 10px; text-decoration: none; white-space: nowrap;
}
.house-go:hover { background: var(--orange); color: #1a0f05; }
.empty { color: var(--muted); font-size: .9rem; text-align: center; padding: 14px; background: var(--card); border-radius: 12px; list-style: none; }

.sec-title { font-size: 1.05rem; margin-top: 10px; }
.mini-wrap { position: relative; height: 260px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.mini-overlay { position: absolute; inset: 0; z-index: 900; background: linear-gradient(180deg, rgba(20,16,28,.15), rgba(20,16,28,0) 40%, rgba(20,16,28,.25)); border: 0; display: block; }
.chip { position: absolute; top: 10px; left: 10px; background: rgba(20,16,28,.88); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: .78rem; font-weight: 800; }
.chip-r { top: auto; left: auto; right: 10px; bottom: 10px; }
#slot-mini .leaflet-control-container { display: none; }

.cta {
  display: block; text-align: center; text-decoration: none; background: var(--orange); color: #1a0f05; font-weight: 800; font-size: 1.1rem;
  padding: 14px; border-radius: var(--radius); box-shadow: 0 6px 22px rgba(255,122,26,.35); margin-top: 4px;
}
.cta small { display: block; font-size: .78rem; font-weight: 600; opacity: .8; }
.cta:hover { background: var(--orange-d); }

.foot { font-size: .8rem; color: var(--muted); display: grid; gap: 8px; border-top: 1px solid var(--line); padding: 12px 0 calc(24px + env(safe-area-inset-bottom)); margin: 8px 16px 0; }
.wa img { display: block; }
.legal, .credits { font-size: .72rem; opacity: .9; }
.admin-link { display: inline-block; padding: 0 7px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted) !important; text-decoration: none; }
.admin-link:hover { color: var(--text) !important; border-color: var(--muted); }

/* ---------- vistes amb mapa a pantalla completa ---------- */
/* el mapa ocupa gairebé tota la pantalla, però capçalera i peu es mantenen (es fa scroll fora del mapa) */
.view-mapa, .view-afegir { display: flex; flex-direction: column; }
.full-wrap { position: relative; height: calc(100vh - 150px); height: calc(100dvh - 150px); min-height: 420px; margin: 0 12px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.add-wrap { height: calc(100vh - 230px); height: calc(100dvh - 230px); min-height: 520px; }
.map-slot { position: absolute; inset: 0; }
#map { position: absolute; inset: 0; background: #0d0a12; }
body.dim-houses .pin:not(.pin-temp) { opacity: .55; }

/* ---------- vista Afegir ---------- */
.add-top { padding: 2px 12px 10px; display: grid; gap: 8px; background: var(--bg); }
.steps { list-style: none; display: flex; gap: 6px; }
.steps li { flex: 1; text-align: center; background: var(--card); border: 1px solid transparent; border-radius: 10px; padding: 5px; font-size: .75rem; color: var(--muted); }
.steps li b { display: block; color: var(--muted); font-size: .9rem; }
.steps li.on { border-color: var(--orange); color: var(--text); }
.steps li.on b { color: var(--orange); }
.search { position: relative; display: flex; gap: 8px; }
.search-results {
  position: absolute; z-index: 2000; top: calc(100% + 6px); left: 0; right: 0; list-style: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.search-results button { width: 100%; text-align: left; background: none; border: 0; color: var(--text); padding: 11px 12px; border-bottom: 1px solid var(--line); }
.search-results button:hover { background: rgba(255,122,26,.12); }
.search-results .muted { padding: 10px 12px; color: var(--muted); font-size: .9rem; }

.sheet {
  position: absolute; z-index: 1100; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom));
  background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px;
  box-shadow: 0 -6px 30px rgba(0,0,0,.6); max-height: 62%; overflow-y: auto;
}
.sheet-empty { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
.sheet-empty strong { color: var(--text); font-size: 1rem; }
.tip { font-size: .8rem; margin-top: 4px; }

/* ---------- formularis i botons ---------- */
input[type=search], .hw-form input:not([type=checkbox]), .hw-form textarea, .admin input, .admin textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: #120e19; color: var(--text); font: inherit; font-size: 16px;
}
input:focus, textarea:focus { outline: 2px solid var(--orange); outline-offset: 0; border-color: transparent; }
.hw-form { display: grid; gap: 7px; }
.hw-form .check { display: flex; gap: 8px; align-items: flex-start; font-weight: 600; font-size: .78rem; color: var(--muted); }
.hw-form .check input { margin-top: 2px; width: 18px; height: 18px; accent-color: var(--orange); flex: 0 0 auto; }
.form-addr { font-weight: 800; }
.hint { font-size: .75rem; color: var(--muted); margin-top: -4px; }
.form-err { color: var(--red); font-weight: 700; font-size: .85rem; }
.form-err:empty { display: none; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; }
.btn.btn-del { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn.btn-del:hover { background: var(--red); color: #fff; }
.hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }

.btn {
  border: 0; border-radius: 999px; padding: 10px 16px; font-weight: 800; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; line-height: 1.1; transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--orange); color: #1a0f05; }
.btn-primary:hover { background: var(--orange-d); color: #fff; }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn-ghost:hover { background: rgba(255,255,255,.06); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-round { width: 42px; height: 42px; padding: 0; background: var(--bg2); color: var(--text); border: 1px solid var(--line); font-size: 1.3rem; }
.link { background: none; border: 0; color: var(--orange); text-decoration: underline; padding: 0; font-size: inherit; text-align: left; }

.toast {
  position: fixed; z-index: 3000; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #0f0b15; color: var(--text); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.5); font-weight: 600; text-align: center;
}
.toast.ok { border-color: var(--green); }
.toast.err { border-color: var(--red); }
body[data-view="afegir"] .toast { bottom: 55%; }

/* ---------- marcadors ---------- */
.pin { background: none; border: 0; }
.pin span {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); background: #1b1424; border: 3px solid var(--orange); box-shadow: 0 3px 10px rgba(0,0,0,.55);
}
.pin i { font-style: normal; transform: rotate(45deg); line-height: 1; font-size: 21px; font-family: 'Apple Color Emoji','Segoe UI Emoji','Noto Color Emoji',sans-serif; }
.pin-mine span { border-color: var(--green); box-shadow: 0 0 0 4px rgba(123,216,143,.35), 0 3px 10px rgba(0,0,0,.55); }
.pin-temp span { width: 44px; height: 44px; border-color: #fff; background: var(--purple); animation: bob 1.2s ease-in-out infinite; }
@keyframes bob { 50% { margin-top: -6px; } }

/* ---------- popups i controls leaflet ---------- */
.leaflet-popup-content-wrapper { background: var(--card); color: var(--text); border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.6); }
.leaflet-popup-tip { background: var(--card); }
.leaflet-popup-content { margin: 14px 16px; font-family: inherit; font-size: .92rem; }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }
.pop h3 { font-size: 1.1rem; color: var(--orange); margin-bottom: 6px; padding-right: 14px; }
.pop p { margin: 4px 0 !important; }
.pop-addr, .pop-time { color: var(--muted); }
.pop-notes { background: rgba(255,255,255,.05); padding: 6px 8px; border-radius: 8px; }
.pop-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.pop-actions a.btn-primary { color: #1a0f05; }
.pop-mine { font-size: .8rem; color: var(--green); }
.leaflet-bar a, .leaflet-control-layers { background: var(--bg2) !important; color: var(--text) !important; border-color: var(--line) !important; }
.leaflet-control-layers { border-radius: 10px !important; }
.leaflet-control-layers-expanded { padding: 8px 10px; }
.leaflet-control-attribution { background: rgba(20,16,28,.7) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-control .locate { box-shadow: 0 1px 5px rgba(0,0,0,.4); }

/* capçalera més compacta a les pestanyes de mapa (mòbil) */
@media (max-width: 760px) {
  body[data-view="mapa"] .hero, body[data-view="afegir"] .hero { padding: 14px 16px 6px; }
  body[data-view="mapa"] .hero h1, body[data-view="afegir"] .hero h1 { font-size: 2rem; }
  body[data-view="mapa"] .hero-moon, body[data-view="afegir"] .hero-moon { width: 46px; height: 46px; top: 10px; }
}

/* ---------- escriptori ---------- */
@media (min-width: 761px) {
  body { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .mini-wrap { height: 340px; }
  .hero h1 { font-size: 3rem; }
}
/* ===== Admin ===== */
body.admin { min-height: 100vh; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; background: var(--bg2); border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 10px; align-items: center; }
.brand-icon { font-size: 1.8rem; }
.brand small { display: block; color: var(--muted); }
.admin-main { max-width: 860px; margin: 0 auto; padding: 18px 16px 40px; display: grid; gap: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.login-card { max-width: 360px; margin: 40px auto; display: grid; gap: 12px; width: 100%; }
.login-card label, .admin-form label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 700; }
.flash { background: #1f3b2a; border: 1px solid var(--green); padding: 10px 14px; border-radius: 12px; }
.stats { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; }
.stats > div { display: grid; }
.stats .num { font-size: 1.8rem; font-weight: 800; color: var(--orange); line-height: 1; }
.stats .phase { flex: 1; min-width: 200px; }
.stats .phase small { color: var(--muted); }
.phase-open strong { color: var(--green); }
.stats-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.admin-list { display: grid; gap: 8px; }
.admin-item summary { cursor: pointer; display: grid; gap: 2px; list-style: none; }
.admin-item summary::-webkit-details-marker { display: none; }
.ai-name { font-weight: 800; }
.ai-meta { color: var(--muted); font-size: .85rem; }
.admin-item.is-hidden { opacity: .6; }
.admin-form { display: grid; gap: 8px; margin-top: 12px; }
.danger-zone { text-align: right; margin-top: 16px; }
.empty { text-align: center; }
body.admin { max-width: none; display: block; border: 0; }
.hw-form .row { flex-wrap: nowrap; }
.hw-form .row .btn { padding: 10px 12px; }
