:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #1b1f27; --muted: #6b7280; --border: #e3e6eb;
  --primary: #2563eb; --primary-dark: #1d4ed8; --danger: #dc2626; --success: #16a34a; --warn: #f59e0b;
  --free: #ffffff; --free-stroke: #8a94a6; --reserved: #f59e0b; --paid: #16a34a; --inactive: #cbd1da;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --topbar-h: 56px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* Top bar */
#topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); display: flex; align-items: center; gap: 16px; padding: 0 16px; background: #fff; border-bottom: 1px solid var(--border); z-index: 50; }
body.with-topbar #app { padding-top: var(--topbar-h); min-height: 100vh; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); font-size: 16px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-icon { font-size: 22px; }
#nav { display: flex; gap: 4px; }
#nav a { padding: 8px 12px; border-radius: 8px; color: var(--text); font-weight: 500; }
#nav a:hover { background: var(--bg); text-decoration: none; }
#nav a.active { background: #e8efff; color: var(--primary); }
.user-menu { display: flex; align-items: center; gap: 8px; }
.user-chip { color: var(--text); font-size: 14px; }
.nav-toggle { display: none; }
@media (max-width: 860px) {
  .nav-toggle { display: inline-flex; }
  #nav { display: none; position: absolute; top: var(--topbar-h); left: 0; right: 0; background: #fff; border-bottom: 1px solid var(--border); flex-direction: column; padding: 8px; }
  #nav.open { display: flex; }
  .user-chip .muted { display: none; }
  #logout-btn { display: none; }
}

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f7f8fa; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; border-color: #f3b4b4; color: var(--danger); }
.btn-danger:hover { background: #fff1f1; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn.active { background: #e8efff; border-color: #b9ccff; color: var(--primary); }
.input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; background: #fff; color: var(--text); }
.input:focus { outline: 2px solid #bcd0ff; border-color: var(--primary); }
textarea.input { min-height: 70px; resize: vertical; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field-label { font-size: 13px; font-weight: 600; color: #374151; }
.field-hint { font-size: 12px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.form-error { background: #fff1f1; color: var(--danger); border: 1px solid #f3b4b4; padding: 8px 10px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; }
.notice { background: #fff8e6; border: 1px solid #fde4a8; color: #7a5200; padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { width: 38px; height: 22px; border-radius: 11px; background: #cfd4dc; position: relative; transition: background .15s; flex: none; }
.switch .slider::after { content: ''; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff; top: 2px; left: 2px; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::after { transform: translateX(16px); }
.switch input:disabled + .slider { opacity: .5; }

/* Cards, pages, tables */
.page { padding: 20px; max-width: 1400px; margin: 0 auto; }
.page.narrow { max-width: 720px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .input { width: auto; min-width: 140px; }
.toolbar .search { min-width: 240px; flex: 1; max-width: 420px; }
.table-wrap { overflow: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { background: #f9fafb; font-weight: 600; white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { background: #f1f3f6; }
.table th .arrow { color: var(--primary); margin-left: 4px; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: #f6f8ff; }
.table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-free { background: #eef2f7; color: #475569; }
.badge-reserved { background: #fff3dc; color: #9a5b00; }
.badge-paid { background: #e3f6e9; color: #146c2e; }
.badge-gray { background: #e5e7eb; color: #6b7280; }
.badge-yes { background: #e3f6e9; color: #146c2e; }
.badge-no { background: #fdecec; color: #a11b1b; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; }
.chip .x { cursor: pointer; opacity: .8; margin-left: 2px; }
.chip .x:hover { opacity: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.spot-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 6px; background: #eef2ff; color: #1e3a8a; font-weight: 600; font-size: 13px; }
.spot-chip a { color: inherit; }
.stat { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1.5px solid rgba(0,0,0,.25); }
.dot.free { background: var(--free); border-color: var(--free-stroke); }
.dot.reserved { background: var(--reserved); }
.dot.paid { background: var(--paid); }
.dot.inactive { background: var(--inactive); }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.count { font-size: 13px; color: var(--muted); margin-left: auto; }

/* Auth */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, #e8efff 0%, #f4f5f7 60%); }
.auth-box { width: 100%; max-width: 420px; background: #fff; border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.auth-head { text-align: center; margin-bottom: 18px; }
.auth-icon { font-size: 44px; }
.auth-head h1 { margin: 6px 0 2px; font-size: 22px; }
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab { flex: 1; padding: 10px; border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Modal & toast */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transform: translateY(10px); transition: all .25s; box-shadow: var(--shadow); max-width: 90vw; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: #166534; }
.toast-error { background: #991b1b; }

/* ---------- Map view ---------- */
body[data-view="plan"] #app { padding-top: var(--topbar-h); height: 100vh; overflow: hidden; }
.map-layout { display: grid; grid-template-columns: 1fr 380px; grid-template-rows: auto 1fr; height: calc(100vh - var(--topbar-h)); }
.map-toolbar { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--border); }
.map-toolbar .input { width: auto; }
.map-toolbar .search { width: 220px; }
.map-stage { position: relative; overflow: hidden; background: #e9ebef; touch-action: none; cursor: grab; user-select: none; }
.map-stage.dragging { cursor: grabbing; }
.map-stage.placing { cursor: crosshair; }
.map-inner { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }
.map-inner img { display: block; width: 5000px; height: 3087px; pointer-events: none; -webkit-user-drag: none; }
.map-inner svg { position: absolute; left: 0; top: 0; width: 5000px; height: 3087px; overflow: visible; }
.marker { cursor: pointer; }
.marker circle.body { fill: var(--free); stroke: var(--free-stroke); stroke-width: 4; }
.marker.reserve circle.body { fill: var(--reserved); stroke: #b45309; }
.marker.paye circle.body { fill: var(--paid); stroke: #14532d; }
.marker.inactif circle.body { fill: var(--inactive); stroke: #9aa3b0; stroke-dasharray: 8 6; }
.marker text { font: 700 26px system-ui, sans-serif; fill: #111; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.marker.reserve text, .marker.paye text { fill: #fff; }
.marker.inactif text { fill: #666; }
.marker.selected circle.body { stroke: var(--primary); stroke-width: 9; }
.marker.selected circle.ring { display: block; }
.marker circle.ring { display: none; fill: none; stroke: var(--primary); stroke-width: 4; opacity: .5; }
.marker.dimmed { opacity: .15; }
.marker.hit circle.body { stroke: #7c3aed; stroke-width: 9; }
.marker circle.carac { stroke: #fff; stroke-width: 3; }
/* Zoomed out: small dots, no labels, no characteristic dots */
.map-inner svg:not(.zoomed) .marker circle.body { r: 13px; stroke-width: 3; }
.map-inner svg:not(.zoomed) .marker circle.carac { display: none; }
.map-inner svg:not(.zoomed) .marker.selected circle.body { stroke-width: 6; }
.map-inner svg:not(.zoomed) .marker.selected circle.ring { r: 26px; }
.map-inner svg.editing .marker { cursor: move; }
.map-zoom { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 4px; z-index: 2; }
.map-zoom .btn { width: 38px; height: 38px; padding: 0; font-size: 18px; }
.map-legend { position: absolute; left: 12px; bottom: 12px; background: rgba(255,255,255,.92); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; display: flex; gap: 12px; font-size: 12px; z-index: 2; }
.map-hint { position: absolute; left: 50%; top: 12px; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 8px 14px; border-radius: 999px; font-size: 13px; z-index: 3; box-shadow: var(--shadow); }
.map-panel { background: #fff; border-left: 1px solid var(--border); overflow: auto; padding: 16px; }
.panel-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.panel-title h2 { margin: 0; font-size: 20px; }
.panel-section { border-top: 1px solid var(--border); padding-top: 12px; margin-top: 12px; }
.person-card { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.person-card .name { font-weight: 700; font-size: 15px; }
.carac-list { display: flex; flex-wrap: wrap; gap: 6px; }
.carac-opt { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); background: #fff; cursor: pointer; font-size: 13px; }
.carac-opt input { margin: 0; }
.carac-opt.on { border-color: transparent; color: #fff; }
.carac-opt.on .swatch { border-color: #fff; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.2); }
.suggest { position: relative; }
.suggest-list { position: absolute; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); max-height: 240px; overflow: auto; z-index: 10; }
.suggest-item { padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.suggest-item:hover, .suggest-item.active { background: #f0f4ff; }
.suggest-item .muted { font-size: 12px; }
@media (max-width: 900px) {
  .map-layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .map-panel { border-left: 0; border-top: 1px solid var(--border); max-height: 48vh; }
  .map-panel.no-selection { max-height: 120px; padding: 10px 16px; }
  .map-panel.no-selection .report-grid, .map-panel.no-selection .panel-section:not(.unplaced) { display: none; }
  .map-legend { display: none; }
  .map-toolbar .input:not(.search) { flex: 1; min-width: 120px; }
}

/* Person detail */
.detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.detail-head h1 { margin: 0; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.gallery .thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); background: #f3f4f6; }
.gallery .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; }
.gallery .thumb .del { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 6px; width: 26px; height: 26px; cursor: pointer; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; z-index: 150; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 95vh; object-fit: contain; }

/* Import */
.steps { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.step { padding: 6px 12px; border-radius: 999px; background: #eef2f7; color: var(--muted); font-size: 13px; font-weight: 600; }
.step.active { background: #e8efff; color: var(--primary); }
.step.done { background: #e3f6e9; color: #146c2e; }
.mapping-grid { display: grid; grid-template-columns: 200px 1fr; gap: 8px 12px; align-items: center; }
.preview-table { font-size: 12px; }
.preview-table th, .preview-table td { padding: 4px 8px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.report-stat { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 10px; text-align: center; }
.report-stat .n { font-size: 26px; font-weight: 700; }
.report-stat .l { font-size: 12px; color: var(--muted); }
.dropzone { border: 2px dashed #b9c3d3; border-radius: 12px; padding: 28px; text-align: center; background: #fff; cursor: pointer; }
.dropzone.over { border-color: var(--primary); background: #f0f4ff; }

@media print {
  #topbar, .toolbar, .btn { display: none !important; }
  body.with-topbar #app { padding-top: 0; }
  .table-wrap { border: 0; }
}
