:root,
html[data-theme="dark"] {
  --bg: #07111c;
  --card: #102033;
  --ink: #e8f0f8;
  --muted: #93a6bd;
  --line: rgba(168, 206, 214, 0.14);
  --nav: #d5e4ef;
  --side: #0b1830;
  --teal: #00b0a0;
  --teal-deep: #7eefe4;
  --teal-soft: rgba(0, 176, 160, 0.16);
  --navy: #d6e4f5;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
  --input: #0c1a2e;
  --danger: #fca5a5;
  --warn: #fdba74;
  --info: #93c5fd;
}

html[data-theme="light"] {
  --bg: #f3f7f6;
  --card: #ffffff;
  --ink: #122033;
  --muted: #5c6e82;
  --line: rgba(12, 35, 72, 0.1);
  --nav: #1c3358;
  --side: #ffffff;
  --teal: #009e90;
  --teal-deep: #0b6e64;
  --teal-soft: rgba(0, 176, 160, 0.12);
  --navy: #0c2348;
  --shadow: 0 12px 30px rgba(16, 36, 72, 0.06);
  --input: #ffffff;
  --danger: #b91c1c;
  --warn: #b45309;
  --info: #1d4ed8;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  font-family: Outfit, system-ui, sans-serif;
  background:
    radial-gradient(900px 380px at 100% -10%, rgba(0, 176, 160, 0.16), transparent 55%),
    radial-gradient(680px 320px at -8% 100%, rgba(12, 35, 72, 0.08), transparent 50%),
    var(--bg);
  color: var(--ink);
}
a { color: var(--teal-deep); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }

