:root{
  --bg:#FAF9F5;
  --surface:#FFFFFF;
  --surface-2:#F1EFE8;
  --border:#E3E0D6;
  --text:#1C1E1B;
  --text-muted:#69675E;
  --accent:#1F6F5C;
  --accent-soft:#E4EFE9;
  --accent-ink:#0F4A3C;
  --warn:#9A6A17;
  --warn-soft:#F7EDDA;
  --crit:#A23B2E;
  --crit-soft:#F8E7E3;
  --shadow: 0 1px 2px rgba(28,30,27,0.06), 0 6px 16px -8px rgba(28,30,27,0.12);
}
@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg:#15170F; --surface:#1D2018; --surface-2:#242820; --border:#33372B;
    --text:#EDEBE0; --text-muted:#A3A08F; --accent:#5FBFA0; --accent-soft:#213A32; --accent-ink:#9CE0C6;
    --warn:#E0B156; --warn-soft:#3A311D; --crit:#E38B7B; --crit-soft:#3B241F;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 6px 20px -8px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"]{
  --bg:#15170F; --surface:#1D2018; --surface-2:#242820; --border:#33372B;
  --text:#EDEBE0; --text-muted:#A3A08F; --accent:#5FBFA0; --accent-soft:#213A32; --accent-ink:#9CE0C6;
  --warn:#E0B156; --warn-soft:#3A311D; --crit:#E38B7B; --crit-soft:#3B241F;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 6px 20px -8px rgba(0,0,0,0.5);
}

*{box-sizing:border-box;}
html,body{height:100%;}
body{margin:0; background:var(--bg); color:var(--text); font-family:'IBM Plex Sans',-apple-system,'Segoe UI',sans-serif; font-size:14px;}
.num{font-family:'IBM Plex Mono',monospace; font-variant-numeric:tabular-nums;}
h1,h2,h3{font-family:'Fraunces',serif; font-weight:600; margin:0;}
a{color:inherit;}

/* ---- auth screens ---- */
.auth-wrap{min-height:100dvh; display:flex; align-items:center; justify-content:center; padding:24px; position:relative;}
.auth-theme-toggle{position:absolute; top:18px; right:18px;}
.auth-card{background:var(--surface); border:1px solid var(--border); border-radius:14px; box-shadow:var(--shadow); padding:32px 30px; width:100%; max-width:380px;}
.auth-brand{display:flex; align-items:center; gap:10px; margin-bottom:22px;}
.auth-brand .name{font-family:'Fraunces',serif; font-weight:600; font-size:19px;}
.auth-card h2{font-size:19px; margin-bottom:4px;}
.auth-sub{color:var(--text-muted); font-size:12.5px; margin-bottom:20px;}
.auth-error{background:var(--crit-soft); color:var(--crit); font-size:12.5px; padding:9px 12px; border-radius:8px; margin-bottom:14px;}
.auth-msg{background:var(--accent-soft); color:var(--accent-ink); font-size:12.5px; padding:9px 12px; border-radius:8px; margin-bottom:14px;}
.auth-switch{margin-top:16px; font-size:12.5px; color:var(--text-muted); text-align:center;}
.auth-switch button{background:none; border:none; color:var(--accent-ink); font-weight:600; cursor:pointer; font-family:inherit; font-size:inherit; padding:0;}

/* ---- shell ---- */
/* A hard viewport height (not min-height) is what makes the internal
   scroll areas below (.catalog, .cart-items) actually bounded — with
   min-height the shell was free to grow taller than the screen to fit
   its content, so a long cart just pushed the WHOLE page down instead
   of scrolling inside its own little box. */
.app{display:flex; flex-direction:column; height:100dvh;}
.topbar{
  display:flex; align-items:center; justify-content:space-between; gap:10px;
  padding:12px 16px; padding-top:calc(12px + env(safe-area-inset-top,0px));
  background:var(--surface); border-bottom:1px solid var(--border); flex:none; flex-wrap:wrap;
}
.brand{display:flex; align-items:center; gap:8px;}
.brand-name{font-family:'Fraunces',serif; font-weight:600; font-size:16px;}
.biz-name{font-size:11.5px; color:var(--text-muted); margin-left:6px; padding-left:10px; border-left:1px solid var(--border);}
.tab-switch{display:flex; gap:2px; background:var(--surface-2); padding:3px; border-radius:8px; flex-wrap:wrap;}
.tab-switch button{border:none; background:none; font-family:inherit; font-size:12.5px; font-weight:600; padding:6px 11px; border-radius:6px; color:var(--text-muted); cursor:pointer;}
.tab-switch button.active{background:var(--surface); color:var(--accent-ink); box-shadow:var(--shadow);}
.top-right{display:flex; align-items:center; gap:6px;}
.signout-btn{background:none; border:none; color:var(--text-muted); font-family:inherit; font-size:12px; cursor:pointer; text-decoration:underline; margin-left:4px;}
.theme-toggle{width:30px; height:30px; border:1px solid var(--border);}
.theme-toggle svg{width:16px;height:16px;}

