/* ============================================================
   Aoua Designs ERP — Design system
   Palette carried over from the Burkina Cajou POS app per the
   client's request, adapted to Aoua Designs branding.
   ============================================================ */
:root {
  --brun: #7A3B12;
  --brun-fonce: #4E2509;
  --or: #D4A017;
  --or-clair: #F2D492;
  --fond: #F7F3EC;
  --carte: #FFFFFF;
  --texte: #2B2118;
  --texte-clair: #7A7168;
  --bordure: #E4DACB;
  --vert: #2E7D32;
  --rouge: #C62828;
  --bleu: #1565C0;
  --orange: #E67E22;
  --rayon: 12px;
  --rayon-sm: 7px;
  --ombre: 0 2px 10px rgba(78, 37, 9, 0.08);
  --nav-w: 235px;
  --nav-w-collapsed: 68px;
  --topbar-h: 60px;
  --mobilenav-h: 60px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--fond); color: var(--texte);
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px; -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: inherit; }

/* ---------- App shell ---------- */
#appShell { display: none; min-height: 100vh; }
#appShell.visible { display: block; }

#sideNav {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--nav-w);
  background: var(--brun-fonce); color: #f1e9dc; z-index: 40;
  display: flex; flex-direction: column; transition: width .18s ease;
  overflow-y: auto;
  scrollbar-color: #D9C6AD var(--brun-fonce); /* nude thumb on the dark nav track (Firefox) */
  scrollbar-width: thin;
}
#sideNav::-webkit-scrollbar { width: 8px; }
#sideNav::-webkit-scrollbar-track { background: var(--brun-fonce); }
#sideNav::-webkit-scrollbar-thumb { background: #D9C6AD; border-radius: 4px; }
#sideNav::-webkit-scrollbar-thumb:hover { background: #E8D9C3; }
#logoBar { padding: 20px 18px 14px; font-size: 17px; font-weight: 700; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.12); display: flex; align-items: center; gap: 10px; }
.navLink { display: flex; align-items: center; gap: 10px; padding: 10px 20px; font-size: 13.3px;
  color: #d9cdb9; text-decoration: none; border-left: 3px solid transparent; cursor: pointer; }
.navLink:hover { background: rgba(255,255,255,.06); color: #fff; }
.navLink.active { background: rgba(212,160,23,.16); border-left-color: var(--or); color: #fff; font-weight: 600; }
.navGroupLabel { padding: 16px 20px 4px; font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: #a89377; }
#footBar { margin-top: auto; padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: 12.5px; }
#footBar .userName { font-weight: 600; color: #fff; }
/* .btn-outline defaults to dark brown text/border, meant for light
   backgrounds — invisible on this dark sidebar without an override. */
#footBar .btn-outline { color: #fff; border-color: rgba(255,255,255,.5); }
#footBar .btn-outline:hover { background: rgba(255,255,255,.1); }

#mainArea { margin-left: var(--nav-w); min-height: 100vh; display: flex; flex-direction: column; transition: margin-left .18s ease; }
#topBar { height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; background: var(--carte); border-bottom: 1px solid var(--bordure); position: sticky; top: 0; z-index: 30; }
#pageContainer { flex: 1; padding: 20px; }
.page { display: none; }
.page.active { display: block; }

/* ---------- Cards / stat tiles ---------- */
.card { background: var(--carte); border: 1px solid var(--bordure); border-radius: var(--rayon); box-shadow: var(--ombre); padding: 18px; }
.statGrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.statTile { background: var(--carte); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 16px 18px; }
.statTile .label { font-size: 11.5px; color: var(--texte-clair); text-transform: uppercase; letter-spacing: .05em; }
.statTile .value { font-size: 24px; font-weight: 700; margin-top: 4px; color: var(--brun-fonce); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: none; border-radius: var(--rayon-sm);
  padding: 10px 16px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.btn-principal { background: var(--brun); color: #fff; }
.btn-or { background: var(--or); color: #3a2c00; }
.btn-vert { background: var(--vert); color: #fff; }
.btn-rouge { background: var(--rouge); color: #fff; }
.btn-bleu { background: var(--bleu); color: #fff; }
.btn-outline { background: transparent; color: var(--brun); border: 1px solid var(--brun); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12px; color: var(--texte-clair); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=tel], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--bordure); border-radius: var(--rayon-sm);
  font-size: 14px; background: #fff; color: var(--texte);
}
.field { margin-bottom: 14px; }
.pwdToggleBtn { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: none;
  cursor: pointer; font-size: 15px; padding: 4px 8px; line-height: 1; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-vert { background: #DFF2DF; color: #216B21; }
.badge-rouge { background: #FBE0DE; color: #A32B22; }
.badge-bleu { background: #DCEAFB; color: #124C87; }
.badge-jaune { background: #FFF3CD; color: #8A6D00; }
.badge-gris { background: #EAE5DB; color: #6B6055; }

/* ---------- Auth screen ---------- */
#authScreen { min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--brun-fonce), var(--brun) 60%, var(--or)); padding: 20px; }
#authCard { width: 100%; max-width: 380px; background: var(--carte); border-radius: var(--rayon); padding: 32px 28px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
#authCard h1 { font-size: 20px; margin: 0 0 4px; color: var(--brun-fonce); }
#authCard .sub { font-size: 12.5px; color: var(--texte-clair); margin-bottom: 22px; }
.authError { background: #FBE0DE; color: #A32B22; border-radius: var(--rayon-sm); padding: 10px 12px; font-size: 12.5px; margin-bottom: 14px; display: none; }
.authError.show { display: block; }

/* ---------- Offline / sync indicator ---------- */
#connBanner { display: none; align-items: center; gap: 8px; padding: 8px 20px; font-size: 12.5px; font-weight: 600; }
#connBanner.offline { display: flex; background: #FDF3E3; color: #8A6D00; border-bottom: 1px solid var(--or); }
#connBanner.syncing { display: flex; background: #DCEAFB; color: #124C87; border-bottom: 1px solid var(--bleu); }
.pendingDot { width: 8px; height: 8px; border-radius: 50%; background: var(--orange); display: inline-block; }

/* ---------- Toasts ---------- */
#toastHost { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--brun-fonce); color: #fff; padding: 12px 18px; border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.25); font-size: 13.5px; max-width: 340px; }
.toast.err { background: var(--rouge); }
.toast.ok { background: var(--vert); }

/* ---------- Mobile nav ---------- */
#mobileNav { display: none; }

/* ---------- Responsive data lists (table on desktop, cards on mobile) ---------- */
.tableScroll { width: 100%; overflow-x: auto; }
table.dataTbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.dataTbl th { background: var(--brun); color: #fff; text-align: left; padding: 10px 12px; font-size: 12px; font-weight: 600; white-space: nowrap; }
table.dataTbl td { padding: 9px 12px; border-bottom: 1px solid var(--bordure); }
table.dataTbl tr:hover td { background: #FBF7EF; }
.cardList { display: none; flex-direction: column; gap: 10px; }
.dataCard { background: var(--carte); border: 1px solid var(--bordure); border-radius: var(--rayon-sm); padding: 12px 14px; }
.dataCard .dcTitle { font-weight: 700; margin-bottom: 6px; color: var(--brun-fonce); font-size: 14px; }
.dataCard .dcRow { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; padding: 2px 0; }
.dataCard .dcLabel { color: var(--texte-clair); flex-shrink: 0; }
.dataCard .dcVal { text-align: right; }
.dataCard .dcActions { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.pageHead { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.pageHead h2 { margin: 0; color: var(--brun-fonce); }
.searchBar { margin-bottom: 12px; max-width: 320px; }
.modalOverlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; align-items: center; justify-content: center; padding: 16px; }
.modalOverlay.show { display: flex; }
.modalBox { width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; }
.modalBox.wide { max-width: 720px; }
/* Auto-injected "close" button for any popup that doesn't already build
   its own (see ensureModalCloseButtons in ui.js) — floated into the
   top-right corner so it sits next to the title without needing every
   modal's markup to be rewritten individually. */
.modalCloseX { float: right; margin: -4px -4px 8px 10px; padding: 3px 10px; font-size: 14px; line-height: 1;
  border: 1px solid var(--bordure); background: var(--carte); border-radius: var(--rayon-sm); cursor: pointer; color: var(--texte); }
.modalCloseX:hover { background: var(--fond); }
.formRow2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .formRow2 { grid-template-columns: 1fr; } }

@media (max-width: 900px) {
  .cardList { display: flex; }
}

/* ============================================================
   Responsive — mobile-first: below 900px the sidebar becomes a
   slide-out drawer and a bottom tab bar (covering ALL nav groups
   via a "More" sheet) takes over primary navigation.
   ============================================================ */
@media (max-width: 900px) {
  #sideNav { transform: translateX(-100%); transition: transform .2s ease; width: 260px; z-index: 60; }
  #sideNav.open { transform: translateX(0); box-shadow: 0 0 30px rgba(0,0,0,.3); }
  #navScrim { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 50; }
  #navScrim.show { display: block; }
  #mainArea { margin-left: 0; }
  #pageContainer { padding: 14px 14px calc(var(--mobilenav-h) + 14px); }
  #mobileNav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: var(--mobilenav-h);
    background: var(--carte); border-top: 1px solid var(--bordure); z-index: 40;
    justify-content: space-around; align-items: center;
  }
  #mobileNav .mnItem { display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 10.5px; color: var(--texte-clair); flex: 1; padding: 6px 0; cursor: pointer; }
  #mobileNav .mnItem.active { color: var(--brun); font-weight: 700; }
  #mobileNav .mnIcon { font-size: 18px; }
  .statGrid { grid-template-columns: repeat(2, 1fr); }
  table.dataTbl { display: none; } /* card view takes over, see per-page rendering */
}

@media (max-width: 480px) {
  .statGrid { grid-template-columns: 1fr 1fr; }
  #authCard { padding: 26px 20px; }
}

/* ---------- POS / Caisse — matches the old Point de Vente layout: product
   grid on the left, a white cart panel with cream (#f8f0e8) rows on the
   right, gold used only as an accent (icons, prices, totals). ---------- */
#page-pos { --pos-gold: #C9A84C; }
.pos-layout { display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: stretch; }
.pos-left { display: flex; flex-direction: column; gap: 16px; }
.pos-search-wrap { background: var(--carte); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 14px; }
.pos-products { flex: 1; background: var(--carte); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 14px; min-height: 300px; max-height: 60vh; overflow-y: auto; }
.pos-product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; height: 100%; }
.pos-product-card { background: #f8f0e8; border: 1px solid var(--bordure); border-radius: 10px; padding: 14px; cursor: pointer; transition: all .2s ease; text-align: center; }
.pos-product-card:hover { border-color: var(--pos-gold); transform: translateY(-2px); }
.pos-product-name { color: #2c1c0d; font-weight: 600; font-size: 13px; }
.pos-product-price { color: #7a5010; font-weight: 700; font-size: 12.5px; margin-top: 4px; }
.pos-empty-state { grid-column: 1/-1; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--texte-clair); }
.pos-empty-state .icon { font-size: 40px; opacity: .5; margin-bottom: 8px; }
.pos-right { display: flex; flex-direction: column; background: var(--carte); border: 1px solid var(--bordure); border-radius: var(--rayon); overflow: hidden; }
.cart-header { padding: 16px 20px; border-bottom: 1px solid var(--bordure); background: #f8f0e8; flex-shrink: 0; }
.cart-title { color: #2c1c0d; font-weight: 700; font-size: 15px; }
.cart-items { flex: 1; padding: 12px; overflow-y: auto; }
.cart-item { display: flex; align-items: center; gap: 10px; padding: 10px; background: #f8f0e8; border-radius: 10px; margin-bottom: 8px; }
.cart-item-name { flex: 1; font-size: 12.5px; color: #2c1c0d; font-weight: 600; }
.cart-item-price { font-size: 12.5px; color: #7a5010; font-weight: 700; white-space: nowrap; }
.qty-btn { background: rgba(201,168,76,.18); border: none; color: #7a5010; width: 24px; height: 24px; border-radius: 5px; cursor: pointer; font-size: 14px; font-weight: 700; }
.qty-val { width: 32px; text-align: center; background: #fff; border: 1px solid var(--bordure); color: #2c1c0d; font-size: 12.5px; border-radius: 5px; padding: 3px 0; }
.cart-footer { padding: 16px 20px; background: #f8f0e8; flex-shrink: 0; }
.cart-total-row { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 12.5px; color: #5a4030; }
.cart-total-row.total { font-size: 15px; font-weight: 700; color: #2c1c0d; padding-top: 8px; border-top: 1px solid var(--bordure); }
.pos-empty-cart { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: var(--texte-clair); font-size: 12.5px; }
.pos-empty-cart .icon { font-size: 34px; opacity: .4; display: block; margin-bottom: 6px; }
.pos-check { display: flex; align-items: center; gap: 8px; color: #2c1c0d; font-size: 12.5px; margin-top: 8px; }
.pos-check input { accent-color: var(--pos-gold); }
.btn-gold { background: var(--pos-gold); color: #2c1c0d; }
@media (max-width: 900px) {
  .pos-layout { grid-template-columns: 1fr; }
}

/* ---------- Print ---------- */
@media print {
  #sideNav, #topBar, #mobileNav, #connBanner, #toastHost, #navScrim { display: none !important; }
  #mainArea { margin-left: 0; }
}
