:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eaeef2;
  --text: #14202b;
  --muted: #62707d;
  --line: #d9e0e6;
  --accent: #0b7a75;
  --accent-text: #ffffff;
  --bubble-me: #0b7a75;
  --bubble-me-text: #ffffff;
  --warn: #b45309;
  --danger: #b42318;
  --ok: #157f3d;
  --radius: 16px;
  --bar: 56px;
  --tabs: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1720;
    --surface: #17212c;
    --surface-2: #1f2c39;
    --text: #e8eef3;
    --muted: #93a1ae;
    --line: #2a3a49;
    --accent: #2bb3ab;
    --accent-text: #06201f;
    --bubble-me: #167a74;
    --bubble-me-text: #ffffff;
    --warn: #f2a65a;
    --danger: #ff8a80;
    --ok: #5fd28a;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.screen { height: 100dvh; display: flex; flex-direction: column; }

/* Connexion */
#login { align-items: center; justify-content: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px;
  align-items: stretch; text-align: center; background: var(--surface);
  border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px;
}
.login-card img { align-self: center; border-radius: 16px; }
.login-card h1 { margin: 4px 0 0; font-size: 26px; }
.login-card p { margin: 0; }
input[type="password"], .field {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
button.primary {
  background: var(--accent); color: var(--accent-text); border: 0; border-radius: 12px;
  padding: 13px 16px; font-weight: 600;
}
button.primary:disabled { opacity: .6; }
button.ghost { background: none; border: 0; color: var(--muted); padding: 8px; }
button.small {
  border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px;
  padding: 7px 12px; font-size: 14px;
}
button.small.ok { background: var(--accent); color: var(--accent-text); border-color: transparent; }

/* Structure */
.topbar {
  height: calc(var(--bar) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 16px 0;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--line); background: var(--surface); flex: none;
}
.topbar h1 { margin: 0; font-size: 19px; }
.bar-actions { display: flex; gap: 2px; }
.bar-actions .ghost { color: var(--accent); font-weight: 600; }
.bar-actions #logout { color: var(--muted); font-weight: 400; }
main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; padding: 14px 16px 24px; }
#view-chat { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.tabs {
  height: calc(var(--tabs) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface);
  border-top: 1px solid var(--line); flex: none;
}
.tabs button { background: none; border: 0; color: var(--muted); font-size: 14px; font-weight: 500; }
.tabs button.active { color: var(--accent); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }

/* Chat */
.messages { flex: 1; overflow-y: auto; padding: 14px 14px 8px; display: flex; flex-direction: column; gap: 8px; }
.msg {
  max-width: 86%; padding: 10px 13px; border-radius: var(--radius); white-space: pre-wrap;
  overflow-wrap: anywhere; background: var(--surface); border: 1px solid var(--line);
}
.msg.user { align-self: flex-end; background: var(--bubble-me); color: var(--bubble-me-text); border-color: transparent; border-bottom-right-radius: 5px; }
.msg.assistant { align-self: flex-start; border-bottom-left-radius: 5px; }
.msg time { display: block; margin-top: 4px; font-size: 11px; opacity: .65; }
.msg.typing { color: var(--muted); font-style: italic; }
.composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; background: var(--surface);
  border-top: 1px solid var(--line); flex: none;
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px; padding: 10px 12px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--bg); outline: none;
}
.icon-btn, .send {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center; border-radius: 50%;
  border: 0; background: none; color: var(--muted);
}
.send { background: var(--accent); color: var(--accent-text); }
.icon-btn.rec { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .6; } }

/* Cartes */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { margin: 0 0 8px; font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
.row:first-of-type { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .sub { color: var(--muted); font-size: 13px; }
.row .actions { display: flex; gap: 6px; flex: none; }
.late { color: var(--danger); font-weight: 600; }
.chip { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; background: var(--surface-2); color: var(--muted); }
.chip.ok { color: var(--ok); } .chip.warn { color: var(--warn); } .chip.bad { color: var(--danger); }
.empty { color: var(--muted); padding: 6px 0; }
.bar { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.bar.over > i { background: var(--danger); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.kpi b { display: block; font-size: 20px; }
.kpi span { color: var(--muted); font-size: 13px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form .field { flex: 1 1 90px; min-width: 0; }

.pending {
  flex: none; background: color-mix(in srgb, var(--warn) 16%, var(--surface));
  border-bottom: 1px solid var(--warn); padding: 10px 16px;
}
.pending p { margin: 0 0 8px; }
.pending .actions { display: flex; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs) + 24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; max-width: 90vw; z-index: 10;
}
@media (min-width: 720px) {
  .view, .messages { padding-left: calc(50% - 340px); padding-right: calc(50% - 340px); }
  #view-chat .composer { padding-left: calc(50% - 340px); padding-right: calc(50% - 340px); }
}
