/* PORTEO Patrimoine — feuille de style unique, sans dépendance externe */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #dfe3e8;
  --text: #1c2430;
  --text-2: #4a5565;
  --muted: #6b7584;
  --brand: #12355b;
  --brand-ink: #ffffff;
  --accent: #e08a00;
  --primary: #1d5fa8;
  --primary-hover: #174d89;
  --focus: #3b82f6;
  --good-bg: #e3f4ea;   --good-fg: #1b6b3a;
  --pending-bg: #e6effa; --pending-fg: #1d4f8c;
  --warning-bg: #fdf1dc; --warning-fg: #8a5300;
  --critical-bg: #fbe6e6; --critical-fg: #9b1c1c;
  --neutral-bg: #eceef1; --neutral-fg: #4a5565;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --surface: #171e27; --surface-2: #1c2530; --border: #2b3542;
    --text: #e6eaef; --text-2: #b8c1cc; --muted: #8a95a3;
    --brand: #0d2742; --primary: #4b8fd8; --primary-hover: #66a3e3; --accent: #f0a32a;
    --good-bg: #173524; --good-fg: #8fd8aa;
    --pending-bg: #172a42; --pending-fg: #9cc3f0;
    --warning-bg: #3a2a10; --warning-fg: #f2c27a;
    --critical-bg: #3f1a1a; --critical-fg: #f3a5a5;
    --neutral-bg: #252e39; --neutral-fg: #b8c1cc;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 .6rem; }
h2:first-child { margin-top: 0; }
h3 { font-size: .95rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small, small { font-size: .82rem; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .88em; }
.center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* --- Structure --- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: .55rem 1rem; background: var(--brand); color: var(--brand-ink);
}
.brand { display: flex; align-items: center; gap: .6rem; color: inherit; }
.brand:hover { text-decoration: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { opacity: .75; font-size: .75rem; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 6px;
  background: var(--accent); color: #1c1200; font-weight: 800; letter-spacing: .5px;
}
.brand-mark-lg { width: 52px; height: 52px; font-size: 1.2rem; }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 1rem; font-size: .85rem; }
.userbox a, .userbox .link { color: var(--brand-ink); opacity: .85; }
.userbox-name { display: flex; flex-direction: column; text-align: right; line-height: 1.2; }
.userbox-name small { opacity: .7; }
.nav-toggle { display: none; background: none; border: 0; color: inherit; font-size: 1.4rem; cursor: pointer; padding: .2rem .4rem; }

