/* GestPatri — feuille de style unique (CSS natif : variables, grid, flex, dialog). */

:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f0f1ed;
  --ink: #1c2421;
  --ink-2: #4b5651;
  --ink-3: #7b857f;
  --line: #e0e3dd;
  --brand: #1f5f4a;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe9;
  --pos: #1b7a4b;
  --neg: #b3402f;
  --warn: #9a6a0a;
  --c-physical: #2b7a64;
  --c-intellectual: #6a55b8;
  --c-financial: #c08a1e;
  --sidebar-bg: #16241f;
  --sidebar-ink: #cfdcd5;
  --sidebar-line: #26382f;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 4px 14px rgba(20, 30, 25, .05);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101613;
    --surface: #18211d;
    --surface-2: #202b26;
    --ink: #e8eeea;
    --ink-2: #b4c0b9;
    --ink-3: #85928b;
    --line: #2a3832;
    --brand: #4fb392;
    --brand-ink: #0c1a14;
    --brand-soft: #1c3329;
    --pos: #5cc88f;
    --neg: #ee8b79;
    --warn: #e0b250;
    --c-physical: #4fb392;
    --c-intellectual: #9d8ae8;
    --c-financial: #e0b250;
    --sidebar-bg: #0c120f;
    --sidebar-line: #1b2822;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 .75rem; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 0.85em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: .1em .4em; border-radius: 4px; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; vertical-align: -.2em; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--brand); color: var(--brand-ink); padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: 0; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.center { text-align: center; }