.app {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}
.side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 1rem 0.85rem 1rem;
  background: var(--side);
  border-right: 1px solid var(--line);
  z-index: 40;
}
.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.25rem 0.45rem 0.7rem;
  text-decoration: none;
}
.brand-logo { height: 74px; width: auto; display: block; }
html[data-theme="light"] .brand-logo--dark { display: none !important; }
html[data-theme="dark"] .brand-logo--light,
html:not([data-theme]) .brand-logo--light { display: none !important; }
.brand-kicker, .kicker {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--teal);
  font-weight: 700;
}
.nav { display: flex; flex-direction: column; gap: 0.2rem; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.62rem 0.75rem;
  border-radius: 12px;
  color: var(--nav);
  text-decoration: none;
  font-weight: 600;
}
.nav-link .ico { width: 1.15rem; height: 1.15rem; flex: 0 0 auto; }
.nav-link:hover { background: var(--teal-soft); }
.nav-link.is-active { background: var(--teal-soft); color: var(--teal-deep); }
.badge {
  margin-left: auto;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--teal);
  color: #fff;
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 700;
}
.side-card {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  padding: 0.85rem 0.9rem;
  border-radius: 16px;
  text-decoration: none;
  color: var(--ink);
  background: var(--teal-soft);
  border: 1px solid transparent;
}
.side-card span { color: var(--teal-deep); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.side-card strong { font-size: 0.95rem; }
.side-card em { font-style: normal; color: var(--muted); font-size: 0.82rem; }
.side-card.is-active { border-color: var(--teal); }

.main { min-width: 0; }
.bar {
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  padding: 1.15rem 1.4rem 0.35rem;
}
.bar-titles { min-width: 0; flex: 1; }
.bar-titles h1 {
  margin: 0.1rem 0 0;
  font-family: Syne, Outfit, sans-serif;
  font-size: clamp(1.45rem, 2vw, 1.9rem);
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.sub, .lead { color: var(--muted); }
.sub { margin: 0.25rem 0 0; }
.menu-btn { display: none; }
.icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn .ico { width: 1.15rem; height: 1.15rem; }

.content {
  padding: 0.8rem 1.4rem 2.4rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.flash {
  margin: 0.6rem 1.4rem 0;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: var(--teal-soft);
  color: var(--teal-deep);
  font-weight: 600;
}
.flash--err { background: rgba(185, 28, 28, 0.12); color: var(--danger); }

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1.2rem;
  padding: 1.45rem 1.5rem;
  border-radius: 22px;
  color: #f4fffd;
  background:
    radial-gradient(420px 180px at 100% 0%, rgba(255, 255, 255, 0.2), transparent 60%),
    linear-gradient(128deg, #0c2348 0%, #0e4d62 46%, #00b0a0 100%);
  box-shadow: 0 16px 40px rgba(12, 35, 72, 0.22);
}
.hero-kicker { margin: 0; letter-spacing: 0.14em; text-transform: uppercase; font-size: 0.75rem; font-weight: 700; opacity: 0.85; }
.hero-sum {
  margin: 0.15rem 0;
  font-family: Syne, Outfit, sans-serif;
  font-weight: 800;
  letter-spacing: -0.04em;
  font-size: clamp(2.1rem, 4vw, 3.3rem);
  line-height: 1;
}
.hero-meta, .hero-next { margin: 0.25rem 0 0; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 0.55rem; justify-content: flex-end; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  border-radius: 999px;
  padding: 0.68rem 1.05rem;
  background: var(--teal);
  color: #fff;
  font-weight: 700;
}
.btn:hover { filter: brightness(1.06); }
.btn--ghost {
  background: transparent;
  color: var(--teal-deep);
  border: 1px solid var(--line);
}
.btn--light { background: #fff; color: #0c2348; }
.btn--ghost-light { background: transparent; color: #fff; border: 1px solid rgba(255, 255, 255, 0.45); }
.btn--block { width: 100%; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
}
.stat, .panel, .card, .sheet, .paper {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.stat {
  padding: 0.9rem 1rem;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.stat span { color: var(--muted); font-size: 0.86rem; }
.stat strong {
  font-family: Syne, Outfit, sans-serif;
  font-size: 1.7rem;
  color: var(--navy);
}
html[data-theme="dark"] .stat strong { color: var(--teal-deep); }
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 0.9rem; }
.panel { padding: 0.95rem 1rem 0.4rem; }
.panel h2, .sheet h2, .paper h2 { margin: 0; font-size: 1.05rem; }
.panel-head, .card-top, .sheet-head, .toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}
.panel-head { margin-bottom: 0.35rem; }
.panel-head a { font-weight: 700; text-decoration: none; }
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.75rem 0;
  border-top: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
}
.row-main { display: flex; flex-direction: column; gap: 0.12rem; min-width: 0; }
.row-main span, .card .lead { color: var(--muted); }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 0.3rem; flex: 0 0 auto; }
.row-side b { font-variant-numeric: tabular-nums; }

.chantier-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; padding-bottom: 0.8rem; }
.chantier-grid--page { padding: 0; }
.chantier-card { display: block; text-decoration: none; color: inherit; }
.chantier-card p { margin: 0.35rem 0 0; color: var(--muted); }
.chantier-top { display: flex; justify-content: space-between; gap: 0.6rem; align-items: baseline; }
.chantier-top span, .pct {
  font-family: Syne, Outfit, sans-serif;
  color: var(--teal-deep);
  font-weight: 800;
}
.pct { margin: 0; font-size: 1.6rem; }
.bar { height: 8px; border-radius: 999px; background: var(--teal-soft); overflow: hidden; margin-top: 0.55rem; }
.bar span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #0c2348, #00b0a0); }
.bar--lg { height: 12px; margin: 0.8rem 0; }
.next { color: var(--ink) !important; font-weight: 600; }

.toolbar { margin-bottom: 0.2rem; }
.toolbar-sum { margin: 0; color: var(--muted); }
.toolbar-sum strong { color: var(--navy); font-size: 1.05rem; }
html[data-theme="dark"] .toolbar-sum strong { color: var(--teal-deep); }
.filters { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.chip {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-weight: 600;
}
.chip.is-on { background: #0c2348; color: #fff; border-color: #0c2348; }
html[data-theme="dark"] .chip.is-on { background: var(--teal); color: #06221e; border-color: var(--teal); }

.cards { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.card, .sheet, .paper { padding: 1rem 1.05rem 1.05rem; }
.card-id { margin: 0 0 0.15rem; color: var(--teal-deep); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em; }
.card h2, .sheet h2 { font-size: 1.12rem; letter-spacing: -0.02em; }
.card-link { text-decoration: none; color: inherit; display: block; }
.meta, .totals, .identity, .rib {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.7rem;
  margin: 0.85rem 0 0;
}
.meta div, .totals div, .identity div, .rib div { min-width: 0; }
.meta dt, .totals dt, .identity dt, .rib dt { color: var(--muted); font-size: 0.75rem; }
.meta dd, .totals dd, .identity dd, .rib dd { margin: 0.12rem 0 0; font-weight: 700; }
.identity, .rib { grid-template-columns: 1fr 1fr; }
.card-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.9rem; }
.totals { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.totals-due dd { color: var(--teal-deep); font-size: 1.15rem; }
.due-date { color: var(--muted); }
.lines { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.lines th, .lines td { text-align: left; padding: 0.55rem 0.3rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines th { color: var(--muted); font-size: 0.78rem; font-weight: 600; }
.lines td:nth-child(n+2), .lines th:nth-child(n+2) { text-align: right; white-space: nowrap; }
.backline { margin: 0; }
.backline a { display: inline-flex; align-items: center; gap: 0.2rem; font-weight: 700; text-decoration: none; }
.backline .ico { width: 1rem; height: 1rem; }
.empty { color: var(--muted); padding: 0.4rem 0 0.8rem; }
.hint { color: var(--muted); font-size: 0.86rem; }

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--teal-soft);
  color: var(--teal-deep);
  white-space: nowrap;
}
.pill--retard { background: rgba(185, 28, 28, 0.12); color: var(--danger); }
.pill--a_payer, .pill--attente { background: rgba(180, 83, 9, 0.14); color: var(--warn); }
.pill--partielle, .pill--cours { background: rgba(29, 78, 216, 0.12); color: var(--info); }
.pill--haute { background: rgba(185, 28, 28, 0.12); color: var(--danger); }

.thread { list-style: none; margin: 1rem 0; padding: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.bubble { max-width: min(100%, 40rem); padding: 0.8rem 0.95rem; }
.bubble p { margin: 0; }
.bubble--support {
  margin-right: auto;
  background: #0c2348;
  color: #f4fbff;
  border-radius: 18px 18px 18px 6px;
}
.bubble--client {
  margin-left: auto;
  background: #00a99a;
  color: #fff;
  border-radius: 18px 18px 6px 18px;
}
.bubble-who { opacity: 0.78; font-size: 0.78rem; margin-bottom: 0.28rem !important; }
.reply, .form { display: flex; flex-direction: column; align-items: flex-start; gap: 0.4rem; }
.reply textarea, .form textarea, .form input, .form select, .gate input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--input);
  padding: 0.7rem 0.8rem;
}
.form { gap: 0.35rem; }
.form label, .reply label { font-weight: 600; margin-top: 0.35rem; }
.phases { list-style: none; display: flex; flex-wrap: wrap; gap: 0.45rem; padding: 0; margin: 1rem 0; }
.phases li {
  padding: 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px dashed var(--line);
  color: var(--muted);
}
.phases .is-done { border-style: solid; color: var(--teal-deep); background: var(--teal-soft); }
.phases .is-now { background: #0c2348; color: #fff; border-style: solid; }
html[data-theme="dark"] .phases .is-now { background: var(--teal); color: #06221e; }
.journal { list-style: none; margin: 0; padding: 0; }
.journal li { display: grid; grid-template-columns: 7.5rem 1fr; gap: 0.8rem; padding: 0.7rem 0; border-top: 1px solid var(--line); }
.journal time { color: var(--teal-deep); font-weight: 700; }
.journal p { margin: 0; }

.table-wrap { overflow-x: auto; margin-top: 0.35rem; }
.log-table { min-width: 42rem; }
.log-table th:nth-child(n+2),
.log-table td:nth-child(n+2) { text-align: left; }
.log-table td { white-space: normal; }
.log-table td strong { display: block; }
.log-rel {
  display: block;
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}
.log-ip {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--navy);
}
html[data-theme="dark"] .log-ip { color: var(--teal-deep); }
.sheet h3, .notif h3 { margin: 1rem 0 0.4rem; }
.person { margin: 0.4rem 0 0; font-family: Syne, Outfit, sans-serif; font-size: 1.35rem; }
.check { display: flex; gap: 0.55rem; align-items: flex-start; margin: 0.35rem 0; }
.paper p { line-height: 1.5; }

.dock, .scrim { display: none; }
.modal { border: 0; padding: 0; background: transparent; }
.modal::backdrop { background: rgba(6, 16, 32, 0.55); }
.modal-card {
  width: min(32rem, calc(100vw - 1.5rem));
  background: var(--card);
  color: var(--ink);
  border-radius: 20px;
  padding: 1rem 1rem 1.1rem;
  border: 1px solid var(--line);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-ref { color: var(--muted); margin: 0.4rem 0 0; }
.modal-amount {
  margin: 0.2rem 0 0.8rem;
  font-family: Syne, Outfit, sans-serif;
  font-size: 1.8rem;
  color: var(--teal-deep);
}
.pay-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.mode span {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.65rem 0.7rem;
  font-weight: 700;
}
.mode input { accent-color: var(--teal); }
.mode .ico { width: 1.1rem; height: 1.1rem; }
.pay-panel { margin-top: 0.8rem; display: flex; flex-direction: column; gap: 0.45rem; }
.pay-panel label, .gate label { display: flex; flex-direction: column; gap: 0.25rem; font-weight: 600; font-size: 0.9rem; }
.pay-panel input {
  border: 1px solid var(--line);
  background: var(--input);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
}
.split-fields, .pay-panel .split { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.9rem; }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.gate-card {
  width: min(26rem, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 1.4rem 1.3rem 1.3rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.gate-logo .brand-logo { height: 88px; }
.gate h1 { margin: 0.2rem 0 0; font-family: Syne, Outfit, sans-serif; }
.gate .lead { margin-top: 0; }

.delta-who__avatar {
  background: radial-gradient(circle at 35% 30%, #14b8a6, #0c2348 72%) !important;
  border-color: rgba(0, 176, 160, 0.75) !important;
  color: #fff !important;
}
.delta-who__role {
  background: rgba(0, 176, 160, 0.16) !important;
  color: #0f766e !important;
}
html[data-theme="dark"] .delta-who__role { color: #7eefe4 !important; }
.delta-who__out {
  color: #0f766e !important;
  border-color: rgba(0, 158, 144, 0.45) !important;
}
html[data-theme="dark"] .delta-who__out {
  color: #7eefe4 !important;
  border-color: rgba(0, 176, 160, 0.45) !important;
  background: rgba(8, 22, 40, 0.8) !important;
}

@media (max-width: 980px) {
  .stats, .meta, .totals { grid-template-columns: 1fr 1fr; }
  .totals { grid-template-columns: 1fr 1fr; }
  .split, .chantier-grid { grid-template-columns: 1fr; }
  .hero { flex-direction: column; align-items: flex-start; }
  .hero-actions { justify-content: flex-start; }
}
@media (max-width: 860px) {
  .app { display: block; }
  .side {
    position: fixed;
    width: min(86vw, 320px);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  body.nav-open .side { transform: none; }
  .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    border: 0;
    background: rgba(6, 16, 32, 0.48);
  }
  .menu-btn { display: grid; }
  .content { padding-bottom: 6.2rem; }
  .dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: var(--card);
    border-top: 1px solid var(--line);
    padding: 0.35rem 0.2rem calc(0.35rem + env(safe-area-inset-bottom));
  }
  .dock a, .dock button {
    border: 0;
    background: transparent;
    color: var(--muted);
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.12rem;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 0.25rem 0;
  }
  .dock .ico { width: 1.15rem; height: 1.15rem; }
  .dock .is-active { color: var(--teal-deep); }
  .journal li { grid-template-columns: 1fr; gap: 0.15rem; }
  .bar { padding-right: 3.4rem; }
}
@media (max-width: 520px) {
  .pay-panel .split { grid-template-columns: 1fr; }
  .modal-card { max-height: calc(100vh - 1.5rem); overflow: auto; }
  .meta { grid-template-columns: 1fr 1fr; }
}
  .side, .bar, .dock, .flash, .card-actions, .reply, .backline, .scrim,
  .delta-back, .delta-theme-toggle, .delta-who { display: none !important; }
  .app { display: block; }
  body { background: #fff; color: #122033; }
  .sheet, .paper, .card { box-shadow: none; }
}
