/* ================================================================ tokens */
:root {
  --bg: #0b0d12;
  --bg-glow: rgba(124, 140, 255, 0.10);
  --surface: #12151d;
  --surface-2: #181c27;
  --surface-3: #1f2432;
  --border: #242a39;
  --text: #e9ecf3;
  --muted: #8d95a8;
  --faint: #5c6478;
  --accent: #7c8cff;
  --accent-2: #b48cff;
  --accent-ink: #ffffff;
  --user-bubble: linear-gradient(135deg, #6f7ff7, #9a7cf5);
  --danger: #ff6b7a;
  --ok: #34d399;

  --p-42: #5b8cff;
  --p-benagency: #ff9f43;
  --p-sport: #34d399;
  --p-sommeil: #a78bfa;
  --p-life: #f5c84c;

  --radius: 18px;
  --radius-sm: 11px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --topbar: 58px;
  --tabbar: 64px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f9;
    --bg-glow: rgba(124, 140, 255, 0.12);
    --surface: #ffffff;
    --surface-2: #f6f7fb;
    --surface-3: #eceef5;
    --border: #e3e6ee;
    --text: #151823;
    --muted: #646c80;
    --faint: #9aa1b2;
    --accent: #5b6cf0;
    --accent-2: #8f63f0;
    --shadow: 0 10px 30px rgba(20, 24, 40, 0.08);
    --p-life: #d9a514;
    color-scheme: light;
  }
}

/* ================================================================ base */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(900px 500px at 15% -10%, var(--bg-glow), transparent 60%),
    radial-gradient(700px 400px at 110% 10%, rgba(180, 140, 255, 0.07), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); font-size: 13.5px; margin: 0; }

/* ================================================================ orb (logo) */
.orb {
  width: 26px; height: 26px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #fff 0 8%, transparent 9%),
              conic-gradient(from 200deg, var(--accent), var(--accent-2), #5be0d0, var(--accent));
  box-shadow: 0 0 18px rgba(124, 140, 255, 0.55);
  flex: none;
}
.orb-lg { width: 64px; height: 64px; margin: 0 auto 8px; animation: breathe 4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.06); box-shadow: 0 0 34px rgba(124, 140, 255, 0.7); } }

/* ================================================================ buttons */
.btn {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; padding: 7px 14px; font-weight: 500; font-size: 14px;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: scale(.97); }
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0; color: var(--accent-ink); padding: 12px 18px; font-weight: 600;
}
.btn-ghost { background: transparent; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border-radius: 12px; border: 0; background: transparent; color: var(--muted);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ================================================================ login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(360px, 100%); display: grid; gap: 12px; text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 24px; padding: 32px 24px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0; font-size: 26px; letter-spacing: -.02em; }
.login-card p { margin: 0 0 8px; }
.login-card input {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }

/* ================================================================ layout */
.app { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar); flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; letter-spacing: -.01em; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }

.layout {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
}

/* ================================================================ chat */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.messages {
  flex: 1; overflow-y: auto; padding: 24px 16px 12px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}
.messages > * { width: 100%; max-width: 760px; margin-inline: auto; }

.welcome { text-align: center; margin: auto; padding: 40px 0; }
.welcome .orb { margin-bottom: 18px; }
.welcome h1 { font-size: 26px; margin: 0 0 6px; letter-spacing: -.02em; }
.welcome p { margin: 0 auto; color: var(--muted); max-width: 420px; }

