/* Mise en page : barre latérale claire (barre d'onglets en bas sur mobile), cartes blanches très arrondies
   sur fond lavande, accent indigo, statuts en pilules sombres, icônes dans des pastilles colorées. */
/* Palette : bleu marine (menu), bleu vif (actions), blanc (cartes), gris (fonds et textes secondaires).
   Vert / orange / rouge réservés aux statuts. */
:root {
  --primary: #1d6fe0; --on-primary: #ffffff; --primary-light: #e7f0fc;
  --navy: #0f2747;
  --accent: #d62839; --accent-bg: #fde8ea;
  --bg: #f1f3f6; --surface: #ffffff; --surface-2: #f6f7f9; --hover: #eef2f7;
  --text: #16202e; --muted: #6b7686; --border: #dfe3e9; --border-soft: #eceff3;
  --ink: #0f2747; --on-ink: #ffffff;
  --nav-bg: #0f2747; --nav-text: #b9c7da; --nav-hover: rgba(255, 255, 255, .08); --nav-active: rgba(255, 255, 255, .14); --nav-strong: #ffffff;
  --glow-1: #e3edfb; --glow-2: #eef1f5;
  --ok: #17885a; --ok-bg: #e1f4ea; --warn: #b06a08; --warn-bg: #fff1d9;
  --danger: #d33a4a; --danger-bg: #fde7ea; --danger-border: #f2c0c6; --info: #1d6fe0; --info-bg: #e7f0fc;
  --t-blue: #1d6fe0; --t-blue-bg: #e7f0fc; --t-pink: var(--accent); --t-pink-bg: var(--accent-bg);
  --t-green: #0e7fb6; --t-green-bg: #e0f1f9; --t-violet: #3b5b8c; --t-violet-bg: #e6ecf4;
  --t-amber: #5b6676; --t-amber-bg: #eceef2;
  --section-bg: #e7f0fc; --note-bg: #f6f7f9; --overlay: rgba(15, 25, 40, .4); --shadow: rgba(15, 39, 71, .10);
  --radius: 12px; --radius-card: 20px;
  --font: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #5aa0f2; --on-primary: #08182c; --primary-light: #16304f;
    --navy: #0a1a30;
    --accent: #ff5c6c; --accent-bg: #3a1a20;
    --bg: #0e141c; --surface: #161e29; --surface-2: #1b2430; --hover: #212c3a;
    --text: #e8edf3; --muted: #95a1b2; --border: #2a3544; --border-soft: #222c39;
    --ink: #e8edf3; --on-ink: #0e141c;
    --nav-bg: #0a1a30; --nav-text: #a9b8cc; --nav-hover: rgba(255, 255, 255, .06); --nav-active: rgba(255, 255, 255, .12); --nav-strong: #ffffff;
    --glow-1: #132840; --glow-2: #161e29;
    --ok: #5fcf97; --ok-bg: #143023; --warn: #f0b95b; --warn-bg: #352812;
    --danger: #ff7b8a; --danger-bg: #3a1a20; --danger-border: #6a2d37; --info: #8cbcf6; --info-bg: #16304f;
    --t-blue: #8cbcf6; --t-blue-bg: #16304f; --t-pink: var(--accent); --t-pink-bg: var(--accent-bg);
    --t-green: #7cc8ea; --t-green-bg: #13303f; --t-violet: #a9bfdc; --t-violet-bg: #1d2a3b;
    --t-amber: #b5c0ce; --t-amber-bg: #222b37;
    --section-bg: #16304f; --note-bg: #1b2430; --overlay: rgba(0, 0, 0, .6); --shadow: rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --primary: #5aa0f2; --on-primary: #08182c; --primary-light: #16304f;
  --navy: #0a1a30;
  --accent: #ff5c6c; --accent-bg: #3a1a20;
  --bg: #0e141c; --surface: #161e29; --surface-2: #1b2430; --hover: #212c3a;
  --text: #e8edf3; --muted: #95a1b2; --border: #2a3544; --border-soft: #222c39;
  --ink: #e8edf3; --on-ink: #0e141c;
  --nav-bg: #0a1a30; --nav-text: #a9b8cc; --nav-hover: rgba(255, 255, 255, .06); --nav-active: rgba(255, 255, 255, .12); --nav-strong: #ffffff;
  --glow-1: #132840; --glow-2: #161e29;
  --ok: #5fcf97; --ok-bg: #143023; --warn: #f0b95b; --warn-bg: #352812;
  --danger: #ff7b8a; --danger-bg: #3a1a20; --danger-border: #6a2d37; --info: #8cbcf6; --info-bg: #16304f;
  --t-blue: #8cbcf6; --t-blue-bg: #16304f; --t-pink: var(--accent); --t-pink-bg: var(--accent-bg);
  --t-green: #7cc8ea; --t-green-bg: #13303f; --t-violet: #a9bfdc; --t-violet-bg: #1d2a3b;
  --t-amber: #b5c0ce; --t-amber-bg: #222b37;
  --section-bg: #16304f; --note-bg: #1b2430; --overlay: rgba(0, 0, 0, .6); --shadow: rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); display: flex; min-height: 100vh; -webkit-font-smoothing: antialiased; }
[x-cloak] { display: none !important; }
.sr-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--primary); }
svg.i { width: 18px; height: 18px; flex-shrink: 0; vertical-align: -4px; }

/* Navigation */
#nav { width: 232px; flex-shrink: 0; background: var(--nav-bg); color: var(--nav-text); padding: 20px 14px; position: sticky; top: env(safe-area-inset-top, 0px); height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
#nav a { display: flex; align-items: center; gap: 12px; color: var(--nav-text); text-decoration: none; padding: 10px 12px; border-radius: 12px; font-weight: 500; }
#nav a:hover { background: var(--nav-hover); color: var(--nav-strong); }
#nav a.active { background: var(--nav-active); color: var(--nav-strong); font-weight: 700; box-shadow: inset 3px 0 0 var(--accent); }
#nav a.brand { font-weight: 800; font-size: 18px; color: var(--nav-strong); padding: 4px 8px 20px; background: none; letter-spacing: -0.02em; box-shadow: none; }
#nav .logo { width: 30px; height: 30px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-style: italic; font-size: 16px; }
#nav .nav-actions { margin-top: auto; padding-top: 16px; display: grid; gap: 8px; }
#nav a.btn-new { justify-content: center; background: var(--accent); color: #fff; border-radius: 999px; font-weight: 700; padding: 10px; }
#nav a.btn-new:hover { background: var(--accent); filter: brightness(1.1); }
#nav a.btn-new.alt { background: transparent; color: var(--nav-strong); border: 1px solid rgba(255, 255, 255, .28); }
#nav a.btn-new.alt:hover { background: var(--nav-hover); filter: none; }
#tabbar { display: none; }
#nav .nav-user { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding: 12px 6px 2px; border-top: 1px solid rgba(255, 255, 255, .12); }
#nav .nav-user .avatar { width: 34px; height: 34px; font-size: 12px; }
#nav .nav-user .who { flex: 1; min-width: 0; line-height: 1.25; }
#nav .nav-user strong { display: block; color: var(--nav-strong); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#nav .nav-user small { display: block; color: var(--nav-text); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#nav .nav-user .icon-btn { width: 34px; height: 34px; background: transparent; border-color: rgba(255, 255, 255, .25); color: var(--nav-strong); }
#nav .nav-user .icon-btn:hover { background: var(--nav-hover); }

main { flex: 1; padding: 28px 32px; min-width: 0; }
h1 { margin: 0 0 18px; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; text-wrap: balance; }
h2 { font-size: 16px; font-weight: 700; margin: 0 0 12px; letter-spacing: -0.01em; }
code { font-size: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 18px; }
.toolbar .spacer { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-card); padding: 18px; margin-bottom: 16px; min-width: 0; overflow-x: auto; box-shadow: 0 1px 2px var(--shadow); }
.grid { display: grid; gap: 12px; }
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input, select, textarea { width: 100%; font: inherit; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--primary-light); border-color: var(--primary); }
input[type=checkbox] { width: auto; accent-color: var(--primary); }
input[type=color] { padding: 2px; }
textarea { resize: vertical; min-height: 60px; }
textarea.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; min-height: 420px; white-space: pre; tab-size: 2; }
button, .btn { font: inherit; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 8px 16px; border-radius: 999px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { background: var(--hover); }
button:focus-visible, .btn:focus-visible, a:focus-visible { outline: 3px solid var(--primary-light); outline-offset: 2px; }
button.primary, .btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: var(--danger-border); }
button.small, .btn.small { padding: 4px 10px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { display: inline-flex; align-items: center; width: 40px; height: 40px; padding: 0; justify-content: center; border-radius: 50%; background: var(--surface); border: 1px solid var(--border); color: var(--text); position: relative; flex-shrink: 0; }
.icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); border: 2px solid var(--surface); }
table.list { width: 100%; border-collapse: collapse; background: var(--surface); font-variant-numeric: tabular-nums; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 10px 8px; border-bottom: 1px solid var(--border); }
table.list td { padding: 10px 8px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: var(--hover); }
.num { text-align: right !important; white-space: nowrap; font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* Statuts : pilule sombre avec pastille de couleur */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--ink); color: var(--on-ink); white-space: nowrap; --dot: var(--muted); }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--dot); }
.badge.envoye, .badge.emise { --dot: #7fb4f5; }
.badge.accepte, .badge.payee, .badge.facture { --dot: #4fd68d; }
.badge.refuse, .badge.annulee { --dot: #ff6b7f; }
.badge.partielle { --dot: #f6c050; }
.badge.late { background: var(--danger-bg); color: var(--danger); --dot: var(--danger); }
.badge.soft { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* Pastilles d'icônes colorées */
.tile-ic { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; background: var(--t-blue-bg); color: var(--t-blue); }
.tile-ic.pink { background: var(--t-pink-bg); color: var(--t-pink); }
.tile-ic.green { background: var(--t-green-bg); color: var(--t-green); }
.tile-ic.violet { background: var(--t-violet-bg); color: var(--t-violet); }
.tile-ic.amber { background: var(--t-amber-bg); color: var(--t-amber); }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0; color: #0f2747; background: linear-gradient(135deg, var(--a1, #dce9fb), var(--a2, #eef3fa)); }

/* Pilules de filtre */
.pills { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.pills button { flex-shrink: 0; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: 13px; padding: 7px 15px; }
.pills button.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.search-pill { position: relative; }
.search-pill svg { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-pill input { border-radius: 999px; padding: 12px 18px 12px 44px; background: var(--surface); border-color: var(--border-soft); box-shadow: 0 1px 2px var(--shadow); }

.kpi { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-card); padding: 16px 18px; box-shadow: 0 1px 2px var(--shadow); }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 800; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 1px solid var(--border); background: var(--surface); }
.tabs button.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.modal-bg { position: fixed; inset: 0; background: var(--overlay); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border-radius: 24px; width: 100%; max-width: 760px; padding: 24px; box-shadow: 0 20px 60px var(--shadow); min-width: 0; }
.modal.wide { max-width: 1000px; }
.modal.confirm { max-width: 440px; margin-top: 10vh; }
.modal.confirm .confirm-msg { margin: 0; font-size: 15px; line-height: 1.5; }
.modal h2 { margin-bottom: 16px; font-size: 18px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }
#toasts { position: fixed; bottom: 84px; right: 20px; display: grid; gap: 8px; z-index: 100; max-width: calc(100vw - 40px); }
.toast { background: var(--ink); color: var(--on-ink); padding: 12px 18px; border-radius: 16px; box-shadow: 0 8px 24px var(--shadow); max-width: 420px; font-weight: 500; }
.toast.error { background: var(--danger); color: #fff; }
.empty { text-align: center; color: var(--muted); padding: 30px; }

/* Éditeur de document */
table.lines { width: 100%; border-collapse: collapse; min-width: 860px; font-variant-numeric: tabular-nums; }
table.lines th { font-size: 12px; color: var(--muted); text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
table.lines td { padding: 4px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
table.lines input, table.lines select, table.lines textarea { padding: 6px 8px; border-radius: 10px; }
table.lines textarea { min-height: 30px; font-size: 12px; margin-top: 4px; }
table.lines tr.section td { background: var(--section-bg); }
table.lines tr.section td:first-child { border-radius: 12px 0 0 12px; }
table.lines tr.section td:last-child { border-radius: 0 12px 12px 0; }
table.lines tr.section input { font-weight: 700; }
table.lines tr.text td { background: var(--note-bg); }
table.lines .w-qty { width: 80px; } table.lines .w-unit { width: 80px; } table.lines .w-price { width: 105px; }
table.lines .w-disc { width: 70px; } table.lines .w-vat { width: 80px; } table.lines .w-total { width: 110px; }
table.lines .w-actions { width: 110px; white-space: nowrap; }
table.lines .w-actions button { padding: 3px 7px; }
.handle { cursor: grab; color: var(--muted); user-select: none; padding: 0 4px; }
.totals-box { margin-left: auto; min-width: min(320px, 100%); }
.totals-box table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.totals-box th { text-align: left; font-weight: 500; padding: 5px 8px; color: var(--muted); }
.totals-box td { text-align: right; padding: 5px 8px; white-space: nowrap; }
.totals-box tr.grand td, .totals-box tr.grand th { font-weight: 800; font-size: 17px; color: var(--text); border-top: 1px solid var(--border); }
.search-results { max-height: 420px; overflow: auto; border: 1px solid var(--border); border-radius: 16px; }
.locked-banner { background: var(--warn-bg); color: var(--warn); padding: 12px 16px; border-radius: 16px; margin-bottom: 14px; font-weight: 500; }
.preview-frame { width: 100%; height: 75vh; border: 1px solid var(--border); border-radius: 16px; background: #e5e5e5; }
.var-list code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.var-list td { padding: 3px 6px; vertical-align: top; }
.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 160px; padding-top: 10px; }
.bar-chart .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bar-chart .bar div.fill { width: 100%; max-width: 34px; background: var(--primary); border-radius: 8px 8px 3px 3px; min-height: 2px; }
.bar-chart .bar span { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* Assistant IA (chat) */
#chat-fab { position: fixed; right: 20px; bottom: 20px; z-index: 75; display: inline-flex; align-items: center; gap: 8px; padding: 12px 18px; border-radius: 999px; border: 0; background: var(--ink); color: var(--on-ink); font-weight: 700; box-shadow: 0 10px 30px var(--shadow); }
#chat-fab:hover { background: var(--ink); filter: brightness(1.15); }
#chat-fab svg.i { color: #ff6b78; }
body.chat-open #chat-fab { display: none; }
#chat-panel { position: fixed; right: 20px; bottom: 20px; z-index: 80; width: min(420px, calc(100vw - 40px)); height: min(640px, calc(100vh - 40px)); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 24px; box-shadow: 0 24px 70px var(--shadow); overflow: hidden; }
#chat-panel[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 12px 16px; border-bottom: 1px solid var(--border-soft); background: linear-gradient(135deg, var(--glow-1), var(--surface) 70%); }
.chat-head .tile-ic { width: 36px; height: 36px; }
.chat-title { flex: 1; min-width: 0; }
.chat-title strong { display: block; }
.chat-title small { color: var(--muted); }
.chat-head .icon-btn { width: 34px; height: 34px; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.chat-hello { background: var(--surface-2); border-radius: 18px; padding: 14px; color: var(--muted); }
.chat-hello strong { color: var(--text); }
.chat-hello p { margin: 4px 0 0; line-height: 1.5; }
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 18px; line-height: 1.5; overflow-wrap: anywhere; }
.bubble.user { align-self: flex-end; background: var(--primary); color: var(--on-primary); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.bubble.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border-soft); border-bottom-left-radius: 6px; }
.bubble p { margin: 0 0 6px; } .bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: 4px 0 6px; padding-left: 18px; }
.bubble a { font-weight: 700; }
.typing { color: var(--muted); }
.dots { display: inline-flex; gap: 3px; margin-right: 6px; vertical-align: middle; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dots i { animation: none; } }
.chat-suggest { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 16px 10px; }
.chat-suggest[hidden] { display: none; }
.chat-suggest button { font-size: 12.5px; font-weight: 600; padding: 6px 12px; white-space: normal; text-align: left; }
.chat-off { margin: 0; padding: 14px 16px; color: var(--muted); border-top: 1px solid var(--border-soft); }
.chat-form { display: flex; align-items: flex-end; gap: 8px; padding: 12px; border-top: 1px solid var(--border-soft); }
.chat-form[hidden] { display: none; }
.chat-form textarea { flex: 1; min-height: 42px; max-height: 140px; resize: none; border-radius: 20px; padding: 10px 14px; }
.chat-form .icon-btn { width: 42px; height: 42px; }
.chat-form .send { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.chat-form .icon-btn[hidden] { display: none; }
.chat-files { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px 0; border-top: 1px solid var(--border-soft); }
.chat-files[hidden] { display: none; }
.chat-files + .chat-form { border-top: 0; }
.file-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 4px 6px 4px 8px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); font-size: 12px; font-weight: 600; color: var(--text); overflow: hidden; }
.file-chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 6px; }
.file-chip svg.i { width: 15px; height: 15px; color: var(--muted); }
.file-chip button { width: 22px; height: 22px; padding: 0; justify-content: center; border: 0; background: none; border-radius: 50%; }
.file-chip button svg.i { width: 13px; height: 13px; }
.bubble-files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.bubble.user .bubble-files:first-child { margin-top: 0; }
.bubble.user .file-chip { background: rgba(255, 255, 255, .18); border-color: transparent; color: var(--on-primary); }
.bubble.user .file-chip svg.i { color: var(--on-primary); }
#chat-panel.drop { outline: 3px dashed var(--primary); outline-offset: -8px; }
#chat-mic.on { background: var(--danger); border-color: var(--danger); color: #fff; }

@media (max-width: 1000px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  body { display: block; padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  #nav { display: none; }
  #nav.open { display: flex; position: fixed; inset: auto 0 0 0; top: auto; height: auto; max-height: 80vh; width: auto; z-index: 60; border-radius: 24px 24px 0 0; border: 0; box-shadow: 0 -10px 40px var(--shadow); padding: 18px 16px calc(90px + env(safe-area-inset-bottom, 0px)); }
  #nav.open a.brand { padding-bottom: 10px; }
  #tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 70; background: var(--surface); border-top: 1px solid var(--border); padding: 8px 6px calc(8px + env(safe-area-inset-bottom, 0px)); justify-content: space-around; }
  #tabbar a, #tabbar button { display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 1; font-size: 11px; font-weight: 600; color: var(--muted); text-decoration: none; background: none; border: 0; padding: 4px 0; border-radius: 12px; }
  #tabbar .active { color: var(--primary); }
  #tabbar svg.i { width: 22px; height: 22px; }
  main { padding: 18px 16px; }
  h1 { font-size: 21px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .grid [style*="grid-column"] { grid-column: auto !important; }
  .modal-bg { padding: 16px; }
  #toasts { bottom: calc(150px + env(safe-area-inset-bottom, 0px)); }
  #chat-fab { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); right: 16px; padding: 12px; }
  #chat-fab span { display: none; }
  #chat-panel { inset: 0; width: auto; height: auto; border-radius: 0; border: 0; z-index: 90; padding-bottom: env(safe-area-inset-bottom, 0px); }
}
