/* ==========================================================================
   PK BUSINESS SUITE — Feuille de style principale (Bootstrap 5.3 + surcouche)
   Charte : bleu royal #0b57d0, marine #0a1f44, or #e3a21a (issus du logo)
   Thème de l'entreprise : core/brand.js remplace --ks-primary, --ks-primary-rgb, --ks-primary-dark et
   --ks-accent ; toutes les autres teintes en dérivent (bloc @supports ci-dessous).
   ========================================================================== */
:root {
  --ks-primary: #0b57d0;
  --ks-primary-rgb: 11, 87, 208;
  --ks-primary-dark: #0a1f44;
  --ks-accent: #e3a21a;
  --ks-accent-dark: #b7790c;
  /* Teintes dérivées (valeurs de la charte PK pour les navigateurs sans color-mix) */
  --ks-primary-hover: #0947b0;
  --ks-primary-darker: #071733;
  --ks-primary-soft: #dbe8ff;
  --ks-nav-active: rgba(56, 142, 255, .22);
  --ks-side-text: #d6e2f7;
  --ks-side-muted: #9fb6dc;
  --ks-side-dim: #7f93b8;
  --ks-ico-dark-bg: #13306b;
  --ks-ico-dark-fg: #93c5fd;
  --ks-bg: #f3f6fb;
  --ks-card: #ffffff;
  --ks-border: #e5e7eb;
  --ks-muted: #6b7280;
  --ks-sidebar-w: 256px;
  --ks-radius: 14px;
  --ks-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --bs-primary: var(--ks-primary);
  --bs-primary-rgb: var(--ks-primary-rgb);
  --bs-link-color: var(--ks-primary);
  --bs-link-color-rgb: var(--ks-primary-rgb);
  --bs-link-hover-color: var(--ks-primary-dark);
  --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --bs-border-radius: .6rem;
}
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root {
    --ks-accent-dark: color-mix(in srgb, var(--ks-accent) 80%, #000);
    --ks-primary-hover: color-mix(in srgb, var(--ks-primary) 86%, #000);
    --ks-primary-darker: color-mix(in srgb, var(--ks-primary-dark) 72%, #000);
    --ks-primary-soft: color-mix(in srgb, var(--ks-primary) 15%, #fff);
    --ks-nav-active: color-mix(in srgb, var(--ks-primary) 45%, transparent);
    --ks-side-text: color-mix(in srgb, var(--ks-primary) 16%, #fff);
    --ks-side-muted: color-mix(in srgb, var(--ks-primary) 40%, #fff);
    --ks-side-dim: color-mix(in srgb, var(--ks-side-text) 55%, var(--ks-primary-dark));
    --ks-ico-dark-bg: color-mix(in srgb, var(--ks-primary) 38%, #0a1224);
    --ks-ico-dark-fg: color-mix(in srgb, var(--ks-primary) 40%, #fff);
  }
}
[data-bs-theme="dark"] {
  --ks-bg: #0a1224;
  --ks-card: #101a33;
  --ks-border: #1e2a47;
  --ks-muted: #9aa6bf;
  --ks-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}

html, body { height: 100%; }
body { background: var(--ks-bg); font-size: .925rem; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
iconify-icon { display: inline-block; width: 1.15em; height: 1.15em; vertical-align: -0.2em; }

.btn-primary {
  --bs-btn-bg: var(--ks-primary); --bs-btn-border-color: var(--ks-primary);
  --bs-btn-hover-bg: var(--ks-primary-hover); --bs-btn-hover-border-color: var(--ks-primary-hover);
  --bs-btn-active-bg: var(--ks-primary-dark); --bs-btn-active-border-color: var(--ks-primary-dark);
  --bs-btn-disabled-bg: var(--ks-primary); --bs-btn-disabled-border-color: var(--ks-primary);
}
.btn-outline-primary {
  --bs-btn-color: var(--ks-primary); --bs-btn-border-color: var(--ks-primary);
  --bs-btn-hover-bg: var(--ks-primary); --bs-btn-hover-border-color: var(--ks-primary);
  --bs-btn-active-bg: var(--ks-primary-dark); --bs-btn-active-border-color: var(--ks-primary-dark);
}
.text-primary { color: var(--ks-primary) !important; }
.bg-primary { background-color: var(--ks-primary) !important; }
.form-control:focus, .form-select:focus, .form-check-input:focus {
  border-color: rgba(var(--ks-primary-rgb), .5); box-shadow: 0 0 0 .2rem rgba(var(--ks-primary-rgb), .15);
}
.form-check-input:checked { background-color: var(--ks-primary); border-color: var(--ks-primary); }
.form-label { font-weight: 500; font-size: .85rem; margin-bottom: .3rem; }
.required::after { content: ' *'; color: #dc2626; }
.text-uppercase::placeholder { text-transform: none; }

/* ------------------------------- Démarrage ------------------------------- */
.boot { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; background: var(--ks-bg); z-index: 2000; }
.boot img { max-width: 60vw; height: auto; }
[data-bs-theme="dark"] .boot img { background: #fff; border-radius: 16px; padding: 10px; }

/* ------------------------------- Authentification ------------------------------- */
.auth-view { min-height: 100vh; display: grid; grid-template-columns: 1fr; }
@media (min-width: 992px) { .auth-view { grid-template-columns: 1.05fr 1fr; } }
.auth-hero {
  display: none; position: relative; overflow: hidden; color: #eef4ff; padding: 56px;
  background: radial-gradient(circle at 18% 18%, rgba(56, 142, 255, .40), transparent 45%),
              radial-gradient(circle at 85% 85%, rgba(227, 162, 26, .30), transparent 40%),
              linear-gradient(135deg, #0a1f44 0%, #0b2f6b 55%, #0a1f44 100%);
}
@media (min-width: 992px) { .auth-hero { display: flex; flex-direction: column; justify-content: space-between; } }
.auth-hero h1 { font-weight: 800; font-size: 2.3rem; line-height: 1.15; }
.auth-hero .feature { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 14px; }
.auth-hero .feature iconify-icon { font-size: 1.4rem; color: #f5c451; flex-shrink: 0; }
.tagline { font-weight: 800; font-size: 1.25rem; letter-spacing: .01em; }
.tagline .t1 { color: #7fb6ff; } .tagline .t2 { color: #ffffff; } .tagline .t3 { color: #f5c451; }
.brand-chip { background: #fff; border-radius: 10px; padding: 4px 6px; display: inline-flex; box-shadow: 0 2px 8px rgba(0, 0, 0, .15); }
.brand-chip img { width: auto !important; height: 28px !important; }
.auth-logo { width: 240px; max-width: 70%; height: auto; }
[data-bs-theme="dark"] .auth-logo { background: #fff; border-radius: 16px; padding: 8px; }
.auth-panel { display: flex; align-items: center; justify-content: center; padding: 32px 16px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .card { border: 1px solid var(--ks-border); border-radius: 18px; box-shadow: 0 10px 30px rgba(10, 31, 68, .10); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .04em; }
.brand img { width: 36px; height: 36px; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--ks-muted); font-size: .8rem; margin: 18px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--ks-border); }
.grecaptcha-badge { visibility: hidden !important; }
.recaptcha-note { font-size: .72rem; color: var(--ks-muted); }
.pwd-toggle { cursor: pointer; }
#google-btn { min-height: 44px; display: flex; justify-content: center; }

/* ------------------------------- Structure de l'application ------------------------------- */
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; width: var(--ks-sidebar-w); z-index: 1040;
  background: linear-gradient(180deg, var(--ks-primary-dark) 0%, var(--ks-primary-darker) 100%); color: var(--ks-side-text); display: flex; flex-direction: column;
}
.sidebar .brand { color: #fff; padding: 16px 16px; border-bottom: 1px solid rgba(255, 255, 255, .08); font-size: .85rem; }
.sidebar .brand img { width: 64px; height: auto; background: #fff; border-radius: 10px; padding: 4px 5px; flex-shrink: 0; }
.sidebar .brand img.brand-logo { width: auto; height: auto; max-width: 76px; max-height: 44px; object-fit: contain; }
.sidebar .brand-name { overflow-wrap: anywhere; letter-spacing: .01em; }
.sidebar .biz { font-size: .72rem; color: var(--ks-side-muted); font-weight: 500; letter-spacing: 0; }
.sidebar nav { overflow-y: auto; padding: 10px 12px 20px; flex: 1; }
.nav-group { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ks-side-dim); margin: 16px 10px 6px; font-weight: 600; }
.sidebar .nav-link {
  display: flex; align-items: center; gap: 10px; color: var(--ks-side-text); border-radius: 10px; padding: 8px 12px; font-weight: 500;
}
.sidebar .nav-link iconify-icon { font-size: 1.2rem; opacity: .9; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar .nav-link.active { background: var(--ks-nav-active); color: #fff; box-shadow: inset 3px 0 0 var(--ks-accent); }
.sidebar .nav-link .badge { margin-left: auto; }
.sidebar-foot { padding: 12px 20px; font-size: .7rem; color: var(--ks-side-dim); border-top: 1px solid rgba(255, 255, 255, .08); }

.main { margin-left: var(--ks-sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 1030; background: color-mix(in srgb, var(--ks-card) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--ks-border); padding: 10px 24px;
  display: flex; align-items: center; gap: 12px; min-height: 60px;
}
.topbar h1 { font-size: 1.1rem; font-weight: 700; margin: 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar > .ms-auto { flex-shrink: 0; }
/* Téléphone : titre abrégé, boutons compacts ; le menu du compte (profil, déconnexion) reste dans l'écran. */
@media (max-width: 575.98px) {
  .topbar { gap: 6px; padding: 8px 10px; }
  .topbar > .ms-auto { gap: 4px !important; }
  .topbar .btn { padding: .3rem .45rem; }
  .topbar h1 { font-size: 1rem; }
  #tenant-zone .badge { font-size: .68rem; padding: .3em .45em; }
}
.content { padding: 24px; flex: 1; }
.backdrop { display: none; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .backdrop.open { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 1035; }
  .content { padding: 16px; }
  .topbar { padding: 10px 16px; }
}

/* ------------------------------- Composants ------------------------------- */
.card { border: 1px solid var(--ks-border); border-radius: var(--ks-radius); box-shadow: var(--ks-shadow); background: var(--ks-card); }
.card-header { background: transparent; border-bottom: 1px solid var(--ks-border); font-weight: 600; padding: 14px 18px; }
.card-body { padding: 18px; }
.kpi { display: flex; gap: 14px; align-items: center; }
.kpi .ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 1.35rem; flex-shrink: 0; }
.kpi .label { color: var(--ks-muted); font-size: .78rem; font-weight: 500; }
.kpi .value { font-size: 1.3rem; font-weight: 700; line-height: 1.2; }
.kpi .sub { font-size: .75rem; color: var(--ks-muted); }
.ico-teal { background: var(--ks-primary-soft); color: var(--ks-primary); }
.ico-amber { background: #fef3c7; color: #b45309; }
.ico-blue { background: #dbeafe; color: #1d4ed8; }
.ico-rose { background: #ffe4e6; color: #be123c; }
.ico-violet { background: #ede9fe; color: #6d28d9; }
[data-bs-theme="dark"] .ico-teal { background: var(--ks-ico-dark-bg); color: var(--ks-ico-dark-fg); }
[data-bs-theme="dark"] .ico-amber { background: #451a03; color: #fbbf24; }
[data-bs-theme="dark"] .ico-blue { background: #172554; color: #93c5fd; }
[data-bs-theme="dark"] .ico-rose { background: #4c0519; color: #fda4af; }
[data-bs-theme="dark"] .ico-violet { background: #2e1065; color: #c4b5fd; }

.table { --bs-table-bg: transparent; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .6rem .75rem; }
.table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ks-muted); font-weight: 600; white-space: nowrap; background: color-mix(in srgb, var(--ks-bg) 70%, transparent); }
.table-hover tbody tr { cursor: default; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 36px 16px; color: var(--ks-muted); }
.empty iconify-icon { font-size: 2.4rem; opacity: .5; display: block; margin: 0 auto 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.toolbar .search { min-width: 200px; flex: 1; max-width: 360px; }
.badge-soft { font-weight: 600; padding: .35em .6em; border-radius: 999px; font-size: .72rem; }
.bs-teal { background: #ccfbf1; color: #115e59; }
.bs-amber { background: #fef3c7; color: #92400e; }
.bs-rose { background: #ffe4e6; color: #9f1239; }
.bs-gray { background: #e5e7eb; color: #374151; }
.bs-blue { background: #dbeafe; color: #1e40af; }
[data-bs-theme="dark"] .bs-teal { background: #134e4a; color: #99f6e4; }
[data-bs-theme="dark"] .bs-amber { background: #451a03; color: #fde68a; }
[data-bs-theme="dark"] .bs-rose { background: #4c0519; color: #fecdd3; }
[data-bs-theme="dark"] .bs-gray { background: #374151; color: #e5e7eb; }
[data-bs-theme="dark"] .bs-blue { background: #172554; color: #bfdbfe; }
.muted { color: var(--ks-muted); }
.small-muted { color: var(--ks-muted); font-size: .8rem; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.clickable { cursor: pointer; }
.chart-box { position: relative; height: 280px; }

/* ------------------------------- Caisse (POS) ------------------------------- */
.pos { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 1200px) { .pos { grid-template-columns: 1fr 400px; } }
.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; max-height: calc(100vh - 250px); overflow-y: auto; padding: 2px; }
@media (max-width: 1199.98px) { .pos-grid { max-height: 420px; } }
.pos-item {
  border: 1px solid var(--ks-border); border-radius: 12px; padding: 12px; background: var(--ks-card); text-align: left;
  transition: border-color .15s, transform .05s; display: flex; flex-direction: column; gap: 4px; min-height: 104px;
}
.pos-item:hover { border-color: var(--ks-primary); }
.pos-item:active { transform: scale(.98); }
.pos-item .name { font-weight: 600; font-size: .85rem; line-height: 1.25; }
.pos-item .price { color: var(--ks-primary); font-weight: 700; margin-top: auto; }
.pos-item.out { opacity: .55; }
.cart { position: sticky; top: 76px; }
.cart-lines { max-height: 340px; overflow-y: auto; }
.cart-line { display: grid; grid-template-columns: 1fr auto; gap: 6px; padding: 10px 0; border-bottom: 1px dashed var(--ks-border); }
.qty-ctl { display: inline-flex; align-items: center; border: 1px solid var(--ks-border); border-radius: 8px; overflow: hidden; }
.qty-ctl button { border: 0; background: transparent; width: 30px; height: 30px; }
.qty-ctl input { width: 58px; border: 0; text-align: center; background: transparent; height: 30px; }
.total-big { font-size: 1.6rem; font-weight: 800; }
.pay-methods .btn { flex: 1 1 30%; font-size: .78rem; }

/* Barre de caisse mobile : total toujours visible, accès direct au panier */
.pos-mobile-bar { display: none; }
@media (max-width: 1199.98px) {
  .pos-mobile-bar {
    display: flex; align-items: center; gap: 12px; position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 1020;
    background: var(--ks-primary-dark); color: #fff; border-radius: 14px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  }
  .pos-mobile-bar .t { font-weight: 800; font-size: 1.1rem; }
  .pos { padding-bottom: 72px; }
}

/* Notifications sous la barre supérieure (ne masquent pas le menu utilisateur) */
#toasts { top: 64px !important; z-index: 1090; }
@media (max-width: 575.98px) { #toasts { left: 0; right: 0; } #toasts .toast { width: 100%; } }

/* ------------------------------- Rôles ------------------------------- */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 18px; }

/* ------------------------------- Impression thermique (rouleau 58 / 80 mm) -------------------------------
   Zone imprimable : 72 mm (rouleau 80) ou 48 mm (rouleau 58), fixée par --print-w au moment d'imprimer.
   Seul #print-area est rendu : le reste de la page est retiré du flux (pas de papier blanc gaspillé). */
#print-area { display: none; }
@media print {
  @page { margin: 0; }
  html, body { height: auto !important; min-height: 0 !important; overflow: visible !important; background: #fff !important; }
  body > :not(#print-area) { display: none !important; }
  #print-area { display: block !important; width: var(--print-w, 72mm); margin: 0; padding: 0; color: #000; }
  .print-block { break-inside: avoid; }
  .print-block.break { break-before: page; }
  #print-area .receipt, #print-area .pk-label { width: 100%; margin: 0; padding: 1mm 0 3mm; box-shadow: none; }
  #print-area .receipt.w58 { font-size: 10.5px; }
}

.receipt { width: 72mm; max-width: 100%; margin: 0 auto; padding: 10px; background: #fff; color: #000;
  font-family: 'Courier New', Courier, monospace; font-size: 12px; line-height: 1.3; }
.receipt.w58 { width: 48mm; font-size: 11px; }
.receipt .c { text-align: center; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 5px 0; opacity: 1; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt td { padding: 1px 0; vertical-align: top; }
.receipt .r { text-align: right; white-space: nowrap; padding-left: 4px; }
.receipt .tot td { font-weight: bold; font-size: 1.2em; padding-top: 3px; }
.receipt .r-logo { display: block; margin: 0 auto 4px; width: auto; height: auto; max-width: 60%; max-height: 26mm; filter: grayscale(1) contrast(1.15); } /* rendu proche de l'impression thermique (noir et blanc) */
.receipt.w58 .r-logo { max-width: 70%; max-height: 20mm; }
.receipt .r-biz { font-size: 1.15em; text-transform: uppercase; }
.receipt .r-qr { margin: 4px 0; }
.receipt .r-bar .barcode { display: block; width: 100%; max-width: 56mm; height: 10mm; margin: 4px auto 0; }
.receipt .r-qr svg { display: inline-block; }
.receipt .r-brand { margin-top: 4px; font-size: .8em; letter-spacing: .08em; }
/* Ticket-facture : titre, mention d'essai, montant en lettres, zone de signature */
.receipt .r-title { font-size: 1.35em; font-weight: bold; letter-spacing: .25em; margin: 2px 0 4px; }
.receipt .r-mark { border: 1px dashed #000; font-weight: bold; letter-spacing: .12em; padding: 2px 4px; margin: 5px 0; }
.receipt .r-words { font-size: .9em; margin: 2px 0 4px; }
.receipt .r-sign { margin: 8px 0 6px; height: 16mm; border: 1px solid #000; padding: 2px 4px; font-size: .85em; }
.receipt .r-legal { font-size: .72em; margin-top: 4px; line-height: 1.25; }

/* Étiquette produit : nom, prix, code-barres Code 128 (classe distincte de .kpi .label) */
.pk-label { width: 72mm; margin: 0 auto; padding: 6px 4px; background: #fff; color: #000; text-align: center; font-family: Arial, Helvetica, sans-serif; }
.pk-label.w58 { width: 48mm; }
.pk-label .l-name { font-weight: 700; font-size: 12px; line-height: 1.2; max-height: 2.4em; overflow: hidden; }
.pk-label .l-price { font-weight: 800; font-size: 16px; margin: 2px 0; }
.pk-label .barcode { display: block; width: 100%; max-width: 60mm; height: 12mm; margin: 2px auto 0; } /* hauteur fixe : lecture fiable à la douchette */
.pk-label .l-code { font-family: 'Courier New', Courier, monospace; font-size: 11px; letter-spacing: .12em; }
.label-preview { background: #f3f4f6; border-radius: 12px; padding: 12px; }
.label-preview .pk-label { border: 1px dashed #9ca3af; }

/* ------------------------------- Paramètres : logo et thème ------------------------------- */
.logo-box { width: 140px; height: 96px; border: 1px dashed var(--ks-border); border-radius: 12px; display: grid; place-items: center;
  background: #fff repeating-conic-gradient(#f3f4f6 0 25%, #fff 0 50%) 0 0 / 16px 16px; flex-shrink: 0; overflow: hidden; }
.logo-box img { max-width: 124px; max-height: 80px; object-fit: contain; }
.logo-box iconify-icon { font-size: 2rem; color: #9ca3af; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.theme-chip { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 1px solid var(--ks-border); border-radius: 10px;
  padding: 7px 9px; font-size: .8rem; font-weight: 500; background: var(--ks-card); }
.btn-check:checked + .theme-chip { border-color: var(--ks-primary); box-shadow: 0 0 0 2px rgba(var(--ks-primary-rgb), .35); }
.btn-check:focus-visible + .theme-chip { outline: 2px solid var(--ks-primary); outline-offset: 2px; }
.theme-chip .sw { width: 26px; height: 26px; border-radius: 8px; flex-shrink: 0; border: 1px solid rgba(0, 0, 0, .08); }
.theme-custom { display: flex; align-items: center; gap: 8px; }
.theme-custom .form-control-color { width: 46px; height: 38px; padding: 4px; }

/* Fonction réservée aux abonnés : contenu visible (aperçu de la valeur) mais inactif */
.premium-locked .brand-fields { opacity: .55; }
.premium-locked .brand-fields .theme-chip { cursor: not-allowed; }
.sidebar .nav-link .nav-lock { margin-left: auto; color: var(--ks-accent); font-size: .85rem; display: inline-flex; }
.sidebar .nav-link .nav-lock + .badge { margin-left: 6px; }
/* Hors connexion : pages qui exigent le serveur (seule la caisse reste active) */
.sidebar .nav-link.nav-off { opacity: .45; }
#net-zone { display: inline-flex; align-items: center; gap: 6px; }
#net-zone:empty { display: none; }