.msg { display: flex; flex-direction: column; animation: rise .22s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.msg-user { align-items: flex-end; }
.bubble {
  max-width: min(92%, 640px); padding: 11px 15px; border-radius: var(--radius);
  overflow-wrap: anywhere;
}
.msg-user .bubble { background: var(--user-bubble); color: #fff; border-bottom-right-radius: 6px; }
.msg-bot .bubble {
  background: var(--surface); border: 1px solid var(--border);
  border-bottom-left-radius: 6px; max-width: 100%;
}
.msg-error .bubble { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.msg-meta { font-size: 11.5px; color: var(--faint); margin: 4px 6px 0; display: flex; gap: 6px; align-items: center; }
.msg-tag {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600;
  color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
  padding: 1px 7px; border-radius: 999px;
}

/* rendu markdown */
.bubble p { margin: 0 0 8px; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble h4 { margin: 12px 0 6px; font-size: 15px; }
.bubble h4:first-child { margin-top: 0; }
.bubble ul, .bubble ol { margin: 4px 0 10px; padding-left: 20px; }
.bubble li { margin: 3px 0; }
.bubble li::marker { color: var(--faint); }
.bubble code { font-size: 13px; background: var(--surface-3); padding: 1px 6px; border-radius: 6px; }
.bubble hr { border: 0; border-top: 1px solid var(--border); margin: 10px 0; }
.bubble strong { font-weight: 600; }

.typing .bubble { display: inline-flex; gap: 5px; padding: 15px 16px; width: fit-content; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* composer */
.composer { flex: none; padding: 8px 16px 16px; }
.composer > * { max-width: 760px; margin-inline: auto; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface);
  border-radius: 999px; padding: 7px 13px; font-size: 13.5px; color: var(--text);
  transition: border-color .15s, background .15s;
}
.chip:hover { border-color: var(--accent); background: var(--surface-2); }
.input-row {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 6px 6px 6px 16px; box-shadow: var(--shadow);
  transition: border-color .15s;
}
.input-row:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.input-row textarea {
  flex: 1; resize: none; border: 0; outline: none; background: transparent;
  padding: 9px 0; max-height: 160px; line-height: 1.45; font-size: 15.5px;
}
.input-row textarea::placeholder { color: var(--faint); }
.send {
  width: 40px; height: 40px; border-radius: 50%; border: 0; flex: none;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  transition: opacity .15s, transform .1s;
}
.send:disabled { opacity: .4; cursor: default; }
.send:active:not(:disabled) { transform: scale(.94); }
.mic.rec { color: #fff; background: var(--danger); animation: pulse 1.2s infinite; }
.mic.busy { opacity: .5; pointer-events: none; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px color-mix(in srgb, var(--danger) 25%, transparent); } }

/* ================================================================ journée */
.day {
  border-left: 1px solid var(--border); overflow-y: auto; padding: 20px 16px 24px;
  display: flex; flex-direction: column; gap: 14px;
  background: color-mix(in srgb, var(--surface) 35%, transparent);
}
.day-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 4px; }
.eyebrow { margin: 0; font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 600; }
.day-head h2 { margin: 2px 0 0; font-size: 20px; letter-spacing: -.02em; }
.day-head h2::first-letter { text-transform: uppercase; }

.ring { position: relative; width: 52px; height: 52px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 3.2; }
.ring-bg { stroke: var(--surface-3); }
.ring-fg { stroke: var(--ok); stroke-linecap: round; stroke-dasharray: 97.4; stroke-dashoffset: 97.4; transition: stroke-dashoffset .5s ease; }
.ring span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 600; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card h3 { margin: 0; font-size: 14px; font-weight: 600; }
.empty { color: var(--faint); font-size: 13.5px; padding: 6px 2px; }

/* récupération */
.checkin-line { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 4px 0; }
.checkin-label { font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.opts { display: flex; gap: 5px; }
.opt {
  min-width: 36px; height: 32px; padding: 0 8px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 13px; font-weight: 500; color: var(--muted);
  transition: all .15s;
}
.opt:hover { color: var(--text); border-color: var(--faint); }
.opt.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.garmin-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 8px; margin-bottom: 10px; }
.metric { background: var(--surface-2); border-radius: 12px; padding: 8px 10px; }
.metric b { display: block; font-size: 17px; font-weight: 600; letter-spacing: -.01em; }
.metric span { font-size: 11.5px; color: var(--muted); }

/* agenda */
.events { display: flex; flex-direction: column; gap: 6px; }
.event {
  display: grid; grid-template-columns: 52px 1fr; gap: 10px; align-items: start;
  padding: 8px 10px; border-radius: 12px; background: var(--surface-2);
  border-left: 3px solid var(--pc, var(--accent));
}
.event.past { opacity: .5; }
.event.now { background: color-mix(in srgb, var(--pc, var(--accent)) 14%, var(--surface-2)); }
.event-time { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.event-time span { color: var(--muted); font-weight: 400; }
.event-title { font-size: 14px; font-weight: 500; }
.event-title small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }

/* tâches */
.tasks { display: flex; flex-direction: column; }
.task {
  display: flex; align-items: flex-start; gap: 11px; padding: 9px 2px;
  border-bottom: 1px solid var(--border);
}
.task:last-child { border-bottom: 0; }
.check {
  flex: none; width: 21px; height: 21px; margin-top: 1px; border-radius: 50%;
  border: 2px solid var(--pc, var(--faint)); background: transparent;
  display: grid; place-items: center; color: #fff; padding: 0;
  transition: background .15s, transform .1s;
}
.check:hover { background: color-mix(in srgb, var(--pc) 20%, transparent); }
.check:active { transform: scale(.88); }
.task.is-done .check { background: var(--pc); }
.task.is-done .task-title { text-decoration: line-through; color: var(--faint); }
.task-body { flex: 1; min-width: 0; }
.task-title { font-size: 14px; font-weight: 500; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 3px; font-size: 11.5px; color: var(--muted); }
.tag { color: var(--pc); font-weight: 600; }
.flag { color: var(--danger); font-weight: 600; }
.late { color: var(--danger); }
.mini {
  flex: none; border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 999px; font-size: 11.5px; padding: 3px 9px; color: var(--muted);
}
.mini:hover { color: var(--text); border-color: var(--accent); }

.quick-add { display: flex; gap: 6px; margin-top: 10px; }
.quick-add input, .quick-add select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px;
  padding: 8px 10px; outline: none; font-size: 13.5px; min-width: 0;
}
.quick-add input { flex: 1; }
.quick-add input:focus, .quick-add select:focus { border-color: var(--accent); }
.icon-btn.add { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }

/* ================================================================ tabbar (mobile) */
.tabbar { display: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--surface-3); border: 1px solid var(--border); color: var(--text);
  padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; z-index: 50;
  max-width: calc(100% - 32px);
}

/* ================================================================ responsive */
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .day { border-left: 0; background: transparent; }
  body[data-view="chat"] .day { display: none; }
  body[data-view="day"] .chat { display: none; }
  .tabbar {
    display: flex; flex: none; height: calc(var(--tabbar) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(14px);
  }
  .tab {
    flex: 1; border: 0; background: transparent; color: var(--faint);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font-size: 11.5px; font-weight: 500;
  }
  .tab.on { color: var(--accent); }
  .toast { bottom: calc(var(--tabbar) + 16px + env(safe-area-inset-bottom)); }
}
@media (max-width: 520px) {
  .hide-sm { display: none; }
  .messages { padding-top: 16px; }
  .composer { padding: 6px 12px 10px; }
  .day { padding: 16px 12px 20px; }
  .opt { min-width: 32px; padding: 0 6px; }
}
