:root {
  --bg: #f4f2ec;
  --surface: #ffffff;
  --surface-2: #f6f4ef;
  --surface-3: #ece8de;
  --text: #17201d;
  --muted: #6b746f;
  --border: #e6e1d6;
  --primary: #0c4a3e;
  --primary-2: #13695a;
  --primary-soft: #e3efea;
  --accent: #d99a1e;
  --accent-soft: #fbf1db;
  --danger: #c0412c;
  --danger-soft: #fbe9e5;
  --ok: #2c8a57;
  --ok-soft: #e2f3e8;
  --info: #3466c2;
  --info-soft: #e5ecfa;

  --st-libre: #2c8a57;
  --st-occupee: #0c4a3e;
  --st-reservee: #3466c2;
  --st-nettoyage: #d99a1e;
  --st-maintenance: #c0412c;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(23, 32, 29, .04), 0 4px 16px rgba(23, 32, 29, .05);
  --shadow-lg: 0 12px 40px rgba(23, 32, 29, .18);
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 15px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
h2 { font-size: 1rem; font-weight: 700; }
a { color: var(--primary-2); }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.num { font-variant-numeric: tabular-nums; }
svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Mise en page ---------- */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--primary); color: #fff;
  padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px; }
.brand img { border-radius: 12px; box-shadow: 0 0 0 2px rgba(255, 255, 255, .15); }
.brand strong { display: block; font-size: .95rem; line-height: 1.25; }
.brand span { font-size: .78rem; opacity: .7; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px;
  color: rgba(255, 255, 255, .78); text-decoration: none; font-weight: 600; font-size: .93rem;
  transition: background .15s, color .15s;
}
.nav a svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
.nav a.active { background: #fff; color: var(--primary); }
.nav-settings { margin-top: 8px; }
.net { margin-top: auto; font-size: .8rem; opacity: .8; padding: 0 10px; }
.net .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; }

.main { min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 24px 32px 8px; max-width: 1360px;
}
.eyebrow { display: block; font-size: .8rem; color: var(--muted); font-weight: 500; text-transform: capitalize; margin-bottom: 2px; }
.topbar h1 { font-size: 1.6rem; font-weight: 800; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.view { padding: 12px 32px 40px; display: flex; flex-direction: column; gap: 20px; max-width: 1360px; }
.show-sm { display: none !important; }

.icon-btn {
  width: 42px; height: 42px; border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
}
.fab {
  position: fixed; right: 16px; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 25;
  width: 56px; height: 56px; border-radius: 18px; border: 0; cursor: pointer;
  background: var(--accent); color: #1d1607; box-shadow: 0 8px 24px rgba(217, 154, 30, .45);
  align-items: center; justify-content: center;
}
.fab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: auto 0 0 0; height: auto; z-index: 30; padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    flex-direction: row; background: var(--surface); color: var(--text); border-top: 1px solid var(--border);
    box-shadow: 0 -4px 20px rgba(23, 32, 29, .06);
  }
  .brand, .net, .nav-settings { display: none !important; }
  .nav { flex-direction: row; width: 100%; gap: 2px; }
  .nav a {
    flex: 1; flex-direction: column; gap: 3px; padding: 7px 2px; font-size: .68rem; font-weight: 600;
    color: var(--muted); border-radius: 12px; text-align: center;
  }
  .nav a svg { width: 22px; height: 22px; }
  .nav a:hover { background: none; color: var(--muted); }
  .nav a.active { background: var(--primary-soft); color: var(--primary); }
  .topbar {
    position: sticky; top: 0; z-index: 20; padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
    background: rgba(244, 242, 236, .92); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  }
  .topbar h1 { font-size: 1.3rem; }
  .view { padding: 4px 16px calc(96px + env(safe-area-inset-bottom)); gap: 14px; }
  .hide-sm { display: none !important; }
  .show-sm { display: inline-flex !important; }
}

