/* Finance Heiwa — design system v2 (porté depuis l'app RH Swiss Piscine +
   maquette validée mockups/finance-redesign.html). Manrope + Inter, icônes
   au trait (line-SVG), jamais d'émoji. */

/* ===== Tokens (source: swiss-piscine-app/frontend/css/app.css :root) ===== */
:root {
  --navy: #0c2b38;
  --ink: #14313c;
  --muted: #6a7d85;
  --line: #e4eaec;
  --line-soft: #eef2f3;
  --aqua: #127d89;
  --aqua-dark: #0c5e68;
  --aqua-soft: #e8f2f3;
  --bg: #f5f7f8;
  --white: #ffffff;
  --ok: #2f8f63;
  --ok-soft: #e3f3ea;
  --warn: #d99a2b;
  --warn-soft: #fbf0d8;
  --danger: #c0463a;
  --danger-soft: #f7e3e1;
  --violet: #5957c9;
  --violet-soft: #ececfa;
  --coral: #e0735a;
  --coral-soft: #fceae5;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(12,43,56,.04), 0 8px 24px rgba(12,43,56,.05);
  --sidebar-w: 236px;
  --header-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font-display: "Manrope", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Couleur d'accent de la société active — surchargée en JS par les tâches
     suivantes (ex: applyTheme() pose --co-accent selon la société sélectionnée). */
  --co-accent: var(--aqua-dark);
  font-family: var(--font-body);
}

/* ===== Base ===== */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); -webkit-font-smoothing: antialiased; }
#app { min-height: 100%; }
a { color: var(--aqua-dark); text-decoration: none; }
h1, h2, h3, strong, .display { font-family: var(--font-display); font-weight: 700; letter-spacing: -.022em; color: var(--navy); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1rem; }
.eyebrow { font-size: .68rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

.loading { padding: 40px; text-align: center; color: var(--muted); font-size: .9rem; }

/* --- Icônes au trait (jamais d'émoji) --- */
svg { stroke-width: 2; stroke: currentColor; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.icon { width: 20px; height: 20px; stroke: currentColor; stroke-width: 1.6; fill: none; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; vertical-align: middle; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 26px; height: 26px; }

/* ===== Sidebar / nav (source: mockups/finance-redesign.html, motif tabbar→sidebar de l'app RH) ===== */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--white); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 4px; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 auto;
  background: linear-gradient(150deg, var(--navy), var(--aqua-dark));
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.brand b { font-family: var(--font-display); font-weight: 800; font-size: 1.02rem; color: var(--navy); line-height: 1.05; letter-spacing: -.02em; }
.brand span { display: block; font-size: .72rem; color: var(--muted); font-weight: 500; }

.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; border: 0; background: none;
  width: 100%; text-align: left; color: var(--ink); font-family: var(--font-body); font-size: .92rem; font-weight: 500;
  cursor: pointer; position: relative;
}
.nav-item .icon { width: 20px; height: 20px; color: var(--muted); flex: 0 0 auto; }
.nav-item:hover { background: var(--line-soft); }
.nav-item.active { background: var(--aqua-soft); color: var(--co-accent, var(--aqua-dark)); font-weight: 600; }
.nav-item.active .icon { color: var(--co-accent, var(--aqua-dark)); }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 9px; bottom: 9px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--co-accent, var(--aqua-dark));
}
.nav-sep { flex: 1; }

.copicker { margin-top: 8px; border-top: 1px solid var(--line-soft); padding-top: 12px; position: relative; }
.copicker .lbl { font-size: .68rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); padding: 0 8px 6px; font-weight: 600; }
.co-btn, .copicker-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--white); cursor: pointer;
  font-family: var(--font-body); font-size: .86rem; color: var(--ink);
}
.co-btn:hover, .copicker-btn:hover { background: var(--line-soft); }
.copicker-btn .chev { color: var(--muted); }
.copicker-menu {
  position: absolute; z-index: 30; min-width: 260px; background: var(--white);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 30px rgba(12,43,56,.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: .88rem; }
.copicker-menu .opt:hover { background: var(--line-soft); }
.copicker-menu .sep { height: 1px; background: var(--line); margin: 6px 4px; }
.copicker-menu .act { display: flex; justify-content: space-between; padding: 4px; }
.copicker-menu .act a { font-size: .78rem; cursor: pointer; }
.grp-label, .grp-h {
  font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 14px 0 6px; padding: 0 6px;
}

.who { display: flex; align-items: center; gap: 9px; padding: 10px 8px 2px; margin-top: 6px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--aqua-dark); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: .78rem; flex: 0 0 auto; }
.who small { color: var(--muted); font-size: .74rem; display: block; }
.who b { font-size: .82rem; font-weight: 600; color: var(--ink); }