.block { display: block; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Layout */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar-bg); color: var(--sidebar-ink);
  display: flex; flex-direction: column; padding: 1.25rem 1rem; gap: 1.5rem;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: .65rem; font-weight: 700; font-size: 1.15rem; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 9px;
  background: var(--brand); color: var(--brand-ink); font-weight: 800;
}
.nav { display: flex; flex-direction: column; gap: .15rem; flex: 1; }
.nav-link {
  display: flex; align-items: center; gap: .7rem; padding: .6rem .75rem; border-radius: 9px;
  color: var(--sidebar-ink); font-weight: 500;
}
.nav-link:hover { background: var(--sidebar-line); text-decoration: none; }
.nav-link.is-active { background: var(--brand); color: var(--brand-ink); }
.sidebar-foot { display: grid; gap: .75rem; border-top: 1px solid var(--sidebar-line); padding-top: 1rem; }
.who { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.avatar { display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: 50%; background: var(--sidebar-line); font-weight: 700; flex: none; }
.who-text { display: grid; min-width: 0; }
.who-text strong, .who-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-text small { color: var(--ink-3); }
.main-col { min-width: 0; }
.topbar { display: none; }
.content { max-width: 1180px; margin: 0 auto; padding: 1.75rem 1.75rem 4rem; }

/* ---------- Composants */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head p { margin: .25rem 0 0; }
.crumbs { font-size: .85rem; color: var(--ink-3); margin-bottom: .35rem !important; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); margin-bottom: 1.25rem; }
.card-title { font-size: 1rem; margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1.25rem; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 1.25rem; }
.grid-sim { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.grid-sim > form.card { position: sticky; top: 1rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem 1rem; border-radius: 9px; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--surface-2); }
.sidebar .btn-ghost { color: var(--sidebar-ink); border-color: var(--sidebar-line); }
.sidebar .btn-ghost:hover { background: var(--sidebar-line); }
.btn-danger { background: var(--neg); color: #fff; }
.btn-danger-ghost { background: transparent; border-color: var(--line); color: var(--neg); }
.btn-danger-ghost:hover { background: var(--surface-2); }
.btn-block { width: 100%; }
.btn-sm { padding: .35rem .7rem; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: progress; }
.icon-btn { background: transparent; border: 0; padding: .4rem; border-radius: 8px; cursor: pointer; color: var(--ink-2); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.badge, .status, .pill { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.badge.cat-physical { background: color-mix(in srgb, var(--c-physical) 16%, transparent); color: var(--c-physical); }
.badge.cat-intellectual { background: color-mix(in srgb, var(--c-intellectual) 16%, transparent); color: var(--c-intellectual); }
.badge.cat-financial { background: color-mix(in srgb, var(--c-financial) 18%, transparent); color: var(--c-financial); }
.status { background: var(--surface-2); color: var(--ink-2); }
.status-active { background: color-mix(in srgb, var(--pos) 15%, transparent); color: var(--pos); }
.status-expired { background: color-mix(in srgb, var(--neg) 15%, transparent); color: var(--neg); }
.pill-ok { background: color-mix(in srgb, var(--pos) 15%, transparent); color: var(--pos); }
.pill-warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill-bad { background: color-mix(in srgb, var(--neg) 15%, transparent); color: var(--neg); }

.flash { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; font-weight: 500; transition: opacity .4s; }
.flash.is-hidden { opacity: 0; pointer-events: none; height: 0; padding: 0; margin: 0; border: 0; overflow: hidden; }
.flash-success { background: color-mix(in srgb, var(--pos) 12%, var(--surface)); border-color: color-mix(in srgb, var(--pos) 40%, transparent); color: var(--pos); }
.flash-error { background: color-mix(in srgb, var(--neg) 10%, var(--surface)); border-color: color-mix(in srgb, var(--neg) 40%, transparent); color: var(--neg); }
.flash-info { background: var(--brand-soft); border-color: var(--line); color: var(--ink); }

/* ---------- KPI */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.15rem; display: grid; gap: .2rem; box-shadow: var(--shadow); min-width: 0; }
.kpi-main { background: var(--brand); color: var(--brand-ink); border-color: transparent; }
.kpi-main .kpi-label, .kpi-main .kpi-sub, .kpi-main a { color: color-mix(in srgb, var(--brand-ink) 78%, transparent); }
.kpi-label { font-size: .8rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.kpi-value { font-size: 1.45rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-sub { font-size: .85rem; color: var(--ink-3); }

/* ---------- Tableaux */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .7rem 1rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th.num, .table td.num { text-align: right; }
.table th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; white-space: nowrap; }
.table th a { color: inherit; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-hover tbody tr:hover { background: var(--surface-2); }
.table-compact th, .table-compact td { padding: .5rem .6rem; }
.card > .table { margin: 0; }
.row-link { font-weight: 600; }

/* ---------- Formulaires */
.form { display: grid; gap: 1rem; }
.form-wide { gap: 1.5rem; }
.form fieldset { border: 0; margin: 0; padding: 0; display: grid; gap: 1rem; min-width: 0; }
.form legend { font-weight: 700; font-size: 1rem; padding: 0 0 .5rem; border-bottom: 1px solid var(--line); width: 100%; margin-bottom: .25rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .75rem; }
.field { display: grid; gap: .35rem; align-content: start; min-width: 0; }
.field.grow { flex: 1; }
label { font-weight: 600; font-size: .88rem; }
label.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; cursor: pointer; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=file], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--ink); font: inherit;
}
input:disabled { background: var(--surface-2); color: var(--ink-3); }
input[type=checkbox] { width: 1.05rem; height: 1.05rem; accent-color: var(--brand); }
textarea { resize: vertical; }
.hint { color: var(--ink-3); font-size: .82rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: .75rem; align-items: flex-end; margin: 1rem 0 0; }
.inline-form .field { flex: 0 1 auto; }
.filters { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; padding: 1rem 1.25rem; }
.filters .field { min-width: 150px; }
.filters .field.grow { min-width: 220px; }
.rates { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem; margin: 1rem 0; }

/* ---------- Détails / listes */
.details { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1.25rem; margin: 0; }
.details dt { color: var(--ink-3); }
.details dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.desc { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--ink-2); }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; }

