/* =====================================================================
   theme.css — Light / Dark mode, background image, gradient, darken, blur.
   Loaded AFTER styles.css and pos-sell.css so it can override them.
   All colours come from CSS variables that theme.js writes on <html>.

   Stack order (bottom → top):
     1. #theme-bg .tb-base  solid colour or gradient
     2. #theme-bg .tb-img   uploaded image (+ blur)
     3. #theme-bg .tb-dim   black overlay (darken)
     4. the app (sidebar, header, cards) coloured by Light / Dark mode
   ===================================================================== */

/* ---------- background layers ---------- */
#theme-bg{position:fixed;top:0;right:0;bottom:0;left:0;z-index:-1;overflow:hidden;pointer-events:none;display:none}
body.t-on #theme-bg{display:block}
#theme-bg i{position:absolute;top:0;right:0;bottom:0;left:0;display:block}
#theme-bg .tb-img{display:none;background-position:center;background-size:cover;background-repeat:no-repeat}
body.t-img #theme-bg .tb-img{display:block}
@media print{#theme-bg{display:none!important}}

/* styles.css paints html/body/.shell/.main/.content with !important teal.
   Hand all of that over to the layer above (only after sign-in). */
html{background:var(--t-base,#ccfbf1)!important}
html body.t-on,
html body.t-on .shell,
html body.t-on .main,
html body.t-on .content{background:transparent!important}
html body.t-on .sx{background:transparent!important}

/* ---------- shell colours that styles.css forced with !important ---------- */
html body.t-on .side{background:var(--side)!important}
html body.t-on .top{background:var(--theme-header)!important;border-bottom-color:var(--line)!important;color:var(--ink)}
html body.t-on .card,
html body.t-on .kpi,
html body.t-on .strip>div{background:var(--t-card)!important;color:var(--ink)}
html body.t-on .nav button.on{background:var(--t-nav-on)!important;color:#fff!important}
body.t-on .nav button:hover{background:rgba(255,255,255,.10)}
/* the POS "Card" payment button also carries the class .card — keep its own colours */
html body.t-on .sx-pm button.card{background:linear-gradient(180deg,#16877d,#1349c4)!important;color:#fff!important}
body.t-on .top h2,body.t-on .page-h h1{color:var(--ink)}

/* cashier Light/Dark button (injected by theme.js) */
.t-toggle{display:inline-flex;align-items:center;gap:6px;white-space:nowrap}
.sx-top .t-toggle{margin-left:auto;height:40px;border:0;border-radius:12px;padding:0 14px;color:#fff;background:rgba(255,255,255,.16);font-size:15px}
.sx-top .t-toggle:hover{background:rgba(255,255,255,.28)}
.sx-top .t-toggle+.sx-gear{margin-left:0}
@media(max-width:700px){.sx-top .t-toggle{padding:0 11px}.sx-top .t-toggle .t-lbl{display:none}}

/* =====================================================================
   DARK MODE — Facebook palette
   bg #18191A · card/side/header #242526 · text #E4E6EB · muted #B0B3B8
   border #3A3B3C · hover #3A3B3C · accent #2E89FF
   ===================================================================== */
body.theme-dark{color:var(--ink)}
body.theme-dark a,body.theme-dark .link{color:var(--t-pri-text)}
body.theme-dark small,body.theme-dark .muted,body.theme-dark .note,body.theme-dark .lbl{color:var(--muted)}
body.theme-dark .chk{color:var(--ink)}
body.theme-dark hr{border-color:var(--line)}

/* buttons, inputs, chips */
body.theme-dark .btn,
body.theme-dark .pill,
body.theme-dark .chip,
body.theme-dark .tile,
body.theme-dark .keys button,
body.theme-dark .ubtn,
body.theme-dark .scanin,
body.theme-dark .l-qty button,
body.theme-dark .l-qty button.qv{background:var(--surface);color:var(--ink);border-color:var(--line)}
body.theme-dark .btn:hover,
body.theme-dark .pill:hover,
body.theme-dark .chip:hover,
body.theme-dark .tile:hover,
body.theme-dark .ubtn:hover,
body.theme-dark .keys button:hover{background:var(--t-hover);border-color:var(--line)}
body.theme-dark .btn-pri,
body.theme-dark .pill.on,
body.theme-dark .keys .go{background:var(--pri);border-color:var(--pri);color:#fff}
body.theme-dark .btn-pri:hover{background:var(--pri-d);border-color:var(--pri-d)}
body.theme-dark .btn-ghost{background:transparent}
body.theme-dark .btn-danger{background:#7f1d1d;border-color:#7f1d1d;color:#fff}
body.theme-dark .chip.on{background:var(--pri);border-color:var(--pri);color:#fff}
body.theme-dark .input,
body.theme-dark select.input,
body.theme-dark textarea.input,
body.theme-dark .lic-input,
body.theme-dark .pills input[type=date]{background:var(--t-input);color:var(--ink);border-color:var(--line)}
body.theme-dark [style*="background:#f8fafc"]{background:var(--t-sub)!important;color:var(--ink)}   /* e.g. read-only Margin box */
body.theme-dark .input::placeholder,
body.theme-dark .scanin input::placeholder{color:var(--muted)}
body.theme-dark .input:focus{border-color:var(--pri);box-shadow:0 0 0 3px rgba(46,137,255,.25)}
body.theme-dark select option{background:var(--surface);color:var(--ink)}
body.theme-dark .scanin input{color:var(--ink)}
body.theme-dark .seg{background:var(--t-input)}
body.theme-dark .seg button{color:var(--muted)}
body.theme-dark .seg button.on{background:var(--surface);color:var(--t-pri-text);box-shadow:none}
body.theme-dark .x:hover{background:var(--t-hover)}
body.theme-dark .t-tag,body.theme-dark .badge.b-gray{background:var(--t-input);color:var(--muted)}

/* tables, KPI, info boxes */
body.theme-dark .tbl,
body.theme-dark .tbl td{background:var(--surface);color:var(--ink);border-bottom-color:var(--line)}
body.theme-dark .tbl th,
body.theme-dark .tbl tfoot td{background:var(--t-sub);color:var(--muted);border-color:var(--line)}
body.theme-dark .tbl tr:hover td{background:var(--t-hover)}
body.theme-dark .k-i,body.theme-dark .t-art,body.theme-dark .paytot{background:var(--pri-l)}
body.theme-dark .paytot b{color:var(--t-pri-text)}
body.theme-dark .t-p{color:var(--t-pri-text)}
body.theme-dark .info,body.theme-dark .chg,body.theme-dark .rbox,
body.theme-dark .photo-row,body.theme-dark .photo-box,body.theme-dark .thumb{background:var(--t-sub);border-color:var(--line);color:var(--ink)}
body.theme-dark .bundle-box{background:var(--t-sub);border-color:var(--line)}
body.theme-dark .hb-b{background:var(--t-input)}
body.theme-dark .chart .gl{stroke:var(--line)}
body.theme-dark .chart text{fill:var(--muted)}
body.theme-dark .chart .dt1{fill:var(--ink)}
body.theme-dark .receipt{color:#111827}            /* printed receipt stays paper-white */

/* modals + cart panel of the standard layout */
body.theme-dark .modal,
body.theme-dark .cart,
body.theme-dark .sx-pop{background:var(--surface);color:var(--ink)}
body.theme-dark .modal{border:1px solid var(--line)}
body.theme-dark .mh,body.theme-dark .mf,body.theme-dark .cart-h,body.theme-dark .sum,
body.theme-dark .line{border-color:var(--line)}
body.theme-dark .ov{background:rgba(0,0,0,.7)}

/* ---------- POS (Sell) screen ---------- */
body.theme-dark .sx{--ink:#E4E6EB;--navy:#3A3B3C;--sky:#3A3B3C;--sky2:#2D2E2F;color:var(--ink)}
body.theme-dark .sx-top{background:var(--theme-header);box-shadow:0 1px 0 var(--line)}
body.theme-dark .sx-search{background:var(--t-input);box-shadow:none;color:var(--muted)}
body.theme-dark .sx-search input{color:var(--ink)}
body.theme-dark .sx-search input::placeholder{color:var(--muted)}
body.theme-dark .sx-icon{color:var(--muted)}
body.theme-dark .sx-icon:hover,body.theme-dark .sx-pop button:hover{background:var(--t-hover)}
body.theme-dark .sx-stat{background:var(--surface);color:var(--muted)}
body.theme-dark .sx-chip,
body.theme-dark .sx-tile,
body.theme-dark .sx-foot button,
body.theme-dark .sx-menu button,
body.theme-dark .sx-q{background:var(--surface);border-color:var(--line);color:var(--ink);box-shadow:none}
body.theme-dark .sx-chip.on{background:var(--pri);border-color:var(--pri);color:#fff}
body.theme-dark .sx-tile:hover,
body.theme-dark .sx-foot button:not(:disabled):hover,
body.theme-dark .sx-menu button:hover{background:var(--t-hover);border-color:var(--pri)}
body.theme-dark .sx-name,body.theme-dark .sx-line .nm b,body.theme-dark .sx-line .amt b{color:var(--ink)}
body.theme-dark .sx-price,body.theme-dark .sx-sum .tot b{color:var(--t-pri-text)}
body.theme-dark .sx-price small,body.theme-dark .sx-line .pr,body.theme-dark .sx-line .ix,
body.theme-dark .sx-empty,body.theme-dark .sx-cempty,body.theme-dark .sx-line .amt s{color:var(--muted)}
body.theme-dark .sx-cempty b{color:var(--ink)}
body.theme-dark .sx-cart{background:var(--surface);border-color:var(--line)}
body.theme-dark .sx-cart-h{background:var(--t-sub);border-bottom:1px solid var(--line)}
body.theme-dark .sx-thead{background:var(--t-sub);border-color:var(--line);color:var(--muted)}
body.theme-dark .sx-lines{background:var(--surface)}
body.theme-dark .sx-li{border-color:var(--line)}
body.theme-dark .sx-li:nth-child(even){background:var(--t-sub)}
body.theme-dark .sx-q button{color:var(--t-pri-text)}
body.theme-dark .sx-q button:hover{background:var(--t-hover)}
body.theme-dark .sx-del{color:var(--muted)}
body.theme-dark .sx-sum{background:var(--t-sub);border-color:var(--line)}
body.theme-dark .sx-sum .tot{color:var(--ink)}
body.theme-dark .sx-pm{background:var(--t-sub)}
body.theme-dark .sx-foot{background:var(--theme-header);border-top-color:var(--line)}
body.theme-dark .sx-foot .ico{background:var(--pri)}
body.theme-dark .sx-bnote.off{background:var(--t-input);color:var(--muted);border-color:var(--line)}
body.theme-dark .sx-bnote button{background:var(--surface)}
body.theme-dark .sx-tile.is-exp-expired,
body.theme-dark .sx-tile.is-exp-today,
body.theme-dark .sx-tile.is-exp-urgent{background:var(--surface)}
body.theme-dark .sx-cam{background:var(--surface);border-color:var(--line);color:var(--t-pri-text)}
body.theme-dark .sx-img img{filter:drop-shadow(0 5px 5px rgba(0,0,0,.5))}

/* ---------- Theme Settings page ---------- */
.t-img-row{display:flex;gap:14px;align-items:center;flex-wrap:wrap;margin-bottom:6px}
.t-thumb{width:120px;height:80px;border-radius:10px;border:1px dashed var(--line);background:var(--t-sub,#f1f5f9) center/cover no-repeat;display:grid;place-items:center;color:var(--muted);font-size:12px;text-align:center;flex:none;overflow:hidden}
.t-range{display:grid;gap:4px;margin-top:14px}
.t-range-h{display:flex;justify-content:space-between;align-items:baseline;gap:8px}
.t-range-h output{font-weight:800;color:var(--t-pri-text,var(--pri));font-variant-numeric:tabular-nums}
.t-range input[type=range]{width:100%;accent-color:var(--pri);height:28px;cursor:pointer}
.t-range input[type=range]:disabled{opacity:.45;cursor:not-allowed}
.t-hints{display:flex;justify-content:space-between;font-size:11.5px;color:var(--muted)}
.t-lock{opacity:.55;pointer-events:none}

/* live preview: same layer stack as the real app, in miniature */
.theme-preview{position:relative;isolation:isolate;background:transparent}
.theme-preview .pv-bg{position:absolute;top:0;right:0;bottom:0;left:0;z-index:-1;overflow:hidden}
.theme-preview .pv-bg i{position:absolute;top:0;right:0;bottom:0;left:0;display:block}
.theme-preview .pv-img{background-position:center;background-size:cover;background-repeat:no-repeat;display:none}
.theme-preview.has-img .pv-img{display:block}
.theme-preview .pv-side,.theme-preview .pv-main{position:relative}

/* ==========================================================================
   LOGIN + ACTIVATION ARE EXCLUDED FROM THEME
   Theme, Dark/Light, Gradient, Uploaded Image, Darken and Blur only apply
   inside the dashboard (after sign-in, when theme.js adds body.t-on).
   Login/Activation (.auth) always keep auth-supermarket-bg.png from auth.css.
   ========================================================================== */
body:not(.t-on) #theme-bg,
body:has(.auth) #theme-bg{display:none!important}
html:has(body .auth){background:transparent!important}
html body .auth,
html body.t-on .auth,
html body.theme-dark .auth,
html body.t-img .auth{
  background-color:#0b3d2e!important;
  background-image:url('auth-supermarket-bg.png')!important;
  background-position:center center!important;
  background-size:cover!important;
  background-repeat:no-repeat!important;
  background-attachment:fixed!important;
  color-scheme:light;
}
