:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-soft: #ccfbf1;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 2px 8px rgba(15, 23, 42, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --surface: #111a2b; --surface-2: #0f172a; --border: #22304a; --text: #e2e8f0; --muted: #94a3b8;
    --brand: #2dd4bf; --brand-2: #14b8a6; --brand-soft: #134e4a; --danger: #f87171; --danger-soft: #450a0a;
    --warn: #fbbf24; --warn-soft: #422006; --ok: #4ade80; --ok-soft: #052e16;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.02rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: .75rem; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .6rem 1rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.logo { display: flex; align-items: center; gap: .5rem; font-weight: 800; letter-spacing: .04em; color: var(--brand); text-decoration: none; }
.logo img { width: 30px; height: 30px; }
.logo small { font-weight: 500; letter-spacing: 0; color: var(--muted); font-size: .75rem; }
.nav { display: flex; gap: .25rem; }
.nav a {
  position: relative; display: flex; align-items: center; gap: .4rem; padding: .45rem .75rem; border-radius: 999px;
  text-decoration: none; color: var(--muted); font-weight: 600; font-size: .92rem;
}
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav .badge { position: absolute; top: 0; right: 0; }
.me { display: flex; align-items: center; gap: .5rem; margin-left: auto; }
main { max-width: 1280px; margin: 0 auto; padding: 1rem; }
@media (max-width: 760px) {
  .topbar { padding: .5rem .75rem; }
  .topbar .nav { position: fixed; bottom: 0; left: 0; right: 0; justify-content: space-around; background: var(--surface);
    border-top: 1px solid var(--border); padding: .35rem .25rem calc(.35rem + env(safe-area-inset-bottom)); }
  .nav a { flex-direction: column; gap: 0; font-size: .7rem; padding: .3rem .4rem; border-radius: 10px; }
  .nav a .ico { font-size: 1.2rem; }
  main { padding: .75rem .75rem 5.5rem; }
  .me .name { display: none; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.grid-2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem; border: 1px solid var(--border);
  background: var(--surface); padding: .5rem .9rem; border-radius: 10px; cursor: pointer; font-weight: 600; min-height: 38px;
}
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #042f2e; } }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: .25rem .6rem; min-height: 30px; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label.field { display: block; }
label.field > span { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: .25rem; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], input[type=datetime-local], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); min-height: 40px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg label { padding: .45rem .8rem; cursor: pointer; border-right: 1px solid var(--border); user-select: none; }
.seg label:last-child { border-right: 0; }
.seg input { display: none; }
.seg label:has(input:checked) { background: var(--brand); color: #fff; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700; }
.tag { display: inline-flex; align-items: center; gap: .25rem; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); }
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.tag.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.alert { padding: .65rem .8rem; border-radius: 10px; font-size: .9rem; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.danger { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--brand-soft); color: var(--brand); }
.avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .8rem; flex: none; }
.avatar.lg { width: 96px; height: 96px; font-size: 2rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table-wrap { overflow-x: auto; }

/* ---------- toasts & modal ---------- */
#toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: 1rem; display: grid; gap: .5rem; width: min(92vw, 420px); }
@media (max-width: 760px) { #toasts { bottom: 5rem; } }
.toast { padding: .7rem 1rem; border-radius: 10px; background: #0f172a; color: #fff; box-shadow: var(--shadow); animation: pop .2s ease; }
.toast.error { background: var(--danger); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.modal-bg { position: fixed; inset: 0; z-index: 50; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; padding: 1rem; }
.modal { background: var(--surface); border-radius: 16px; width: min(560px, 100%); max-height: 92vh; overflow: auto; padding: 1.25rem; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal header { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; }
.modal header h2 { margin: 0; flex: 1; }
.modal footer { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1.25rem; flex-wrap: wrap; }
@media (max-width: 760px) { .modal-bg { align-items: flex-end; padding: 0; } .modal { border-radius: 16px 16px 0 0; max-height: 88vh; } }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: radial-gradient(circle at 20% 10%, var(--brand-soft), transparent 50%), var(--bg); }
.login .card { width: min(400px, 100%); padding: 2rem; }
.login .brand { text-align: center; margin-bottom: 1.5rem; }
.login .brand img { width: 64px; height: 64px; }
.login .brand h1 { color: var(--brand); letter-spacing: .08em; margin: .5rem 0 .15rem; }

/* ---------- plan des chambres ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { font-size: .8rem; color: var(--muted); }
.loads { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .5rem; margin-bottom: 1rem; }
.load { display: flex; align-items: center; gap: .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .75rem; }
.load .bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: .3rem; border: 1px solid var(--border); }
.load .bar i { display: block; height: 100%; }
.load.absent { opacity: .55; }
.rooms { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .75rem; }
.room { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem; box-shadow: var(--shadow); }
.room-head { display: flex; align-items: center; gap: .4rem; font-weight: 700; margin-bottom: .45rem; }
.room-head .kind { font-weight: 500; font-size: .75rem; color: var(--muted); }
.beds { display: grid; gap: .4rem; }
.room.double .beds { grid-template-columns: 1fr 1fr; }
.bed {
  min-height: 74px; border: 2px dashed var(--border); border-radius: 10px; padding: .4rem; cursor: pointer;
  display: flex; flex-direction: column; gap: .2rem; position: relative; transition: border-color .15s, background .15s;
}
.bed .pos { font-size: .72rem; font-weight: 700; color: var(--muted); }
.bed.free:hover, .bed.drop { border-color: var(--brand-2); background: var(--brand-soft); }
.bed.blocked { border-style: solid; border-color: var(--danger); background: repeating-linear-gradient(45deg, var(--danger-soft), var(--danger-soft) 6px, transparent 6px, transparent 12px); }
.bed.blocked .why { font-size: .72rem; color: var(--danger); font-weight: 600; }
.bed.occupied { border-style: solid; }
.bed.target { outline: 3px solid var(--brand-2); outline-offset: 1px; }
.pchip {
  display: flex; flex-direction: column; gap: .1rem; border-radius: 8px; padding: .3rem .45rem; background: var(--surface-2);
  border-left: 5px solid var(--c, var(--brand)); cursor: grab; user-select: none;
}
.pchip b { font-size: .98rem; }
.pchip .meta { font-size: .72rem; color: var(--muted); display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; }
.pchip.moving { outline: 3px solid var(--warn); }
.pchip .exit { color: var(--warn); font-weight: 700; }
.waiting { margin-top: 1rem; border: 2px dashed var(--warn); border-radius: var(--radius); padding: .75rem; background: var(--warn-soft); }
.waiting.drop { background: var(--brand-soft); border-color: var(--brand-2); }
.waiting .list { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .5rem; }
.waiting .pchip { min-width: 140px; }
.move-banner { position: sticky; top: 56px; z-index: 15; margin-bottom: .75rem; }

/* ---------- agenda ---------- */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal .wd { background: var(--surface-2); padding: .4rem; font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; text-align: center; }
.cal .day { background: var(--surface); min-height: 110px; padding: .3rem; display: flex; flex-direction: column; gap: .2rem; }
.cal .day.out { background: var(--surface-2); opacity: .55; }
.cal .day.we { background: var(--surface-2); }
.cal .day.today .num { background: var(--brand); color: #fff; border-radius: 999px; padding: 0 .4rem; }
.cal .num { font-weight: 700; font-size: .82rem; align-self: flex-start; }
.cal .num .full { display: none; }
.cal .hol { font-size: .68rem; color: var(--danger); font-weight: 600; }
.ev { font-size: .74rem; padding: .1rem .35rem; border-radius: 5px; line-height: 1.3; border-left: 3px solid var(--c, var(--brand)); background: var(--surface-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: default; }
.ev.leave { background: color-mix(in srgb, var(--c) 18%, transparent); }
.ev.pending { border-left-style: dashed; background: transparent; outline: 1px dashed var(--c); }
.ev.event { border-left-color: #7c3aed; cursor: pointer; }
.legend { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin: .75rem 0; }
@media (max-width: 760px) {
  .cal { display: block; background: none; border: 0; }
  .cal .wd, .cal .day.out, .cal .day.empty { display: none; }
  .cal .day { min-height: 0; border: 1px solid var(--border); border-radius: 10px; margin-bottom: .4rem; padding: .5rem; }
  .cal .num .short { display: none; } .cal .num .full { display: inline; }
  .ev { white-space: normal; font-size: .82rem; }
}

/* ---------- misc ---------- */
.leave-item { display: flex; gap: .75rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.leave-item:last-child { border-bottom: 0; }
.pending-card { border: 1px solid var(--border); border-radius: 10px; padding: .75rem; }
.pending-card + .pending-card { margin-top: .75rem; }
video.cam { width: 100%; border-radius: 12px; background: #000; }
.qr { display: block; margin: .5rem auto; width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 8px; }
.empty-state { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* ---------- V2 ---------- */
.avatar.sm { width: 24px; height: 24px; font-size: .65rem; }
.ev.astreinte { border-left-color: #0ea5e9; background: color-mix(in srgb, #0ea5e9 14%, transparent); }
img.thumb { display: block; max-width: 160px; max-height: 120px; border-radius: 8px; margin-top: .35rem; cursor: zoom-in; object-fit: cover; }
img.thumb.big { max-width: 100%; max-height: 70vh; cursor: zoom-out; }
.tx { border-left: 3px solid var(--border); padding: .35rem .6rem; background: var(--surface-2); border-radius: 0 8px 8px 0; }
.tx.important { border-left-color: var(--warn); }
.tx-body { white-space: pre-wrap; word-break: break-word; margin-top: .2rem; }
textarea { width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); resize: vertical; }

.chat { display: flex; flex-direction: column; height: calc(100vh - 110px); max-width: 860px; margin: 0 auto; }
.feed { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; padding: .5rem .25rem; }
.msg { display: flex; gap: .5rem; align-items: flex-end; max-width: 80%; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble { background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px 14px 14px 4px; padding: .45rem .7rem; }
.msg.mine .bubble { background: var(--brand-soft); border-color: transparent; border-radius: 14px 14px 4px 14px; }
.day-sep { align-self: center; font-size: .75rem; color: var(--muted); background: var(--surface-2); padding: .1rem .7rem; border-radius: 999px; margin: .5rem 0; }
.composer { border-top: 1px solid var(--border); padding-top: .6rem; }
.composer textarea { resize: none; min-height: 40px; }
@media (max-width: 760px) { .chat { height: calc(100vh - 150px); padding: .6rem; } .msg { max-width: 92%; } }

.task { border: 1px solid var(--border); border-radius: 10px; padding: .6rem .75rem; }
.task + .task { margin-top: .5rem; }

.share-row { display: grid; grid-template-columns: 140px 1fr 110px; gap: .75rem; align-items: center; }
.share-name { display: flex; align-items: center; gap: .4rem; font-weight: 600; }
.share-bar { position: relative; height: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; }
.share-bar i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; }
.share-bar em { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--text); }
.share-val { text-align: right; }
.stats-table td, .stats-table th { white-space: nowrap; text-align: center; }
.stats-table td:first-child, .stats-table th:first-child { text-align: left; }
@media (max-width: 760px) {
  .share-row { grid-template-columns: 90px 1fr 80px; gap: .4rem; }
  .topbar .nav { overflow-x: auto; justify-content: flex-start; }
  .nav a { min-width: 64px; flex: none; }
}
@media print {
  .topbar, .seg, .btn, select, #toasts { display: none !important; }
  main { padding: 0; } .card { box-shadow: none; break-inside: avoid; }
}
@media (min-width: 761px) and (max-width: 1180px) {
  .nav a > span:not(.ico):not(.badge) { display: none; }
  .nav a .ico { font-size: 1.15rem; }
  .logo small, .me .name { display: none; }
}

/* ---------- V3 ---------- */
#polls { margin-bottom: .5rem; max-height: 45%; overflow-y: auto; border-bottom: 1px solid var(--border); padding-bottom: .5rem; }
#polls summary { cursor: pointer; padding: .25rem 0; }
.polls { display: grid; gap: .6rem; margin-top: .5rem; }
.poll { border: 1px solid var(--border); border-radius: 10px; padding: .6rem .75rem; }
.poll.closed { opacity: .75; }
.poll-opt { display: grid; grid-template-columns: auto minmax(90px, 1fr) 2fr auto; gap: .5rem; align-items: center; padding: .3rem .4rem; border-radius: 8px; cursor: pointer; }
.poll-opt.chosen { background: var(--brand-soft); }
.poll-bar { height: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.poll-bar i { display: block; height: 100%; background: var(--brand-2); border-radius: 0 3px 3px 0; }
.poll-names { grid-column: 2 / -1; margin-top: -.25rem; }
.poll-names:empty { display: none; }

.rules { padding-left: 1.1rem; margin: .75rem 0; display: grid; gap: .45rem; font-size: .92rem; }
.rules li { list-style: none; margin-left: -1.1rem; }

.help-frame { display: block; width: 100%; height: calc(100vh - 90px); border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
@media (max-width: 760px) { .help-frame { height: calc(100vh - 140px); } }
