/* Ma Maison — styles */
:root {
  --bg: #F3F2EE;
  --surface: #FFFFFF;
  --surface-2: #F8F7F4;
  --ink: #1D2024;
  --ink-2: #4A4F57;
  --muted: #80858C;
  --line: #E4E2DB;
  --accent: #2D5B4C;
  --accent-ink: #FFFFFF;
  --accent-soft: #E2ECE7;
  --ok: #2F7A55;   --ok-bg: #E3F1E8;
  --warn: #9A6412; --warn-bg: #FBF0DC;
  --bad: #B03A36;  --bad-bg: #F8E3E1;
  --info: #2D5A88; --info-bg: #E3ECF6;
  --mute-bg: #ECEBE6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 22, 26, .04), 0 4px 16px rgba(20, 22, 26, .04);
  --gap: clamp(14px, 1.6vw, 24px);
  --pad: clamp(16px, 2vw, 28px);
  --side: clamp(210px, 17vw, 250px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131518; --surface: #1C1F23; --surface-2: #22262B;
    --ink: #ECEBE6; --ink-2: #BDBFC2; --muted: #8B9097; --line: #2D3137;
    --accent: #86BBA6; --accent-ink: #10201A; --accent-soft: #23352E;
    --ok: #7CC79C; --ok-bg: #1E3327; --warn: #E2B061; --warn-bg: #3A2E19;
    --bad: #EE8F89; --bad-bg: #3D2221; --info: #8FB6E3; --info-bg: #1F2D3D; --mute-bg: #2A2E33;
    --shadow: none;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: clamp(14.5px, .82rem + .22vw, 16.5px); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 1rem/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: clamp(1.5rem, 1.1rem + 1.4vw, 2.1rem); line-height: 1.15; }
h2 { font-size: 1.02rem; display: flex; align-items: center; gap: .5em; }
h3 { font-size: .85rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .05em; margin-bottom: .4em; }
code { font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
.i { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.dim { color: var(--muted); font-weight: 400; }
.muted { color: var(--ink-2); }
.center { text-align: center; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .92em; letter-spacing: .01em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.up { color: var(--bad); }
.down { color: var(--ok); }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1.2rem; padding: 1.4rem 1rem; border-right: 1px solid var(--line); background: var(--surface-2); overflow-y: auto; }
.brand { display: flex; align-items: center; justify-content: space-between; }
.brand a { display: flex; align-items: center; gap: .6rem; font-weight: 650; font-size: 1.08rem; color: var(--ink); }
.logo { display: grid; place-items: center; width: 2rem; height: 2rem; border-radius: 9px; background: var(--accent); color: var(--accent-ink); }
.logo.big { width: 3rem; height: 3rem; border-radius: 13px; margin: 0 auto .8rem; }
.logo.big .i { width: 1.6rem; height: 1.6rem; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a, .side-foot a, .side-foot .linklike { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 9px; color: var(--ink-2); font-size: .95rem; }
.side nav a:hover, .side-foot a:hover, .side-foot .linklike:hover { background: var(--surface); color: var(--ink); }
.side nav a.on, .side-foot a.on { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }
.side nav a.on .i { color: var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: .8rem; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; width: 100%; text-align: left; }
.search { position: relative; }
.search .i { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 2.2rem; background: var(--surface); }
.navtoggle { display: none; }
.main { padding: var(--pad) clamp(16px, 3.2vw, 48px) 4rem; max-width: 1280px; width: 100%; display: flex; flex-direction: column; gap: var(--gap); }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: sticky; z-index: 10; height: auto; padding: .8rem 1rem; gap: 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .side nav, .side .search, .side-foot { display: none; }
  body.nav-open .side nav, body.nav-open .side .search, body.nav-open .side-foot { display: flex; margin-top: .8rem; }
  body.nav-open .side .search { display: block; }
  .navtoggle { display: grid; gap: 5px; place-content: center; width: 2.4rem; height: 2.4rem; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); cursor: pointer; }
  .navtoggle span { display: block; width: 16px; height: 1.6px; background: var(--ink); border-radius: 2px; }
}

/* ---------- Header ---------- */
.ph { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; padding-top: .3rem; }
.eyebrow { margin: 0 0 .35rem; color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: .5em; }
.actions, .quick { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form, .quick form { margin: 0; }
.crumb { margin: 0 0 -.6rem; font-size: .9rem; color: var(--muted); }

/* ---------- Boutons & formulaires ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; padding: .6rem 1.05rem; border-radius: 10px; border: 1px solid transparent; font-family: inherit; font-weight: 500; font-size: .93rem; line-height: 1.2; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.btn.ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn.ghost:hover { border-color: var(--ink-2); color: var(--ink); }
.btn.danger { background: transparent; border-color: var(--line); color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad); }
.btn.sm { padding: .4rem .75rem; font-size: .85rem; }
.btn.wide { width: 100%; padding: .8rem; }

input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .75rem; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 6rem; }
.field { display: flex; flex-direction: column; gap: .35rem; min-width: 0; }
.field label { font-size: .85rem; font-weight: 500; color: var(--ink-2); }
.field label em { color: var(--bad); font-style: normal; }
.field small { color: var(--muted); font-size: .78rem; }
.field.full { grid-column: 1 / -1; }
.check { display: flex !important; align-items: center; gap: .5rem; padding: .6rem 0; cursor: pointer; font-size: .95rem !important; color: var(--ink) !important; }
.check input { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); }
.suffix { position: relative; }
.suffix input { padding-right: 2rem; text-align: right; font-variant-numeric: tabular-nums; }
.suffix span { position: absolute; right: .8rem; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.form .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr)); gap: 1rem 1.2rem; }
.formbar { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.stack { display: flex; flex-direction: column; gap: .9rem; align-items: flex-start; }
.stack .field { width: 100%; }
.drop { position: relative; display: flex; align-items: center; justify-content: center; text-align: center; min-height: 4.2rem; padding: 1rem; border: 1.5px dashed var(--line); border-radius: 12px; color: var(--muted); font-size: .9rem; cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop u { color: var(--accent); }
form.inline { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); gap: .6rem; margin-top: 1rem; }

/* ---------- Cartes ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--pad); box-shadow: var(--shadow); min-width: 0; }
.card > h2 { margin-bottom: 1rem; }
.cardhead { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr)); gap: var(--gap); align-items: start; }
.flash { padding: .75rem 1rem; border-radius: 10px; background: var(--ok-bg); color: var(--ok); font-weight: 500; }
.flash.bad { background: var(--bad-bg); color: var(--bad); }
.empty { color: var(--muted); margin: 0; }
.emptystate { text-align: center; padding: 3rem 1rem; border: 1.5px dashed var(--line); border-radius: var(--radius); color: var(--ink-2); }
.emptystate p { max-width: 34rem; margin: 0 auto 1.2rem; }
.onboard { background: var(--accent-soft); border-radius: var(--radius); padding: var(--pad); }
.onboard ol { margin: .8rem 0 0; padding-left: 1.2rem; display: grid; gap: .5rem; }
.onboard a { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr)); gap: var(--gap); }
.kpi { display: flex; flex-direction: column; gap: .25rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); transition: border-color .15s; }
a.kpi:hover { border-color: var(--accent); color: inherit; }
.kpi span { font-size: .82rem; color: var(--muted); font-weight: 500; }
.kpi strong { font-size: clamp(1.4rem, 1.1rem + 1vw, 1.9rem); font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi em { font-style: normal; font-size: .82rem; color: var(--ink-2); }
.kpi.alert strong { color: var(--warn); }

/* ---------- Tags ---------- */
.tag { display: inline-block; padding: .14em .6em; border-radius: 99px; font-size: .78rem; font-weight: 550; white-space: nowrap; background: var(--mute-bg); color: var(--ink-2); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.info { background: var(--info-bg); color: var(--info); }
.stars { color: #D49B2B; letter-spacing: .05em; }
.stars .dim { color: var(--line); }

/* ---------- Tables ---------- */
.toolbar { display: flex; gap: .6rem; }
.toolbar .filter { max-width: 26rem; }
.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .tablewrap { border: 0; box-shadow: none; border-radius: 0; margin: 0 calc(var(--pad) * -1); }
table { width: 100%; border-collapse: collapse; font-size: .93rem; }
th { text-align: left; font-size: .76rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: .75rem .9rem; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; background: var(--surface); }
th.nosort { cursor: default; }
th[data-dir="asc"]::after { content: " ↑"; } th[data-dir="desc"]::after { content: " ↓"; }
td { padding: .7rem .9rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.card .tablewrap th:first-child, .card .tablewrap td:first-child { padding-left: var(--pad); }
.card .tablewrap th:last-child, .card .tablewrap td:last-child { padding-right: var(--pad); }
tbody tr:last-child td { border-bottom: 0; }
tr[data-href] { cursor: pointer; }
tr[data-href]:hover td { background: var(--surface-2); }
tr.faded td { opacity: .55; }
.rowlink { font-weight: 600; }
td.pj { color: var(--muted); font-size: .82rem; white-space: nowrap; width: 1%; }
td.pj .i { width: .95em; height: .95em; vertical-align: -2px; margin-right: 2px; }
tfoot td { font-weight: 650; border-top: 1px solid var(--line); border-bottom: 0; background: var(--surface-2); }
table.mini { font-size: .9rem; }
table.mini th, table.mini td { padding: .55rem .4rem; }
table.mini th:first-child, table.mini td:first-child { padding-left: 0; }
table.mini th:last-child, table.mini td:last-child { padding-right: 0; }

@media (max-width: 640px) {
  .tablewrap table.sortable thead { display: none; }
  .tablewrap table.sortable tr { display: grid; grid-template-columns: 1fr auto; gap: .15rem .8rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
  .tablewrap table.sortable td { display: block; padding: 0 !important; border: 0; text-align: left; font-size: .88rem; color: var(--ink-2); }
  .tablewrap table.sortable td:first-child { grid-column: 1 / -1; font-size: 1rem; color: var(--ink); }
  .tablewrap table.sortable td.num { text-align: right; }
  .tablewrap table.sortable tfoot tr { background: var(--surface-2); }
  .card .tablewrap { margin: 0 calc(var(--pad) * -1); }
}

/* ---------- Fiche ---------- */
.dl { margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 12rem), 1fr)); gap: 1.1rem 1.4rem; }
.dl div { min-width: 0; }
.dl dt { font-size: .78rem; color: var(--muted); margin-bottom: .2rem; }
.dl dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.dl .hl { grid-column: 1 / -1; background: var(--accent-soft); border-radius: 10px; padding: .7rem .9rem; }
.copy { border: 0; background: none; padding: .2rem; color: var(--muted); cursor: pointer; border-radius: 6px; display: inline-grid; }
.copy:hover { background: var(--surface-2); color: var(--accent); }
.copy.done { color: var(--ok); }
.notes { margin-top: 1.4rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
.notes p { margin: 0; color: var(--ink-2); }
.files { list-style: none; margin: 0 0 1rem; padding: 0; display: grid; gap: .4rem; }
.files li { display: flex; align-items: center; gap: .5rem; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; }
.files a { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.files strong { font-weight: 550; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.files span { font-size: .78rem; color: var(--muted); }
.files form, td form { margin: 0; }
.x { border: 0; background: none; color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer; padding: .1rem .4rem; border-radius: 6px; }
.x:hover { color: var(--bad); background: var(--bad-bg); }

/* ---------- Graphiques ---------- */
.chart { width: 100%; height: auto; display: block; margin: .6rem 0 1rem; overflow: visible; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; }
.chart .area { fill: var(--accent-soft); opacity: .7; }
.chart .base { stroke: var(--line); }
.chart circle { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }
.chart text { font-size: 11px; fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.chart text.d { fill: var(--muted); }
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: .7rem; }
.bars li { display: grid; grid-template-columns: minmax(6rem, 9rem) 1fr auto 2.6rem; align-items: center; gap: .7rem; font-size: .9rem; }
.bars li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.bars div { height: .55rem; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bars i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bars b { font-weight: 600; font-variant-numeric: tabular-nums; }
.bars small { color: var(--muted); text-align: right; }
.months { display: grid; grid-template-columns: repeat(12, 1fr); gap: clamp(3px, .6vw, 8px); height: 10rem; align-items: end; }
.months div { height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .35rem; }
.months i { display: block; width: 100%; min-height: 2px; background: var(--accent); border-radius: 5px 5px 2px 2px; opacity: .85; }
.months div:hover i { opacity: 1; }
.months span { font-size: .7rem; color: var(--muted); }

/* ---------- Alertes ---------- */
.alerts { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.alerts a { display: grid; grid-template-columns: 6.2rem 1fr; gap: .9rem; align-items: center; padding: .6rem .8rem; border-radius: 10px; background: var(--surface-2); border-left: 3px solid var(--line); }
.alerts li.soon a { border-left-color: var(--warn); }
.alerts li.late a { border-left-color: var(--bad); }
.alerts a:hover { background: var(--accent-soft); color: inherit; }
.alerts time { font-weight: 600; font-size: .88rem; font-variant-numeric: tabular-nums; display: flex; flex-direction: column; }
.alerts time small { font-weight: 400; color: var(--muted); font-size: .76rem; }
.alerts span { font-size: .9rem; min-width: 0; }
.alerts b { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }

/* ---------- Projets ---------- */
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr)); gap: .8rem; }
.proj { display: flex; flex-direction: column; gap: .7rem; padding: 1rem; border: 1px solid var(--line); border-radius: 12px; transition: border-color .15s; }
.proj:hover { border-color: var(--accent); color: inherit; }
.ptop { display: flex; justify-content: space-between; gap: .6rem; align-items: flex-start; }
.meter { position: relative; height: .6rem; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.meter i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; }
.meter .eng { background: var(--accent-soft); outline: 1px solid var(--accent); outline-offset: -1px; }
.meter .paid { background: var(--accent); }
.meter u { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); margin-left: -1px; }
.pmeta { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .8rem; color: var(--ink-2); }
.pmeta .warn { color: var(--warn); font-weight: 600; }
.kpis.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); }
.links a { color: var(--accent); margin-right: .6rem; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.authcard { width: min(100%, 23rem); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 2rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 1rem; text-align: center; }
.authcard .field { text-align: left; }
.authcard h1 { font-size: 1.4rem; margin-bottom: .2rem; }
.authcard p { margin: 0; font-size: .9rem; }
.err { color: var(--bad); font-weight: 500; }

/* ---------- Coffre / espace client ---------- */
.pwfield { position: relative; }
.pwfield input { padding-right: 2.6rem; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.pwfield .eye { position: absolute; right: .35rem; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); padding: .35rem; border-radius: 6px; cursor: pointer; display: grid; }
.pwfield .eye:hover { color: var(--accent); background: var(--surface-2); }
.check.small { padding: .2rem 0 0; font-size: .82rem !important; color: var(--ink-2) !important; }
.check.small input { width: .95rem; height: .95rem; }
.secret { letter-spacing: .08em; }
.secret.shown { letter-spacing: .01em; background: var(--warn-bg); padding: .05em .4em; border-radius: 5px; }
.portal { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; display: flex; flex-direction: column; gap: .8rem; background: var(--surface-2); }
.portal-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap; }
.portal-head dt { display: flex; align-items: center; gap: .45rem; font-size: .9rem !important; font-weight: 600; color: var(--ink) !important; margin: 0 !important; }
.portal-head dt .i { color: var(--accent); }
.portal-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 11rem), 1fr)); gap: .8rem 1.4rem; }
.portal dd { flex-wrap: nowrap; } .portal dd .secret { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