.body-area{flex:1; display:flex; min-height:0; overflow:hidden;}

/* ---- sale screen ---- */
.catalog{flex:1.4; overflow-y:auto; padding:14px 14px 20px;}
.cat-grid{display:grid; grid-template-columns:repeat(auto-fill, minmax(122px,1fr)); gap:10px;}
.prod-card{background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:10px 10px 9px; cursor:pointer; text-align:left; font-family:inherit; box-shadow:var(--shadow); display:flex; flex-direction:column; gap:5px;}
.prod-card:active{transform:scale(0.97);}
.prod-card .pname{font-size:12.5px; font-weight:600; line-height:1.3;}
.prod-card .pstock{font-size:10.5px; color:var(--text-muted);}
.prod-card .pprice{font-family:'IBM Plex Mono'; font-size:13px; color:var(--accent-ink); font-weight:500; margin-top:2px;}
.prod-card.out{opacity:.45; cursor:not-allowed;}
.quota-banner{border-radius:10px; padding:10px 14px; margin-bottom:12px; font-size:12.5px; line-height:1.5;}
.quota-banner.warn{background:var(--warn-soft); color:var(--warn);}
.quota-banner.crit{background:var(--crit-soft); color:var(--crit);}
.quota-banner .qb-track{height:5px; border-radius:4px; background:rgba(0,0,0,0.08); overflow:hidden; margin-bottom:7px;}
.quota-banner .qb-fill{height:100%; background:currentColor; opacity:0.55;}
.quota-banner .qb-text strong{font-weight:700;}
.cat-search{padding:2px 0 12px;}
.cat-search input{width:100%; padding:9px 12px; border-radius:8px; border:1px solid var(--border); background:var(--surface); color:var(--text); font-family:inherit; font-size:13.5px;}
.empty-catalog{color:var(--text-muted); font-size:13px; padding:30px 10px; text-align:center;}

.cart-panel{width:300px; flex:none; background:var(--surface); border-left:1px solid var(--border); display:flex; flex-direction:column; min-height:0;}
.cart-head{padding:14px 16px 10px; border-bottom:1px solid var(--border);}
.cart-head h3{font-size:15px;}
.cart-items{flex:1; overflow-y:auto; padding:8px 12px;}
.cart-empty{color:var(--text-muted); font-size:12.5px; text-align:center; padding:30px 10px;}
.cart-line{display:flex; align-items:center; gap:8px; padding:8px 4px; border-bottom:1px solid var(--border);}
.cart-line:last-child{border-bottom:none;}
.cl-name{flex:1; font-size:12.5px; line-height:1.3;}
.cl-name .sub{font-size:10.5px; color:var(--text-muted); font-family:'IBM Plex Mono';}
.qty-stepper{display:flex; align-items:center; gap:6px; background:var(--surface-2); border-radius:7px; padding:2px;}
.qty-stepper button{width:20px;height:20px; border:none; background:var(--surface); border-radius:5px; font-size:13px; cursor:pointer; color:var(--text); font-family:inherit; line-height:1;}
.qty-stepper .qv{width:18px; text-align:center; font-family:'IBM Plex Mono'; font-size:12px;}
.cl-total{width:56px; text-align:right; font-family:'IBM Plex Mono'; font-size:12.5px;}
.cl-remove{width:20px;height:20px; border:none; background:none; color:var(--text-muted); cursor:pointer; font-size:15px; line-height:1;}