/* ---------- Cartes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head a { font-size: .84rem; font-weight: 600; text-decoration: none; }
.grid { display: grid; gap: 20px; }
.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.55fr) minmax(0, 1fr); }
@media (max-width: 1180px) { .grid-dash { grid-template-columns: minmax(0, 1fr); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } .grid { gap: 14px; } .card { padding: 16px; border-radius: 14px; } }

/* ---------- Indicateurs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); min-width: 0; position: relative; overflow: hidden;
}
.kpi::before { content: ""; position: absolute; left: 0; top: 18px; bottom: 18px; width: 4px; border-radius: 0 4px 4px 0; background: var(--primary-2); }
.kpi .label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 1.55rem; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1.15; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: 6px; }
.kpi.alert { background: var(--danger-soft); border-color: #f1cfc7; }
.kpi.alert::before { background: var(--danger); }
.kpi.alert .value { color: var(--danger); }
@media (max-width: 1180px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .kpis { gap: 10px; }
  .kpi { padding: 14px; border-radius: 14px; }
  .kpi::before { top: 14px; bottom: 14px; }
  .kpi .value { font-size: 1.12rem; }
  .kpi .sub { font-size: .74rem; }
}

/* ---------- Boutons ---------- */
.btn {
  font: inherit; font-weight: 700; font-size: .88rem; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 10px 16px; border-radius: 12px; cursor: pointer; transition: background .15s, filter .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: .8rem; border-radius: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-col { display: flex; flex-direction: column; gap: 8px; }
.btn-col .btn { justify-content: flex-start; padding: 12px 14px; }

.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: .74rem; font-weight: 700; white-space: nowrap; }
.b-libre { background: var(--ok-soft); color: var(--ok); }
.b-occupee { background: var(--primary-soft); color: var(--primary); }
.b-reservee { background: var(--info-soft); color: var(--info); }
.b-nettoyage { background: var(--accent-soft); color: #94660a; }
.b-maintenance { background: var(--danger-soft); color: var(--danger); }
.b-terminee { background: var(--surface-3); color: var(--muted); }

/* ---------- Plan des chambres ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .78rem; color: var(--muted); font-weight: 500; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.floor { margin-top: 16px; }
.floor-title { font-size: .74rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr)); gap: 8px; }
.room {
  border: 0; border-radius: 12px; padding: 10px 4px 8px; cursor: pointer; color: #fff;
  font: inherit; font-weight: 800; font-size: .95rem; text-align: center; min-height: 58px;
  display: flex; flex-direction: column; justify-content: center; gap: 1px; position: relative;
  transition: transform .12s, box-shadow .12s;
}
.room:hover { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(23, 32, 29, .16); }
.room small { font-weight: 600; font-size: .64rem; opacity: .85; 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); color: #2a1d02; }
.room.maintenance { background: var(--st-maintenance); }
.room.waste::after {
  content: ""; position: absolute; top: 5px; right: 5px; width: 9px; height: 9px; border-radius: 50%;
  background: #ff5a3c; box-shadow: 0 0 0 2px #fff;
}
@media (max-width: 760px) { .rooms { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; } .room { min-height: 52px; font-size: .88rem; border-radius: 10px; } }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 10px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
td.r, th.r { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr[data-action] { cursor: pointer; }
tbody tr[data-action]:hover td { background: var(--surface-2); }

/* Sur téléphone, chaque ligne devient une carte */
@media (max-width: 760px) {
  .table-wrap { margin: 0; padding: 0; overflow: visible; }
  table.rtable thead { display: none; }
  table.rtable, table.rtable tbody, table.rtable tr, table.rtable td { display: block; width: 100%; }
  table.rtable tr { padding: 12px 0; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
  table.rtable tbody tr:last-child { border-bottom: 0; }
  table.rtable td { border: 0; padding: 0; text-align: left !important; font-size: .88rem; min-width: 0; }
  table.rtable td::before { content: attr(data-label); display: block; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  table.rtable td:first-child { grid-column: 1 / -1; font-size: .95rem; }
  table.rtable td:first-child::before { display: none; }
  table.rtable td:empty, table.rtable td.nolabel::before { display: none; }
  tbody tr[data-action]:hover td { background: none; }
}

/* ---------- Alertes ---------- */
.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert-item {
  display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 12px 14px; border-radius: 12px;
  background: var(--accent-soft); font-size: .86rem; align-items: start;
}
.alert-item::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 6px; grid-row: span 2; }
.alert-item.danger { background: var(--danger-soft); }
.alert-item.danger::before { background: var(--danger); }
.alert-item.ok { background: var(--ok-soft); }
.alert-item.ok::before { background: var(--ok); }
.alert-item b { font-weight: 700; }
.alert-item span { color: #3f4744; }
.more { font-size: .84rem; font-weight: 700; color: var(--primary-2); background: none; border: 0; cursor: pointer; padding: 6px 0 0; font-family: inherit; }

/* ---------- Graphiques ---------- */
.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .grid-line { stroke: var(--border); }
.chart-legend { display: flex; gap: 6px 16px; font-size: .78rem; color: var(--muted); margin-top: 10px; flex-wrap: wrap; font-weight: 500; }
.chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.bar-row { display: grid; grid-template-columns: 64px 1fr 96px; gap: 10px; align-items: center; font-size: .85rem; margin-bottom: 10px; }
.bar-row.wide { grid-template-columns: minmax(110px, 160px) 1fr 104px; }
.bar-track { background: var(--surface-3); border-radius: 6px; height: 10px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--primary-2); }
.bar-fill.bad { background: var(--danger); }
@media (max-width: 760px) {
  .bar-row.wide { grid-template-columns: 1fr auto; }
  .bar-row.wide .bar-track { grid-column: 1 / -1; grid-row: 2; }
}

/* ---------- Formulaires ---------- */
form .fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 560px) { form .fields { grid-template-columns: minmax(0, 1fr); } }
label { display: flex; flex-direction: column; gap: 6px; font-size: .8rem; font-weight: 700; color: var(--muted); }
label.full { grid-column: 1 / -1; }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--text); font-weight: 600; font-size: .9rem; }
label.check input { width: 20px; height: 20px; accent-color: var(--primary); }
input, select, textarea {
  font: inherit; font-size: 1rem; color: var(--text); font-weight: 500;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 11px 12px; width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(19, 105, 90, .15); }
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 42px; background: var(--surface); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
@media (max-width: 560px) { .form-actions .btn { flex: 1; } }

