:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f1eee6;
  --text: #1d2321;
  --muted: #66706c;
  --border: #e3dfd4;
  --primary: #0f5c4d;
  --primary-soft: #dcebe6;
  --accent: #e8a317;
  --danger: #c2412d;
  --danger-soft: #f8e1dc;
  --warn-soft: #fcefd0;
  --ok-soft: #dcefe0;

  --st-libre: #2f9e61;
  --st-occupee: #0f5c4d;
  --st-reservee: #3b6fd1;
  --st-nettoyage: #e8a317;
  --st-maintenance: #c2412d;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121615;
    --surface: #1b2120;
    --surface-2: #232a29;
    --text: #e8ece9;
    --muted: #9aa6a1;
    --border: #2e3735;
    --primary: #4fb79d;
    --primary-soft: #1c3631;
    --danger-soft: #3a211c;
    --warn-soft: #3a3019;
    --ok-soft: #1d3324;
    --st-occupee: #4fb79d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Mise en page ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px; }
.brand img { border-radius: 9px; }
.brand strong { display: block; font-size: .95rem; }
.brand span { font-size: .8rem; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 9px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav .ico { width: 20px; text-align: center; }
.net { margin-top: auto; font-size: .8rem; color: var(--muted); padding: 0 8px; }
.net .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 24px 8px;
}
.topbar h1 { font-size: 1.35rem; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.today { color: var(--muted); font-size: .9rem; }
.view { padding: 8px 24px 32px; display: flex; flex-direction: column; gap: 16px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto; z-index: 20;
    flex-direction: row; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--border);
  }
  .brand, .net { display: none; }
  .nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: .68rem; flex: 1; text-align: center; }
  .nav .ico { font-size: 1.1rem; }
  .topbar { padding: 14px 16px 4px; }
  .today { display: none; }
  .view { padding: 8px 16px 96px; }
}

/* ---------- Composants ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
  min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-dash { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-dash { grid-template-columns: 1fr; } }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi .label { font-size: .8rem; color: var(--muted); }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.kpi.alert { border-color: var(--danger); background: var(--danger-soft); }
@media (max-width: 520px) { .kpi .value { font-size: 1.15rem; } }

.btn {
  font: inherit; font-weight: 600; font-size: .9rem;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 9px; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: .82rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.b-libre { background: var(--ok-soft); color: var(--st-libre); }
.b-occupee { background: var(--primary-soft); color: var(--st-occupee); }
.b-reservee { background: #e1e9fa; color: var(--st-reservee); }
.b-nettoyage { background: var(--warn-soft); color: #9a6a06; }
.b-maintenance { background: var(--danger-soft); color: var(--danger); }
.b-terminee { background: var(--surface-2); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .b-reservee { background: #1d2a44; color: #8eaef0; }
  .b-nettoyage { color: var(--accent); }
}

/* Plan des chambres */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.floor { margin-top: 12px; }
.floor-title { font-size: .8rem; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.rooms { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); gap: 6px; }
@media (max-width: 760px) { .rooms { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.room {
  border: 0; border-radius: 9px; padding: 8px 4px; cursor: pointer; color: #fff;
  font: inherit; font-weight: 700; text-align: center; min-height: 54px;
  display: flex; flex-direction: column; justify-content: center; gap: 1px;
}
.room small { font-weight: 500; font-size: .66rem; opacity: .9; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room.libre { background: var(--st-libre); }
.room.occupee { background: var(--st-occupee); }
.room.reservee { background: var(--st-reservee); }
.room.nettoyage { background: var(--st-nettoyage); }
.room.maintenance { background: var(--st-maintenance); }
.room.waste { outline: 3px solid var(--danger); outline-offset: 1px; }
@media (prefers-color-scheme: dark) { .room.occupee { color: #0d1f1b; } }

/* Tableaux */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 8px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
td.r, th.r { text-align: right; }
tr:last-child td { border-bottom: 0; }

/* Alertes */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert-item { display: flex; gap: 10px; padding: 10px 12px; border-radius: 9px; background: var(--warn-soft); font-size: .9rem; }
.alert-item.danger { background: var(--danger-soft); }
.alert-item.ok { background: var(--ok-soft); }
.alert-item b { white-space: nowrap; }

/* Graphiques */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { fill: var(--muted); font-size: 10px; }
.chart .grid-line { stroke: var(--border); }
.chart-legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bar-row { display: grid; grid-template-columns: 70px 1fr 100px; gap: 8px; align-items: center; font-size: .85rem; margin-bottom: 6px; }
.bar-track { background: var(--surface-2); border-radius: 5px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 5px; background: var(--primary); }
.bar-fill.bad { background: var(--danger); }

/* Formulaires */
form .fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 520px) { form .fields { grid-template-columns: 1fr; } }
label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; font-weight: 600; color: var(--muted); }
label.full { grid-column: 1 / -1; }
input, select, textarea {
  font: inherit; font-size: .95rem; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select, .filters input { width: auto; }
.chip { font: inherit; font-size: .82rem; padding: 5px 12px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Modale */
dialog {
  border: 0; border-radius: 14px; padding: 0; width: min(560px, calc(100vw - 24px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 20, 18, .45); }
.modal-inner { padding: 20px; max-height: 85vh; overflow-y: auto; }
.modal-inner h2 { margin-bottom: 4px; font-size: 1.15rem; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .9rem; margin: 12px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* CNIB */
.id-box { border: 1px dashed var(--border); border-radius: 10px; padding: 12px; margin-bottom: 14px; background: var(--surface-2); }
.id-shots { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.id-shot {
  aspect-ratio: 1.58; border-radius: 9px; border: 1px solid var(--border); background: var(--surface) center / cover no-repeat;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--text); font-size: .9rem;
}
.id-shot.has-img span { background: rgba(0, 0, 0, .55); color: #fff; padding: 2px 8px; border-radius: 6px; font-size: .75rem; align-self: flex-end; margin-bottom: 6px; }
input.filled { background: var(--ok-soft); }

.empty { text-align: center; color: var(--muted); padding: 24px; }
.hint { font-size: .82rem; color: var(--muted); background: var(--surface-2); border-radius: 9px; padding: 10px 12px; }
