:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6c6c70;
  --line: #e1e1e6;
  --accent: #0a64d6;
  --accent-text: #ffffff;
  --danger: #d62f2f;
  --ok: #2b8a3e;
  --c-reunion: #0a64d6;
  --c-visio: #7b3fe4;
  --c-rendu: #e8590c;
  --c-chantier: #2b8a3e;
  --c-autre: #6c757d;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #98989f;
    --line: #38383a;
    --accent: #4d9bff;
    --accent-text: #001a3d;
    --danger: #ff6b6b;
    --ok: #51cf66;
    --c-reunion: #4d9bff;
    --c-visio: #b197fc;
    --c-rendu: #ff922b;
    --c-chantier: #51cf66;
    --c-autre: #adb5bd;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- Structure ---------- */
#app { height: 100%; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.topbar {
  padding: calc(var(--safe-top) + 10px) 14px 8px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 8px;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 700; text-transform: capitalize; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.topbar { gap: 2px; }
.topbar .icon-btn { width: 34px; }
.topbar .segmented { margin-left: 6px; }
.content { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px 24px; }
.tabbar {
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: none; padding: 9px 4px 7px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px;
}
.tabbar button svg { width: 24px; height: 24px; }
.tabbar button.on { color: var(--accent); }
.badge { background: var(--danger); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }

/* ---------- Boutons ---------- */
.btn {
  border: 0; border-radius: 10px; padding: 10px 16px; background: var(--accent); color: var(--accent-text);
  font-weight: 600;
}
a.btn { display: inline-block; text-align: center; text-decoration: none; }
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.icon-btn {
  border: 0; background: none; color: var(--accent); width: 38px; height: 38px; border-radius: 19px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 22px;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: var(--line); }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--safe-bottom) + 72px); width: 56px; height: 56px; border-radius: 28px;
  border: 0; background: var(--accent); color: var(--accent-text); font-size: 30px; line-height: 1;
  box-shadow: 0 4px 14px rgba(0,0,0,.28); z-index: 5;
}

/* ---------- Cartes ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.card h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 8px; }
.grow { flex: 1; min-width: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* ---------- Agenda ---------- */
.month { background: var(--card); border-radius: var(--radius); padding: 6px; margin-bottom: 12px; }
.dow, .grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.dow span { text-align: center; font-size: 11px; color: var(--muted); padding: 4px 0; text-transform: uppercase; }
.day {
  border: 0; background: none; padding: 5px 0 4px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-height: 52px; border-radius: 10px;
}
.day .n { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; border-radius: 15px; font-size: 16px; }
.day.other { opacity: .35; }
.day.today .n { color: var(--accent); font-weight: 700; }
.day.sel .n { background: var(--accent); color: var(--accent-text); }
.dots { display: flex; gap: 3px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 3px; background: var(--c-autre); }
.dot.reunion { background: var(--c-reunion); } .dot.visio { background: var(--c-visio); }
.dot.rendu { background: var(--c-rendu); } .dot.chantier { background: var(--c-chantier); }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.segmented button { border: 0; background: none; padding: 5px 12px; font-size: 14px; color: var(--muted); }
.segmented button.on { background: var(--accent); color: var(--accent-text); }
.dayhead { font-weight: 700; margin: 14px 4px 8px; text-transform: capitalize; }
.dayhead.today { color: var(--accent); }
.ev {
  display: flex; gap: 10px; background: var(--card); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px;
  border: 0; width: 100%; text-align: left;
}
.ev .bar { width: 4px; border-radius: 2px; background: var(--c-autre); flex: none; }
.ev.reunion .bar { background: var(--c-reunion); } .ev.visio .bar { background: var(--c-visio); }
.ev.rendu .bar { background: var(--c-rendu); } .ev.chantier .bar { background: var(--c-chantier); }
.ev .t { font-weight: 600; }
.ev .time { color: var(--muted); font-size: 13px; min-width: 58px; }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--bg); color: var(--muted); margin-right: 4px; }
.chip.ok { color: var(--ok); } .chip.warn { color: var(--c-rendu); } .chip.bad { color: var(--danger); }

