/* =====================================================================
 *  Interface — recu.grostech.ma
 * ===================================================================== */
:root {
  --bg: #f4f6fa; --card: #fff; --text: #1d2433; --muted: #6b7385; --line: #e2e6ee;
  --primary: #1d4ed8; --primary-d: #1e3a8a; --danger: #c62828; --ok: #1b7f3b; --warn: #b26a00;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--primary); }
h1 { font-size: 1.5rem; margin: .2em 0 .8em; }
.muted { color: var(--muted); } .small { font-size: .85em; } .center { text-align: center; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Barre du haut */
.topbar { background: #0f172a; color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; min-height: 56px; position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.brand small { color: #93a3c4; font-weight: 400; font-size: .75rem; letter-spacing: .08em; }
.brand-mark { background: var(--primary); width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.mainnav { display: flex; gap: 4px; align-items: center; }
.mainnav a, .linklike { color: #cbd5e1; text-decoration: none; padding: 8px 12px; border-radius: 8px; background: none; border: 0; font: inherit; cursor: pointer; }
.mainnav a:hover, .linklike:hover, .mainnav a.active { background: #1e293b; color: #fff; }
.menu-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.5rem; cursor: pointer; }
form.inline { display: inline; margin: 0; }

.container { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.container.wide { max-width: 1400px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }

/* Formulaires */
label { display: block; margin-bottom: 12px; font-weight: 600; font-size: .92rem; }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=date], input[type=file], select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px; border: 1px solid #cdd3df; border-radius: 8px; font: inherit; font-weight: 400; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #93b4ff; border-color: var(--primary); }
input.invalid { border-color: var(--danger); background: #fff5f5; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; margin: 0; }
.input-prefix { display: flex; align-items: stretch; margin-top: 4px; }
.input-prefix span { background: #eef1f6; border: 1px solid #cdd3df; border-right: 0; border-radius: 8px 0 0 8px; padding: 10px; font-weight: 400; color: var(--muted); white-space: nowrap; }
.input-prefix input { margin-top: 0; border-radius: 0 8px 8px 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 8px; border: 1px solid #cdd3df; background: #fff; color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f1f4f9; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-lg { padding: 12px 20px; font-size: 1.05rem; }
.btn-sm { padding: 5px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .6; cursor: wait; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.1rem; cursor: pointer; padding: 6px; }
.icon-btn:hover { color: var(--danger); }

.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-ok { background: #ecf8f0; border-color: #a6dbb7; color: var(--ok); }
.alert-error { background: #fdeeee; border-color: #f2b8b8; color: var(--danger); }
.big-msg { font-size: 1.3rem; text-align: center; font-weight: 700; padding: 30px; }

/* Auth & accueil */
.auth-box { max-width: 440px; margin: 30px auto; padding: 24px; }
.hero { text-align: center; padding: 40px 0 20px; }
.hero h1 { font-size: 2rem; }
.hero p { color: var(--muted); max-width: 620px; margin: 0 auto 20px; }
.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; margin-top: 30px; }
.store-logo { max-width: 140px; max-height: 100px; }
.stack > * { margin-bottom: 10px; }

/* Vente */
.sale { display: grid; grid-template-columns: 1fr 330px; gap: 16px; align-items: start; }
.sale-side { position: sticky; top: 72px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 12px; }
.seg-item { margin: 0; }
.seg-item input { position: absolute; opacity: 0; pointer-events: none; }
.seg-item span { display: block; text-align: center; padding: 10px 6px; border: 1px solid #cdd3df; border-radius: 8px; cursor: pointer; }
.seg-item span small { display: block; color: var(--muted); font-weight: 400; }
.seg-item input:checked + span { background: var(--primary); border-color: var(--primary); color: #fff; }
.seg-item input:checked + span small { color: #dbe5ff; }
.seg-item input:focus-visible + span { outline: 2px solid #93b4ff; }
.bl-only { display: none; }
.sale.is-bl .bl-only { display: flex; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
table.lines { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
table.lines th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; padding: 4px; }
table.lines th.num { text-align: right; }
table.lines td { padding: 4px; vertical-align: middle; }
table.lines td input { margin: 0; }
table.lines td:nth-child(2) { width: 110px; } table.lines td:nth-child(3) { width: 80px; }
table.lines td:nth-child(4) { width: 100px; font-weight: 600; } table.lines td:nth-child(5) { width: 34px; }
.tot-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.tot-row.grand { font-size: 1.35rem; border-bottom: 2px solid var(--text); margin: 6px 0 12px; }
.tot-row.due, .due { color: var(--danger); }
.discount { padding: 6px 0; }
.discount-inputs { display: grid; grid-template-columns: 1fr 80px; gap: 6px; }
.discount-inputs input, .discount-inputs select { margin-top: 4px; }
.paid { margin-top: 10px; }
input.big { font-size: 1.3rem; padding: 12px; }

/* Historique & tableaux */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters input, .filters select { width: auto; margin: 0; }
.filters .search-scan { display: flex; gap: 6px; flex: 1 1 320px; }
.filters .search-scan input { flex: 1; }
.inline-label { display: flex; align-items: center; gap: 6px; margin: 0; font-weight: 500; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.table th { background: #f8fafc; font-size: .82rem; color: var(--muted); }
.table th.num, .table td.num { text-align: right; }
.actions-cell { white-space: nowrap; }
.badge { display: inline-block; font-size: .72rem; padding: 2px 8px; border-radius: 99px; background: #eef1f6; color: #3c465a; font-weight: 600; }
.badge-pending { background: #fff4e0; color: var(--warn); } .badge-active { background: #e6f6ec; color: var(--ok); } .badge-disabled { background: #fdeeee; color: var(--danger); }
.badge-type-F { background: #e8efff; color: var(--primary); } .badge-type-BL { background: #f3e8ff; color: #7c3aed; }
.pager { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.pager a { padding: 6px 11px; border: 1px solid var(--line); border-radius: 6px; background: #fff; text-decoration: none; }
.pager a.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.stats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; text-decoration: none; color: var(--text); }
.stat.on { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.sub-form { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.sub-form select, .sub-form input { width: auto; margin: 0; padding: 5px 6px; font-size: .85rem; }

/* Paramètres */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.settings-grid fieldset { margin: 0; }
.settings-grid legend { font-weight: 700; padding: 0 6px; }
.form-actions { grid-column: 1 / -1; }
.logo-preview { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; }
.logo-preview img { max-height: 70px; max-width: 160px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; }
.font-sample { padding: 10px; border: 1px dashed var(--line); border-radius: 8px; margin: -4px 0 12px; font-size: 1.05rem; }
.help { color: var(--muted); font-size: .88rem; padding-left: 18px; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 500; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.slider { width: 46px; height: 26px; background: #cbd2dd; border-radius: 99px; position: relative; flex: none; transition: .2s; }
.slider::after { content: ""; position: absolute; width: 20px; height: 20px; top: 3px; left: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::after { left: 23px; }
.switch input:focus-visible + .slider { outline: 2px solid #93b4ff; }

/* Fiche document */
.doc-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.center-bar { justify-content: center; margin: 10px 0 16px; }
.print-status { background: #eef4ff; border: 1px solid #c4d5ff; color: var(--primary-d); padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.print-status.error { background: #fdeeee; border-color: #f2b8b8; color: var(--danger); }
.doc-stage { overflow-x: auto; padding: 16px 0; display: flex; justify-content: center; }

/* Modale scan */
.modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .7); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 12px; width: min(480px, 100%); padding: 14px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
#scan-reader { width: 100%; min-height: 240px; background: #000; border-radius: 8px; overflow: hidden; }

/* Responsive */
@media (max-width: 860px) {
  .sale { grid-template-columns: 1fr; }
  .sale-side { position: static; }
}
@media (max-width: 700px) {
  .menu-toggle { display: block; }
  .mainnav { display: none; width: 100%; flex-direction: column; align-items: stretch; padding-bottom: 10px; }
  .mainnav.open { display: flex; }
  .topbar .mainnav.open { flex-direction: row; width: auto; padding: 0; }
  .topbar .menu-toggle + .mainnav.open { flex-direction: column; width: 100%; padding-bottom: 10px; }
  .grid-2 { grid-template-columns: 1fr; }
  h1 { font-size: 1.3rem; }
  table.lines thead { display: none; }
  table.lines tr.line { display: grid; grid-template-columns: 1fr 1fr 34px; gap: 4px; padding: 8px 0; border-bottom: 1px solid var(--line); }
  table.lines tr.line td:nth-child(1) { grid-column: 1 / 3; }
  table.lines tr.line td:nth-child(2), table.lines tr.line td:nth-child(3), table.lines tr.line td:nth-child(4) { width: auto; }
  table.lines tr.line td:nth-child(4) { grid-column: 1 / 3; text-align: right; }
  table.lines tr.line td:nth-child(5) { grid-column: 3; grid-row: 1; }
  .table thead { display: none; }
  .table tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .table td { display: flex; justify-content: space-between; gap: 10px; border: 0; padding: 4px 10px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; text-align: left; }
  .table td.num { text-align: right; }
  .filters > * { flex: 1 1 100%; }
  .filters input, .filters select { width: 100%; }
}

@media print {
  .no-print, .topbar, .alert { display: none !important; }
  body, .container { background: #fff; padding: 0; margin: 0; max-width: none; }
  .doc-stage { padding: 0; display: block; overflow: visible; }
}
