/* Houma حومة — design system (direction « communautaire et chaleureuse »)
   Palette, typographies et composants : voir docs/BRAND.md */

/* Polices vendorisées (aucun appel réseau — WebView & réseaux lents) */
@font-face {
  font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('../vendor/fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('../vendor/fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('../vendor/fonts/ibm-plex-sans-latin-700-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('../vendor/fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 600; font-display: swap;
  src: url('../vendor/fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2') format('woff2');
}
@font-face {
  font-family: 'IBM Plex Sans Arabic'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('../vendor/fonts/ibm-plex-sans-arabic-arabic-700-normal.woff2') format('woff2');
}

:root {
  --bg: #FAF7F1;            /* sable clair */
  --surface: #FFFFFF;
  --text: #22303C;          /* encre */
  --muted: #5C6B79;
  --border: #E5E0D6;
  --primary: #17557E;       /* bleu Méditerranée */
  --primary-dark: #0F3A57;  /* bleu nuit */
  --secondary: #C4622D;     /* terracotta */
  --danger: #C7392F;        /* corail — danger uniquement */
  --ok: #1E7F52;
  --warn: #9A6A00;
  --info-bg: #EAF2F8;
  --elec: #B97F0A;
  --water: #1B76B4;
  --fire: #C24A21;
  --internet: #0E7C72;
  --other: #5B7185;
  --radius: 14px;
  --shadow: 0 2px 14px rgba(15, 58, 87, .14);
  --tap: 48px;
  --font-latin: 'IBM Plex Sans', -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --font-ar: 'IBM Plex Sans Arabic', 'IBM Plex Sans', 'Segoe UI', Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-latin);
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
/* L'arabe n'est jamais une langue secondaire : même famille, mêmes tailles. */
html[lang="ar"] body, html[lang="ar"] input, html[lang="ar"] select,
html[lang="ar"] textarea, html[lang="ar"] button { font-family: var(--font-ar); }
html[lang="ar"] p, html[lang="ar"] label { line-height: 1.6; }

h1 { font-size: 1.25rem; font-weight: 700; margin: 0; }
h2 { font-size: 1.09rem; font-weight: 600; margin: 0 0 .5rem; }
p { margin: .4rem 0; }
a { color: var(--primary); }
.muted { color: var(--muted); font-size: .875rem; }
.small { font-size: .8125rem; }
.brand-logo { width: 34px; height: 34px; flex-shrink: 0; }

/* Boutons — cibles tactiles ≥ 48px */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: var(--tap); padding: 0 1.25rem; border-radius: var(--radius);
  border: 1px solid transparent; font-size: 1rem; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff; width: 100%; text-decoration: none;
  font-family: inherit; transition: background .15s;
}
.btn:hover, .btn:active { background: var(--primary-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: #F1EDE4; }
.btn.danger { background: var(--danger); }
.btn.ghost { background: transparent; color: var(--primary); width: auto; }
.btn.small-btn { min-height: 40px; font-size: .875rem; width: auto; padding: 0 .875rem; }

/* Champs */
label { display: block; font-weight: 600; font-size: .9375rem; margin: .875rem 0 .25rem; }
input[type=text], input[type=tel], input[type=email], input[type=number],
input[type=datetime-local], input[type=password], select, textarea {
  width: 100%; min-height: var(--tap); padding: .625rem .875rem; font-size: 1rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  color: var(--text); font-family: inherit;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 3px solid rgba(23, 85, 126, .4); outline-offset: 1px;
}
.field-error { color: var(--danger); font-size: .875rem; margin-top: .25rem; }
/* Numéros de téléphone et dates : toujours de gauche à droite, même en RTL */
input[type=tel], input[type=datetime-local], input[type=email], .otp-input { direction: ltr; }
html[dir="rtl"] input[type=tel], html[dir="rtl"] input[type=email] { text-align: right; }
html[dir="rtl"] input[type=datetime-local] { text-align: right; }

/* Cartes / panneaux */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin: .75rem 0;
}
.notice { border-inline-start: 4px solid var(--primary); background: var(--info-bg); padding: .75rem 1rem; border-radius: 10px; margin: .75rem 0; }
.notice.danger { border-color: var(--danger); background: #FBEDEA; }
.notice.warn { border-color: var(--warn); background: #F8F0DC; }
.notice.ok { border-color: var(--ok); background: #E8F4EC; }

/* Barre supérieure */
.topbar {
  position: sticky; top: 0; z-index: 1200; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: .625rem 1rem;
  display: flex; align-items: center; gap: .75rem; min-height: 56px;
}
.topbar .back {
  min-width: var(--tap); min-height: var(--tap); display: inline-flex; align-items: center;
  justify-content: center; border: none; background: none; font-size: 1.4rem; cursor: pointer;
  color: var(--text); text-decoration: none;
}
html[dir="rtl"] .topbar .back .arrow { display: inline-block; transform: scaleX(-1); }

.lang-switch {
  min-height: 40px; padding: 0 .8rem; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; font-size: .85rem; cursor: pointer;
  color: var(--primary); font-family: var(--font-latin), var(--font-ar);
}

/* Page container */
.page { max-width: 640px; margin: 0 auto; padding: 1rem 1rem 5rem; }

/* Accueil : carte plein écran */
#map { position: fixed; inset: 0; z-index: 1; }
.home-top {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000; padding: .75rem;
  display: flex; flex-direction: column; gap: .5rem; pointer-events: none;
}
.home-top > * { pointer-events: auto; }
.home-brandbar { display: flex; align-items: center; gap: .5rem; }
.home-brandbar .brand-name {
  background: var(--surface); border-radius: 20px; padding: .3rem .8rem; font-weight: 700;
  box-shadow: var(--shadow); display: inline-flex; align-items: center; gap: .45rem; font-size: .95rem;
}
.home-brandbar .brand-name img { width: 22px; height: 22px; }
.home-brandbar .spacer { flex: 1; }
.searchbox { position: relative; }
.searchbox input { box-shadow: var(--shadow); border: none; }
.search-results {
  position: absolute; top: 100%; left: 0; right: 0; background: var(--surface);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 4px; overflow: hidden; z-index: 1100;
}
.search-results button {
  display: block; width: 100%; text-align: start; padding: .75rem 1rem; min-height: var(--tap);
  border: none; background: none; font-size: .9375rem; cursor: pointer;
  border-bottom: 1px solid var(--border); font-family: inherit; color: var(--text);
}
.search-results button:hover { background: #F1EDE4; }
.chips { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: 2px; }
.chip {
  min-height: 40px; padding: 0 .875rem; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface); font-size: .875rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: .375rem; white-space: nowrap;
  box-shadow: var(--shadow); font-family: inherit; color: var(--text);
}
.chip[aria-pressed="true"] { background: var(--primary-dark); color: #fff; border-color: var(--primary-dark); }
.home-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: .5rem; pointer-events: none;
}
.home-bottom > * { pointer-events: auto; }
.counter {
  align-self: center; background: var(--surface); border-radius: 20px; padding: .375rem .875rem;
  font-size: .8125rem; font-weight: 600; box-shadow: var(--shadow);
}
.btn-declare { box-shadow: var(--shadow); font-size: 1.0625rem; }
.row { display: flex; gap: .5rem; }
.row > * { flex: 1; }

/* Bottom sheets */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1500;
  background: var(--surface); border-radius: 18px 18px 0 0; box-shadow: 0 -4px 24px rgba(15,58,87,.22);
  max-height: 80vh; overflow-y: auto; padding: 1rem 1rem calc(1.25rem + env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .25s ease;
}
.sheet.open { transform: translateY(0); }
.sheet .handle { width: 44px; height: 4px; background: var(--border); border-radius: 2px; margin: 0 auto .75rem; }

/* Badges type / statut — couleur + icône + libellé, jamais la couleur seule */
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .2rem .6rem;
  border-radius: 14px; font-size: .8125rem; font-weight: 700; color: #fff;
}
.badge.electricity { background: var(--elec); }
.badge.water { background: var(--water); }
.badge.fire { background: var(--fire); }
.badge.internet { background: var(--internet); }
.badge.other { background: var(--other); }
.badge.status { background: #ECE8DF; color: var(--text); font-weight: 600; }
.badge.status.active { background: #E8F4EC; color: var(--ok); }
.badge.status.resolved { background: #ECE8DF; color: var(--muted); }

/* Liste d'incidents */
.list-item {
  display: flex; gap: .75rem; align-items: flex-start; padding: .875rem .5rem;
  border-bottom: 1px solid var(--border); cursor: pointer; background: none; border-radius: 0;
  width: 100%; text-align: start; border-inline: none; border-top: none; font: inherit; color: inherit;
}
.list-item:hover { background: #F1EDE4; }
.type-dot {
  width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center;
  justify-content: center; font-size: 1.1rem; color: #fff; flex-shrink: 0;
}
.type-dot.electricity { background: var(--elec); }
.type-dot.water { background: var(--water); }
.type-dot.fire { background: var(--fire); }
.type-dot.internet { background: var(--internet); }
.type-dot.other { background: var(--other); }

/* Wizard */
.progress { display: flex; gap: 4px; margin: .75rem 0 1rem; }
.progress span { flex: 1; height: 5px; border-radius: 3px; background: var(--border); }
.progress span.done { background: var(--primary); }
.type-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.type-card {
  min-height: 108px; border: 2px solid var(--border); border-radius: var(--radius);
  background: var(--surface); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: .4rem; font-size: .9375rem; font-weight: 700; cursor: pointer;
  color: var(--text); font-family: inherit;
}
.type-card .icon { font-size: 2rem; }
.type-card[aria-pressed="true"] { border-color: var(--primary); background: var(--info-bg); }
.seg { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.seg button {
  flex: 1; min-height: var(--tap); border: none; background: var(--surface); font-size: .9rem;
  font-weight: 600; cursor: pointer; color: var(--text); border-inline-end: 1px solid var(--border);
  font-family: inherit;
}
.seg button:last-child { border-inline-end: none; }
.seg button[aria-pressed="true"] { background: var(--primary); color: #fff; }
#miniMap, #manageMap { height: 260px; border-radius: var(--radius); z-index: 1; }
.checkbox-row { display: flex; align-items: flex-start; gap: .625rem; margin: .875rem 0; }
.checkbox-row input { width: 22px; height: 22px; margin-top: 2px; flex-shrink: 0; accent-color: var(--primary); }
.checkbox-row label { margin: 0; font-weight: 400; font-size: .9rem; }

/* OTP */
.otp-input { letter-spacing: .5em; text-align: center; font-size: 1.5rem; font-variant-numeric: tabular-nums; font-weight: 600; }

/* États */
.sandbox-banner {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 2900;
  background: var(--secondary); color: #fff; text-align: center;
  padding: .4rem .75rem calc(.4rem + env(safe-area-inset-bottom));
  font-size: .8125rem; font-weight: 600;
}
.offline-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 3000; background: var(--warn); color: #fff;
  text-align: center; padding: .5rem; font-size: .875rem; font-weight: 600; display: none;
}
.offline-banner.visible { display: block; }
.spinner {
  width: 22px; height: 22px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .8s linear infinite; display: inline-block;
}
.spinner.dark { border-color: rgba(0,0,0,.15); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton {
  background: linear-gradient(90deg, #EFEBE2 25%, var(--bg) 50%, #EFEBE2 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Admin */
.admin-nav {
  display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--border);
  background: var(--surface); padding: 0 .5rem; position: sticky; top: 0; z-index: 100;
}
.admin-nav button {
  min-height: var(--tap); padding: 0 .875rem; border: none; background: none; font-size: .9rem;
  font-weight: 600; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent;
  white-space: nowrap; font-family: inherit;
}
.admin-nav button[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th, td { text-align: start; padding: .5rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }

/* Marqueurs Leaflet */
.marker-pin {
  display: flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border-radius: 50% 50% 50% 6px; transform: rotate(-45deg); border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(15,58,87,.35);
}
.marker-pin span { transform: rotate(45deg); font-size: 15px; }
.marker-pin.electricity { background: var(--elec); }
.marker-pin.water { background: var(--water); }
.marker-pin.fire { background: var(--fire); }
.marker-pin.internet { background: var(--internet); }
.marker-pin.other { background: var(--other); }
.marker-pin.resolved { opacity: .55; }
.cluster-badge {
  background: var(--text); color: #fff; border-radius: 50%; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  border: 3px solid #fff; box-shadow: 0 2px 6px rgba(15,58,87,.3);
}

/* Leaflet reste LTR même quand la page est RTL (contrôles, attribution) */
.leaflet-container { direction: ltr; }

@media (min-width: 700px) {
  .sheet { max-width: 480px; left: auto; right: 1rem; border-radius: 18px; bottom: 1rem; }
  html[dir="rtl"] .sheet { right: auto; left: 1rem; }
  .home-bottom { max-width: 480px; left: 50%; transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