.deadline-list, .doc-list, .legend { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.deadline { display: grid; grid-template-columns: 5.5rem 1fr auto auto; gap: .75rem; align-items: center; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 10px; border-left: 4px solid var(--line); }
.deadline.is-soon { border-left-color: var(--warn); }
.deadline.is-late { border-left-color: var(--neg); }
.deadline.is-done { opacity: .55; }
.deadline.is-done strong { text-decoration: line-through; }
.deadline-date { font-weight: 600; font-variant-numeric: tabular-nums; font-size: .88rem; }
.deadline-main { display: grid; min-width: 0; }
.deadline-main small { color: var(--ink-3); }
.deadline-delta { font-size: .82rem; color: var(--ink-3); white-space: nowrap; }
.is-late .deadline-delta { color: var(--neg); font-weight: 600; }
.row-actions { display: flex; gap: .15rem; }
.doc-list li { display: flex; align-items: center; gap: .75rem; padding: .5rem .25rem; border-bottom: 1px solid var(--line); }
.doc-main { display: grid; flex: 1; min-width: 0; overflow-wrap: anywhere; }
.doc-main small { color: var(--ink-3); }

/* ---------- Graphiques */
.chart { min-height: 160px; }
.split { display: grid; grid-template-columns: 200px 1fr; gap: 1.5rem; align-items: center; }
.donut-svg { width: 100%; max-width: 200px; height: auto; }
.donut-track { stroke: var(--surface-2); }
.donut-label { fill: var(--ink-3); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.donut-value { fill: var(--ink); font-size: 15px; font-weight: 700; }
.line-svg { width: 100%; height: auto; display: block; }
.grid-line { stroke: var(--line); stroke-width: 1; }
.axis-text { fill: var(--ink-3); font-size: 11px; }
.line-path { stroke: var(--brand); stroke-width: 2.5; stroke-linejoin: round; }
.area { fill: color-mix(in srgb, var(--brand) 14%, transparent); }
.line-dot { fill: var(--surface); stroke: var(--brand); stroke-width: 2; }
.legend li { display: grid; grid-template-columns: .8rem 1fr auto; gap: .65rem; align-items: center; }
.legend-main { display: grid; }
.legend-main small { color: var(--ink-3); }
.legend-value { font-weight: 600; font-variant-numeric: tabular-nums; }
.dot { width: .8rem; height: .8rem; border-radius: 3px; }
.dot.cat-physical { background: var(--c-physical); }
.dot.cat-intellectual { background: var(--c-intellectual); }
.dot.cat-financial { background: var(--c-financial); }

/* ---------- Simulation */
.trace { margin: 0 0 1rem; padding-left: 1.2rem; display: grid; gap: .35rem; }
.disclaimer { font-size: .85rem; color: var(--ink-3); border-left: 3px solid var(--warn); padding: .5rem .85rem; background: var(--surface); border-radius: 0 8px 8px 0; }

/* ---------- États vides, dialogue */
.empty { text-align: center; padding: 2.5rem 1.5rem; }
.empty h2 { margin-bottom: .5rem; }
.empty-code { font-size: 4rem; font-weight: 800; color: var(--brand); margin: 0; }
.dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 1.5rem; max-width: 26rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.dialog::backdrop { background: rgba(10, 16, 13, .55); }
.dialog-title { margin-bottom: .75rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; }

/* ---------- Invité (connexion / inscription) */
.guest-shell { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.guest-hero { background: var(--sidebar-bg); color: var(--sidebar-ink); padding: 3rem clamp(1.5rem, 5vw, 4.5rem); display: flex; flex-direction: column; justify-content: center; gap: 1.5rem; }
.guest-hero h1 { font-size: clamp(1.8rem, 3.2vw, 2.6rem); color: #fff; }
.guest-hero p { max-width: 34rem; font-size: 1.05rem; }
.hero-points { list-style: none; margin: 0; padding: 0; display: grid; gap: .75rem; }
.hero-points li { display: flex; align-items: center; gap: .75rem; }
.hero-points .icon { color: var(--brand); width: 1.4em; height: 1.4em; }
.guest-card { display: flex; flex-direction: column; justify-content: center; max-width: 30rem; width: 100%; margin: 0 auto; padding: 2rem 1.5rem; gap: 1rem; }
.guest-card h2 { font-size: 1.5rem; margin-bottom: .5rem; }

/* ---------- Impression (inventaire) */
@media print {
  .sidebar, .topbar, .actions, .btn, .filters, .pager, .inline-form { display: none !important; }
  .shell { display: block; }
  body { background: #fff; color: #000; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }

/* ---------- Vues 3D */
.v3d { padding: 0; overflow: hidden; }
.v3d-toolbar { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; padding: .75rem 1rem; border-bottom: 1px solid var(--line); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; max-width: 100%; }
.seg-btn { border: 0; background: transparent; color: var(--ink-2); font: inherit; font-weight: 600; padding: .45rem 1rem; border-radius: 8px; cursor: pointer; min-height: 2.5rem; }
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.v3d-controls { display: flex; gap: .15rem; }
.v3d-controls .icon-btn { width: 2.5rem; height: 2.5rem; }
.v3d-stage { position: relative; background: radial-gradient(120% 90% at 50% 20%, var(--surface) 0%, var(--surface-2) 100%); }
.v3d-canvas { display: block; width: 100%; height: clamp(340px, 62vh, 640px); touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none; }
.v3d-canvas:active { cursor: grabbing; }
.v3d-canvas:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; }
.v3d-tip { position: absolute; z-index: 2; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .55rem .8rem; box-shadow: 0 6px 24px rgba(0, 0, 0, .18); display: grid; gap: .1rem; max-width: min(260px, 80%); font-size: .86rem; }
.v3d-tip.is-pinned { pointer-events: auto; border-color: var(--brand); }
.tip-sub { color: var(--ink-3); }
.tip-val { font-weight: 700; font-variant-numeric: tabular-nums; }
.tip-link { font-weight: 600; padding-top: .25rem; }
.v3d-foot { display: flex; gap: .5rem 1.5rem; justify-content: space-between; align-items: center; flex-wrap: wrap; padding: .75rem 1rem; border-top: 1px solid var(--line); }
.v3d-foot p { margin: 0; }
.legend-inline { display: flex; flex-wrap: wrap; gap: .4rem 1.25rem; }
.legend-inline li { display: flex; align-items: center; gap: .5rem; }
.v3d-table { padding: 0; }
.v3d-table > summary { cursor: pointer; font-weight: 600; padding: 1rem 1.25rem; }
.v3d-table[open] > summary { border-bottom: 1px solid var(--line); }
.v3d-table .table-wrap { box-shadow: none; border: 0; margin: 0; border-radius: 0; }

/* ======================================================================
   Responsive — approche "mobile d'abord" corrigée par paliers :
   ≤1180 : colonnes empilées · ≤960 : menu hors-champ · ≤640 : tableaux en cartes · ≤420 : compact
   ====================================================================== */
h1, h2, h3, .kpi-value, .deadline-main, .details dd { overflow-wrap: anywhere; }
.grid-2 > *, .grid-sim > *, .kpi, .card, .field, .split > * { min-width: 0; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.kpi-value { font-size: clamp(1.15rem, .9rem + 1vw, 1.5rem); }
.scrim { display: none; }
.content { padding-left: max(1.75rem, env(safe-area-inset-left)); padding-right: max(1.75rem, env(safe-area-inset-right)); }

@media (max-width: 1180px) {
  .grid-2, .grid-sim { grid-template-columns: 1fr; }
  .grid-sim > form.card { position: static; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(290px, 86vw); height: 100dvh; z-index: 60;
    transform: translateX(-102%); visibility: hidden; overflow-y: auto;
    transition: transform .22s ease, visibility 0s linear .22s;
    padding-top: max(1.25rem, env(safe-area-inset-top)); padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  }
  .sidebar.is-open { transform: none; visibility: visible; transition-delay: 0s; box-shadow: 8px 0 40px rgba(0, 0, 0, .35); }
  .nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(8, 14, 11, .55); }
  .nav-open { overflow: hidden; }
  .topbar {
    display: flex; align-items: center; gap: .5rem; position: sticky; top: 0; z-index: 30;
    padding: .35rem max(.75rem, env(safe-area-inset-right)) .35rem max(.5rem, env(safe-area-inset-left));
    background: var(--surface); border-bottom: 1px solid var(--line);
  }
  .topbar-title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .menu-toggle { width: 2.75rem; height: 2.75rem; }
  .content { padding: 1.25rem max(1rem, env(safe-area-inset-right)) 3rem max(1rem, env(safe-area-inset-left)); }
  .guest-shell { grid-template-columns: 1fr; }
  .guest-hero { padding: 1.75rem 1.5rem; gap: 1rem; }
  .guest-hero p, .hero-points { display: none; }
  .guest-card { padding: 1.5rem 1.25rem 2.5rem; }
}

@media (max-width: 760px) {
  .split { grid-template-columns: 1fr; justify-items: center; }
  .split .legend { width: 100%; }
  .page-head { margin-bottom: 1rem; }
  .page-head > .actions, .page-head > .btn { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .page-head .actions form { flex: 1 1 auto; display: flex; }
  .page-head .actions form .btn { width: 100%; }
  .card { padding: 1rem; }
  .table-wrap, .v3d-table { padding: 0; }
  .filters { padding: 1rem; }
  .filters .field, .filters .field.grow { flex: 1 1 calc(50% - .5rem); min-width: 0; }
  .filters .field.grow { flex-basis: 100%; }
  .filters .btn { flex: 1 1 100%; }
  .inline-form .field { flex: 1 1 100%; }
  .inline-form .btn { width: 100%; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions .btn { width: 100%; }
  .deadline { grid-template-columns: 1fr auto; gap: .35rem .75rem; }
  .deadline-date { grid-column: 1 / -1; }
  .deadline .btn { grid-column: 1 / -1; }
  .pager { flex-wrap: wrap; }
  .details { grid-template-columns: 1fr; gap: .1rem; }
  .details dd { margin-bottom: .6rem; }
  .v3d-toolbar { padding: .6rem .75rem; }
  .v3d-foot { padding: .6rem .75rem; }
  .seg { width: 100%; }
  .seg-btn { flex: 1; padding-inline: .5rem; }
  .v3d-controls { margin-left: auto; }
  .v3d-canvas { height: clamp(300px, 58svh, 560px); }
}

/* Tableaux → cartes empilées sur petits écrans (les <td> portent data-label) */
@media (max-width: 640px) {
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr { padding: .75rem 1rem; border-bottom: 1px solid var(--line); }
  .table-stack tbody tr:last-child { border-bottom: 0; }
  .table-stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; border: 0; padding: .2rem 0; text-align: right; white-space: normal; }
  .table-stack td::before { content: attr(data-label); color: var(--ink-3); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; text-align: left; flex: none; }
  .table-stack td:first-child { font-size: 1.02rem; justify-content: flex-start; text-align: left; }
  .table-stack td:first-child::before { display: none; }
  .table-stack td.num { white-space: normal; }
}

/* Écrans tactiles : cibles ≥ 44 px, champs 16 px (évite le zoom automatique d'iOS) */
@media (pointer: coarse), (max-width: 760px) {
  .btn { min-height: 2.75rem; }
  .btn-sm { min-height: 2.5rem; }
  .icon-btn { min-width: 2.75rem; min-height: 2.75rem; }
  .nav-link { min-height: 2.75rem; }
  input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], select, textarea { font-size: 16px; min-height: 2.75rem; }
  input[type=file] { min-height: 2.75rem; }
  label.check { min-height: 2.5rem; }
  input[type=checkbox] { width: 1.25rem; height: 1.25rem; }
  .row-actions .icon-btn { min-width: 2.5rem; }
}

@media (max-width: 520px) {
  .kpis, .kpis-3 { grid-template-columns: 1fr; gap: .75rem; }
  .kpi { padding: .85rem 1rem; }
  .content { padding-top: 1rem; }
  h1 { font-size: 1.35rem; }
  .brand { font-size: 1.05rem; }
  .rates { grid-template-columns: 1fr 1fr; }
  .dialog { max-width: calc(100vw - 2rem); }
}
@media (max-width: 360px) {
  .rates { grid-template-columns: 1fr; }
  .seg-btn { font-size: .85rem; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .v3d-canvas { height: max(240px, 78svh); }
}
.kpi-sub a { display: inline-block; padding: .55rem 0; }
/* spécificité : le padding de .card (mobile) ne doit pas écraser celui de la scène 3D */
.card.v3d, .card.v3d-table { padding: 0; }

/* ======================================================================
   Photos, visionneuse, localisation
   ====================================================================== */
.asset-cell { display: flex; align-items: center; gap: .75rem; min-width: 0; }
.thumb { width: 44px; height: 44px; border-radius: 9px; object-fit: cover; flex: none; background: var(--surface-2); }
.thumb-ph { display: grid; place-items: center; }
.thumb-ph.cat-physical { background: color-mix(in srgb, var(--c-physical) 16%, transparent); color: var(--c-physical); }
.thumb-ph.cat-intellectual { background: color-mix(in srgb, var(--c-intellectual) 16%, transparent); color: var(--c-intellectual); }
.thumb-ph.cat-financial { background: color-mix(in srgb, var(--c-financial) 18%, transparent); color: var(--c-financial); }

.photo-grid { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.photo { position: relative; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.photo.is-cover { grid-column: 1 / -1; aspect-ratio: 16 / 7; max-height: 420px; }
.photo-btn { all: unset; box-sizing: border-box; display: block; width: 100%; height: 100%; cursor: zoom-in; position: relative; }
.photo-btn:focus-visible { outline: 3px solid var(--brand); outline-offset: -3px; }
.photo-btn img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.photo-btn:hover img { transform: scale(1.03); }
.photo-badge { position: absolute; left: .6rem; top: .6rem; background: rgba(10, 16, 13, .7); color: #fff; font-size: .75rem; font-weight: 600; padding: .2rem .6rem; border-radius: 999px; }
.photo-upload { align-items: flex-end; }
.photo-status { flex: 1 1 100%; margin: 0; min-height: 1.2em; }

.lightbox { width: min(1100px, 100vw); max-width: 100vw; max-height: 100dvh; padding: 0; border: 0; border-radius: 12px; background: var(--surface); color: var(--ink); overflow: hidden; }
.lightbox[open] { display: flex; flex-direction: column; }
.lightbox::backdrop { background: rgba(6, 10, 8, .82); }
.lb-bar { display: flex; justify-content: space-between; align-items: center; padding: .35rem .5rem .35rem 1rem; border-bottom: 1px solid var(--line); gap: 1rem; }
.lb-bar .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-stage { position: relative; background: #0b0f0d; display: grid; place-items: center; min-height: 0; flex: 1; }
.lb-stage img { max-width: 100%; max-height: calc(100dvh - 215px); object-fit: contain; display: block; touch-action: pan-y; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 2.75rem; height: 2.75rem; border-radius: 50%; border: 0; cursor: pointer; background: rgba(0, 0, 0, .55); color: #fff; display: grid; place-items: center; }
.lb-nav:first-of-type { left: .6rem; }
.lb-nav:last-of-type { right: .6rem; }
.lb-nav:hover { background: rgba(0, 0, 0, .8); }
.lb-foot { display: flex; flex-wrap: wrap; gap: .75rem 1.25rem; align-items: flex-end; justify-content: space-between; padding: .75rem 1rem; border-top: 1px solid var(--line); }
.lb-foot .inline-form { margin: 0; flex: 1 1 300px; }
.lb-foot .actions form { display: block; }

.geo-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.geo-canvas { display: block; width: 100%; height: 340px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.geo-map-wrap .hint { margin: .5rem 0 0; }
.geo-info .actions { margin-top: 1rem; }
.geo-preview { margin-top: .25rem; }
.geo-preview .geo-canvas { height: 280px; }
.geo-stats { margin: .5rem 0 0; font-weight: 600; font-size: .88rem; min-height: 1.3em; }
textarea#geo_polygon { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; }

@media (max-width: 960px) {
  .geo-layout { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
  .photo.is-cover { aspect-ratio: 16 / 10; }
  .geo-canvas { height: 280px; }
  .geo-preview .geo-canvas { height: 240px; }
  .lightbox { width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; }
  .lb-stage { flex: 1; }
  .lb-stage img { max-height: none; max-width: 100%; height: auto; }
  .lb-foot { padding: .6rem .75rem; }
  .lb-foot .inline-form .field { flex: 1 1 100%; }
  .lb-foot .actions { width: 100%; }
  .lb-foot .actions form { flex: 1; }
  .lb-foot .actions .btn { width: 100%; }
}