.shell { display: flex; min-height: calc(100vh - 54px); }
.sidenav {
  flex: 0 0 230px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 1rem .6rem; display: flex; flex-direction: column; gap: 2px;
}
.sidenav a {
  display: flex; justify-content: space-between; align-items: center;
  padding: .55rem .75rem; border-radius: 6px; color: var(--text-2); font-weight: 500;
}
.sidenav a:hover { background: var(--surface-2); text-decoration: none; }
.sidenav a.active { background: var(--pending-bg); color: var(--pending-fg); }
.sidenav .count { background: var(--accent); color: #1c1200; border-radius: 999px; padding: 0 .5rem; font-size: .75rem; font-weight: 700; }
.sidenav-foot { margin-top: auto; padding: .75rem; font-size: .75rem; color: var(--muted); }

.content { flex: 1; min-width: 0; padding: 1.5rem; max-width: 1400px; }
.content-bare { max-width: none; display: grid; place-items: center; min-height: 100vh; }

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.actions, .form-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form, .form-actions form { margin: 0; }
.two-col { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 1rem; align-items: start; }

/* --- Cartes, alertes, badges --- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin: 0 0 1rem;
}
.card.narrow { max-width: 460px; }
.card-accent { border-left: 4px solid var(--primary); }
.card-warning { border-left: 4px solid var(--accent); }
fieldset.card { min-width: 0; }
legend { font-weight: 650; padding: 0 .35rem; }

.alert { padding: .7rem 1rem; border-radius: var(--radius); margin: 0 0 1rem; border: 1px solid transparent; }
.alert-success { background: var(--good-bg); color: var(--good-fg); }
.alert-info { background: var(--pending-bg); color: var(--pending-fg); }
.alert-warning { background: var(--warning-bg); color: var(--warning-fg); }
.alert-error { background: var(--critical-bg); color: var(--critical-fg); }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-good { background: var(--good-bg); color: var(--good-fg); }
.badge-pending { background: var(--pending-bg); color: var(--pending-fg); }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-critical { background: var(--critical-bg); color: var(--critical-fg); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* --- Boutons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 40px; padding: .45rem 1rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-warning { background: var(--warning-bg); border-color: transparent; color: var(--warning-fg); }
.btn-danger { background: var(--critical-bg); border-color: transparent; color: var(--critical-fg); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; }
.link-danger { color: var(--critical-fg); }

/* --- Formulaires --- */
.form label { display: flex; flex-direction: column; gap: .3rem; font-weight: 550; font-size: .88rem; color: var(--text-2); }
.form label.checkbox, label.checkbox { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--border); border-radius: 6px; padding: .5rem .65rem; min-height: 40px;
}
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }
input[type="file"] { padding: .4rem; }
textarea { resize: vertical; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem 1rem; }
.grid .span-2 { grid-column: span 2; }
.form > .form-actions { margin: .5rem 0 1rem; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; border-top: 1px solid var(--border); z-index: 5; }
.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .35rem 1rem; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; align-items: center; }
.filters input[type="search"] { flex: 1 1 260px; width: auto; }
.filters select, .filters input { width: auto; min-width: 150px; }
.filters .inline { display: flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--muted); }

/* --- Tableaux --- */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; }
.card .table-wrap { border: 0; margin: 0; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
.table th, .table td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:hover { background: var(--surface-2); }
.table-compact th, .table-compact td { padding: .4rem .6rem; }
.row-muted { opacity: .55; }
.row-group td { background: var(--surface-2); }
.indent { padding-left: 1.75rem !important; }
.matrix th { text-transform: none; font-size: .7rem; }
.thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 4px; display: block; }
code.json { font-size: .75rem; word-break: break-all; color: var(--text-2); }

.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; margin: 1rem 0; }

/* --- Fiche --- */
.dl { margin: 0; }
.dl-row { display: grid; grid-template-columns: 200px 1fr; gap: .75rem; padding: .35rem 0; border-bottom: 1px dashed var(--border); }
.dl-row:last-child { border-bottom: 0; }
.dl dt { color: var(--muted); font-size: .85rem; }
.dl dd { margin: 0; white-space: pre-line; }
.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.file { margin: 0; display: block; }
.file img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }
.file figcaption { display: flex; justify-content: space-between; font-size: .78rem; color: var(--muted); padding-top: .2rem; }
.file-doc { display: block; padding: .75rem; border: 1px solid var(--border); border-radius: 6px; font-size: .82rem; word-break: break-word; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: .3rem 0; }
.timeline { list-style: none; padding: 0 0 0 1rem; margin: 1rem 0 0; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 .9rem .75rem; font-size: .88rem; }
.timeline li::before { content: ""; position: absolute; left: -1.38rem; top: .4rem; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); border: 2px solid var(--surface); }
.timeline blockquote { margin: .3rem 0 0; padding: .4rem .6rem; background: var(--surface-2); border-radius: 6px; }

/* --- Tableau de bord --- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; display: flex; flex-direction: column; gap: .15rem; box-shadow: var(--shadow); }
.tile-label { color: var(--muted); font-size: .8rem; font-weight: 550; }
.tile-value { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile-hint { color: var(--muted); font-size: .78rem; }
.tile-warning { border-left: 4px solid var(--accent); }
.tasks { display: grid; gap: .5rem; margin-bottom: 1rem; }
.task { display: block; padding: .7rem 1rem; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.task-pending { background: var(--pending-bg); color: var(--pending-fg); border-color: transparent; }
.task-warning { background: var(--warning-bg); color: var(--warning-fg); border-color: transparent; }
.meter { display: inline-block; vertical-align: middle; width: 90px; height: 8px; background: var(--neutral-bg); border-radius: 4px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--good-fg); border-radius: 4px; }

/* --- Connexion --- */
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; box-shadow: var(--shadow); }
.login-head { text-align: center; margin-bottom: 1.25rem; }
.login-head h1 { font-size: 1.25rem; margin-top: .75rem; }
.login-head p { color: var(--muted); font-size: .9rem; }
.login-card .form { display: grid; gap: 1rem; }

