:root {
  --bg: #f4f5f7;
  --card: #fff;
  --text: #1a1d23;
  --muted: #6b7280;
  --line: #e3e5ea;
  --primary: #1e3a8a;
  --primary-2: #2748a8;
  --success: #15803d;
  --danger: #b91c1c;
  --warn: #b45309;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overscroll-behavior: none; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .5rem; }
a { color: var(--primary); }
[hidden] { display: none !important; }

/* ---------- Pages ---------- */
.page { max-width: 640px; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px 32px; display: flex; flex-direction: column; gap: 14px; }
.page.wide { max-width: 1100px; }
.page-head { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.page-head { flex-wrap: wrap; }
.page-head h1 { flex: 1 1 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: .9rem; font-weight: 600; }
input, select { font: inherit; font-weight: 400; padding: 12px; border: 1px solid #cfd3da; border-radius: 10px; background: #fff; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--primary-2); outline-offset: 0; }
.list { display: flex; flex-direction: column; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.error { color: var(--danger); margin: 0; }
.warn { color: var(--warn); }
.ok-text { color: var(--success); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Boutons ---------- */
.btn { font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 14px; border-radius: 10px; border: 1px solid #cfd3da; background: #fff; color: var(--text); text-decoration: none; cursor: pointer; min-height: 44px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f1c4c4; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.big { padding: 15px; font-size: 1.05rem; width: 100%; }
.btn.small { padding: 7px 10px; min-height: 36px; font-size: .88rem; }
.btn:active { transform: scale(.98); }
.icon-btn { font: inherit; font-size: 1.4rem; line-height: 1; background: none; border: 0; color: inherit; text-decoration: none; padding: 8px 10px; cursor: pointer; }

.badge { font-size: .75rem; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: #e5e7eb; color: #374151; white-space: nowrap; }
.badge.on { background: #dcfce7; color: #166534; }
.badge.off { background: #fee2e2; color: #991b1b; }
.badge.draft { background: #fef3c7; color: #92400e; }

.sync { font-size: .78rem; font-weight: 600; padding: 4px 9px; border-radius: 999px; white-space: nowrap; }
.sync::before { content: "●"; margin-right: 5px; }
.sync.ok { background: #dcfce7; color: #166534; }
.sync.run { background: #dbeafe; color: #1e40af; }
.sync.wait { background: #fef3c7; color: #92400e; }
.sync.err { background: #fee2e2; color: #991b1b; cursor: pointer; }

.tour-card { display: flex; flex-direction: column; gap: 6px; }
.tour-card-head { display: flex; justify-content: space-between; gap: 8px; align-items: center; }

/* ---------- Écran de prise de vue ---------- */
.tour-screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: #111; color: #fff; }
.topbar { display: flex; align-items: center; gap: 8px; padding: max(8px, env(safe-area-inset-top)) 8px 8px; background: #111; z-index: 2; }
.tb-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.tb-title strong, .tb-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tb-title span { font-size: .85rem; color: #c7cbd3; }
.pano-box { flex: 1; min-height: 0; }
.empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; color: var(--text); }
.empty .card { width: 100%; max-width: 480px; }
.banner { background: #fef3c7; color: #3b2a06; padding: 10px 14px; font-size: .92rem; line-height: 1.35; }
.banner strong { margin-right: 4px; }
.bottombar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 10px max(10px, env(safe-area-inset-bottom)); background: #111; }
.bottombar .btn { flex: 1 1 auto; padding-left: 10px; padding-right: 10px; }
.bottombar .btn.ghost { color: #e5e7eb; border-color: #4b5563; }
.seg { display: flex; border: 1px solid #555; border-radius: 10px; overflow: hidden; flex: 0 0 auto; }
.seg-btn { font: inherit; font-size: .85rem; background: transparent; color: #ddd; border: 0; padding: 0 10px; cursor: pointer; }
.seg-btn.on { background: #fff; color: #111; font-weight: 700; }

/* ---------- Visionneuse ---------- */
.pano { position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; background: #1a1a1e; }
.pano-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; transition: opacity .16s; }
.pano-canvas:active { cursor: grabbing; }
.pano-canvas.fading, .pano-layer.fading { opacity: 0; }
.pano-layer { position: absolute; inset: 0; pointer-events: none; transition: opacity .16s; }
.pano-error { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; color: #fff; }
.hs { position: absolute; left: 0; top: 0; pointer-events: auto; background: none; border: 0; padding: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 6px; margin: -22px 0 0 -60px; width: 120px; }
.hs-dot { width: 44px; height: 44px; border-radius: 50%; background: rgba(255, 255, 255, .92); box-shadow: 0 0 0 4px rgba(30, 58, 138, .55), 0 4px 14px rgba(0, 0, 0, .4); position: relative; }
.hs-dot::after { content: ""; position: absolute; left: 50%; top: 52%; width: 14px; height: 14px; border-left: 4px solid var(--primary); border-top: 4px solid var(--primary); transform: translate(-50%, -30%) rotate(45deg); }
.hs-label { font-size: .85rem; font-weight: 700; color: #fff; background: rgba(0, 0, 0, .62); padding: 3px 9px; border-radius: 999px; white-space: nowrap; max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.hs:active .hs-dot { transform: scale(.94); }
.pano-cross { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; pointer-events: none; border: 2px solid rgba(255, 255, 255, .9); border-radius: 50%; box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), inset 0 0 0 1px rgba(0, 0, 0, .5); }
.pano-cross::before, .pano-cross::after { content: ""; position: absolute; background: #fff; box-shadow: 0 0 0 1px rgba(0, 0, 0, .45); }
.pano-cross::before { left: 50%; top: -12px; bottom: -12px; width: 2px; margin-left: -1px; }
.pano-cross::after { top: 50%; left: -12px; right: -12px; height: 2px; margin-top: -1px; }
.pano-ring { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); border: 3px dashed #facc15; border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 9999px rgba(0, 0, 0, .18); }

/* ---------- Fenêtres ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet { background: #fff; color: var(--text); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 16px 16px max(18px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; }
.rooms { display: flex; flex-direction: column; gap: 10px; }
.room { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.room.current { border-color: var(--primary-2); box-shadow: 0 0 0 1px var(--primary-2); }
.room-head { display: flex; gap: 8px; align-items: center; }
.room-head strong { flex: 1; }
.doors { display: flex; flex-direction: column; gap: 6px; border-top: 1px dashed var(--line); padding-top: 8px; }
.door { display: flex; gap: 6px; align-items: center; }
.door span { flex: 1; font-size: .9rem; }
.link-box { font-family: ui-monospace, monospace; font-size: .85rem; background: #f3f4f6; padding: 10px; border-radius: 8px; word-break: break-all; }

.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 40; max-width: 92vw; font-size: .92rem; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); text-align: center; }
.busy { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); color: #fff; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; }
.spinner { width: 42px; height: 42px; border: 4px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Back-office ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input { flex: 1 1 220px; }
.filters select { flex: 0 0 170px; }
table.tours { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.tours th, table.tours td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: .92rem; }
table.tours th { background: #f9fafb; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
table.tours tr:last-child td { border-bottom: 0; }
@media (max-width: 760px) {
  table.tours thead { display: none; }
  table.tours, table.tours tbody, table.tours tr, table.tours td { display: block; width: 100%; }
  table.tours tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.tours td { border: 0; padding: 4px 12px; }
  table.tours td[data-label]::before { content: attr(data-label) " : "; color: var(--muted); }
}

/* ---------- Visite publique ---------- */
.public { position: fixed; inset: 0; display: flex; flex-direction: column; background: #111; color: #fff; }
.public .pano-box { flex: 1; }
.public-head { position: absolute; top: 0; left: 0; right: 0; z-index: 3; display: flex; align-items: center; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 12px 18px; background: linear-gradient(rgba(0, 0, 0, .65), transparent); pointer-events: none; }
.public-head > * { pointer-events: auto; }
.public-head .t { flex: 1; min-width: 0; }
.public-head .t div:first-child { font-weight: 700; }
.public-head .t div:last-child { font-size: .85rem; color: #d1d5db; }
.public-head .icon-btn { font-size: 1.1rem; background: rgba(0, 0, 0, .45); border-radius: 8px; }
.chips { position: absolute; left: 0; right: 0; bottom: 0; z-index: 3; display: flex; gap: 8px; overflow-x: auto; padding: 18px 12px max(12px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0, 0, 0, .65)); }
.chip { font: inherit; font-size: .88rem; flex: 0 0 auto; padding: 8px 12px; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .4); background: rgba(0, 0, 0, .4); color: #fff; cursor: pointer; }
.chip.on { background: #fff; color: #111; font-weight: 700; }
.public .unavailable { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 8px; padding: 24px; }
