/* MADARA — Caisse autonome (caisse.dara-crm.online). Interface point de vente
   dédiée : login puis écran de vente. Tactile, lisible, professionnelle. */
:root {
  --bg: #F3EEE7; --surface: #FFFFFF; --line: #E2D8C9; --ink: #211A16; --muted: #6E625A;
  --terra: #C4593A; --terra-d: #A94827; --green: #3F7A4B; --red: #A83526;
  --slate: #241D18;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
/* L'attribut hidden doit TOUJOURS l'emporter (sinon .screen/.pane display:flex
   le masquent pas -> l'écran de connexion resterait affiché après login). */
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; -webkit-font-smoothing: antialiased; }
button { font-family: inherit; }
.muted { color: var(--muted); }
.err { color: var(--red); font-size: 13.5px; min-height: 18px; margin: 4px 0; }

.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px;
  padding: 11px 18px; font-size: 15px; font-weight: 600; cursor: pointer; transition: filter .12s, background .12s; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--terra); border-color: var(--terra); color: #fff; }
.btn.primary:hover { background: var(--terra-d); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.big { padding: 14px 22px; font-size: 16px; }
.btn.xl { width: 100%; padding: 18px; font-size: 20px; font-weight: 800; margin-top: 14px; }

.fld { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 700; letter-spacing: .02em;
  text-transform: uppercase; color: var(--muted); }
.fld input { font: inherit; font-size: 16px; font-weight: 500; text-transform: none; letter-spacing: normal; color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: var(--surface); outline: none; }
.fld input:focus { border-color: var(--terra); }

/* Écrans */
.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 30px 26px; display: flex; flex-direction: column; gap: 16px; box-shadow: 0 20px 50px rgba(33,26,22,.08); }
.login-brand { font-size: 26px; font-weight: 800; letter-spacing: -.03em; text-align: center; margin-bottom: 4px; }
.login-brand span { color: var(--terra); }

