/* Patrimoine Heiwa — clair, épuré. Barre blanche, accent laiton discret. */
:root {
  color-scheme: light;
  --surface: #f6f7f9;
  --surface-2: #ffffff;
  --border: #e6e8ec;
  --border-strong: #d4d8de;
  --text: #1a2230;
  --text-2: #566072;
  --text-3: #949aa6;
  --brand: #1f6feb;        /* bleu clair, sobre */
  --brand-soft: #eaf1fe;
  --accent: #1f6feb;
  --good: #1a7f37;
  --good-soft: #e8f4ec;
  --warn: #9a6700;
  --warn-soft: #fbf1d8;
  --bad: #c1341f;
  --bad-soft: #fbe9e6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(26, 34, 48, .05), 0 1px 3px rgba(26, 34, 48, .04);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--surface); color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
.loading { padding: 4rem; text-align: center; color: var(--text-3); }

/* ---- barre claire ---- */
header.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px; height: 56px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.topbar .homebtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px; color: var(--text-2);
  border: 1px solid var(--border);
}
.topbar .homebtn:hover { color: var(--brand); border-color: var(--brand); }
.topbar .brand { font-weight: 700; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.topbar .brand a { color: var(--text); }
.topbar .brand svg { stroke: var(--brand); }
.topbar .module-title { color: var(--text-3); font-weight: 500; }
.topbar .module-title::before { content: "/"; margin-right: 10px; color: var(--border-strong); }
.topbar .spacer { flex: 1; }
.topbar .user { color: var(--text-3); font-size: 13px; display: flex; gap: 10px; align-items: center; }
.topbar .user button {
  border: 1px solid var(--border); background: none; border-radius: 8px;
  padding: 5px 11px; cursor: pointer; color: var(--text-2); font-size: 13px;
}
.topbar .user button:hover { border-color: var(--border-strong); }

/* ---- sélecteur de sociétés ---- */
.copicker { position: relative; }
.copicker-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2);
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text);
}
.copicker-btn:hover { border-color: var(--border-strong); }
.copicker-btn .chev { color: var(--text-3); }
.copicker-menu {
  position: absolute; top: 42px; left: 0; min-width: 260px; z-index: 30;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 30px rgba(26,34,48,.12); padding: 6px; display: none;
}
.copicker-menu.open { display: block; }
.copicker-menu .opt {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  cursor: pointer; font-size: 14px;
}
.copicker-menu .opt:hover { background: var(--surface); }
.copicker-menu .opt input { accent-color: var(--brand); width: 16px; height: 16px; }
.copicker-menu .sep { height: 1px; background: var(--border); margin: 6px 4px; }
.copicker-menu .act { display: flex; justify-content: space-between; padding: 4px; }
.copicker-menu .act a { font-size: 12px; cursor: pointer; }

main { max-width: 1120px; margin: 0 auto; padding: 26px 20px 90px; }
h1 { font-size: 21px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 26px 0 12px; color: var(--text); }
.sub { color: var(--text-3); font-size: 13px; margin-bottom: 22px; }

/* ---- stat tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow);
}
.tile .label { font-size: 12px; color: var(--text-3); font-weight: 500; }
.tile .value { font-size: 23px; font-weight: 700; margin-top: 3px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.tile .value.pos { color: var(--good); }
.tile .value.neg { color: var(--bad); }
.tile .hint { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ---- cards ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  color: inherit; display: block; transition: transform .1s, box-shadow .1s;
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px rgba(26,34,48,.08); }
.card .photo { height: 128px; background: var(--brand-soft); background-size: cover; background-position: center; position: relative; }
.card .photo .badge {
  position: absolute; top: 8px; right: 8px; font-size: 11px; font-weight: 600;
  background: rgba(255,255,255,.94); border-radius: 6px; padding: 2px 8px; color: var(--text-2);
}
.card .body { padding: 12px 14px; }
.card .name { font-weight: 700; }
.card .loc { color: var(--text-3); font-size: 12px; margin-bottom: 8px; }
.card .row { display: flex; justify-content: space-between; font-size: 13px; padding: 2px 0; }
.card .row .k { color: var(--text-3); }
.card .row .v { font-variant-numeric: tabular-nums; font-weight: 500; }

/* ---- panneau ---- */
.panel { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 14px; }
.panel .ptitle { font-weight: 700; font-size: 14px; margin-bottom: 12px; }

