/* Reproduction de l'apparence du fichier Numbers (thème sombre). */
:root {
  --z: 1.3;
  --bg: #000;
  --hdr: #434443;        /* ligne d'en-tête */
  --namecol: #2c2c2c;    /* première colonne (noms) */
  --grid: #b5b5b5;       /* quadrillage */
  --green: #a8cc84;      /* Restant dû = 0 */
  --violet: #d0bade;     /* Restant dû ≠ 0 et en-tête */
  --red: #db504e;
  --blue: #8fbcf8;
  --tab-green: #5fbd5e;
  --sel: #5fbd5e;
  --font: "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-h: Verdana, Geneva, sans-serif;
  --fs: calc(10px * var(--z));
  --fs-h: calc(12px * var(--z));
  --row-h: calc(20px * var(--z));
  --letters-h: calc(16px * var(--z));
  --title-h: calc(30px * var(--z));
  --rn-w: calc(25px * var(--z));
  --gap-w: calc(11px * var(--z));
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: #fff; font-family: var(--font); }

/* ---------------------------------------------------------------- application */
body.app { display: flex; flex-direction: column; overflow: hidden; }

.tabbar {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  background: #393a3b; height: 40px; padding: 0 12px 0 16px; border-bottom: 1px solid #2a2a2a;
  user-select: none; -webkit-user-select: none;
}
.tabs { display: flex; align-items: center; gap: 18px; }
.tab {
  font: 15px var(--font); color: #a9a9a9; background: transparent; border: 0; border-radius: 7px;
  padding: 4px 22px; cursor: pointer; min-width: 104px;
}
.tab.on { background: var(--tab-green); color: #fff; }
.tab:not(.on):hover { color: #d8d8d8; }
.tab-sep { width: 1px; height: 22px; background: #5a5a5a; }
.tabbar-right { display: flex; align-items: center; gap: 14px; }
.save-status { font-size: 12px; color: #8a8a8a; }
.save-status.saving { color: #b0b0b0; }
.save-status.error { color: #ff6b6b; font-weight: bold; }
.year {
  font: 13px var(--font); color: #cfcfcf; background: #2d2e2f; border: 1px solid #4a4a4a;
  border-radius: 5px; padding: 2px 6px; cursor: pointer;
}

.banner {
  display: none; flex: 0 0 auto; background: #c62828; color: #fff; font-size: 15px;
  padding: 10px 16px; text-align: center; line-height: 1.35;
}
.banner.show { display: block; }
.banner a { color: #fff; font-weight: bold; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: 640px;
  background: #fff3cd; color: #3d2f00; border: 1px solid #e0c060; border-radius: 8px;
  padding: 10px 16px; font-size: 15px; box-shadow: 0 4px 16px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none; transition: opacity .15s;
}
.toast.show { opacity: 1; }

.sheet-wrap { flex: 1 1 auto; overflow: auto; position: relative; padding: 0 12px 40px 0; }

table.sheet {
  border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: var(--fs);
  user-select: none; -webkit-user-select: none; cursor: cell;
}
.sheet col.rn-col { width: var(--rn-w); }
.sheet col.gap-col { width: var(--gap-w); }

/* lettres de colonnes (barre blanche arrondie) */
.sheet tr.letters th {
  position: sticky; top: 0; z-index: 3; height: var(--letters-h); padding: 0;
  font: calc(10px * var(--z)) var(--font); font-weight: normal; color: #6d6d6d; background: var(--bg);
}
.sheet tr.letters th.letter { background: #fff; border-left: 1px solid #e3e3e3; }
.sheet tr.letters th.letter.first { border-left: 0; border-radius: 4px 0 0 4px; }
.sheet tr.letters th.letter.last { border-radius: 0 4px 4px 0; }
.sheet tr.letters th.letter.on { background: #dcf5e0; }
.sheet tr.letters th.corner { left: 0; z-index: 5; }

/* titre « Tableau 1 » */
.sheet tr.title th {
  position: sticky; top: var(--letters-h); z-index: 3; height: var(--title-h); background: var(--bg);
  font: calc(12px * var(--z)) var(--font); font-weight: normal; color: #fff; text-align: center;
  vertical-align: middle; padding: calc(6px * var(--z)) 0 0;
}
.sheet tr.title th.rn-top { border-radius: 5px 5px 0 0; background: #fff; }

/* ligne d'en-tête */
.sheet tr.header th {
  position: sticky; top: calc(var(--letters-h) + var(--title-h)); z-index: 3;
  height: calc(23px * var(--z)); background: var(--hdr); color: #fff; padding: 0 calc(4px * var(--z));
  border-right: 0.5px solid var(--grid); border-bottom: 1px solid var(--grid);
  overflow: hidden; white-space: nowrap;
}
.sheet tr.header th.gap, .sheet tr.header th.rn { border: 0; }
.sheet tr.header th.gap { background: var(--bg); }
.sheet tr.header th.rn { background: #fff; color: #6d6d6d; font: calc(10px * var(--z)) var(--font); }
.sheet tr.header th:nth-child(3) { border-left: 0.5px solid var(--grid); }
.sheet tr.header th.hh { font: var(--fs-h) var(--font-h); text-align: center; }
.sheet tr.header th.restant-h { background: var(--violet); color: #000; }
.sheet tr.header th.eh { font: bold var(--fs) var(--font); text-align: left; }

/* numéros de lignes (colonne blanche) */
.sheet th.rn {
  position: sticky; left: 0; z-index: 2; background: #fff; color: #6d6d6d;
  font: calc(10px * var(--z)) var(--font); font-weight: normal; text-align: center; padding: 0;
}
.sheet thead th.rn { z-index: 5; }
.sheet tbody th.rn.on { background: #dcf5e0; color: #3a9a3a; }
.sheet tbody tr:last-child th.rn { border-radius: 0 0 5px 5px; }
.sheet .gap { background: var(--bg); border: 0; padding: 0; }

/* cellules */
.sheet td {
  height: var(--row-h); padding: calc(2px * var(--z)) calc(4px * var(--z));
  border-right: 0.5px solid var(--grid); border-bottom: 0.5px solid var(--grid);
  vertical-align: top; line-height: 1.25; white-space: nowrap; overflow: hidden; color: #fff;
  background: var(--bg);
}
.sheet td:nth-child(3) { border-left: 0.5px solid var(--grid); }
.sheet td.text { white-space: normal; overflow-wrap: anywhere; }
.sheet td.name { background: var(--namecol); font-weight: bold; white-space: normal; overflow-wrap: anywhere; }
.sheet td.money, .sheet td.date { text-align: right; }
.sheet td.restant { text-align: right; color: #000; }
.sheet td.restant.zero { background: var(--green); }
.sheet td.restant.nonzero { background: var(--violet); }
.sheet td.side-label { text-align: center; }
.sheet td.lbl-red { background: var(--red); }
.sheet td.lbl-blue { background: var(--blue); }
.sheet td.side-value { text-align: right; }
.sheet td.enc-ca-label { text-align: center; }
.sheet td.enc-month { text-align: left; }
.sheet td.enc-value { text-align: left; }
.sheet td.sel { box-shadow: inset 0 0 0 2px var(--sel); }

/* zone de saisie posée sur la case sélectionnée */
.editor {
  position: absolute; z-index: 1; opacity: 0; caret-color: transparent; pointer-events: none;
  border: 0; outline: none; margin: 0; padding: calc(2px * var(--z)) calc(4px * var(--z));
  font: var(--fs) var(--font); color: #fff; background: #000;
}
.editor.right { text-align: right; }
.editor.bold { font-weight: bold; }
.editor.active {
  opacity: 1; caret-color: #fff; pointer-events: auto; box-shadow: inset 0 0 0 2px var(--sel);
}

/* ---------------------------------------------------------------- connexion */
body.login-page { display: flex; align-items: center; justify-content: center; }
.login-box {
  width: 340px; background: #1c1c1e; border: 1px solid #3a3a3c; border-radius: 12px;
  padding: 28px 28px 24px; display: flex; flex-direction: column;
}
.login-box h1 { font-size: 22px; font-weight: 600; margin: 0 0 20px; text-align: center; }
.login-box label { font-size: 14px; color: #c7c7c7; margin: 10px 0 6px; }
.login-box input {
  font: 16px var(--font); padding: 9px 10px; border-radius: 7px; border: 1px solid #4a4a4c;
  background: #000; color: #fff;
}
.login-box input:focus { outline: 2px solid var(--tab-green); border-color: transparent; }
.login-box button {
  margin-top: 16px; font: 600 16px var(--font); padding: 10px; border: 0; border-radius: 8px;
  background: var(--tab-green); color: #fff; cursor: pointer;
}
.login-box button:disabled { opacity: .6; cursor: default; }
.login-error { min-height: 20px; color: #ff6b6b; font-size: 14px; margin: 12px 0 0; }
