:root {
  --bg: #f3f6fb; --card: #ffffff; --ink: #0f172a; --ink2: #334155; --muted: #64748b; --line: #e2e8f0;
  --brand: #1d4ed8; --brand-d: #0b1f4d; --brand-l: #e8efff; --sky: #0ea5e9;
  --green: #16a34a; --amber: #d97706; --red: #dc2626; --violet: #7c3aed;
  --radius: 16px; --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0a1020; --card: #111a2e; --ink: #e6edf8; --ink2: #c3cde0; --muted: #8b9ab3; --line: #1f2b45; --brand: #5b8cff; --brand-l: #17264a; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
body.noscroll { overflow: hidden; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0 0 .2rem; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; display: flex; align-items: center; gap: .4rem; }
h3 { font-size: 1rem; margin: .6rem 0 .3rem; }
p { margin: .3rem 0 .6rem; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .center { text-align: center; } .mono { font-family: ui-monospace, Consolas, monospace; }
.red-t { color: var(--red); } .amber-t { color: var(--amber); } .green-t { color: var(--green); }
.row { display: flex; align-items: center; } .gap { gap: .5rem; } .wrap { flex-wrap: wrap; } .between { justify-content: space-between; } .grow { flex: 1; min-width: 0; }

/* Boutons */
.btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--ink); padding: .62rem 1rem; border-radius: 11px; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .4rem; transition: transform .08s, background .15s, border-color .15s; text-align: center; }
.btn:hover { border-color: #c7d2fe; } .btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn.ghost:hover { background: var(--brand-l); }
.btn.light { background: #fff; color: var(--brand-d); border-color: #fff; }
.btn.ghost-light { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); }
.btn.danger-ghost { background: transparent; color: var(--red); border-color: transparent; }
.btn.danger-ghost:hover { background: rgba(220,38,38,.08); }
.btn.on { color: var(--amber); border-color: var(--amber); }
.btn.block { width: 100%; margin-top: .6rem; } .btn.small { padding: .4rem .7rem; font-size: .85rem; }
.link { background: none; border: 0; color: var(--brand); font: inherit; cursor: pointer; padding: .4rem 0; margin-top: .4rem; }
.icon-btn { background: var(--card); border: 1px solid var(--line); border-radius: 11px; width: 42px; height: 42px; font-size: 1.1rem; cursor: pointer; flex: none; }
.mini-btn { background: transparent; border: 1px solid var(--line); color: var(--ink2); border-radius: 8px; padding: .25rem .5rem; font: inherit; font-size: .8rem; cursor: pointer; }
.mini-btn:disabled { opacity: .3; }

/* Formulaires */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink2); margin: .6rem 0; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: .62rem .75rem; margin-top: .3rem; outline: none; transition: border-color .15s, box-shadow .15s; }
label.inline input { width: 6rem; margin: 0; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(29, 78, 216, .15); }
textarea { resize: vertical; }
select.mini, input.mini { width: auto; padding: .35rem .6rem; font-size: .85rem; margin: 0; }
.check { display: flex; align-items: center; gap: .55rem; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.form .two label { margin: .6rem 0; }
.hint { font-size: .82rem; color: var(--muted); }
.err { color: var(--red); font-size: .9rem; min-height: 1.2em; }
.title-input { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; border: 1px solid transparent; background: transparent; padding: .2rem .4rem; margin: .1rem 0 0 -.4rem; }
.title-input:hover { border-color: var(--line); }

/* Démarrage / connexion */
.boot { min-height: 100vh; display: grid; place-content: center; text-align: center; color: var(--muted); }
.boot img { width: 72px; height: 72px; border-radius: 18px; animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: .55; transform: scale(.96); } }
.auth { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.2rem; background: radial-gradient(1200px 600px at 20% -10%, #1e40af 0%, transparent 60%), linear-gradient(160deg, #0b1f4d, #061230); }
.auth-card { width: 100%; max-width: 420px; background: var(--card); border-radius: 22px; padding: 1.6rem; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.auth-brand { display: flex; align-items: center; gap: .8rem; margin-bottom: 1.2rem; }
.auth-brand img { width: 48px; height: 48px; border-radius: 12px; }
.auth-brand b { display: block; font-size: 1.15rem; } .auth-brand span { color: var(--muted); font-size: .85rem; }
.auth-foot { color: #c7d2fe; font-size: .8rem; max-width: 420px; text-align: center; margin-top: 1rem; opacity: .85; }
.meter { height: 5px; background: var(--line); border-radius: 9px; overflow: hidden; margin-top: -.2rem; }
.meter i { display: block; height: 100%; width: 0; background: var(--red); transition: width .2s; }
.meter i[data-s="2"] { background: var(--amber); } .meter i[data-s="3"], .meter i[data-s="4"] { background: var(--green); }
.code { font: 600 1.15rem/1.6 ui-monospace, Consolas, monospace; letter-spacing: .06em; text-align: center; background: var(--brand-l); color: var(--brand-d); border: 2px dashed var(--brand); border-radius: 14px; padding: 1rem; margin: 1rem 0 .6rem; word-break: break-word; }
@media (prefers-color-scheme: dark) { .code { color: #dbe6ff; } }

/* Structure */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; background: var(--brand-d); color: #c7d2fe; padding: 1.1rem .8rem; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-size: 1.05rem; padding: .2rem .5rem 1.2rem; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.side nav a { display: flex; align-items: center; gap: .7rem; color: #c7d2fe; padding: .65rem .75rem; border-radius: 11px; font-weight: 600; margin-bottom: 2px; }
.side nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.side nav a.on { background: rgba(255,255,255,.13); color: #fff; }
.side-foot { margin-top: auto; padding: .5rem .75rem; font-size: .8rem; }
#sync::before { content: "●"; margin-right: .4rem; color: #4ade80; }
#sync[data-s="saving"]::before { color: #fbbf24; } #sync[data-s="err"]::before { color: #f87171; }
main { min-width: 0; padding: 1.2rem 2rem 3rem; max-width: 1180px; width: 100%; }
.top { display: flex; gap: .6rem; margin-bottom: 1.4rem; position: sticky; top: 0; z-index: 5; background: var(--bg); padding: .6rem 0; }
.search { flex: 1; display: flex; align-items: center; gap: .5rem; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 0 .8rem; }
.search input { border: 0; background: transparent; margin: 0; padding: .7rem 0; box-shadow: none !important; }
.search.in-sheet { margin: .4rem 0 .8rem; }
.tabbar { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.back { font-size: .9rem; font-weight: 600; display: inline-block; margin-bottom: .3rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.cols { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1rem; align-items: start; }
.cols > .card { margin-bottom: 0; } .cols { margin-bottom: 1rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 1rem; }

.hero { background: linear-gradient(135deg, #1e40af, #0b1f4d 70%); color: #fff; border-radius: 20px; padding: 1.5rem 1.6rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; position: relative; overflow: hidden; }
.hero::after { content: "✈"; position: absolute; right: 1.2rem; top: -1.2rem; font-size: 7rem; opacity: .08; transform: rotate(-20deg); }
.hero h1 { color: #fff; } .hero p { color: #c7d2fe; margin: 0; }
.hero-actions { display: flex; gap: .5rem; flex-wrap: wrap; position: relative; z-index: 1; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.2rem; color: var(--ink); box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.8rem; letter-spacing: -.02em; } .stat span { color: var(--muted); font-size: .85rem; }

.line { display: flex; align-items: center; gap: .75rem; padding: .7rem .4rem; border-radius: 10px; color: var(--ink); width: 100%; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: 0; }
.line:hover { background: var(--bg); }
.line b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .line small { color: var(--muted); }
.ic { font-size: 1.35rem; width: 2rem; text-align: center; flex: none; } .ic.big { font-size: 2rem; width: 2.6rem; }
.chev { color: var(--muted); font-size: 1.4rem; }
.empty { color: var(--muted); padding: .4rem 0; }
.empty-big { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-big div { font-size: 2.6rem; } .empty-big b { color: var(--ink); display: block; font-size: 1.1rem; margin: .3rem 0; } .empty-big p { max-width: 420px; margin: .3rem auto 1rem; }

.pill { font-size: .75rem; font-weight: 700; padding: .2rem .55rem; border-radius: 99px; white-space: nowrap; flex: none; }
.pill.slate { background: #e2e8f0; color: #334155; } .pill.amber { background: #fef3c7; color: #92400e; } .pill.red { background: #fee2e2; color: #991b1b; }
.pill.green { background: #dcfce7; color: #166534; } .pill.blue { background: #dbeafe; color: #1e40af; } .pill.violet { background: #ede9fe; color: #5b21b6; }
.bar { height: 6px; background: var(--line); border-radius: 9px; overflow: hidden; margin: .35rem 0; }
.bar.big { height: 9px; margin: .2rem 0 1rem; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--sky)); border-radius: 9px; transition: width .3s; }

.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; }
.cat { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: .8rem; color: var(--ink); display: flex; flex-direction: column; gap: .15rem; }
.cat:hover { border-color: var(--brand); } .cat span { font-size: 1.4rem; } .cat b { font-size: .88rem; } .cat small { color: var(--muted); }
.cat.dim { opacity: .55; }

.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: .6rem; scrollbar-width: none; }
.chip { flex: none; background: var(--card); border: 1px solid var(--line); color: var(--ink2); padding: .4rem .8rem; border-radius: 99px; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.chip small { color: var(--muted); font-weight: 500; } .chip.on { background: var(--brand); border-color: var(--brand); color: #fff; } .chip.on small { color: #dbe6ff; }
.group { font-size: .9rem; color: var(--muted); margin: 1.2rem 0 .4rem; text-transform: none; }
.group small { font-weight: 500; }
.drop { border-radius: var(--radius); min-height: 120px; transition: background .15s, outline-color .15s; outline: 2px dashed transparent; outline-offset: 4px; }
.drop.over { background: var(--brand-l); outline-color: var(--brand); }
.doclist { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .5rem; }
.doc { display: flex; align-items: center; gap: .7rem; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .7rem .8rem; font: inherit; color: var(--ink); text-align: left; cursor: pointer; width: 100%; }
.doc:hover { border-color: var(--brand); }
.doc b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .doc small { color: var(--muted); }
.star { color: var(--amber); }

.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .8rem; }
.app-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; color: var(--ink); box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .15rem; }
a.app-card:hover { border-color: var(--brand); }
.app-card h3 { margin: .4rem 0 .1rem; font-size: 1.02rem; }
.app-card .row.gap { margin-top: auto; padding-top: .5rem; }

.items { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .8rem; }
.item { display: flex; align-items: center; gap: .7rem; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.item.ok { border-color: rgba(22, 163, 74, .35); }
.item b { display: block; font-size: .92rem; }
.tick { width: 26px; height: 26px; border-radius: 8px; border: 2px solid var(--line); background: var(--card); color: #fff; font-weight: 800; cursor: pointer; flex: none; display: grid; place-content: center; }
.item.ok .tick { background: var(--green); border-color: var(--green); }
.linked { background: none; border: 0; padding: 0; font: inherit; font-size: .85rem; color: var(--brand); cursor: pointer; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.item-actions { display: flex; gap: .3rem; flex: none; }
.prep { background: var(--brand-l); border-radius: 14px; padding: .9rem 1rem; }
.prep h3 { margin-top: 0; }

.pf { display: flex; align-items: center; gap: .8rem; width: 100%; padding: .65rem .3rem; border: 0; border-bottom: 1px solid var(--line); background: none; font: inherit; color: var(--ink); text-align: left; cursor: pointer; }
.pf:last-of-type { border-bottom: 0; }
.pf:hover { background: var(--bg); }
.pf-l { width: 42%; color: var(--muted); font-size: .88rem; flex: none; }
.pf-v { flex: 1; font-weight: 600; word-break: break-word; white-space: pre-wrap; }
.pf .cp { font-size: .75rem; color: var(--brand); opacity: 0; font-weight: 600; } .pf:hover .cp { opacity: 1; }
.pf.edit { cursor: default; } .pf.edit input, .pf.edit textarea { margin: 0; } .pf.edit .pf-l { width: 38%; }
.list .line { border-bottom: 1px solid var(--line); }

.editor { min-height: 55vh; font-size: 16px; line-height: 1.65; margin: .8rem 0; background: var(--card); }

/* Feuille modale */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(2, 6, 23, .5); display: flex; align-items: center; justify-content: center; padding: 1rem; opacity: 0; transition: opacity .18s; }
.sheet-wrap.in { opacity: 1; }
.sheet { position: relative; background: var(--card); border-radius: 20px; width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; box-shadow: 0 24px 80px rgba(0,0,0,.35); transform: translateY(12px); transition: transform .2s; }
.sheet-wrap.in .sheet { transform: none; }
.sheet-body { padding: 1.3rem 1.4rem 1.4rem; }
.sheet-body > .row { margin: .6rem 0; }
.sheet-x { position: absolute; top: .7rem; right: .7rem; width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--bg); color: var(--ink2); cursor: pointer; font-size: .95rem; z-index: 2; }
.sheet-head { display: flex; align-items: center; gap: .7rem; padding-right: 2.2rem; }
.sheet-head h2 { margin: 0; word-break: break-word; }
.preview { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; margin: 1rem 0 .6rem; min-height: 120px; display: grid; place-content: center; overflow: hidden; }
.preview img { max-width: 100%; max-height: 52vh; display: block; margin: auto; }
.preview iframe { width: min(600px, 80vw); height: 52vh; border: 0; display: block; background: #fff; }
.pv-icon { text-align: center; font-size: 2.6rem; padding: 1.2rem; } .pv-icon small { display: block; font-size: .85rem; color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#toasts { position: fixed; left: 50%; bottom: calc(1.2rem + var(--safe-b)); transform: translateX(-50%); z-index: 80; display: flex; flex-direction: column; gap: .5rem; align-items: center; pointer-events: none; width: min(92vw, 480px); }
.toast { background: #0f172a; color: #fff; padding: .7rem 1rem; border-radius: 12px; font-weight: 600; font-size: .9rem; box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: tin .2s; text-align: center; }
.toast.err { background: #991b1b; } .toast.out { opacity: 0; transition: opacity .3s; }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* Mobile */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: .4rem .9rem calc(5.5rem + var(--safe-b)); }
  .top { padding-top: calc(.5rem + env(safe-area-inset-top, 0px)); margin: 0 -.9rem 1rem; padding-left: .9rem; padding-right: .9rem; }
  h1 { font-size: 1.35rem; }
  .cols, .grid3 { grid-template-columns: 1fr; }
  .grid3 { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .stat { padding: .7rem; } .stat b { font-size: 1.4rem; } .stat span { font-size: .72rem; line-height: 1.2; display: block; }
  .hero { padding: 1.2rem; } .hero-actions { width: 100%; } .hero-actions .btn { flex: 1; }
  .doclist, .apps { grid-template-columns: 1fr; }
  .tabbar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: .35rem .2rem calc(.35rem + var(--safe-b)); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: .68rem; font-weight: 600; color: var(--muted); padding: .2rem 0; }
  .tabbar a span { font-size: 1.3rem; line-height: 1.3; filter: grayscale(1); opacity: .7; }
  .tabbar a.on { color: var(--brand); } .tabbar a.on span { filter: none; opacity: 1; }
  .sheet-wrap { align-items: flex-end; padding: 0; }
  .sheet { border-radius: 20px 20px 0 0; max-height: 94vh; transform: translateY(40px); }
  .sheet-body { padding-bottom: calc(1.4rem + var(--safe-b)); }
  .form .two { grid-template-columns: 1fr; gap: 0; }
  .pf { flex-wrap: wrap; gap: .1rem; } .pf-l, .pf.edit .pf-l { width: 100%; } .pf .cp { opacity: 1; }
  .pf.edit { flex-wrap: nowrap; flex-direction: column; align-items: stretch; gap: .3rem; }
  .item { flex-wrap: wrap; } .item-actions { width: 100%; justify-content: flex-end; }
  .page-head .btn { flex: 1; } .page-head > .row { width: 100%; }
}
@media (prefers-color-scheme: dark) {
  .pill.slate { background: #1f2b45; color: #c3cde0; } .pill.amber { background: #3b2a0a; color: #fcd34d; } .pill.red { background: #3b0f0f; color: #fca5a5; }
  .pill.green { background: #0c2e1a; color: #86efac; } .pill.blue { background: #13254d; color: #93c5fd; } .pill.violet { background: #241a45; color: #c4b5fd; }
  .top { background: var(--bg); }
}