/* ---- tables ---- */
table { width: 100%; border-collapse: collapse; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 9px 13px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--text-3); font-weight: 600; background: var(--surface); font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }
.total-row td { font-weight: 700; background: var(--surface); }

/* ---- chart ---- */
.chart-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.chart-box .title { font-weight: 600; margin-bottom: 10px; font-size: 14px; }
.chart-tip {
  position: fixed; pointer-events: none; background: var(--text); color: #fff;
  border-radius: 7px; padding: 6px 10px; font-size: 12px; z-index: 50; display: none;
  white-space: nowrap;
}
.bar { fill: var(--brand); }
.bar.neg { fill: var(--bad); }
.bar.est { fill: var(--brand); opacity: .4; }
.axis-label { font-size: 10px; fill: var(--text-3); }
.gridline { stroke: var(--border); }
.cumline { fill: none; stroke: var(--text); stroke-width: 1.5; }

/* ---- login ---- */
.login-wrap { max-width: 380px; margin: 12vh auto; text-align: center; }
.login-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px; padding: 30px; box-shadow: var(--shadow); }
.login-card input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 15px; margin: 14px 0;
}
.login-card button, .btn {
  background: var(--brand); color: #fff; border: none; border-radius: 9px;
  padding: 10px 18px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn.secondary { background: none; color: var(--text-2); border: 1px solid var(--border); }
.btn:disabled { opacity: .45; cursor: default; }
.msg { margin-top: 12px; font-size: 13px; color: var(--text-2); }
.msg.err { color: var(--bad); }

/* ---- pills & chips ---- */
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 10px; font-size: 12px; font-weight: 600; }
.pill.ok { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.chip {
  display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: 12px;
  font-weight: 600; cursor: pointer; margin: 2px 2px 2px 0;
}
.chip.paye { background: var(--good-soft); color: var(--good); }
.chip.impaye { background: var(--bad-soft); color: var(--bad); }
.chip.partiel { background: var(--warn-soft); color: var(--warn); }
.chip.attente { background: var(--surface); color: var(--text-3); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr; } }
.muted { color: var(--text-3); }
.section-empty { color: var(--text-3); font-size: 13px; padding: 28px; text-align: center; }

/* ---- lanceur d'accueil ---- */
.launcher { max-width: 760px; margin: 5vh auto 0; }
.launcher-hello { color: var(--text-3); font-size: 14px; margin-bottom: 8px; }
.launcher h1 { font-size: 24px; margin-bottom: 24px; }
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.app-tile {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px 16px; box-shadow: var(--shadow);
  color: inherit; display: flex; align-items: center; gap: 14px;
  transition: transform .12s, box-shadow .12s;
}
.app-tile:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(26,34,48,.09); }
.app-icon {
  width: 46px; height: 46px; border-radius: 12px; background: var(--brand-soft);
  color: var(--brand); display: flex; align-items: center; justify-content: center; flex: none;
}
.app-icon svg { width: 24px; height: 24px; }
.app-label { font-weight: 700; font-size: 15px; }
.app-hint { color: var(--text-3); font-size: 12px; margin-top: 1px; }

@media (max-width: 640px) {
  header.topbar { padding: 0 12px; gap: 8px; }
  .topbar .brand span { display: none; }
  .topbar .module-title { display: none; }
  .copicker-btn .co-full { display: none; }
  main { padding: 18px 12px 70px; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .tile .value { font-size: 19px; }
  .cards { grid-template-columns: 1fr; }
  .apps { grid-template-columns: 1fr; }
  h1 { font-size: 19px; }
  body { padding-top: env(safe-area-inset-top); }
}