/* ===== Main / page head ===== */
.main { margin-left: var(--sidebar-w); padding: 30px 40px 60px; max-width: 1080px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 8px; }
.page-head h1 { font-size: 1.5rem; }
.page-head .sub, .sub { color: var(--muted); font-size: .9rem; }

/* ===== Onglets internes (sous-écrans) ===== */
.subtabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.subtab {
  background: none; border: none; padding: 9px 14px; font-size: .86rem; font-weight: 600;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; font-family: var(--font-body);
}
.subtab:hover { color: var(--ink); }
.subtab.active { color: var(--co-accent, var(--aqua-dark)); border-bottom-color: var(--co-accent, var(--aqua-dark)); }

/* ===== Cartes module (encadrés type Odoo) ===== */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.mod-card {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 18px 16px; cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s;
  position: relative; overflow: hidden;
}
.mod-card:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(12,43,56,.06), 0 14px 34px rgba(12,43,56,.09); border-color: #d4dde0; }
.mod-card .top { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.mod-card .chip { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex: 0 0 auto; }
.mod-card .chip .icon { width: 20px; height: 20px; }
.mod-card h3 { font-size: 1rem; color: var(--navy); }
.mod-card .big { font-size: 1.7rem; font-weight: 800; font-family: var(--font-display); letter-spacing: -.03em; color: var(--navy); line-height: 1; }
.mod-card .cap { font-size: .8rem; color: var(--muted); margin-top: 5px; }
.mod-card .go { position: absolute; right: 14px; bottom: 14px; color: var(--muted); opacity: 0; transition: opacity .12s; }
.mod-card:hover .go { opacity: 1; }

/* Teintes (chip / valeur) */
.tint-aqua .chip { background: var(--aqua-soft); color: var(--aqua-dark); }
.tint-ok .chip { background: var(--ok-soft); color: var(--ok); }
.tint-ok .big { color: var(--ok); }
.tint-violet .chip { background: var(--violet-soft); color: var(--violet); }
.tint-warn .chip { background: var(--warn-soft); color: var(--warn); }
.tint-coral .chip { background: var(--coral-soft); color: var(--coral); }
.tint-danger .chip { background: var(--danger-soft); color: var(--danger); }
.tint-danger .big { color: var(--danger); }

/* ===== KPI / panel / tableaux ===== */
.kpi-row, .tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpi, .tile { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.kpi .eyebrow, .tile .label { margin-bottom: 9px; }
.kpi .big, .tile .value { font-size: 1.55rem; font-weight: 800; font-family: var(--font-display); letter-spacing: -.03em; color: var(--navy); }
.tile .value.pos { color: var(--ok); }
.tile .value.neg { color: var(--danger); }
.tile .hint { font-size: .78rem; color: var(--muted); margin-top: 2px; }

.panel { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-top: 4px; }
.panel + .panel { margin-top: 14px; }
.panel .ptitle { font-family: var(--font-display); font-weight: 700; color: var(--navy); margin-bottom: 10px; font-size: 1rem; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
td, th { padding: 8px 0; border-top: 1px solid var(--line-soft); text-align: left; }
tr:first-child td, tr:first-child th { border-top: 0; }
td.r, th.r, td.num, th.num { text-align: right; }
td.num, th.num, .num { font-variant-numeric: tabular-nums; color: var(--ink); }
.table-wrap { overflow-x: auto; }
.total-row td { font-weight: 700; color: var(--navy); border-top: 2px solid var(--line); }
.neg { color: var(--danger); }

.badge-inc {
  display: inline-block; font-size: .62rem; font-weight: 600; letter-spacing: .03em; color: var(--warn);
  background: var(--warn-soft); padding: 1px 7px; border-radius: 999px; margin-left: 6px; vertical-align: middle;
}
.badge-muted { display: inline-block; font-size: .62rem; font-weight: 600; letter-spacing: .03em; color: var(--muted); background: var(--line-soft); padding: 1px 7px; border-radius: 999px; margin-left: 6px; vertical-align: middle; }
.detail-back {
  display: inline-flex; align-items: center; gap: 6px; color: var(--aqua-dark); background: none; border: 0; cursor: pointer;
  font-family: var(--font-body); font-size: .86rem; font-weight: 600; margin-bottom: 14px; padding: 0;
}
.detail-back:hover { color: var(--navy); }
.hint { position: fixed; bottom: 14px; right: 16px; background: var(--navy); color: #fff; font-size: .72rem; padding: 7px 12px; border-radius: 999px; opacity: .85; }
.section-empty { color: var(--muted); font-size: .86rem; padding: 28px; text-align: center; }

/* ===== Pastilles / puces (badges de statut, chips) ===== */
.pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 2px 10px; font-size: .78rem; font-weight: 600; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.chip { display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: .78rem; font-weight: 600; cursor: pointer; margin: 2px 2px 2px 0; }
.chip.paye { background: var(--ok-soft); color: var(--ok); }
.chip.impaye { background: var(--danger-soft); color: var(--danger); }
.chip.partiel { background: var(--warn-soft); color: var(--warn); }
.chip.attente { background: var(--line-soft); color: var(--muted); }

/* ===== Boutons (source: app RH) ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; border: 0; border-radius: 11px; cursor: pointer;
  font-family: var(--font-body); font-size: .96rem; font-weight: 600; padding: 0 18px;
  background: var(--navy); color: var(--white); letter-spacing: .01em;
  transition: background .15s, transform .12s, box-shadow .15s;
}
.btn:hover { background: var(--aqua-dark); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--white); color: var(--navy); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--line-soft); }
.btn.secondary.active { background: var(--aqua-soft); color: var(--aqua-dark); border-color: var(--aqua); }

/* ===== Champs (source: app RH) ===== */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.field input, .field select, .field textarea, .login-card input {
  width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 11px; padding: 0 13px;
  font-size: 1rem; background: #fbfdfe; font-family: var(--font-body); color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus, .login-card input:focus { outline: 2px solid var(--aqua); border-color: var(--aqua); }
.form-error, .err, .msg.err { color: var(--danger); font-size: .88rem; margin: 0 0 12px; min-height: 1.1em; }
.msg { margin-top: 12px; font-size: .86rem; color: var(--muted); }

/* ===== Connexion (source: app RH) ===== */
.login-wrap { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login-card { background: var(--white); border-radius: 18px; padding: 26px; box-shadow: 0 14px 44px rgba(12,34,51,.25); }
.login-card h2 { margin: 0 0 4px; font-size: 1.3rem; }
.login-card p.sub { margin: 0 0 20px; color: var(--muted); font-size: .9rem; }
body.screen-login { background: linear-gradient(160deg, var(--navy), var(--aqua-dark)); }

/* ===== Lanceur d'accueil (multi-app) ===== */
.launcher { max-width: 760px; margin: 5vh auto 0; }
.launcher-hello { color: var(--muted); font-size: .88rem; margin-bottom: 8px; }
.launcher h1 { font-size: 1.5rem; margin-bottom: 24px; }
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; }
.app-tile {
  background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); 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(12,43,56,.09); }
.app-icon { width: 46px; height: 46px; border-radius: 12px; background: var(--aqua-soft); color: var(--aqua-dark); display: flex; align-items: center; justify-content: center; flex: none; }
.app-icon svg { width: 24px; height: 24px; }
.app-label { font-weight: 700; font-size: .95rem; font-family: var(--font-display); color: var(--navy); }
.app-hint { color: var(--muted); font-size: .78rem; margin-top: 1px; }

/* ===== Feuille / bottom sheet (source: app RH + maquette finance) ===== */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(12,43,56,0); transition: background .3s;
  display: flex; align-items: flex-end; justify-content: center; pointer-events: none;
}
.sheet-overlay.open { background: rgba(12,43,56,.42); pointer-events: auto; }
.sheet {
  width: 100%; max-width: 460px; max-height: 86vh; overflow-y: auto; background: var(--bg);
  border-radius: 22px 22px 0 0; transform: translateY(100%); transition: transform .32s cubic-bezier(.32,.72,0,1);
  padding: 0 16px calc(22px + var(--safe-bottom)); box-shadow: 0 -8px 34px rgba(12,43,56,.2);
}
.sheet-overlay.open .sheet { transform: translateY(0); }
.sheet-handle { display: flex; justify-content: center; padding: 11px 0 7px; position: sticky; top: 0; background: var(--bg); cursor: grab; touch-action: none; }
.sheet-handle span { width: 42px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet-head { padding: 2px 4px 6px; display: flex; align-items: baseline; justify-content: space-between; }
.sheet-head h3 { font-size: 1.2rem; }
.sheet-head a { color: var(--aqua-dark); font-size: .82rem; font-weight: 600; cursor: pointer; }

/* Sélecteur de sociétés (feuille) */
.co-grp { font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 14px 6px 6px; }
.co-row { display: flex; align-items: center; gap: 12px; padding: 12px 8px; border-bottom: 1px solid var(--line-soft); cursor: pointer; }
.co-row:last-child { border-bottom: 0; }
.co-row:hover { background: var(--line-soft); }
.co-row .box { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--line); flex: 0 0 auto; display: flex; align-items: center; justify-content: center; color: #fff; transition: .12s; }
.co-row.on .box { background: var(--co-accent, var(--aqua-dark)); border-color: var(--co-accent, var(--aqua-dark)); }
.co-row .box svg { width: 14px; height: 14px; opacity: 0; }
.co-row.on .box svg { opacity: 1; }
.co-row .nm { flex: 1; font-size: .94rem; font-weight: 500; color: var(--ink); }
.co-full { }

/* ===== Graphiques (chart.js maison) ===== */
.chart-box { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.chart-box .title { font-weight: 600; margin-bottom: 10px; font-size: .9rem; color: var(--navy); }
.chart-tip {
  position: fixed; pointer-events: none; background: var(--navy); color: #fff;
  border-radius: 7px; padding: 6px 10px; font-size: .78rem; z-index: 50; display: none; white-space: nowrap;
}
.bar { fill: var(--aqua); }
.bar.neg { fill: var(--danger); }
.bar.est { fill: var(--aqua); opacity: .4; }
.axis-label { font-size: .625rem; fill: var(--muted); }
.gridline { stroke: var(--line); }
.cumline { fill: none; stroke: var(--navy); stroke-width: 1.5; }

/* ===== Cartes génériques (biens, listes) ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card { background: var(--white); border: 1px solid var(--line); 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(12,43,56,.08); }
.card .body { padding: 12px 14px; }
.card .name { font-weight: 700; color: var(--navy); }
.card .loc { color: var(--muted); font-size: .78rem; margin-bottom: 8px; }
.card .row { display: flex; justify-content: space-between; font-size: .82rem; padding: 2px 0; }
.card .row .k { color: var(--muted); }
.card .row .v { font-variant-numeric: tabular-nums; font-weight: 500; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ===== Responsive ===== */
/* ≥900px : layout desktop par défaut (sidebar fixe à gauche, cf. règles ci-dessus). */
/* <820px : la sidebar se replie ; on garde le contenu simple (pleine largeur) pour
   cette tâche — la barre de navigation basse dédiée mobile sera affinée par les
   tâches d'écrans suivantes (4-7). */
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 0 2000px rgba(12,43,56,.35); }
  .main { margin-left: 0; padding: 20px 16px 40px; }
  .kpi-row, .tiles { grid-template-columns: repeat(2, 1fr); }
  .card-grid, .cards, .apps { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  body { padding-top: env(safe-area-inset-top); }
}
