/* Karmini Couture — feuille de style unique.
   Pensée pour une tablette 10 pouces : grosses cibles, grosses polices,
   rail latéral en paysage, barre basse en portrait. */

:root {
  --bg: #f6f1e8;
  --card: #fffdf8;
  --ink: #2a2521;
  --muted: #7d746a;
  --line: #e4dbcc;
  --accent: #1f6b73;
  --accent-soft: #e1efef;
  --terra: #bf5f3b;
  --terra-soft: #f6e5dc;
  --green: #3e7d4f;
  --green-soft: #e2efe4;
  --amber: #a86b12;
  --amber-soft: #f7ecd6;
  --rail: #243b40;
  --radius: 18px;
  --serif: 'Lora', Georgia, 'Times New Roman', serif;
  --sans: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; font-family: var(--serif); font-weight: 600; }
h1 { font-size: 30px; }
h2 { font-size: 22px; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ------------------------------------------------------------ ossature */

#app { display: flex; height: 100%; }

nav.rail {
  display: flex;
  flex-direction: column;
  width: 186px;
  flex-shrink: 0;
  background: var(--rail);
  color: #d9e4e4;
  padding: 22px 12px;
  gap: 4px;
}
.rail .brand { padding: 4px 12px 20px; }
.rail .brand b { display: block; font-family: var(--serif); font-size: 20px; color: #fff; font-weight: 600; line-height: 1.15; }
.rail .brand span { font-size: 13px; color: #9fb4b6; }
.rail button {
  display: flex; align-items: center; gap: 12px;
  height: 52px; padding: 0 14px; width: 100%;
  border: 0; border-radius: 12px; background: transparent;
  color: #d9e4e4; font-size: 17px; font-weight: 700; cursor: pointer; text-align: left;
}
.rail button.on { background: #fff; color: var(--rail); }
.rail .spacer { flex-grow: 1; }

main {
  flex-grow: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 28px 32px 48px;
  -webkit-overflow-scrolling: touch;
}
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.head .sub { font-size: 16px; color: var(--muted); margin-top: 4px; }
.head .actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* --------------------------------------------------------- composants */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}
.card > h2 { margin-bottom: 14px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* Cliente + les deux dates, en tête d'un devis ou d'une facture. */
.fields-3 { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex-grow: 1; }

button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  height: 54px; padding: 0 22px;
  border-radius: 14px; border: 2px solid var(--accent);
  background: var(--accent); color: #fff;
  font-size: 17px; font-weight: 800; cursor: pointer;
}
button.btn.secondary { background: var(--card); color: var(--accent); }
button.btn.ghost { background: transparent; color: var(--muted); border-color: var(--line); }
button.btn.terra { background: var(--terra); border-color: var(--terra); color: #fff; }
button.btn.danger { background: var(--card); color: var(--terra); border-color: var(--terra); }
button.btn.small { height: 44px; padding: 0 16px; font-size: 15px; }
button.btn:disabled { opacity: .45; cursor: default; }
button.btn svg { flex-shrink: 0; }

.tile {
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 122px; padding: 18px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--card);
  font-size: 20px; font-weight: 800; line-height: 1.15; cursor: pointer; text-align: left;
}
.tile.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.tile.terra { background: var(--terra); border-color: var(--terra); color: #fff; }

label.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
label.field > span {
  font-size: 13px; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: .04em;
}
.field input, .field select, .field textarea {
  height: 54px; padding: 0 14px;
  border: 2px solid var(--line); border-radius: 12px; background: #fff;
  font-size: 18px; font-weight: 600; width: 100%;
}
.field textarea { height: auto; min-height: 90px; padding: 12px 14px; font-weight: 500; line-height: 1.4; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 0; border-color: var(--accent); }
.field input[type="number"] { text-align: right; }
.hint { font-size: 14px; color: var(--muted); line-height: 1.35; }

.chip {
  display: inline-flex; align-items: center; height: 30px; padding: 0 12px;
  border-radius: 15px; font-size: 13px; font-weight: 800; white-space: nowrap;
  background: var(--line); color: var(--muted);
}
.chip.paid { background: var(--green-soft); color: var(--green); }
.chip.due { background: var(--amber-soft); color: var(--amber); }
.chip.late { background: var(--terra-soft); color: var(--terra); }
.chip.ok { background: var(--accent-soft); color: var(--accent); }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 44px; padding: 0 15px; border-radius: 22px;
  border: 2px solid var(--accent); background: var(--accent-soft); color: var(--accent);
  font-size: 15px; font-weight: 800; cursor: pointer; white-space: nowrap;
}
.pill.plain { border-color: var(--line); background: #fff; color: var(--ink); }
.pill.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.pill small { color: var(--muted); font-weight: 700; }
.pill.on small { color: #cfc7bb; }

.list { display: flex; flex-direction: column; }
.item {
  display: grid; align-items: center; gap: 14px;
  padding: 12px; min-height: 64px;
  border-top: 1px solid var(--line);
  font-size: 16px; cursor: pointer; text-align: left;
  background: transparent; border-left: 0; border-right: 0; border-bottom: 0; width: 100%;
}
.item:first-child { border-top: 0; }
.item .strong { font-weight: 800; }
.item .dim { font-size: 14px; color: var(--muted); }
.truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { text-align: right; font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { padding: 28px 4px; color: var(--muted); font-size: 16px; text-align: center; }
.only-phone { display: none; }
.nav-short { display: none; }

/* Gabarits des lignes de liste. Chaque type a ses colonnes en large,
   et se replie en deux étages sur téléphone (voir plus bas). */
.item.doc  { grid-template-columns: 116px minmax(0, 1fr) 108px 126px; }
.item.line { grid-template-columns: minmax(0, 1fr) 46px 92px 96px 28px 30px; gap: 9px; }
.item.line.read { grid-template-columns: minmax(0, 1fr) 46px 92px 96px; }
.item.cli  { grid-template-columns: minmax(0, 1fr) 150px 96px 34px; }
.item.pur  { grid-template-columns: 78px minmax(0, 1fr) 122px 34px; }
.item.cat  { grid-template-columns: minmax(0, 1fr) 132px 108px 28px 30px; gap: 10px; }
.item .l-meta { display: none; }
.item .l-edit, .item .k-edit, .item .c-edit { color: var(--muted); text-align: center; }
.item .r-state, .item .c-kind { text-align: right; }
.item .l-del, .item .p-del, .item .k-del { height: 40px; padding: 0 8px; border: 0; }

.kpi { font-family: var(--serif); font-size: 36px; font-weight: 600; line-height: 1.1; }
.kpi.accent { color: var(--accent); }
.kpi.terra { color: var(--terra); }
.kpi.green { color: var(--green); }
.label { font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.bar { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; margin: 8px 0; }
.bar > div { height: 100%; background: var(--green); }

.chart { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 8px; align-items: end; height: 210px; }
.chart .col { display: flex; flex-direction: column; align-items: center; gap: 5px; justify-content: flex-end; }
.chart .v { font-size: 11px; font-weight: 800; color: var(--muted); height: 15px; white-space: nowrap; }
.chart .b { width: 100%; border-radius: 6px 6px 0 0; background: var(--accent); min-height: 2px; }
.chart .b.none { background: transparent; border-bottom: 2px dashed var(--line); }
.chart .m { font-size: 12px; font-weight: 700; color: var(--muted); }

.totals { display: flex; flex-direction: column; gap: 9px; font-size: 17px; }
.totals .l { display: flex; justify-content: space-between; gap: 12px; }
.totals .l span { color: var(--muted); }
.totals .grand { padding-top: 12px; border-top: 2px solid var(--ink); align-items: baseline; }
.totals .grand span { color: var(--ink); font-size: 18px; font-weight: 800; }
.totals .grand b { font-family: var(--serif); font-size: 30px; font-weight: 600; color: var(--accent); }

.notice {
  display: flex; gap: 11px; align-items: flex-start;
  padding: 13px 15px; border-radius: 12px; background: var(--bg);
  font-size: 14px; line-height: 1.4; color: var(--muted);
}
.notice.warn { background: var(--terra-soft); color: #8c4227; }
.notice b { color: inherit; }

/* ------------------------------------------------------------- modales */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(24, 20, 17, .5);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.modal {
  background: var(--card); border-radius: 22px; padding: 22px 26px;
  width: min(940px, 100%); max-height: 92vh; overflow-y: auto;
  box-shadow: 0 24px 60px rgba(24, 20, 17, .3);
}
.modal.narrow { width: min(560px, 100%); }
.modal .mhead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal .close {
  width: 44px; height: 44px; border-radius: 22px; border: 2px solid var(--line);
  background: transparent; color: var(--muted); font-size: 22px; font-weight: 800; cursor: pointer;
}
.modal .mfoot { display: flex; align-items: center; gap: 14px; padding-top: 16px; margin-top: 18px; border-top: 1px solid var(--line); }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button {
  height: 60px; border-radius: 12px; border: 2px solid var(--line); background: #fff;
  font-size: 25px; font-weight: 800; cursor: pointer;
}
.keypad button.soft { background: var(--bg); color: var(--muted); }
.amount {
  display: flex; align-items: center; justify-content: flex-end;
  height: 62px; padding: 0 16px; border: 2px solid var(--line); border-radius: 12px; background: #fff;
  font-family: var(--serif); font-size: 30px; font-variant-numeric: tabular-nums;
}
.stepper { display: flex; align-items: center; gap: 9px; }
.stepper button {
  width: 52px; height: 52px; border-radius: 12px; border: 2px solid var(--line);
  background: #fff; color: var(--muted); font-size: 26px; font-weight: 800; cursor: pointer;
}
.stepper .val {
  min-width: 72px; height: 52px; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 12px; background: #fff; font-size: 21px; font-weight: 800;
}

.choice {
  display: flex; flex-direction: column; gap: 3px; justify-content: center;
  min-height: 74px; padding: 12px 16px; border-radius: 14px;
  border: 2px solid var(--line); background: #fff; color: var(--muted);
  font-size: 17px; font-weight: 800; cursor: pointer; text-align: left; width: 100%;
}
.choice small { font-size: 13px; font-weight: 600; }
.choice.on { border: 3px solid var(--accent); background: var(--accent-soft); color: var(--accent); }

#toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  background: var(--rail); color: #fff; padding: 14px 22px; border-radius: 14px;
  font-size: 16px; font-weight: 700; z-index: 80; max-width: 90vw; text-align: center;
  box-shadow: 0 10px 30px rgba(24, 20, 17, .3);
}
#toast.err { background: var(--terra); }

/* ---------------------------------------------------- écran de connexion */

#gate {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--rail); padding: 20px;
}
#gate .box { background: var(--card); border-radius: 22px; padding: 30px; width: min(420px, 100%); text-align: center; }
#gate h1 { font-size: 28px; margin-bottom: 6px; }
#gate p { color: var(--muted); font-size: 15px; margin: 0 0 22px; }
#gate input { text-align: center; letter-spacing: .3em; font-size: 24px; }

/* ------------------------------------------------ document imprimable */

#sheet { display: none; }

@media print {
  @page { size: A4; margin: 14mm 15mm; }
  body { background: #fff; }
  #app, #toast, #gate, .overlay { display: none !important; }
  #sheet { display: block !important; font-size: 11pt; color: #000; }
}

#sheet .doc { max-width: 180mm; }
#sheet .top { display: flex; justify-content: space-between; gap: 20mm; margin-bottom: 12mm; }
#sheet .issuer b { font-family: var(--serif); font-size: 16pt; display: block; margin-bottom: 2mm; }
#sheet .issuer div, #sheet .to div { line-height: 1.45; }
#sheet .to { text-align: right; }
#sheet .to .lbl, #sheet .issuer .lbl { font-size: 8pt; letter-spacing: .08em; text-transform: uppercase; color: #555; margin-bottom: 1.5mm; }
#sheet h1 { font-size: 20pt; margin-bottom: 1mm; }
#sheet .meta { color: #444; margin-bottom: 8mm; line-height: 1.5; }
#sheet table { width: 100%; border-collapse: collapse; margin-bottom: 6mm; }
#sheet th { text-align: left; font-size: 8.5pt; text-transform: uppercase; letter-spacing: .05em; color: #555; border-bottom: 1.2pt solid #000; padding: 0 0 2mm; }
#sheet td { padding: 2.5mm 0; border-bottom: .5pt solid #ccc; vertical-align: top; }
#sheet th.r, #sheet td.r { text-align: right; }
#sheet .sums { margin-left: auto; width: 70mm; }
#sheet .sums div { display: flex; justify-content: space-between; padding: 1.5mm 0; }
#sheet .sums .big { border-top: 1.2pt solid #000; margin-top: 1.5mm; padding-top: 2.5mm; font-size: 14pt; font-weight: 700; }
#sheet .legal { margin-top: 10mm; font-size: 9pt; color: #333; line-height: 1.6; }
#sheet .sign { margin-top: 12mm; font-size: 9.5pt; }

/* ------------------------------------------- portrait : tablette et large */

@media (max-width: 899px) {
  #app { flex-direction: column-reverse; }
  nav.rail {
    flex-direction: row; width: auto; height: 70px; flex-shrink: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); gap: 2px;
    border-top: 1px solid #16282c;
  }
  .rail .brand, .rail .spacer { display: none; }
  .rail button {
    flex: 1 1 0; min-width: 0;
    flex-direction: column; justify-content: center; gap: 3px;
    height: 100%; padding: 0 2px; font-size: 11px; font-weight: 700; text-align: center;
    border-radius: 10px;
  }
  .rail button svg { width: 21px; height: 21px; }
  main { padding: 18px 14px 30px; }
  h1 { font-size: 25px; }
  .cols-3, .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal { padding: 18px; border-radius: 18px; }
  .split { grid-template-columns: minmax(0, 1fr) !important; }
  .chart { height: 170px; gap: 5px; }
}

/* ----------------------------------------------------------- téléphone */

@media (max-width: 640px) {
  .only-phone { display: inline-flex; }
  .nav-long { display: none; }
  .nav-short { display: inline; }
  .rail .rail-settings { display: none; }   /* accessible depuis l'accueil */
  .rail button { font-size: 10px; gap: 2px; }

  main { padding: 14px 12px 26px; }
  h1 { font-size: 23px; }
  h2 { font-size: 19px; }
  .head { margin-bottom: 16px; gap: 10px; }
  .head .sub { font-size: 14px; }
  .card { padding: 14px; border-radius: 15px; margin-bottom: 14px; }
  .grid { gap: 12px; }
  .cols-2, .cols-3, .cols-4 { grid-template-columns: minmax(0, 1fr); }

  /* La cliente prend toute la largeur, les deux dates se partagent la ligne
     du dessous : trois champs côte à côte ne tiennent pas sur un téléphone. */
  .fields-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .fields-3 > :first-child { grid-column: 1 / -1; }
  .fields-3 .field input[type="date"] { padding: 0 8px; font-size: 16px; }
  .fields-3 .field > span { font-size: 12px; letter-spacing: .02em; }

  /* Les quatre raccourcis restent sur deux colonnes, mais plus bas. */
  .grid.tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile { min-height: 88px; padding: 13px; font-size: 16px; border-radius: 15px; }
  .tile svg { width: 23px; height: 23px; }

  button.btn { height: 50px; font-size: 16px; padding: 0 18px; }
  button.btn.small { height: 42px; font-size: 14px; padding: 0 13px; }
  .kpi { font-size: 30px; }
  .field input, .field select, .field textarea { font-size: 17px; height: 50px; }

  /* Les lignes de liste passent sur deux étages : l'essentiel à gauche,
     le montant à droite, le reste dessous. Rien n'est plus tronqué au bord. */
  /* Les articles rapides tiennent sur une seule bande qui se fait glisser
     du doigt : empilés, ils mangeaient un demi-écran. */
  .pill { height: 40px; padding: 0 12px; font-size: 13.5px; gap: 5px; }
  .pill svg { width: 15px; height: 15px; }
  .row.quick {
    flex-wrap: nowrap; overflow-x: auto; gap: 8px;
    padding-bottom: 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .row.quick::-webkit-scrollbar { display: none; }
  .row.quick .pill { flex: 0 0 auto; }

  .item { gap: 4px 10px !important; padding: 11px 4px; font-size: 15px; }
  .item .dim { font-size: 13px; }
  .item .l-meta { display: block; }
  .item .l-qty, .item .l-unit, .item .l-edit, .item .k-edit, .item .c-edit { display: none; }

  .item.doc {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "id amount" "body state";
  }
  .item.doc .r-id { grid-area: id; }
  .item.doc .r-body { grid-area: body; }
  .item.doc .r-amount { grid-area: amount; }
  .item.doc .r-state { grid-area: state; }
  .item.doc .r-id .strong, .item.doc .r-id .dim { display: inline; }
  .item.doc .r-id .dim { margin-left: 7px; }

  .item.line {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "lab lab total" "meta meta del";
  }
  .item.line.read { grid-template-areas: "lab lab total" "meta meta meta"; }
  .item.line .l-label { grid-area: lab; }
  .item.line .l-meta { grid-area: meta; }
  .item.line .l-total { grid-area: total; }
  .item.line .l-del { grid-area: del; justify-self: end; }

  .item.cli {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name kind" "phone phone";
  }
  .item.cli .c-name { grid-area: name; }
  .item.cli .c-phone { grid-area: phone; }
  .item.cli .c-kind { grid-area: kind; }

  .item.pur {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "body body amount" "date date del";
  }
  .item.pur .p-date { grid-area: date; }
  .item.pur .p-body { grid-area: body; }
  .item.pur .p-amount { grid-area: amount; }
  .item.pur .p-del { grid-area: del; justify-self: end; }

  .item.cat {
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas: "lab lab price" "kind kind del";
  }
  .item.cat .k-label { grid-area: lab; }
  .item.cat .k-kind { grid-area: kind; }
  .item.cat .k-price { grid-area: price; }
  .item.cat .k-del { grid-area: del; justify-self: end; }

  /* Fenêtres : feuille qui monte du bas, contenu resserré pour que le pavé
     numérique tienne à l'écran, et bouton de validation toujours visible. */
  .overlay { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%; max-height: 98vh; border-radius: 18px 18px 0 0;
    padding: 12px 14px 0; display: flex; flex-direction: column;
  }
  .modal .mhead { margin-bottom: 12px; flex: 0 0 auto; }
  .modal > .grid, .modal > label.field { overflow-y: auto; }
  .modal .mfoot {
    position: sticky; bottom: 0; flex: 0 0 auto;
    margin-top: 10px; padding: 10px 0 calc(10px + env(safe-area-inset-bottom));
    background: var(--card); flex-wrap: nowrap; gap: 8px;
  }
  .modal .mfoot .label, .modal .mfoot .hint { display: none; }  /* le montant suffit */
  .only-wide { display: none !important; }
  /* Dans la fenêtre d'encaissement il ne reste qu'une ligne : le trait est inutile. */
  .modal .totals .grand { border-top: 0; padding-top: 0; }
  .modal .mfoot > div:first-child > div { font-size: 21px !important; }
  .modal .mfoot .btn { flex: 0 1 auto; height: 46px; font-size: 15px; padding: 0 14px; }
  .modal .notice { font-size: 12.5px; line-height: 1.3; padding: 9px 11px; }
  .modal .grid.split { gap: 14px; }

  /* Les deux choix, et les paires de champs courts, restent côte à côte. */
  .choices, .pair { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 10px; }
  .pair .field > span { font-size: 12px; letter-spacing: .02em; }
  .choice { min-height: 52px; font-size: 15px; padding: 10px 12px; }
  .choice small { display: none; }

  .keypad { gap: 6px; }
  .keypad button { height: 44px; font-size: 20px; }
  .amount { height: 46px; font-size: 22px; }
  .notice { padding: 10px 12px; font-size: 13px; gap: 9px; }
  .stepper button { width: 46px; height: 46px; }
  .stepper .val { min-width: 60px; height: 46px; }

  .chart { height: 130px; gap: 3px; }
  .chart .v { display: none; }
  .chart .m { font-size: 10px; }

  .totals { font-size: 15px; }
  .totals .grand b { font-size: 25px; }
}