/* --- Mobile (chantiers) --- */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .dl-row { grid-template-columns: 1fr; gap: 0; }
}
@media (max-width: 760px) {
  .content { padding: 1rem; }
  .nav-toggle { display: block; }
  .brand-text, .userbox-name small, .userbox a { display: none; }
  .userbox { gap: .6rem; }
  .shell { display: block; }
  .sidenav { display: none; position: fixed; inset: 54px 0 auto 0; z-index: 15; border-bottom: 1px solid var(--border); box-shadow: 0 8px 24px rgba(0,0,0,.15); }
  .sidenav.open { display: flex; }
  .grid .span-2 { grid-column: auto; }
  .filters select, .filters input, .filters .btn { flex: 1 1 100%; }
  /* tableaux en cartes empilées */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--border); padding: .5rem 0; }
  .table td { border: 0; padding: .2rem .75rem; text-align: left; }
  .table td[data-label]::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
  .matrix thead { display: table-header-group; }
  .btn { min-height: 44px; }
}

/* --- Phase 2 : contrôle physique, PV, étiquettes --- */
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin: 0 0 .75rem; border-bottom: 1px solid var(--border); }
.tabs a { padding: .5rem .8rem; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tabs a:hover { text-decoration: none; background: var(--surface-2); }
.tiles-compact { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); margin: 0; }
.tiles-compact .tile { box-shadow: none; padding: .6rem .75rem; }
.tiles-compact .tile-value { font-size: 1.35rem; }
.segmented { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.segmented label { flex: 1 1 140px; flex-direction: row !important; align-items: center; gap: .5rem; padding: .7rem .9rem; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; font-weight: 600; color: var(--text); }
.segmented label:has(input:checked) { border-color: var(--primary); background: var(--pending-bg); color: var(--pending-fg); }
.segmented input { width: 18px; height: 18px; min-height: 0; }
.scan-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.scan-form input[name="code"] { flex: 1 1 260px; width: auto; }
.scan-video { margin-top: .75rem; display: grid; gap: .5rem; justify-items: start; }
.scan-video[hidden] { display: none; }
.scan-video video { width: min(420px, 100%); border-radius: 8px; background: #000; }
.ref-photo { width: 100%; max-height: 240px; object-fit: cover; border-radius: 6px; margin-bottom: .75rem; }
details.card summary { cursor: pointer; font-weight: 600; }
details.card[open] summary { margin-bottom: .75rem; }

.identity { display: flex; gap: 1.5rem; justify-content: space-between; align-items: flex-start; }
.identity > div:first-child { flex: 1; min-width: 0; }
.identity-qr { display: flex; flex-direction: column; align-items: center; gap: .25rem; background: #fff; color: #111; padding: .75rem; border-radius: 8px; border: 1px solid var(--border); }
.identity-qr svg, .label-qr svg { width: 132px; height: 132px; display: block; }
.identity-qr a { color: #1d5fa8; }

.pv { max-width: 1100px; }
.pv-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 2px solid var(--text); padding-bottom: .75rem; margin-bottom: 1rem; }
.pv-ref { text-align: right; }
.pv-title { text-align: center; text-transform: uppercase; letter-spacing: .04em; font-size: 1.15rem; margin: 1rem 0 1.25rem; }
.pv-summary th { text-transform: none; font-size: .85rem; }
.pv-items td { font-size: .82rem; }
.pv-signatures { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-top: 2rem; }
.sign-box { height: 70px; border: 1px dashed var(--border); border-radius: 6px; margin-top: .5rem; }

.labels { display: grid; gap: 4mm; }
.labels-standard { grid-template-columns: repeat(3, 1fr); }
.labels-grand { grid-template-columns: repeat(2, 1fr); }
.label { display: flex; align-items: center; gap: 3mm; background: #fff; color: #000; border: 1px solid #999; border-radius: 3mm; padding: 3mm; break-inside: avoid; page-break-inside: avoid; }
.labels-standard .label { height: 38mm; }
.labels-grand .label { height: 70mm; }
.labels-standard .label-qr svg { width: 30mm; height: 30mm; }
.labels-grand .label-qr svg { width: 60mm; height: 60mm; }
.label-text { display: flex; flex-direction: column; gap: 1mm; min-width: 0; line-height: 1.15; }
.label-company { font-size: 7pt; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; }
.label-code { font: 700 11pt ui-monospace, Consolas, monospace; }
.labels-grand .label-code { font-size: 16pt; }
.label-desig { font-size: 8pt; }
.labels-grand .label-desig { font-size: 11pt; }
.label-note { font-size: 6pt; color: #444; }

@media print {
  @page { size: A4; margin: 10mm; }
  body { background: #fff; color: #000; font-size: 10pt; }
  .topbar, .sidenav, .no-print, .alert { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; background: #fff; }
  .table th { background: #eee; color: #000; }
  .table th, .table td { border-color: #bbb; }
  a { color: #000; }
}
@media (max-width: 760px) {
  .identity { flex-direction: column; }
  .pv-signatures { grid-template-columns: 1fr; }
  .labels-standard, .labels-grand { grid-template-columns: 1fr; }
}
.filters input[type="checkbox"] { min-width: 0; width: 18px; flex: none; }

/* --- Phase 3 : comptabilité --- */
.tile-link { color: var(--text); }
.tile-link:hover { text-decoration: none; border-color: var(--primary); }
.tile-money { font-size: 1.1rem !important; }
.text-critical { color: var(--critical-fg); }
.match-card .match-head { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: .5rem; }
.compare th:first-child { width: 160px; }
.compare tr.match-same td { background: var(--good-bg); color: var(--good-fg); }
.match-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }
.match-actions input { flex: 1 1 240px; width: auto; }
.inline-form { display: flex; gap: .35rem; flex-wrap: wrap; }
.inline-form input { width: auto; flex: 1 1 120px; min-height: 34px; padding: .3rem .5rem; }
.inline-form .btn { min-height: 34px; }
.journal input { min-height: 34px; padding: .3rem .5rem; }
.journal input.num { text-align: right; }
.journal tfoot th { background: var(--surface-2); }

/* --- Phase 4 : mouvements, stocks, hors ligne, reporting --- */
[data-for][hidden] { display: none !important; }
.pv-signatures-3, .pv-signatures-4 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; }
.count-sheet input.count-input { width: 110px; display: inline-block; }
.count-sheet tr.row-ecart td { background: var(--warning-bg); }
.offline-bar { position: sticky; top: 54px; z-index: 10; display: flex; gap: 1rem; align-items: center; justify-content: space-between;
  padding: .6rem 1rem; margin-bottom: 1rem; border-radius: var(--radius); background: var(--pending-bg); color: var(--pending-fg); }
.offline-bar.offline { background: var(--warning-bg); color: var(--warning-fg); }
.offline-bar[hidden] { display: none; }
.text-good { color: var(--good-fg); }
.text-warning { color: var(--warning-fg); }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-bottom: .5rem; }
.chart-card { margin: 0; }
.chart-card figcaption { font-weight: 600; font-size: .9rem; margin-bottom: .25rem; }
.chart { width: 100%; height: auto; display: block; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 13px; }
.chart-line { fill: none; stroke: var(--primary); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--primary); stroke: var(--surface); stroke-width: 2; }
.chart-hit { fill: transparent; }
.chart-pt:hover .chart-dot { r: 5; }
@media print { .charts { grid-template-columns: 1fr 1fr; } .chart-line { stroke: #1d5fa8; } .chart-dot { fill: #1d5fa8; } }
