:root {
  --bg: #f4efe6; --surface: #fffdf8; --surface-2: #f8f3ea; --ink: #1d2523; --muted: #6b716c;
  --line: #e4dccd; --accent: #1f3a34; --accent-ink: #f4efe6; --warm: #d9822b; --warm-soft: #f6e3cd;
  --ok: #2f7d55; --ok-soft: #dcefe3; --bad: #b8432f; --bad-soft: #f7dcd5; --info: #2f5f8a; --info-soft: #dbe7f2;
  --radius: 12px; --shadow: 0 1px 2px rgba(29,37,35,.06), 0 4px 16px rgba(29,37,35,.05);
  --serif: "Fraunces", Georgia, serif; --sans: "Inter", system-ui, -apple-system, Segoe UI, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141917; --surface: #1c2220; --surface-2: #222a27; --ink: #ebe6dc; --muted: #9aa29c;
    --line: #2f3834; --accent: #8fc1b2; --accent-ink: #10201b; --warm: #e59a4b; --warm-soft: #3a2a19;
    --ok: #6cc196; --ok-soft: #1c3227; --bad: #e57e69; --bad-soft: #3a211b; --info: #8ab4dc; --info-soft: #1d2b38;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 var(--sans); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
h1, h2, h3 { font-family: var(--serif); font-weight: 650; letter-spacing: -.01em; margin: 0; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
a { color: var(--accent); }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.error { color: var(--bad); min-height: 1.2em; margin: .4rem 0 0; font-size: .9rem; }

/* Boutons et champs */
.btn { font: 500 .92rem var(--sans); border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: .5rem .9rem; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: .3rem .6rem; font-size: .82rem; }
.btn.wide { width: 100%; padding: .7rem; }
.icon-btn { background: none; border: 0; font-size: 1.1rem; cursor: pointer; color: var(--muted); padding: .25rem .4rem; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
label { display: grid; gap: .3rem; font-size: .85rem; font-weight: 500; color: var(--muted); }
input[type=checkbox] { width: 1.15rem; height: 1.15rem; accent-color: var(--accent); cursor: pointer; }

/* Connexion */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: radial-gradient(circle at 20% 10%, var(--warm-soft), transparent 45%), var(--bg); }
.login-card { width: min(380px, 100%); background: var(--surface); padding: 2rem; border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--line); display: grid; gap: 1rem; }
.login-card p { margin: 0; }
.brand { display: flex; align-items: center; gap: .6rem; font-family: var(--serif); font-weight: 650; font-size: 1.3rem; }
.brand.big { font-size: 1.8rem; }

/* Mise en page */
.app { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 1.5rem; padding: 1.4rem 1rem; border-right: 1px solid var(--line); background: var(--surface-2); }
.sidebar nav { display: grid; gap: .15rem; }
.nav-item { display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 9px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav-item:hover { background: var(--surface); }
.nav-item.active { background: var(--accent); color: var(--accent-ink); }
.nav-item .ico { width: 1.2rem; text-align: center; }
.nav-item .count { margin-left: auto; font-size: .75rem; background: var(--warm); color: #fff; border-radius: 99px; padding: 0 .45rem; }
.sidebar-foot { margin-top: auto; display: grid; gap: .4rem; }
main { min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.2rem 2rem; position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); z-index: 5; border-bottom: 1px solid var(--line); }
.topbar-actions { display: flex; gap: .6rem; }
.topbar-actions select { width: auto; min-width: 170px; }
.view { padding: 1.5rem 2rem 6rem; max-width: 1400px; }
.bottom-nav { display: none; }

/* Cartes */
.grid { display: grid; gap: 1rem; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.cards { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.card h2, .card h3 { margin-bottom: .7rem; }
.card.click { cursor: pointer; transition: transform .12s, border-color .12s; }
.card.click:hover { border-color: var(--accent); transform: translateY(-1px); }
.kpi .label { color: var(--muted); font-size: .82rem; font-weight: 500; }
.kpi .value { font-family: var(--serif); font-size: 2rem; font-weight: 650; line-height: 1.1; margin-top: .2rem; }
.kpi.alert .value { color: var(--bad); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 1.6rem 0 .8rem; flex-wrap: wrap; }
.section-head:first-child { margin-top: 0; }
.empty { color: var(--muted); padding: 1.4rem; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* Listes */
.rows { display: grid; }
.row { display: flex; align-items: center; gap: .8rem; padding: .65rem .2rem; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 500; overflow-wrap: anywhere; }
.row .meta { color: var(--muted); font-size: .83rem; display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .1rem; }
.row.done .title { text-decoration: line-through; color: var(--muted); }
.row.clickable { cursor: pointer; } .row.clickable:hover { background: var(--surface-2); }

.pill { display: inline-flex; align-items: center; gap: .3rem; font-size: .75rem; font-weight: 600; padding: .12rem .55rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.warm { background: var(--warm-soft); color: var(--warm); border-color: transparent; }
.pill.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.dot { width: .6rem; height: .6rem; border-radius: 50%; display: inline-block; flex: none; }
.late { color: var(--bad); font-weight: 600; }

/* Filtres */
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search] { max-width: 280px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 2px; }
.seg button { border: 0; background: transparent; font: 500 .85rem var(--sans); color: var(--muted); padding: .35rem .75rem; border-radius: 7px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* Kanban travaux */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 1rem; overflow-x: auto; padding-bottom: .5rem; }
.kcol { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; min-height: 120px; }
.kcol.drop { outline: 2px dashed var(--accent); }
.kcol h3 { font-family: var(--sans); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); display: flex; justify-content: space-between; margin-bottom: .7rem; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .75rem .85rem; margin-bottom: .6rem; cursor: pointer; border-left: 4px solid var(--hc, var(--line)); }
.kcard:hover { border-color: var(--accent); border-left-color: var(--hc, var(--accent)); }
.kcard .t { font-weight: 600; margin-bottom: .35rem; }
.kcard .m { display: flex; flex-wrap: wrap; gap: .35rem; font-size: .8rem; color: var(--muted); }
.progress { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: .5rem; }
.progress > span { display: block; height: 100%; background: var(--ok); }

/* Tableaux */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: .7rem .8rem; border-bottom: 1px solid var(--line); background: var(--surface-2); }
td { padding: .65rem .8rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; } tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.group td { background: var(--surface-2); font-weight: 600; cursor: default; font-family: var(--serif); }
tr.best td:first-child { box-shadow: inset 3px 0 0 var(--ok); }

/* Calendrier */
.cal-head { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; }
.cal-head h2 { min-width: 190px; text-transform: capitalize; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; }
.cal .dow { background: var(--surface-2); padding: .45rem; font-size: .75rem; font-weight: 600; color: var(--muted); text-transform: uppercase; text-align: center; }
.cal .day { background: var(--surface); min-height: 112px; padding: .35rem; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.cal .day:hover { background: var(--surface-2); }
.cal .day.other { background: var(--surface-2); opacity: .55; }
.cal .day .n { font-size: .8rem; font-weight: 600; color: var(--muted); align-self: flex-end; width: 1.6rem; height: 1.6rem; display: grid; place-items: center; border-radius: 50%; }
.cal .day.today .n { background: var(--warm); color: #fff; }
.chip { font-size: .74rem; padding: .12rem .4rem; border-radius: 5px; background: var(--info-soft); color: var(--info); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-left: 3px solid var(--hc, var(--info)); }
.chip.task { background: var(--warm-soft); color: var(--warm); }
.chip.task.done { opacity: .5; text-decoration: line-through; }
.chip.quote { background: var(--bad-soft); color: var(--bad); }
.legend { display: flex; gap: 1rem; margin-top: .8rem; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; gap: .35rem; align-items: center; }

/* Contacts */
.contact .head { display: flex; gap: .8rem; align-items: center; margin-bottom: .6rem; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; background: var(--warm-soft); color: var(--warm); flex: none; }
.contact .lines { display: grid; gap: .25rem; font-size: .88rem; }
.contact .lines a { text-decoration: none; }

/* Détail projet */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; font-size: .9rem; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.back { margin-bottom: 1rem; }
.money { font-variant-numeric: tabular-nums; }
.bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--line); margin: .5rem 0; }
.bar span { background: var(--accent); }

/* Modale */
dialog { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--ink); width: min(620px, calc(100vw - 2rem)); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20,25,23,.45); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 1.1rem 1.3rem .4rem; }
.modal-body { padding: .6rem 1.3rem; display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; max-height: 68vh; overflow-y: auto; }
.modal-body .full { grid-column: 1 / -1; }
.modal .error { padding: 0 1.3rem; }
.modal footer { display: flex; gap: .5rem; justify-content: flex-end; padding: .8rem 1.3rem 1.2rem; }
.modal footer .left { margin-right: auto; }
.filebox { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; padding: .6rem; border: 1px dashed var(--line); border-radius: 8px; }

.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%) translateY(150%); background: var(--ink); color: var(--bg); padding: .65rem 1.1rem; border-radius: 10px; transition: transform .25s, opacity .25s; z-index: 50; font-size: .9rem; opacity: 0; pointer-events: none; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
@media (max-width: 860px) { .toast { bottom: 5rem; } }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: .9rem 1rem; flex-wrap: wrap; }
  .topbar h1 { font-size: 1.3rem; }
  .topbar-actions { width: 100%; }
  .topbar-actions select { flex: 1; min-width: 0; }
  .view { padding: 1rem 1rem 6.5rem; }
  .detail-grid { grid-template-columns: 1fr; }
  .modal-body { grid-template-columns: 1fr; }
  .cal .day { min-height: 64px; }
  .cal .chip { font-size: 0; padding: 0; height: 6px; border-left: 0; }
  .bottom-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line); padding: .3rem .2rem calc(.3rem + env(safe-area-inset-bottom)); z-index: 10; justify-content: space-around; }
  .bottom-nav .nav-item { flex-direction: column; gap: .1rem; font-size: .66rem; padding: .35rem .2rem; flex: 1; }
  .bottom-nav .nav-item .ico { font-size: 1.15rem; }
  .bottom-nav .nav-item .count { display: none; }
  .kanban { grid-auto-columns: 82%; }
}