/* ---------- Feuilles (formulaires) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 94%; border-radius: 18px 18px 0 0; display: flex; flex-direction: column;
  animation: up .18s ease-out;
}
.sheet.full { height: 100%; max-height: 100%; border-radius: 0; max-width: none; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: calc(10px + var(--safe-top) * 0) 12px; background: var(--card); border-radius: 18px 18px 0 0; border-bottom: 1px solid var(--line); }
.sheet.full .sheet-head { border-radius: 0; padding-top: calc(var(--safe-top) + 10px); }
.sheet-head h2 { flex: 1; text-align: center; margin: 0; font-size: 17px; }
.sheet-head .btn-text { border: 0; background: none; color: var(--accent); font-size: 17px; padding: 6px 4px; }
.sheet-head .btn-text.strong { font-weight: 700; }
.sheet-body { overflow-y: auto; padding: 12px; padding-bottom: calc(var(--safe-bottom) + 20px); -webkit-overflow-scrolling: touch; }
.field { background: var(--card); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.field > .line { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); min-height: 46px; }
.field > .line:last-child { border-bottom: 0; }
.field label.l { color: var(--muted); font-size: 14px; min-width: 78px; }
.field input[type=text], .field input[type=email], .field input[type=url], .field input[type=password], .field input[type=number],
.field input[type=datetime-local], .field input[type=date], .field select, .field textarea {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none; padding: 2px 0;
}
.field textarea { min-height: 80px; resize: vertical; width: 100%; padding: 10px 14px; }
.field.plain textarea { display: block; }
.field select { appearance: none; -webkit-appearance: none; text-align: right; color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 14px 0; }
.chips .c { background: var(--bg); border-radius: 14px; padding: 3px 4px 3px 10px; font-size: 14px; display: inline-flex; align-items: center; gap: 4px; }
.chips .c button { border: 0; background: none; color: var(--muted); font-size: 16px; padding: 0 6px; }
.cats { display: flex; gap: 6px; padding: 10px 12px; flex-wrap: wrap; }
.cats button { border: 1px solid var(--line); background: none; border-radius: 16px; padding: 5px 12px; font-size: 14px; display: inline-flex; gap: 6px; align-items: center; }
.cats button.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.cats i { width: 9px; height: 9px; border-radius: 5px; display: inline-block; background: var(--c-autre); }
.cats .reunion i { background: var(--c-reunion); } .cats .visio i { background: var(--c-visio); }
.cats .rendu i { background: var(--c-rendu); } .cats .chantier i { background: var(--c-chantier); }
.hint { font-size: 13px; color: var(--muted); padding: 0 6px 12px; }
.error { color: var(--danger); font-size: 14px; padding: 4px 6px 10px; }

/* ---------- Mail ---------- */
.mailbar { display: flex; gap: 8px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.mailbar select, .mailbar input {
  border: 1px solid var(--line); background: var(--bg); border-radius: 9px; padding: 7px 10px; min-width: 0;
}
.mailbar input { flex: 1; }
.msg { display: flex; gap: 10px; padding: 10px 12px; background: var(--card); border: 0; border-bottom: 1px solid var(--line); width: 100%; text-align: left; }
.msg .dotu { width: 10px; height: 10px; border-radius: 5px; margin-top: 7px; flex: none; }
.msg.unread .dotu { background: var(--accent); }
.msg.unread .from, .msg.unread .subj { font-weight: 700; }
.msg .line1 { display: flex; gap: 8px; }
.msg .from { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg .date { color: var(--muted); font-size: 13px; flex: none; }
.msg .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.maillist { background: var(--card); }
iframe.mailbody { width: 100%; border: 0; background: #fff; border-radius: 10px; min-height: 120px; display: block; }
.attach { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.invite { border-left: 4px solid var(--c-reunion); }
.invite .btns { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- Divers ---------- */
.login { margin: auto; width: min(360px, 92%); text-align: center; padding-top: 12vh; }
.login img { width: 84px; height: 84px; border-radius: 19px; }
.login h1 { margin: 12px 0 18px; }
.login input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); margin-bottom: 10px; }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; margin: 8px 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.copybox { background: var(--bg); border-radius: 10px; padding: 10px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; }
ol.steps { padding-left: 20px; margin: 8px 0; } ol.steps li { margin: 6px 0; }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: calc(var(--safe-bottom) + 84px);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none;
  transition: .2s; z-index: 50; max-width: 90%; text-align: center; font-size: 15px;
}
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--danger); }
.spinner { text-align: center; color: var(--muted); padding: 24px; }
