:root {
  --navy: #14213d; --navy-2: #1f3160; --gold: #fca311; --bg: #f3f4f7; --card: #fff; --text: #1b1f2a; --muted: #6b7280;
  --line: #e5e7eb; --red: #d62839; --green: #2a9d8f; --radius: 14px; --nav-h: 64px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1424; --card: #172036; --text: #e8ebf3; --muted: #9aa3b5; --line: #2a3550; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100dvh; padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
a { color: inherit; }

.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: var(--navy); color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.topbar h1 { flex: 1; margin: 0; font-size: 1.15rem; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 1.5rem; line-height: 1; padding: 4px 8px; cursor: pointer; border-radius: 8px; }
.ai-dot { width: 10px; height: 10px; border-radius: 50%; background: #9aa3b5; }
.ai-dot.idle { background: #3ddc97; } .ai-dot.busy { background: var(--gold); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

main { max-width: 720px; margin: 0 auto; padding: 12px; outline: none; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.card h2 { margin: 0 0 10px; font-size: 1.02rem; }
h3.sub { margin: 16px 4px 8px; font-size: .9rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.hello h2 { margin: 6px 4px 0; font-size: 1.4rem; } .hello p { margin: 2px 4px 12px; text-transform: capitalize; }
.muted { color: var(--muted); } .small, small { font-size: .82rem; } .center { text-align: center; }
.pre { white-space: pre-wrap; word-wrap: break-word; }
.error { color: var(--red); font-weight: 600; }
.meta { font-size: .75rem; color: var(--muted); margin: 6px 0 0; }
.row { display: flex; gap: 8px; align-items: center; } .row.wrap { flex-wrap: wrap; } .row.end { justify-content: flex-end; } .row.between { justify-content: space-between; }
.row > label { flex: 1; } .grow { flex: 1; min-width: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { background: var(--gold); border-color: var(--gold); color: #14213d; } }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger-outline { color: var(--red); border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: 8px; }
.link { background: none; border: 0; color: var(--navy-2); font: inherit; font-weight: 600; text-decoration: none; padding: 6px 0; display: inline-block; cursor: pointer; }
@media (prefers-color-scheme: dark) { .link { color: var(--gold); } }
.mini { background: none; border: 0; font-size: 1.05rem; cursor: pointer; padding: 4px 6px; text-decoration: none; }
.mini-btn { min-height: 34px; padding: 4px 10px; font-size: .85rem; }

input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 42px; }
textarea { resize: vertical; }
label { display: block; font-size: .85rem; font-weight: 600; color: var(--muted); margin: 8px 0 0; }
label > input, label > textarea, label > select { margin-top: 4px; font-weight: 400; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--green); flex: none; }

.login { max-width: 380px; margin: 8vh auto 0; text-align: center; background: var(--card); padding: 28px 22px; border-radius: 20px; }
.login label { text-align: left; } .login h1 { margin: 8px 0 0; } .logo { width: 84px; height: 84px; }

.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; display: flex; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--card); border-top: 1px solid var(--line); }
.bottomnav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .72rem; text-decoration: none; color: var(--muted); }
.bottomnav a span { font-size: 1.25rem; } .bottomnav a.active { color: var(--text); font-weight: 700; }

.mic-fab { position: fixed; right: 16px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 30; width: 60px; height: 60px; border-radius: 50%;
  border: 0; background: var(--gold); font-size: 1.6rem; box-shadow: 0 6px 16px rgba(0,0,0,.25); cursor: pointer; }
.mic-fab.on { background: var(--red); animation: pulse 1s infinite; }
.voice-panel { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 90px); z-index: 30; background: var(--navy);
  color: #fff; border-radius: 16px; padding: 16px; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,.3); }
.voice-panel p { margin: 8px 0 12px; font-size: 1.05rem; } .voice-panel .btn { color: #fff; border-color: rgba(255,255,255,.4); }
.voice-wave { display: flex; justify-content: center; gap: 5px; height: 22px; }
.voice-wave span { width: 5px; background: var(--gold); border-radius: 3px; animation: wave .9s infinite ease-in-out; }
.voice-wave span:nth-child(2) { animation-delay: .15s; } .voice-wave span:nth-child(3) { animation-delay: .3s; }
@keyframes wave { 0%, 100% { height: 6px; } 50% { height: 22px; } }

ul.tasks, ul.mails, ul.atts { list-style: none; margin: 0; padding: 0; }
.task { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; } .task div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.task.late strong::after { content: ' · en retard'; color: var(--red); font-size: .78rem; font-weight: 600; }
.mail { display: block; padding: 11px 12px; text-decoration: none; background: var(--card); border-radius: 12px; margin-bottom: 8px; border-left: 4px solid transparent; }
.card .mail { padding: 10px 0; margin: 0; border-radius: 0; border-bottom: 1px solid var(--line); border-left: 0; }
.mail.unread { border-left-color: var(--gold); } .mail.unread b { font-weight: 800; }
.mail .subj { margin: 2px 0; font-size: .93rem; } .snippet { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { display: inline-block; font-size: .7rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--line); margin-right: 6px; }
.badge.red { background: var(--red); color: #fff; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.cat { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px; border-radius: 12px; background: var(--bg); text-decoration: none; }
.cat span { font-size: 1.3rem; } .cat small { color: var(--muted); }
.chips { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; padding-bottom: 2px; }
.chip { flex: none; padding: 7px 13px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); text-decoration: none; font-size: .85rem; font-weight: 600; }
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.search { margin-bottom: 10px; }

.mail-view h2 { font-size: 1.15rem; } .mail-view p { margin: 2px 0; }
.mail-view .body { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); line-height: 1.5; }
.mail-view select { width: auto; flex: 1; }
.att { display: flex; width: 100%; gap: 10px; align-items: center; padding: 10px; margin-bottom: 6px; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; font: inherit; color: inherit; text-align: left; cursor: pointer; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 20px; }
.ai-out { margin-top: 10px; padding: 12px; background: var(--bg); border-radius: 10px; white-space: pre-wrap; line-height: 1.45; border-left: 3px solid var(--gold); }

.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.msg { max-width: 86%; padding: 10px 12px; border-radius: 14px; line-height: 1.45; }
.msg.user { align-self: flex-end; background: var(--navy); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.msg-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.chat-input { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 6px); display: flex; gap: 8px; align-items: flex-end; background: var(--bg); padding: 8px 76px 8px 0; }
.chat-input textarea { min-height: 44px; max-height: 140px; }
.ctx { background: var(--card); padding: 8px 12px; border-radius: 10px; font-size: .85rem; }

.task-form { display: flex; flex-direction: column; gap: 8px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .85rem; } .tbl th, .tbl td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line); }

.modal-backdrop { position: fixed; inset: 0; z-index: 50; background: rgba(10,14,25,.55); display: flex; align-items: flex-end; justify-content: center; }
.modal { width: 100%; max-width: 560px; max-height: 92dvh; overflow: auto; background: var(--card); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .modal-backdrop { align-items: center; } .modal { border-radius: 18px; } }
.modal h2 { margin: 0 0 8px; font-size: 1.1rem; word-break: break-all; }
.modal .row.end { margin-top: 14px; }
.att-img { max-width: 100%; border-radius: 10px; } .att-text { max-height: 55dvh; overflow: auto; background: var(--bg); padding: 10px; border-radius: 10px; font-size: .82rem; }
.att-frame { width: 100%; height: 60dvh; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 90px); z-index: 60; background: #111827; color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: .9rem; max-width: 90vw; box-shadow: 0 6px 18px rgba(0,0,0,.3); }
