/* Parkman — feuille de style mobile-first.
   Conçue d'abord pour un téléphone, élargie ensuite pour les grands écrans. */

:root {
  --bg: #0f1420;
  --bg-soft: #161d2c;
  --card: #1b2434;
  --card-hi: #222d40;
  --line: #2c3850;
  --text: #e8edf6;
  --muted: #93a1bb;
  --accent: #4c8dff;
  --danger: #ff5f6d;
  --warn: #ffb648;
  --ok: #3ddc97;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --tap: 48px;                       /* cible tactile minimale */
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --tabbar-h: calc(60px + var(--safe-b));
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;    /* pas de resize au changement d'orientation */
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: radial-gradient(1200px 600px at 20% -10%, #1c2740 0%, var(--bg) 55%);
  background-attachment: fixed;
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;                   /* évite le zoom auto d'iOS sur les champs */
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

button, input, select { font: inherit; }
button { touch-action: manipulation; }

h1 { font-size: 1.45rem; margin: 0 0 .25rem; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: 0 0 .9rem; }
.muted { color: var(--muted); margin: 0; font-size: .9rem; line-height: 1.45; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

svg { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Barre supérieure ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(15, 20, 32, .9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  padding-top: var(--safe-t);
}
.topbar-inner {
  max-width: 960px; margin: 0 auto;
  padding: .6rem calc(1rem + var(--safe-r)) .6rem calc(1rem + var(--safe-l));
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.brand { display: inline-flex; align-items: center; gap: .55rem; font-weight: 700; letter-spacing: -.02em; }
.brand-mark {
  width: 20px; height: 20px; border-radius: 6px; flex: none;
  background: linear-gradient(140deg, var(--accent), #7bd0ff);
  box-shadow: 0 0 0 3px rgba(76, 141, 255, .18);
  position: relative;
}
.brand-mark::after {
  content: ""; position: absolute; inset: 6px 4px auto 4px; height: 3px;
  border-radius: 2px; background: rgba(255, 255, 255, .9);
}
.brand-mark.big { width: 46px; height: 46px; border-radius: 14px; }
.brand-mark.big::after { inset: 16px 9px auto 9px; height: 6px; }

.topbar-right { display: flex; align-items: center; gap: .3rem; }
.topbar-right form { margin: 0; display: flex; }
.top-nav { display: none; }          /* remplacée par la barre d'onglets sur mobile */

.icon-btn {
  width: var(--tap); height: var(--tap);
  display: grid; place-items: center;
  background: none; border: 0; border-radius: 12px;
  color: var(--muted); cursor: pointer;
}
.icon-btn svg { width: 21px; height: 21px; }
.icon-btn:active { background: var(--card); color: var(--text); }

/* ---------- Contenu ---------- */
.page {
  max-width: 960px; margin: 0 auto;
  padding: 1.1rem calc(1rem + var(--safe-r)) calc(1.5rem + var(--tabbar-h)) calc(1rem + var(--safe-l));
}
.page-head { margin-bottom: 1.1rem; display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.page-head h1 { display: none; }     /* le titre est déjà dans la barre supérieure */
.section-title { display: flex; align-items: center; margin: 1.5rem 0 .8rem; font-size: .95rem; }

/* ---------- Barre d'onglets (mobile) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex;
  background: rgba(18, 24, 38, .94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  flex: 1; min-height: 60px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .18rem;
  color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600;
}
.tab svg { width: 22px; height: 22px; }
.tab.active { color: var(--accent); }
.tab:active { background: rgba(255, 255, 255, .04); }

/* ---------- Messages ---------- */
.flashes { display: grid; gap: .5rem; margin-bottom: 1rem; }
.flash { padding: .75rem .9rem; border-radius: 12px; font-size: .88rem; line-height: 1.4; border: 1px solid transparent; }
.flash-error   { background: rgba(255, 95, 109, .12); border-color: rgba(255, 95, 109, .35); color: #ffb3b9; }
.flash-success { background: rgba(61, 220, 151, .12); border-color: rgba(61, 220, 151, .3);  color: #9df3cd; }
.flash-info    { background: rgba(76, 141, 255, .12); border-color: rgba(76, 141, 255, .3);  color: #b7d0ff; }

/* ---------- Boutons ---------- */
.btn {
  min-height: var(--tap);
  font-size: .95rem; font-weight: 600;
  padding: .7rem 1.05rem; border-radius: 13px; border: 1px solid transparent;
  cursor: pointer; color: var(--text); background: var(--card-hi);
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  transition: transform .06s ease, opacity .15s ease;
}
.btn:active:not(:disabled) { transform: scale(.975); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-lg { min-height: 54px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #06122a; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn-danger { background: rgba(255, 95, 109, .15); border-color: rgba(255, 95, 109, .35); color: #ff9aa2; }
.btn-lock   { background: rgba(255, 182, 72, .18); border-color: rgba(255, 182, 72, .38); color: #ffd193; }
.btn-unlock { background: rgba(61, 220, 151, .18); border-color: rgba(61, 220, 151, .38); color: #9df3cd; }
.btn-icon-text { padding: .55rem .85rem; font-size: .85rem; min-height: 42px; flex: none; }
.btn-icon-text .ico { width: 16px; height: 16px; }

@media (hover: hover) {
  .btn-primary:hover:not(:disabled) { background: #6ba0ff; }
  .btn-ghost:hover:not(:disabled)   { color: var(--text); border-color: #3d4c6b; }
  .btn-danger:hover:not(:disabled)  { background: rgba(255, 95, 109, .28); }
  .btn-lock:hover:not(:disabled)    { background: rgba(255, 182, 72, .3); }
  .btn-unlock:hover:not(:disabled)  { background: rgba(61, 220, 151, .3); }
}

/* ---------- Connexion ---------- */
.login-page .page { max-width: 420px; padding-top: max(4vh, 1.5rem); padding-bottom: calc(2rem + var(--safe-b)); }
.login-card { padding: .5rem 0; }
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo h1 { margin: .7rem 0 .2rem; display: block; }
.login-form { display: grid; gap: .9rem; justify-items: stretch; }
.login-form label { font-size: .88rem; color: var(--muted); text-align: center; }

.pin-input {
  font-size: 1.7rem; letter-spacing: .45em; text-align: center;
  padding: .75rem .5rem .75rem 1rem; border-radius: 14px;
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  width: 100%;
}
.pin-input:focus { outline: none; border-color: var(--accent); }
.pin-input.is-hidden-field {          /* remplacé visuellement par les points */
  position: absolute; width: 1px; height: 1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.pin-dots { display: flex; justify-content: center; align-items: center; gap: .7rem; min-height: 34px; }
.pin-dots .dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line); background: transparent;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.pin-dots .dot.filled { background: var(--accent); border-color: var(--accent); transform: scale(1.12); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin: .3rem 0 .2rem; }
.key {
  min-height: 62px; font-size: 1.5rem; font-weight: 500;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 15px; cursor: pointer;
  display: grid; place-items: center;
  transition: transform .06s ease, background .12s ease;
}
.key:active { transform: scale(.94); background: var(--card-hi); }
.key-muted { color: var(--muted); font-size: 1.05rem; }
.key-muted svg { width: 24px; height: 24px; }

.hint { text-align: center; font-size: .8rem; color: var(--muted); margin: 1.4rem 0 0; line-height: 1.5; }

/* ---------- Cartes barrières ---------- */
.barrier-grid { display: grid; gap: .85rem; }
.empty { color: var(--muted); }

.skeleton-card {
  height: 190px; border-radius: var(--radius);
  background: linear-gradient(100deg, var(--card) 30%, var(--card-hi) 50%, var(--card) 70%);
  background-size: 220% 100%; animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -120% 0; } }

.barrier-card {
  display: grid; gap: .8rem;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .9rem; box-shadow: var(--shadow);
}
.barrier-card.state-locked   { border-color: rgba(255, 182, 72, .4); }
.barrier-card.state-unlocked { border-color: rgba(61, 220, 151, .35); }
.barrier-card.is-offline     { border-color: rgba(255, 95, 109, .4); opacity: .85; }
.barrier-card.is-busy        { border-color: var(--accent); }

.barrier-top { display: flex; gap: .9rem; align-items: stretch; }
.barrier-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .55rem; }
.barrier-head { display: flex; align-items: center; justify-content: space-between; gap: .4rem; flex-wrap: wrap; }
.barrier-head h2 { margin: 0; font-size: 1.05rem; }

.state-pill {
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: .26rem .55rem; border-radius: 999px; white-space: nowrap;
  background: var(--card-hi); color: var(--muted);
}
.state-locked   .state-pill { background: rgba(255, 182, 72, .16); color: #ffd193; }
.state-unlocked .state-pill { background: rgba(61, 220, 151, .16); color: #9df3cd; }
.state-busy     .state-pill { background: rgba(76, 141, 255, .18); color: #b7d0ff; }
.is-offline     .state-pill { background: rgba(255, 95, 109, .16); color: #ff9aa2; }

.barrier-meta { list-style: none; margin: 0; padding: 0; display: grid; gap: .28rem; font-size: .82rem; }
.barrier-meta li { display: flex; justify-content: space-between; gap: .75rem; }
.barrier-meta span { color: var(--muted); }
.barrier-meta strong { font-weight: 600; text-align: right; }
.barrier-meta li.warn strong { color: var(--warn); }

.barrier-faults {
  font-size: .8rem; color: #ffb3b9; line-height: 1.4;
  background: rgba(255, 95, 109, .1); border-radius: 10px; padding: .5rem .65rem;
}

.barrier-hint {
  margin: 0; font-size: .8rem; line-height: 1.4; color: #ffd193;
  background: rgba(255, 182, 72, .1); border-radius: 10px; padding: .5rem .65rem;
}

.barrier-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .55rem; }
.barrier-actions.single { grid-template-columns: 1fr; }   /* une seule action utile */
.barrier-actions [hidden] { display: none; }
.barrier-msg { margin: 0; font-size: .82rem; text-align: center; }
.barrier-msg.is-ok { color: var(--ok); }
.barrier-msg.is-error { color: #ff9aa2; }

/* ---------- Visuel de la place ---------- */
.barrier-visual { flex: none; display: flex; align-items: center; }
.parking-slot {
  position: relative; width: 78px; height: 108px; border-radius: 11px;
  background: #131a27; border: 1px solid var(--line);
  overflow: hidden; perspective: 300px;
}
.slot-lines { position: absolute; inset: 8px; border: 2px dashed #2f3d58; border-top: 0; border-radius: 0 0 6px 6px; }

/* Barrière : relevée = place bloquée, abaissée = place libre */
.barrier-arm {
  position: absolute; left: 50%; bottom: 24px;
  width: 44px; height: 38px; margin-left: -22px;
  border-radius: 5px;
  background: linear-gradient(180deg, #ffd193, #e8933a);
  transform-origin: bottom center; transform: rotateX(78deg);
  transition: transform .55s cubic-bezier(.4, 1.4, .5, 1), background .3s ease;
  box-shadow: 0 4px 10px rgba(0, 0, 0, .35);
}
.barrier-arm::after {
  content: ""; position: absolute; inset: auto 6px 6px 6px; height: 4px;
  border-radius: 2px; background: rgba(0, 0, 0, .25);
}
.state-locked   .barrier-arm { transform: rotateX(0deg); }
.state-unlocked .barrier-arm { transform: rotateX(84deg); background: linear-gradient(180deg, #9df3cd, #3ddc97); }
.state-busy     .barrier-arm { transform: rotateX(42deg); background: linear-gradient(180deg, #b7d0ff, #4c8dff); }
.is-offline     .barrier-arm { background: linear-gradient(180deg, #55617a, #39435a); }
.is-busy        .barrier-arm { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.car-badge {
  position: absolute; top: 6px; left: 50%; transform: translateX(-50%);
  font-size: .58rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  background: rgba(76, 141, 255, .92); color: #06122a;
  padding: .14rem .38rem; border-radius: 5px; white-space: nowrap;
}

/* ---------- Administration ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.add-panel > summary {
  list-style: none; cursor: pointer;
  min-height: var(--tap); padding: .9rem 1rem;
  display: flex; align-items: center; gap: .55rem;
  font-weight: 600; font-size: .95rem;
}
.add-panel > summary::-webkit-details-marker { display: none; }
.add-panel > summary:active { background: var(--card-hi); border-radius: var(--radius); }
.plus {
  width: 26px; height: 26px; flex: none; border-radius: 8px;
  background: rgba(76, 141, 255, .18); color: var(--accent);
  display: grid; place-items: center; font-size: 1.15rem; line-height: 1;
}
.add-panel[open] > summary { border-bottom: 1px solid var(--line); }
.add-panel[open] .plus { transform: rotate(45deg); }

.user-form { display: grid; gap: .85rem; padding: 1rem; }
.field { display: grid; gap: .35rem; }
.field label { font-size: .82rem; color: var(--muted); }
.field input {
  min-height: var(--tap); padding: .6rem .8rem; border-radius: 12px;
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--text);
  font-size: 1rem; width: 100%;
}
.field input:focus { outline: none; border-color: var(--accent); }
.checkbox { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); font-size: .95rem; cursor: pointer; }
.checkbox input { width: 22px; height: 22px; accent-color: var(--accent); }

.count {
  font-size: .75rem; font-weight: 600; color: var(--muted);
  background: var(--card-hi); padding: .12rem .5rem; border-radius: 999px; margin-left: .4rem;
}

.user-list { display: grid; gap: .7rem; }
.user-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem; display: grid; gap: .55rem;
}
.user-card.is-me { border-color: rgba(76, 141, 255, .4); }
.user-main { display: flex; align-items: center; justify-content: space-between; gap: .6rem; }
.user-ident { display: grid; gap: .1rem; min-width: 0; }
.user-phone { font-size: 1.05rem; font-weight: 600; }
.user-name { font-size: .84rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-sub { display: flex; align-items: center; gap: .6rem; font-size: .82rem; color: var(--muted); }
.you { font-size: .7rem; color: var(--accent); background: rgba(76, 141, 255, .14); padding: .12rem .4rem; border-radius: 6px; }

.role-pill { font-size: .72rem; font-weight: 700; padding: .24rem .6rem; border-radius: 999px; white-space: nowrap; }
.role-admin { background: rgba(76, 141, 255, .16); color: #b7d0ff; }
.role-user  { background: var(--card-hi); color: var(--muted); }

.user-actions { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.user-actions form { margin: 0; display: flex; }
.user-actions .btn { width: 100%; font-size: .88rem; }

/* ---------- Grands écrans ---------- */
@media (min-width: 760px) {
  :root { --tabbar-h: 0px; }
  .tabbar { display: none; }
  .top-nav { display: flex; align-items: center; gap: .3rem; }
  .top-nav a {
    color: var(--muted); text-decoration: none; font-size: .9rem;
    padding: .5rem .75rem; border-radius: 10px;
  }
  .top-nav a.active { color: var(--text); background: var(--card-hi); }
  .top-nav a:hover { color: var(--text); }

  .page { padding: 1.75rem 1.25rem 4rem; }
  .page-head h1 { display: block; }
  .barrier-grid { grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 1rem; }
  .user-form { grid-template-columns: repeat(2, 1fr); align-items: end; }
  .user-form .btn { grid-column: 1 / -1; }
  .user-actions { grid-template-columns: max-content max-content; justify-content: end; }
  .login-page .page { padding-top: 8vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
