:root {
  --ink: #16233a;
  --ink-2: #3c4a63;
  --muted: #74809a;
  --line: #e3e6ec;
  --line-2: #eef0f4;
  --bg: #f6f5f2;
  --card: #ffffff;
  --accent: #b5562f;       /* terre cuite */
  --accent-soft: #f7e9e2;
  --ok: #2f7a55; --ok-soft: #e3f2ea;
  --warn: #a86b0c; --warn-soft: #fbf0dc;
  --bad: #b23a3a; --bad-soft: #f9e4e4;
  --info: #2f5f9e; --info-soft: #e5eef9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(22,35,58,.06), 0 4px 16px rgba(22,35,58,.05);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

/* Layout */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #c9d1e0; padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; font-weight: 800; font-size: 14px; }
.brand-name { font-weight: 700; font-size: 15px; line-height: 1.1; }
.brand-sub { font-size: 11px; color: #8d99b3; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; text-decoration: none; color: #c9d1e0; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.nav svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav .badge { margin-left: auto; background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; }
.side-foot { margin-top: auto; padding: 10px; font-size: 12px; color: #8d99b3; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot b { color: #fff; font-weight: 600; display: block; }
.side-foot button { background: none; border: 0; color: #8d99b3; padding: 0; cursor: pointer; text-decoration: underline; font-size: 12px; margin-top: 4px; }
.main { padding: 26px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 3px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.back { text-decoration: none; color: var(--muted); font-size: 13px; display: inline-block; margin-bottom: 6px; }

/* Cards & grid */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.kpi { padding: 16px 18px; }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.kpi .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.accent .v { color: var(--accent); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 13px; cursor: pointer; text-decoration: none; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #cfd4dd; background: #fafbfc; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #22324f; }
.btn.accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 5px 9px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: default; }

/* Filters */
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1; min-width: 220px; }
.input, .filters input, .filters select { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 11px; outline: none; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 5px 12px; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Tables */
table.list { width: 100%; border-collapse: collapse; background: #fff; }
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); }
table.list th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fbfbfa; position: sticky; top: 0; }
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #fafaf8; }
table.list td.r, table.list th.r { text-align: right; }
.thumb { width: 64px; height: 46px; border-radius: 6px; object-fit: cover; background: var(--line-2); display: block; }
.thumb.ph { display: grid; place-items: center; color: var(--muted); font-size: 10px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Tags */
.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.info { background: var(--info-soft); color: var(--info); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.tag.dark { background: var(--ink); color: #fff; }

/* Tabs */
.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.field .hint { font-size: 11px; color: var(--muted); }
.field input, .field select, .field textarea { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; outline: none; width: 100%; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { border-color: var(--ink-2); box-shadow: 0 0 0 3px rgba(22,35,58,.08); }
.field textarea { min-height: 90px; resize: vertical; }
.field textarea.tall { min-height: 200px; }
.unit { position: relative; }
.unit input { padding-right: 42px; }
.unit span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 12px; pointer-events: none; }
.yn { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; width: max-content; }
.yn button { border: 0; background: #fff; padding: 7px 14px; cursor: pointer; }
.yn button + button { border-left: 1px solid var(--line); }
.yn button.on { background: var(--ink); color: #fff; }
.section { margin-bottom: 22px; }
.section-title { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.section-title h2 { margin: 0; }
.savebar { position: sticky; bottom: 0; background: rgba(246,245,242,.92); backdrop-filter: blur(6px); padding: 12px 0; margin-top: 16px; display: flex; gap: 8px; align-items: center; border-top: 1px solid var(--line); z-index: 5; }
.savebar .dirty { color: var(--warn); font-size: 13px; }

/* Bien header */
.bien-head { display: grid; grid-template-columns: 220px 1fr; gap: 18px; align-items: start; }
.bien-head img, .bien-head .ph { width: 220px; height: 150px; border-radius: 10px; object-fit: cover; background: var(--line-2); display: grid; place-items: center; color: var(--muted); }
.facts { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 12px; }
.facts div .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.facts div .v { font-size: 17px; font-weight: 700; }
.ratio { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-top: 12px; }
.ratio > div { background: #fff; padding: 10px 12px; }
.ratio .l { font-size: 11px; color: var(--muted); }
.ratio .v { font-weight: 700; font-size: 15px; }

/* Photos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.photo { position: relative; border-radius: 8px; overflow: hidden; aspect-ratio: 4/3; background: var(--line-2); cursor: grab; border: 2px solid transparent; }
.photo.drag-over { border-color: var(--accent); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo .x { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 6px; padding: 2px 7px; cursor: pointer; }
.photo .first { position: absolute; left: 6px; top: 6px; }
.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 26px; text-align: center; color: var(--muted); cursor: pointer; margin-bottom: 14px; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 30px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line-2); }
.timeline li:last-child { border: 0; }
.timeline .ic { width: 28px; height: 28px; border-radius: 50%; background: var(--line-2); display: grid; place-items: center; font-size: 13px; }
.timeline .meta { font-size: 12px; color: var(--muted); }
.timeline .todo .ic { background: var(--warn-soft); }

/* Match */
.match { display: grid; grid-template-columns: 54px 64px 1fr auto; gap: 12px; align-items: center; padding: 12px; border-bottom: 1px solid var(--line-2); }
.match:last-child { border: 0; }
.score { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px; border: 3px solid var(--line); }
.score.hi { border-color: var(--ok); color: var(--ok); }
.score.mid { border-color: var(--warn); color: var(--warn); }
.score.lo { border-color: var(--line); color: var(--muted); }
.match .why { font-size: 12px; margin-top: 3px; display: flex; gap: 4px; flex-wrap: wrap; }

/* Lists in cards */
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line-2); }
.rows li:last-child { border: 0; }
.rows li .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(22,35,58,.4); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: min(720px, 100%); max-height: 92vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal header h2 { margin: 0; }
.modal header button { margin-left: auto; }
.modal .body { padding: 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; position: sticky; bottom: 0; background: #fff; }

/* Toast */
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 100; }
#toast.show { opacity: 1; transform: translateX(-50%); }
#toast.err { background: var(--bad); }

/* Auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.auth .card { width: min(400px, 100%); padding: 28px; }
.auth .brand { color: var(--ink); padding: 0 0 20px; }
.auth .brand-sub { color: var(--muted); }
.auth .field { margin-bottom: 12px; }
.err { color: var(--bad); font-size: 13px; margin: 6px 0; }

/* Registre */
.registre-print { display: none; }

/* Responsive */
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } .g4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; overflow-x: auto; padding: 8px; align-items: center; }
  .brand { padding: 0 8px 0 0; } .brand-name, .brand-sub, .side-foot { display: none; }
  .nav { display: flex; } .nav a span.lbl { display: none; }
  .main { padding: 16px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .bien-head { grid-template-columns: 1fr; } .bien-head img, .bien-head .ph { width: 100%; }
  .ratio { grid-template-columns: repeat(2, 1fr); }
}

/* Impression */
@media print {
  .side, .page-head .actions, .savebar, .filters, .tabs, .no-print { display: none !important; }
  .shell { display: block; } .main { padding: 0; }
  body, html { background: #fff; }
  .card, .table-wrap { box-shadow: none; border: 0; }
  table.list th { position: static; }
}

/* Sélecteur avec recherche */
.picker { position: relative; }
.picker input { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
.pick-list { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 280px; overflow: auto; }
.pick-item { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.pick-item:hover { background: var(--bg); }
.pick-item.new { color: var(--accent); font-weight: 600; }