.cart-summary{border-top:1px solid var(--border); padding:12px 16px calc(14px + env(safe-area-inset-bottom,0px));}
.sum-row{display:flex; justify-content:space-between; font-size:12.5px; color:var(--text-muted); margin-bottom:5px;}
.sum-row.total{font-size:16px; font-weight:600; color:var(--text); margin-top:6px; margin-bottom:12px;}
.sum-row.total .val{font-family:'IBM Plex Mono';}
.pay-methods{display:flex; gap:6px; margin-bottom:10px;}
.pay-methods button{flex:1; padding:8px 4px; border-radius:8px; border:1px solid var(--border); background:var(--surface); font-family:inherit; font-size:12px; font-weight:600; color:var(--text-muted); cursor:pointer;}
.pay-methods button.active{background:var(--accent-soft); border-color:var(--accent); color:var(--accent-ink);}
.channel-grid{display:grid; grid-template-columns:repeat(3, 1fr); gap:6px; margin-bottom:10px;}
.channel-grid button{padding:8px 4px; border-radius:8px; border:1px solid var(--border); background:var(--surface); font-family:inherit; font-size:12px; font-weight:600; color:var(--text-muted); cursor:pointer;}
.channel-grid button.active{background:var(--accent-soft); border-color:var(--accent); color:var(--accent-ink);}
.checkout-btn{width:100%; padding:12px; border-radius:9px; border:none; background:var(--accent); color:#fff; font-family:inherit; font-size:14.5px; font-weight:600; cursor:pointer;}
.checkout-btn:disabled{opacity:.4; cursor:not-allowed;}

.toast{position:fixed; bottom:20px; left:50%; transform:translateX(-50%); background:var(--accent-ink); color:#fff; padding:10px 18px; border-radius:9px; font-size:13px; font-weight:500; box-shadow:0 8px 24px -6px rgba(0,0,0,.3); z-index:60; opacity:0; pointer-events:none; transition:opacity .2s, transform .2s;}
.toast.show{opacity:1; transform:translateX(-50%) translateY(-4px);}
.toast.err{background:var(--crit);}

.screen-pad{padding:16px; overflow-y:auto; flex:1;}
/* Profile tab: a single readable column, its sections stacked one below
   the other. On a wide desktop window a flex child otherwise just sits
   pinned to the left with empty space beside it — centering it here
   keeps the "one after another" layout but makes it sit in the middle
   of the screen instead. */
.profile-pad{max-width:600px; width:100%; margin:0 auto;}
.kpis{display:grid; grid-template-columns:repeat(3,1fr); gap:10px; margin-bottom:16px;}
.kpi{background:var(--surface); border:1px solid var(--border); border-radius:10px; padding:13px 14px; box-shadow:var(--shadow);}
.kpi .label{font-size:10.5px; text-transform:uppercase; letter-spacing:.05em; color:var(--text-muted); font-weight:600;}
.kpi .value{font-family:'IBM Plex Mono'; font-size:19px; margin-top:5px;}
table{width:100%; border-collapse:collapse; font-size:13px;}
thead th{text-align:left; font-size:10.5px; text-transform:uppercase; letter-spacing:.05em; color:var(--text-muted); font-weight:600; padding:0 8px 8px; border-bottom:1px solid var(--border);}
tbody td{padding:9px 8px; border-bottom:1px solid var(--border);}
tbody tr:last-child td{border-bottom:none;}
.panel{background:var(--surface); border:1px solid var(--border); border-radius:10px; box-shadow:var(--shadow); padding:16px; overflow-x:auto; margin-bottom:16px;}
.panel-head{display:flex; align-items:center; justify-content:space-between; margin-bottom:12px; gap:10px; flex-wrap:wrap;}
.panel-head h3{font-size:15px;}
.pill{display:inline-flex; align-items:center; gap:5px; padding:2px 9px; border-radius:99px; font-size:11px; font-weight:600; background:var(--accent-soft); color:var(--accent-ink);}
.pill::before{content:''; width:5px;height:5px;border-radius:99px; background:currentColor;}

.report-head{display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:16px; flex-wrap:wrap;}
.mode-switch{display:flex; gap:2px; background:var(--surface-2); padding:3px; border-radius:8px;}
.mode-switch button{border:none; background:none; font-family:inherit; font-size:12.5px; font-weight:600; padding:6px 12px; border-radius:6px; color:var(--text-muted); cursor:pointer;}
.mode-switch button.active{background:var(--surface); color:var(--accent-ink); box-shadow:var(--shadow);}
.date-pick{display:flex; align-items:center; gap:8px;}
.date-pick input{padding:7px 10px; border-radius:7px; border:1px solid var(--border); background:var(--surface); color:var(--text); font-family:inherit; font-size:12.5px;}
.pl-grid{display:grid; grid-template-columns:1.1fr 1fr; gap:16px; align-items:start;}
.pl-lines{display:flex; flex-direction:column;}
.pl-line{display:flex; justify-content:space-between; padding:9px 2px; border-bottom:1px solid var(--border); font-size:13px;}
.pl-line.sub{padding-left:14px; color:var(--text-muted); font-size:12.5px;}
.pl-line.total{border-top:2px solid var(--text); border-bottom:none; font-weight:600; font-size:14.5px; margin-top:4px; padding-top:12px;}
.pl-line .amt{font-family:'IBM Plex Mono';}
.pl-line .amt.neg{color:var(--crit);}
.pl-line .amt.pos{color:var(--accent-ink);}
.bar-row{display:flex; align-items:center; gap:8px; margin-bottom:7px;}
.bar-label{width:52px; font-size:10.5px; color:var(--text-muted); flex:none; font-family:'IBM Plex Mono';}
.bar-label.wide{width:118px; font-family:inherit; color:var(--text); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.bar-track{flex:1; background:var(--surface-2); border-radius:5px; height:13px; overflow:hidden;}
.bar-fill{height:100%; background:var(--accent); border-radius:5px;}
.bar-val{width:66px; text-align:right; font-family:'IBM Plex Mono'; font-size:11px; color:var(--text-muted); flex:none;}
.bar-val.wide{width:110px;}
.margin-tag{font-size:11px; padding:1px 7px; border-radius:99px; font-weight:600;}
.margin-tag.good{background:var(--accent-soft); color:var(--accent-ink);}
.margin-tag.warn{background:var(--warn-soft); color:var(--warn);}
.download-row{display:flex; gap:8px;}

.add-row{display:flex; justify-content:flex-end; margin-bottom:12px; gap:8px;}
.btn{display:inline-flex; align-items:center; gap:6px; padding:8px 14px; border-radius:8px; border:1px solid var(--border); background:var(--surface); color:var(--text); font-family:inherit; font-weight:500; font-size:13px; cursor:pointer;}
.btn.primary{background:var(--accent); border-color:var(--accent); color:#fff;}
.btn svg{width:14px;height:14px;}
.low{color:var(--warn); font-weight:600;}
.row-actions{display:flex; gap:4px;}
.icon-btn{width:26px;height:26px; border:none; background:none; color:var(--text-muted); cursor:pointer; border-radius:6px; display:flex; align-items:center; justify-content:center;}
.icon-btn:hover{background:var(--surface-2); color:var(--text);}
.icon-btn svg{width:14px;height:14px;}

.modal-backdrop{position:fixed; inset:0; background:rgba(20,22,16,.42); display:flex; align-items:center; justify-content:center; padding:20px; z-index:70;}
.modal{background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:22px; width:100%; max-width:380px; box-shadow:0 20px 50px -12px rgba(0,0,0,.35); max-height:90vh; overflow-y:auto;}
.modal h3{font-size:16px; margin-bottom:16px;}
.field{margin-bottom:12px;}
.field-row{display:grid; grid-template-columns:1fr 1fr; gap:10px;}
label{font-size:12px; color:var(--text-muted); font-weight:500; display:block; margin-bottom:4px;}
input,select{font-family:inherit; font-size:13px; padding:8px 10px; border-radius:7px; border:1px solid var(--border); background:var(--surface); color:var(--text); width:100%;}
.modal-actions{display:flex; justify-content:flex-end; gap:8px; margin-top:6px;}

.loading-screen{min-height:100dvh; display:flex; align-items:center; justify-content:center; color:var(--text-muted); font-size:13px;}

@media (max-width: 720px){
  /* On phones we stop trying to fit the whole Sale screen into one fixed-
     height view with two independently-scrolling panels (catalog + cart) —
     that's what let the cart's checkout button get clipped off-screen with
     no way to reach it. Instead the whole page just scrolls normally, like
     an ordinary webpage: product grid, then cart, then checkout, all one
     after another. Same look and components as desktop — only the scroll
     behavior changes. */
  .app{height:auto; min-height:100dvh;}
  .body-area{flex-direction:column; overflow:visible; min-height:0;}
  .catalog{overflow-y:visible; flex:none;}
  .cart-panel{width:100%; border-left:none; border-top:1px solid var(--border); max-height:none; flex:none; overflow:visible;}
  /* The items-added list gets its own bounded, independently-scrolling
     box — so ringing up a long cart scrolls just that list, and the
     channel buttons + delivery field + checkout button right below it
     stay put instead of getting pushed further down the page. */
  .cart-items{overflow-y:auto; flex:none; max-height:38vh;}
  .screen-pad{overflow-y:visible; flex:none;}
  .kpis{grid-template-columns:1fr 1fr;}
  .pl-grid{grid-template-columns:1fr;}
}