.filters { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  font: inherit; font-size: .82rem; font-weight: 700; padding: 8px 14px; border-radius: 99px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; color: var(--text); white-space: nowrap; flex: none;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.toolbar .filters { flex: 1; min-width: 0; }

/* ---------- Fenêtre ---------- */
dialog {
  border: 0; border-radius: 20px; padding: 0; width: min(580px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(12, 30, 26, .5); backdrop-filter: blur(2px); }
.modal-inner { padding: 24px; max-height: 88vh; overflow-y: auto; }
.modal-inner h2 { font-size: 1.2rem; font-weight: 800; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
@media (max-width: 560px) {
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 22px 22px 0 0; }
  dialog[open] { animation: sheet .22s ease-out; }
  .modal-inner { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; }
  .modal-inner::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--surface-3); margin: -8px auto 14px; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: .9rem; margin: 16px 0; padding: 14px; background: var(--surface-2); border-radius: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 600;
  font-size: .9rem; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100vw - 32px); box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 900px) { .toast { bottom: calc(150px + env(safe-area-inset-bottom)); } }

/* CNIB */
.id-box { border: 1.5px dashed #d6d0c1; border-radius: 14px; padding: 14px; margin: 14px 0 18px; background: var(--surface-2); }
.id-shots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.id-shot {
  aspect-ratio: 1.58; border-radius: 12px; 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; font-weight: 700;
}
.id-shot.has-img span { background: rgba(0, 0, 0, .55); color: #fff; padding: 2px 8px; border-radius: 6px; font-size: .74rem; align-self: flex-end; margin-bottom: 6px; }
input.filled { background: var(--ok-soft); border-color: #bfe0cb; }

.list-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.list-row:last-child { border-bottom: 0; }
.list-row .room-tag { width: 44px; height: 36px; border-radius: 10px; background: var(--primary-soft); color: var(--primary); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: .85rem; flex: none; }
.list-row .grow { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Réservations en cartes (téléphone) */
.only-md { display: none; }
@media (max-width: 760px) { .only-md { display: flex; } .hide-md { display: none !important; } }
.res-cards { flex-direction: column; gap: 10px; }
.res-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 10px; }
.rc-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.rc-top b { font-size: .98rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rc-mid { display: flex; align-items: center; gap: 10px; font-size: .86rem; color: var(--muted); font-weight: 500; }
.rc-mid .room-tag, .list-row .room-tag { width: 44px; height: 32px; border-radius: 9px; background: var(--primary-soft); color: var(--primary); font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: .85rem; flex: none; }
.rc-bot { display: flex; justify-content: space-between; font-size: .84rem; color: var(--muted); padding-top: 10px; border-top: 1px solid var(--border); }
.rc-bot b { color: var(--text); }
.rc-bot .due { color: var(--danger); font-weight: 700; }
.rc-bot .paid { color: var(--ok); font-weight: 700; }

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