/* Barre du haut */
.topbar { display: flex; align-items: center; gap: 16px; background: var(--slate); color: #EFE4D5; padding: 12px 20px; }
.tb-brand { font-size: 19px; font-weight: 800; letter-spacing: -.02em; display: flex; gap: 8px; align-items: baseline; }
.tb-brand span { color: #E9A182; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.tb-info { display: flex; flex-direction: column; line-height: 1.2; }
.tb-info b { font-size: 15px; }
.tb-info span { font-size: 12px; color: #B7A895; }
.tb-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.tb-user { font-size: 13px; color: #B7A895; margin-right: 4px; }
.tb-actions .btn { background: transparent; color: #EFE4D5; border-color: rgba(255,255,255,.25); }
.tb-actions .btn:hover { background: rgba(255,255,255,.08); }

.pane { padding: 20px; }
.pane.center { display: flex; justify-content: center; align-items: flex-start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; }
.open-card { width: min(440px, 100%); display: flex; flex-direction: column; gap: 14px; margin-top: 40px; }
.open-card h2 { margin: 0; }

/* Vente */
.sale { display: grid; grid-template-columns: 1fr 360px; gap: 18px; align-items: start; }
@media (max-width: 820px) { .sale { grid-template-columns: 1fr; } }
.col-left { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; min-height: 60vh; }
.scan { width: 100%; font-size: 20px; font-weight: 600; border: 2px solid var(--terra); border-radius: 12px; padding: 16px 18px;
  outline: none; margin-bottom: 14px; }
.scan:focus { box-shadow: 0 0 0 4px rgba(196,89,58,.14); }
.lines { display: flex; flex-direction: column; gap: 8px; }
.line { display: grid; grid-template-columns: 1fr auto; gap: 4px 14px; align-items: center; border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; }
.line .nm { font-weight: 700; }
.line .pu { font-size: 12.5px; color: var(--muted); }
.line .tot { font-size: 18px; font-weight: 800; text-align: right; }
.line-ctrl { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.qty { display: inline-flex; align-items: center; gap: 4px; }
.qty button { width: 38px; height: 38px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px;
  font-size: 20px; font-weight: 700; cursor: pointer; }
.qty b { min-width: 30px; text-align: center; font-size: 17px; }
.line-ctrl .rem { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.line-ctrl .rem input { width: 84px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; text-align: right; }
.line-ctrl .del { margin-left: auto; border: none; background: none; color: var(--red); font-size: 20px; cursor: pointer; }
.empty { text-align: center; color: var(--muted); padding: 50px 10px; }
.empty .big { font-size: 40px; margin-bottom: 8px; }

.col-right { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; position: sticky; top: 20px; }
.sum-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; font-size: 16px; }
.sum-row.muted { color: var(--muted); font-size: 14px; }
.sum-row.net { font-size: 22px; font-weight: 800; border-top: 1px solid var(--line); padding-top: 12px; margin-top: 4px; }
.resume { margin-top: 16px; font-size: 12.5px; color: var(--muted); line-height: 1.7; border-top: 1px dashed var(--line); padding-top: 12px; }

/* Modales */
.modal-bg { position: fixed; inset: 0; background: rgba(33,26,22,.5); display: none; align-items: center; justify-content: center;
  padding: 16px; z-index: 50; }
.modal-bg.show { display: flex; }
.modal { background: var(--surface); border-radius: 16px; padding: 24px; width: min(540px, 100%); max-height: 92vh; overflow: auto; }
.modal h2 { margin: 0 0 12px; }
.pay-head { font-size: 15px; color: var(--muted); margin-bottom: 12px; }
.pay-head b { color: var(--ink); }
.pay-rows { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.pay-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.pay-row b.m { min-width: 120px; }
.pay-row input { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font: inherit; }
.pay-row .rendu { font-size: 12.5px; color: var(--green); font-weight: 700; }
.pay-row .del { margin-left: auto; border: none; background: none; color: var(--red); font-size: 18px; cursor: pointer; }
.pay-add { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pay-add .btn { padding: 9px 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.modal-foot.wrap { flex-wrap: wrap; }

.ticket { font-size: 13px; line-height: 1.55; }
.ticket .center { text-align: center; }
.ticket .row { display: flex; justify-content: space-between; gap: 12px; }
.ticket .row.sub { font-size: 11px; color: var(--muted); }
.ticket .sep { border-top: 1px dashed #999; margin: 8px 0; }
.ticket .tot { font-weight: 800; font-size: 16px; }
.z-line { display: flex; justify-content: space-between; margin-bottom: 6px; }
.z-line.strong { font-weight: 800; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 6px; }
.z-line.ecart.bad { color: var(--red); }

.center { text-align: center; }
.linkbtn { border: none; background: none; color: var(--terra-d); font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; padding: 0; }

/* Menus déroulants (topbar) */
.menu { position: relative; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 16px 40px rgba(33,26,22,.18); min-width: 210px; overflow: hidden; z-index: 40; }
.menu-panel button { display: block; width: 100%; text-align: left; border: none; background: none; padding: 13px 16px;
  font: inherit; font-size: 14.5px; color: var(--ink); cursor: pointer; }
.menu-panel button:hover { background: var(--bg); }
.menu-panel button + button { border-top: 1px solid var(--line); }

/* Fond de caisse par dénominations */
.card.wide { width: min(760px, 100%); margin: 30px auto 0; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.denoms { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 16px 0; }
.denom { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.denom .val { min-width: 54px; font-weight: 700; }
.denom input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px; font: inherit; text-align: right; }
.denom .sub { min-width: 74px; text-align: right; font-size: 12.5px; color: var(--muted); }
.denoms-total { font-size: 18px; text-align: right; margin-bottom: 14px; }
.denoms-total b { font-size: 22px; }

/* Client */
.client-box { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; }
.fld-input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; font: inherit; font-size: 16px; margin-bottom: 10px; }
.cl-results { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow: auto; margin-bottom: 12px; }
.cl-item { display: flex; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; cursor: pointer; }
.cl-item:hover { border-color: var(--terra); background: var(--bg); }
.cl-item small { color: var(--muted); }
.cl-new { border-top: 1px dashed var(--line); padding-top: 12px; }
.cl-new-title { font-weight: 700; margin-bottom: 8px; }
.cl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.cl-grid input { border: 1px solid var(--line); border-radius: 8px; padding: 10px; font: inherit; }

/* Inventaire improvisé */
.inv-lines { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.inv-line { display: grid; grid-template-columns: 1fr auto auto auto; gap: 12px; align-items: center; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; }
.inv-line .nm { font-weight: 700; }
.inv-line .th { font-size: 12.5px; color: var(--muted); }
.inv-line input { width: 90px; border: 1px solid var(--line); border-radius: 8px; padding: 9px; font: inherit; text-align: right; }
.inv-line .ec { min-width: 70px; text-align: right; font-weight: 700; }
.inv-line .ec.bad { color: var(--red); }
.inv-line .ec.ok { color: var(--green); }

/* Règlement — vivant, icônes SVG, rendu monnaie */
.modal-pay { width: min(620px, 100%); }
.pay-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.pay-client { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.pay-client svg { width: 20px; height: 20px; color: var(--muted); }
.pay-figs { display: flex; gap: 10px; }
.fig { text-align: right; border: 1px solid var(--line); border-radius: 12px; padding: 8px 14px; min-width: 122px; }
.fig span { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.fig b { font-size: 22px; }
.fig.reste { transition: background .2s, border-color .2s, color .2s; }
.fig.reste.due { background: #FBEDE9; border-color: #E7BCB0; color: var(--red); }
.fig.reste.ok { background: #EAF3EC; border-color: #B9D8C0; color: var(--green); }

.pay-methods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 520px) { .pay-methods { grid-template-columns: 1fr 1fr; } }
.pm { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 8px; border: 1.5px solid var(--line);
  border-radius: 14px; background: var(--surface); cursor: pointer; font-weight: 700; font-size: 13px; transition: transform .12s, border-color .12s, background .12s; }
.pm svg { width: 26px; height: 26px; }
.pm span { color: var(--ink); }
.pm:hover { transform: translateY(-3px); }
.pm-especes { color: var(--green); } .pm-especes:hover { border-color: var(--green); background: #EAF3EC; }
.pm-cb { color: #345E86; } .pm-cb:hover { border-color: #345E86; background: #E9F0F7; }
.pm-carte { color: var(--terra-d); } .pm-carte:hover { border-color: var(--terra); background: #FBEDE9; }
.pm-avoir { color: #8A6D12; } .pm-avoir:hover { border-color: #B89523; background: #F7F1DF; }

.pay-rows { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.pay-row { display: flex; gap: 12px; align-items: flex-start; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: scale(.97); } }
.pr-ic { flex: none; width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; }
.pr-ic svg { width: 22px; height: 22px; }
.pr-ic.especes { background: #EAF3EC; color: var(--green); }
.pr-ic.cb { background: #E9F0F7; color: #345E86; }
.pr-ic.carte_cadeau { background: #FBEDE9; color: var(--terra-d); }
.pr-ic.avoir { background: #F7F1DF; color: #8A6D12; }
.pr-main { flex: 1; min-width: 0; }
.pr-name { font-weight: 700; margin-bottom: 6px; }
.pr-fields { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pr-fields label { font-size: 12px; color: var(--muted); }
.pr-fields input { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font: inherit; font-size: 15px; width: 110px; }
.pr-quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.pr-quick button { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 6px 11px; font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.pr-quick button:hover { border-color: var(--green); color: var(--green); }
.pr-rendu { margin-top: 8px; font-weight: 800; color: var(--green); font-size: 16px; }
.pr-rendu:empty { display: none; }
.pr-del { flex: none; border: none; background: none; color: var(--red); cursor: pointer; padding: 4px; }
.pr-del svg { width: 20px; height: 20px; }

/* Terminal de paiement plein écran (vraie caisse) */
.pos-overlay { position: fixed; inset: 0; background: var(--bg); display: none; z-index: 60; }
.pos-overlay.show { display: flex; }
.pos { display: grid; grid-template-columns: 1fr 400px; width: 100%; height: 100%; }
@media (max-width: 820px) { .pos { grid-template-columns: 1fr; grid-template-rows: auto auto; overflow: auto; } }
.pos-left { padding: clamp(16px, 3vw, 32px); display: flex; flex-direction: column; min-width: 0; }
.pos-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.pos-head .pay-client { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.pos-head .pay-client svg { width: 20px; height: 20px; color: var(--muted); }
.pos-x { border: 1px solid var(--line); background: var(--surface); width: 42px; height: 42px; border-radius: 10px; font-size: 18px; cursor: pointer; }
.pos-figs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.pos-figs .fig { text-align: left; padding: 14px 18px; min-width: 0; }
.pos-figs .fig b { font-size: 30px; display: block; margin-top: 2px; }
.pos-list { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; min-height: 80px; }
.pos-hint { color: var(--muted); font-size: 14px; padding: 22px; text-align: center; border: 1px dashed var(--line); border-radius: 12px; }
.pos-item { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; animation: pop .18s ease; }
.pi-main { flex: 1; min-width: 0; }
.pi-name { font-weight: 700; }
.pi-ref { margin-top: 6px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; width: 100%; max-width: 240px; }
.pi-rendu { margin-top: 4px; color: var(--green); font-weight: 800; }
.pi-amt { font-size: 20px; font-weight: 800; white-space: nowrap; }
.pos-left #p-valid { margin-top: 14px; }

.pos-right { background: var(--slate); padding: clamp(14px, 2vw, 22px); display: flex; flex-direction: column; gap: 12px; }
.pos-display { background: #fff; border-radius: 14px; padding: 18px 22px; text-align: right; font-size: clamp(32px, 5vw, 42px);
  font-weight: 800; color: var(--ink); letter-spacing: -.02em; }
.pos-display.placeholder { color: #B9AE9E; }
.pos-quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pos-quick button { background: rgba(255,255,255,.10); color: #F0E4D2; border: 1px solid rgba(255,255,255,.16); border-radius: 10px;
  padding: 13px 6px; font: inherit; font-weight: 700; font-size: 15px; cursor: pointer; }
.pos-quick button:hover { background: rgba(255,255,255,.2); }
.pos-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; flex: 1; }
.pos-pad button { background: #fff; border: none; border-radius: 12px; font-size: 24px; font-weight: 700; color: var(--ink); cursor: pointer; min-height: 58px; }
.pos-pad button:hover { filter: brightness(.94); }
.pos-pad button:active { transform: scale(.97); }
.pos-pad .k-fn { background: #EFE1CE; }
.pos-methods { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.pos-methods .pm { background: #fff; border-radius: 12px; padding: 12px 6px; }

.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px;
  align-items: center; z-index: 90; }
.toast { background: var(--slate); color: #F0E4D2; padding: 12px 20px; border-radius: 10px; font-weight: 600; font-size: 14px;
  animation: tin .2s; }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }
