:root {
  --bg: #fbf7f0;
  --surface: #ffffff;
  --text: #2b2118;
  --muted: #7a6a5c;
  --border: #e8ddd0;
  --brand: #7b4a2a;
  --brand-ink: #ffffff;
  --accent: #e8a33d;
  --free: #2e9e5b;
  --busy: #d64545;
  --shadow: 0 8px 30px rgba(60, 35, 15, 0.12);
  --radius: 14px;
  --topbar: 56px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1612;
    --surface: #241d18;
    --text: #f1e8de;
    --muted: #b3a291;
    --border: #3a2f27;
    --brand: #c98a5a;
    --brand-ink: #1b1612;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
a { color: var(--brand); }
h2 { margin: 0 0 0.4rem; font-size: 1.3rem; }
h3 { margin: 1.4rem 0 0.6rem; font-size: 1rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hint { color: var(--muted); font-size: 0.9rem; }
.warn { color: var(--busy); font-size: 0.85rem; }
.danger { color: var(--busy) !important; }

/* Barre du haut */
.topbar {
  position: fixed; inset: 0 0 auto 0; height: var(--topbar); z-index: 1000;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; font-size: 1.2rem; text-decoration: none; color: var(--text); white-space: nowrap; }
.nav { display: flex; align-items: center; gap: 0.9rem; overflow-x: auto; }
.nav a { text-decoration: none; color: var(--text); white-space: nowrap; font-size: 0.95rem; }
.nav a.btn { color: var(--brand-ink); }

/* Carte + panneau */
.layout { position: fixed; inset: var(--topbar) 0 0 0; display: flex; }
.map { flex: 1; height: 100%; background: #ddd; }
.map.is-adding { cursor: crosshair; }
.panel {
  width: 420px; max-width: 100%; height: 100%; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--border);
}
.panel-head { padding: 18px 18px 8px; position: relative; }
.panel-head .close { position: absolute; top: 14px; right: 16px; text-decoration: none; color: var(--muted); font-size: 1.2rem; }
.panel-head h2 { padding-right: 28px; }
.panel-body { padding: 0 18px 32px; }
.description { white-space: pre-wrap; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .map { height: 45%; flex: none; }
  .panel { width: 100%; height: 55%; border-left: 0; border-top: 1px solid var(--border); border-radius: 18px 18px 0 0; margin-top: -14px; z-index: 500; position: relative; box-shadow: var(--shadow); }
  body.panel-open .map { height: 30%; }
  body.panel-open .panel { height: 70%; }
  .nav { gap: 0.6rem; }
}

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  padding: 0.6rem 0.95rem; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600;
  text-decoration: none; cursor: pointer; transition: transform 0.05s, background 0.15s;
}
.btn:hover { background: var(--bg); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #2b2118; }
.btn-ghost { background: transparent; }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.85rem; }
.btn.on { background: var(--text); color: var(--surface); }
.btn.wide { width: 100%; margin-top: 0.8rem; }
.btn-link { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; cursor: pointer; text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.8rem 0; }

/* Marqueurs */
.toilet-marker {
  width: 36px; height: 36px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg);
  background: var(--surface); border: 3px solid var(--free); box-shadow: var(--shadow);
  display: grid; place-items: center; position: relative;
}
.toilet-marker span { transform: rotate(45deg); font-size: 18px; }
.toilet-marker.is-occupied { border-color: var(--busy); }
.toilet-marker.is-flagged { opacity: 0.55; border-style: dashed; }
.toilet-marker.is-selected { border-color: var(--accent); transform: rotate(-45deg) scale(1.2); }
.toilet-marker i {
  position: absolute; transform: rotate(45deg); top: -16px; left: 22px;
  background: var(--busy); color: #fff; font-style: normal; font-size: 10px; font-weight: 700;
  padding: 1px 5px; border-radius: 6px; white-space: nowrap;
}
.map-btn { width: 34px; height: 34px; border-radius: 8px; border: 2px solid rgba(0,0,0,0.2); background: #fff; cursor: pointer; font-size: 16px; }

/* Toilette */
.occupancy { padding: 0.7rem 0.9rem; border-radius: var(--radius); font-weight: 700; margin-bottom: 0.8rem; }
.occupancy.free { background: color-mix(in srgb, var(--free) 15%, transparent); color: var(--free); }
.occupancy.busy { background: color-mix(in srgb, var(--busy) 15%, transparent); color: var(--busy); }
.occupancy.mine { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; font-size: 0.9rem; }
.stars { color: var(--accent); letter-spacing: 1px; }
.legend-box { margin: 0.9rem 0; padding: 0.7rem 0.9rem; border: 1px dashed var(--accent); border-radius: var(--radius); }
.rate-toilet { display: flex; align-items: center; gap: 0.2rem; flex-wrap: wrap; font-size: 0.9rem; }
.star { background: none; border: 0; font-size: 1.5rem; color: var(--border); cursor: pointer; padding: 0 2px; }
.star.on { color: var(--accent); }
.compose { margin-top: 1rem; padding: 0.9rem; background: var(--bg); border-radius: var(--radius); }
.compose label { font-weight: 600; display: block; margin-bottom: 0.4rem; }
.compose textarea { width: 100%; font: inherit; font-family: Georgia, 'Times New Roman', serif; font-size: 1.05rem; line-height: 1.5; padding: 0.7rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); resize: vertical; }
.compose-foot { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.5rem; }
.compose-foot .btn { margin-left: auto; }
.wall-link { display: block; margin: 1rem 0 0; padding: 0.8rem; text-align: center; border: 2px solid var(--text); border-radius: var(--radius); font-weight: 700; text-decoration: none; color: var(--text); background: repeating-linear-gradient(45deg, transparent 0 8px, color-mix(in srgb, var(--accent) 15%, transparent) 8px 16px); }
.report { margin-top: 1.6rem; font-size: 0.9rem; }
.report summary { cursor: pointer; color: var(--muted); }
.badge { display: inline-block; font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); }
.badge.warn { color: var(--busy); border-color: var(--busy); }

/* Onglets */
.tabs { display: flex; gap: 0.3rem; margin-bottom: 0.6rem; }
.tab { border: 0; background: none; padding: 0.4rem 0.7rem; border-radius: 999px; cursor: pointer; font: inherit; color: var(--muted); }
.tab.on { background: var(--text); color: var(--surface); }

/* Publications */
.posts { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.8rem; }
.post { padding: 0.9rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.post-head { font-size: 0.85rem; display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.author { font-weight: 700; text-decoration: none; }
.post-body { white-space: pre-wrap; font-family: Georgia, 'Times New Roman', serif; font-size: 1.05rem; line-height: 1.55; margin: 0.6rem 0; overflow-wrap: anywhere; }
.post-foot { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; font-size: 0.9rem; }
.rate { display: flex; gap: 1px; margin-top: 0.5rem; }
.poop { background: none; border: 0; padding: 2px; cursor: pointer; font-size: 1.15rem; filter: grayscale(1); opacity: 0.35; transition: transform 0.1s; }
.poop.on { filter: none; opacity: 1; }
.rate:hover .poop { filter: none; opacity: 1; }
.rate .poop:hover ~ .poop { filter: grayscale(1); opacity: 0.35; }
.poop:hover { transform: scale(1.25); }

/* Archives */
.archives { display: flex; gap: 0.6rem; overflow-x: auto; padding-bottom: 0.3rem; }
.archive { flex: none; text-align: center; font-size: 0.8rem; text-decoration: none; color: var(--muted); }
.archive img { display: block; width: 240px; image-rendering: pixelated; border: 1px solid var(--border); border-radius: 6px; background: #fff; }

/* Pages plein écran */
.page { position: fixed; inset: var(--topbar) 0 0 0; z-index: 900; overflow-y: auto; background: var(--bg); }
.page-inner { max-width: 1100px; margin: 0 auto; padding: 18px 16px 48px; }
.page-inner.narrow { max-width: 440px; }
.page-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.page-head h2 { margin: 0; }
.prose { max-width: 720px; line-height: 1.6; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.card label { display: block; margin: 0.7rem 0; font-weight: 600; font-size: 0.9rem; }
.card input, .card textarea { display: block; width: 100%; margin-top: 0.3rem; padding: 0.6rem 0.7rem; font: inherit; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.switch { display: inline-flex; gap: 0.4rem; align-items: center; font-size: 0.9rem; cursor: pointer; }

/* Mur graphique */
.wall-toolbar { display: flex; flex-wrap: wrap; gap: 0.8rem; align-items: center; margin-bottom: 0.8rem; }
.zoom, .tools { display: flex; gap: 0.3rem; flex-wrap: wrap; }
.palette { display: flex; flex-wrap: wrap; gap: 4px; }
.swatch { width: 28px; height: 28px; border-radius: 6px; border: 2px solid var(--border); cursor: pointer; }
.swatch.on { outline: 3px solid var(--text); outline-offset: 1px; }
.wall-area { display: flex; gap: 0.8rem; align-items: stretch; }
.wall-scroll { flex: 1; min-width: 0; overflow: auto; max-height: 75vh; border-radius: 8px; border: 2px solid var(--text); background: var(--surface); }
.brush i { display: inline-block; background: currentColor; border-radius: 2px; }
.wall-canvas { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.wall-canvas.is-drawing { touch-action: none; cursor: crosshair; }
.ink { width: 34px; display: flex; flex-direction: column; align-items: center; gap: 0.3rem; font-size: 0.75rem; font-weight: 700; }
.ink-bar { flex: 1; width: 18px; min-height: 160px; border: 2px solid var(--text); border-radius: 10px; position: relative; overflow: hidden; background: var(--surface); }
.ink-fill { position: absolute; bottom: 0; left: 0; right: 0; background: linear-gradient(#2a5bd7, #1d2b53); transition: height 0.1s; }
.ink-fill.low { background: var(--busy); }
.wall-submit { margin-top: 1rem; text-align: right; }

/* Profil */
.profile-head { display: flex; gap: 1rem; align-items: center; }
.avatar { width: 72px; height: 72px; flex: none; border-radius: 50%; display: grid; place-items: center; font-size: 2rem; font-weight: 800; background: var(--brand); color: var(--brand-ink); }
.bio { white-space: pre-wrap; margin: 0.3rem 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 0.6rem; margin: 1.2rem 0; }
.stats div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.8rem; text-align: center; }
.stats strong { display: block; font-size: 1.5rem; }
.stats span { color: var(--muted); font-size: 0.8rem; }
.legends .chip { display: inline-block; margin: 0 0.4rem 0.4rem 0; padding: 0.3rem 0.7rem; border-radius: 999px; background: color-mix(in srgb, var(--accent) 25%, transparent); text-decoration: none; color: var(--text); }
.profile-map { height: 320px; border-radius: var(--radius); border: 1px solid var(--border); position: relative; }
.map-empty { position: absolute; inset: auto 0 12px 0; text-align: center; z-index: 500; font-weight: 600; }

/* Admin */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 0.6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.row-actions { display: flex; gap: 0.3rem; flex-wrap: wrap; }

/* Toasts */
.toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 2000; display: grid; gap: 0.4rem; width: min(92vw, 420px); }
.toast { padding: 0.7rem 1rem; border-radius: 12px; background: var(--text); color: var(--surface); box-shadow: var(--shadow); font-weight: 600; animation: pop 0.2s ease-out; }
.toast-error { background: var(--busy); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* v0.2 : public / personnel, amis, sécurité */
:root { --private: #8a5cc7; }
.segmented { display: flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); margin: 0.4rem 0; }
.seg { flex: 1; border: 0; background: none; padding: 0.45rem 0.4rem; border-radius: 999px; font: inherit; font-size: 0.88rem; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,0.12); }
.add-choice { display: grid; gap: 0.6rem; margin-bottom: 0.8rem; }
.add-choice h3 { margin: 0; }
.choice { text-align: left; padding: 0.8rem 0.9rem; border-radius: var(--radius); border: 2px solid var(--border); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; display: grid; gap: 0.2rem; }
.choice:hover { border-color: var(--brand); }
.choice span { color: var(--muted); font-size: 0.88rem; }
.badge.public { border-color: var(--free); color: var(--free); }
.badge.private { border-color: var(--private); color: var(--private); background: color-mix(in srgb, var(--private) 10%, transparent); }
.safety { margin: 1rem 0; padding: 0.8rem 0.9rem; border-radius: var(--radius); background: color-mix(in srgb, var(--accent) 14%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); font-size: 0.9rem; }
.safety p { margin: 0.3rem 0 0; }
.check, .radio { display: flex; gap: 0.5rem; align-items: flex-start; font-weight: 400 !important; margin: 0.45rem 0 !important; cursor: pointer; }
.check input, .radio input { display: inline-block !important; width: auto !important; margin: 0.2rem 0 0 !important; flex: none; }
.check.confirm { padding: 0.6rem; border-radius: 10px; background: var(--bg); }
fieldset { border: 1px solid var(--border); border-radius: 10px; margin: 0.8rem 0; padding: 0.4rem 0.8rem; }
legend { font-weight: 700; font-size: 0.9rem; padding: 0 0.3rem; }
.toilet-list, .people, .circles { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.toilet-list li, .people li { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; padding: 0.55rem 0.7rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.people .row-actions { margin-left: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.chip { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.8rem; background: color-mix(in srgb, var(--private) 14%, transparent); }
.circle-head { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; justify-content: space-between; }
.search-row { display: flex; gap: 0.5rem; margin-bottom: 0.7rem; }
.search-row input { flex: 1; min-width: 0; padding: 0.55rem 0.7rem; font: inherit; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.friends section { margin-bottom: 1.4rem; }
.locked { padding: 1rem; border: 1px dashed var(--border); border-radius: var(--radius); text-align: center; }
.settings { margin: 1rem 0; }
.toilet-tools { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-top: 1.2rem; }
.nav .count[hidden] { display: none; }
.nav .count { display: inline-block; min-width: 18px; margin-left: 4px; padding: 0 5px; border-radius: 9px; background: var(--busy); color: #fff; font-size: 0.75rem; text-align: center; }
.toilet-marker.is-private { border-color: var(--private); }
.toilet-marker.is-private.is-occupied { border-color: var(--busy); }
.toilet-marker.is-approx { border-style: dashed; }
.modal-backdrop { position: fixed; inset: 0; z-index: 3000; background: rgba(20, 12, 6, 0.45); display: grid; place-items: center; padding: 16px; }
.modal { width: min(520px, 100%); max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-top: 0; color: var(--text); text-transform: none; letter-spacing: 0; font-size: 1.1rem; }
.modal textarea { width: 100%; }

/* Barre du haut compacte sur téléphone : le logo ramène déjà à la carte. */
@media (max-width: 520px) {
  .topbar { gap: 0.5rem; padding: 0 10px; }
  .brand { font-size: 1.05rem; }
  .nav { gap: 0.55rem; }
  .nav a[href="#/"] { display: none; }
  .nav a, .nav .btn-link { font-size: 0.88rem; }
}
