:root{
  --brand:#0f766e;
  --bg:#f4f6f8; --panel:#fff; --ink:#18212b; --muted:#667385; --line:#e3e8ee;
  --side:#111a24; --side-ink:#c5d0dc; --radius:12px;
  --red:#dc2626; --orange:#ea7a0c; --yellow:#c9a100; --green:#15803d; --blue:#2563eb;
  --shadow:0 1px 2px rgba(16,24,40,.05),0 1px 3px rgba(16,24,40,.06);
}
*{box-sizing:border-box}
html{-webkit-text-size-adjust:100%}
body{margin:0;font:15px/1.5 system-ui,-apple-system,"Segoe UI",Roboto,"Noto Sans",sans-serif;color:var(--ink);background:var(--bg)}
a{color:var(--brand);text-decoration:none}
a:hover{text-decoration:underline}
h1,h2,h3{margin:0 0 .5rem;line-height:1.25}
h2{font-size:1.15rem} h3{font-size:1rem}
.muted{color:var(--muted)} .small{font-size:.85rem} .right{text-align:right} .center{text-align:center} .nowrap{white-space:nowrap}
.mt{margin-top:1rem} .mb{margin-bottom:1rem}

/* shell */
.shell{display:flex;min-height:100vh}
.sidebar{width:248px;background:var(--side);color:var(--side-ink);position:fixed;inset:0 auto 0 0;overflow-y:auto;z-index:50;padding-bottom:2rem;transition:transform .2s}
.brand{display:flex;gap:.7rem;align-items:center;padding:1rem 1.1rem;color:#fff;border-bottom:1px solid rgba(255,255,255,.08)}
.brand:hover{text-decoration:none}
.brand img{width:38px;height:38px;object-fit:contain;border-radius:8px;background:#fff;padding:2px}
.brand-mark{width:38px;height:38px;border-radius:10px;background:var(--brand);display:grid;place-items:center;font-weight:700;font-size:1.2rem;color:#fff}
.brand-text{display:flex;flex-direction:column;min-width:0}
.brand-text strong{font-size:1rem;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.brand-text small{font-size:.72rem;color:#8da0b3;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.nav-group{font-size:.68rem;letter-spacing:.08em;text-transform:uppercase;color:#6c7f92;padding:1rem 1.2rem .3rem}
.nav-item{display:flex;align-items:center;gap:.7rem;padding:.55rem 1.2rem;color:var(--side-ink);font-size:.92rem;border-left:3px solid transparent}
.nav-item:hover{background:rgba(255,255,255,.05);text-decoration:none;color:#fff}
.nav-item.active{background:rgba(255,255,255,.08);color:#fff;border-left-color:var(--brand)}
.count{margin-left:auto;background:var(--red);color:#fff;font-style:normal;font-size:.7rem;padding:.05rem .45rem;border-radius:99px}
.main{flex:1;margin-left:248px;min-width:0;display:flex;flex-direction:column}
.topbar{position:sticky;top:0;z-index:30;display:flex;align-items:center;gap:.75rem;padding:.6rem 1.25rem;background:var(--panel);border-bottom:1px solid var(--line);padding-top:max(.6rem,env(safe-area-inset-top))}
.page-title{font-size:1.15rem;margin:0;flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.top-actions{display:flex;align-items:center;gap:.5rem}
.icon-btn{background:none;border:0;padding:.45rem;border-radius:8px;color:var(--ink);cursor:pointer;display:inline-grid;place-items:center}
.icon-btn:hover{background:var(--bg);text-decoration:none}
#menuBtn{display:none}
.dot{position:absolute;top:6px;right:6px;width:9px;height:9px;border-radius:50%;background:var(--red);border:2px solid #fff}
.avatar{width:34px;height:34px;border-radius:50%;background:var(--brand);color:#fff;display:grid;place-items:center;font-weight:600;cursor:pointer;list-style:none}
.avatar::-webkit-details-marker{display:none}
.menu{position:relative}
.menu-pop{position:absolute;right:0;top:44px;min-width:200px;background:var(--panel);border:1px solid var(--line);border-radius:10px;box-shadow:0 8px 24px rgba(16,24,40,.14);padding:.4rem;z-index:60}
.menu-pop a{display:block;padding:.5rem .7rem;border-radius:6px;color:var(--ink)}
.menu-pop a:hover{background:var(--bg);text-decoration:none}
.menu-head{padding:.5rem .7rem;border-bottom:1px solid var(--line);margin-bottom:.3rem;display:flex;flex-direction:column}
.menu-head small{color:var(--muted)}
.content{padding:1.25rem;flex:1}
.foot{padding:1rem 1.25rem;color:var(--muted);font-size:.8rem;text-align:center}
.scrim{display:none}

/* cards, grids */
.card{background:var(--panel);border:1px solid var(--line);border-radius:var(--radius);padding:1.1rem 1.2rem;box-shadow:var(--shadow);margin-bottom:1rem}
.card-head{display:flex;gap:.75rem;align-items:center;justify-content:space-between;flex-wrap:wrap;margin-bottom:.8rem}
.card-head h2,.card-head h3{margin:0}
.grid{display:grid;gap:1rem}
.g2{grid-template-columns:repeat(2,minmax(0,1fr))}
.g3{grid-template-columns:repeat(3,minmax(0,1fr))}
.g4{grid-template-columns:repeat(4,minmax(0,1fr))}
.stat{display:flex;flex-direction:column;gap:.15rem}
.stat .lbl{font-size:.78rem;color:var(--muted);text-transform:uppercase;letter-spacing:.04em}
.stat .val{font-size:1.55rem;font-weight:700}
.stat .sub{font-size:.8rem;color:var(--muted)}
.stat-card{border-left:4px solid var(--brand)}
.stat-card.red{border-left-color:var(--red)} .stat-card.orange{border-left-color:var(--orange)} .stat-card.yellow{border-left-color:var(--yellow)} .stat-card.blue{border-left-color:var(--blue)}

/* forms */
label{display:block;font-size:.82rem;font-weight:600;color:#3b4756;margin-bottom:.25rem}
input[type=text],input[type=number],input[type=password],input[type=email],input[type=date],input[type=search],input[type=tel],input[type=url],input[type=time],select,textarea{
  width:100%;padding:.55rem .7rem;border:1px solid #cfd7e0;border-radius:8px;background:#fff;color:var(--ink);font:inherit;min-height:40px}
textarea{min-height:90px;resize:vertical}
input:focus,select:focus,textarea:focus{outline:2px solid color-mix(in srgb,var(--brand) 35%,transparent);border-color:var(--brand)}
input[type=checkbox],input[type=radio]{width:auto;accent-color:var(--brand);transform:scale(1.15);margin-right:.4rem}
input[type=color]{width:60px;height:40px;padding:2px;border:1px solid #cfd7e0;border-radius:8px;background:#fff}
.field{margin-bottom:.85rem}
.form-grid{display:grid;gap:.85rem 1rem;grid-template-columns:repeat(auto-fill,minmax(220px,1fr))}
.form-grid .full{grid-column:1/-1}
.check{display:flex;align-items:center;font-weight:500;font-size:.92rem;margin:0}
.hint{font-size:.78rem;color:var(--muted);margin-top:.2rem}
.actions{display:flex;gap:.6rem;flex-wrap:wrap;align-items:center}

/* buttons */
.btn{display:inline-flex;align-items:center;justify-content:center;gap:.4rem;padding:.55rem 1rem;border-radius:8px;border:1px solid #cfd7e0;background:#fff;color:var(--ink);font:inherit;font-weight:600;cursor:pointer;min-height:40px;line-height:1.2}
.btn:hover{background:var(--bg);text-decoration:none}
.btn-primary{background:var(--brand);border-color:var(--brand);color:#fff}
.btn-primary:hover{background:var(--brand);filter:brightness(1.08)}
.btn-danger{background:#fff;color:var(--red);border-color:#f1b9b9}
.btn-danger:hover{background:#fef2f2}
.btn-sm{padding:.3rem .65rem;min-height:32px;font-size:.85rem}
.btn[disabled]{opacity:.55;cursor:not-allowed}

/* tables */
.table-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch;border-radius:8px}
table{width:100%;border-collapse:collapse;font-size:.9rem}
th{background:#f8fafc;text-align:left;font-size:.74rem;text-transform:uppercase;letter-spacing:.04em;color:var(--muted);padding:.6rem .7rem;border-bottom:1px solid var(--line);white-space:nowrap}
td{padding:.6rem .7rem;border-bottom:1px solid var(--line);vertical-align:middle}
tr:last-child td{border-bottom:0}
tbody tr:hover{background:#fafcfe}
td.num,th.num{text-align:right;font-variant-numeric:tabular-nums}
tfoot td{font-weight:700;background:#f8fafc}
.badge{display:inline-block;padding:.12rem .55rem;border-radius:99px;font-size:.75rem;font-weight:600;white-space:nowrap}
.b-red{background:#fee2e2;color:#b91c1c}.b-orange{background:#ffedd5;color:#c2410c}.b-yellow{background:#fef9c3;color:#854d0e}
.b-green{background:#dcfce7;color:#166534}.b-gray{background:#eef1f5;color:#4b5766}.b-blue{background:#dbeafe;color:#1d4ed8}
.pager{display:flex;gap:.3rem;align-items:center;flex-wrap:wrap;margin-top:.9rem}
.pager a{padding:.3rem .65rem;border:1px solid var(--line);border-radius:6px;background:#fff;color:var(--ink)}
.pager a.active{background:var(--brand);border-color:var(--brand);color:#fff}
.pager .muted{margin-left:.5rem;font-size:.8rem}
.toolbar{display:flex;gap:.6rem;flex-wrap:wrap;align-items:flex-end;margin-bottom:1rem}
.toolbar .grow{flex:1;min-width:200px}
.toolbar>div{min-width:0}

/* flash */
.flash{padding:.7rem 1rem;border-radius:8px;margin-bottom:1rem;border:1px solid}
.flash-success{background:#f0fdf4;border-color:#bbf7d0;color:#166534}
.flash-error{background:#fef2f2;border-color:#fecaca;color:#991b1b}
.flash-info{background:#eff6ff;border-color:#bfdbfe;color:#1e40af}
.flash-warning{background:#fffbeb;border-color:#fde68a;color:#92400e}

/* tabs */
.tabs{display:flex;gap:.25rem;overflow-x:auto;border-bottom:1px solid var(--line);margin-bottom:1rem;-webkit-overflow-scrolling:touch}
.tabs a{padding:.6rem .9rem;color:var(--muted);white-space:nowrap;border-bottom:2px solid transparent;font-weight:600;font-size:.9rem}
.tabs a.active{color:var(--brand);border-bottom-color:var(--brand)}
.tabs a:hover{text-decoration:none;color:var(--ink)}

/* mini bar chart */
.bars{display:flex;align-items:flex-end;gap:.5rem;height:150px;padding-top:.5rem}
.bar{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:flex-end;height:100%;gap:.25rem;min-width:0}
.bar i{display:block;width:100%;max-width:46px;background:var(--brand);border-radius:6px 6px 0 0;min-height:2px;opacity:.88}
.bar span{font-size:.7rem;color:var(--muted)} .bar b{font-size:.68rem;font-weight:600}

/* list rows for mobile alerts */
.list-row{display:flex;justify-content:space-between;gap:.75rem;padding:.55rem 0;border-bottom:1px solid var(--line)}
.list-row:last-child{border-bottom:0}

/* login */
.auth{min-height:100vh;display:grid;place-items:center;padding:1rem;background:linear-gradient(135deg,color-mix(in srgb,var(--brand) 12%,#fff),#eef2f6)}
.auth-card{width:100%;max-width:400px;background:#fff;border-radius:16px;padding:2rem 1.6rem;box-shadow:0 10px 40px rgba(16,24,40,.12)}
.auth-card .logo{display:flex;flex-direction:column;align-items:center;gap:.4rem;margin-bottom:1.4rem;text-align:center}
.auth-card .logo img{max-height:64px;max-width:200px}
.auth-card .brand-mark{width:56px;height:56px;font-size:1.6rem}

/* POS */
.pos-grid{display:grid;grid-template-columns:minmax(0,1fr) 340px;gap:1rem;align-items:start}
.pos-search{position:relative}
.suggest{position:absolute;left:0;right:0;top:100%;background:#fff;border:1px solid var(--line);border-radius:10px;box-shadow:0 10px 30px rgba(16,24,40,.15);max-height:340px;overflow:auto;z-index:40;margin-top:4px}
.suggest div{padding:.55rem .8rem;cursor:pointer;border-bottom:1px solid var(--line);display:flex;justify-content:space-between;gap:.6rem}
.suggest div:hover,.suggest div.hl{background:#f1f7f6}
.suggest small{color:var(--muted)}
.lines input,.lines select{min-height:34px;padding:.3rem .45rem;font-size:.88rem}
.lines td{padding:.4rem .4rem}
.sum-row{display:flex;justify-content:space-between;padding:.28rem 0}
.sum-row.total{font-size:1.35rem;font-weight:700;border-top:1px solid var(--line);margin-top:.4rem;padding-top:.6rem}
.sticky-side{position:sticky;top:76px}

/* invoice (screen + print) */
.invoice{background:#fff;max-width:820px;margin:0 auto;padding:1.6rem;border:1px solid var(--line);border-radius:var(--radius);font-size:.88rem}
.inv-head{display:flex;justify-content:space-between;gap:1rem;border-bottom:2px solid var(--brand);padding-bottom:.8rem;margin-bottom:.8rem}
.inv-head img{max-height:64px;max-width:180px;object-fit:contain}
.inv-title{text-align:right}
.inv-title h2{color:var(--brand);font-size:1.3rem;margin-bottom:.2rem;text-transform:uppercase;letter-spacing:.05em}
.inv-meta{display:flex;justify-content:space-between;gap:1rem;flex-wrap:wrap;margin-bottom:.8rem}
.invoice table{font-size:.82rem}
.invoice th{background:color-mix(in srgb,var(--brand) 10%,#fff);color:#1f2937}
.inv-totals{margin-left:auto;width:290px;margin-top:.6rem}
.inv-foot{display:flex;justify-content:space-between;gap:1rem;margin-top:1.2rem;border-top:1px dashed var(--line);padding-top:.8rem}
.thermal{max-width:302px;padding:.5rem;font-size:.75rem;border-radius:0}
.thermal .inv-head{flex-direction:column;text-align:center;align-items:center;border-bottom:1px dashed #000}
.thermal .inv-title{text-align:center}
.thermal .inv-totals{width:100%}
.thermal table{font-size:.72rem}
.thermal th,.thermal td{padding:.2rem .2rem}

/* misc */
.empty{text-align:center;color:var(--muted);padding:2rem 1rem}
.kv{display:grid;grid-template-columns:140px 1fr;gap:.3rem .8rem}
.kv dt{color:var(--muted)} .kv dd{margin:0}
.preview-logo{max-height:70px;max-width:220px;border:1px dashed var(--line);padding:6px;border-radius:8px;background:#fff}
.pill-list{display:flex;flex-wrap:wrap;gap:.35rem}
.code{font-family:ui-monospace,Menlo,Consolas,monospace;background:#f1f5f9;padding:.1rem .4rem;border-radius:5px;font-size:.82rem}
pre.code-block{background:#0f172a;color:#e2e8f0;padding:.8rem 1rem;border-radius:8px;overflow:auto;font-size:.82rem;white-space:pre-wrap;word-break:break-all}

/* ---------- Tablet / mobile ---------- */
@media (max-width:1100px){
  .g4{grid-template-columns:repeat(2,minmax(0,1fr))}
  .g3{grid-template-columns:repeat(2,minmax(0,1fr))}
  .pos-grid{grid-template-columns:1fr}
  .sticky-side{position:static}
}
@media (max-width:860px){
  .sidebar{transform:translateX(-100%);width:270px;visibility:hidden;transition:transform .2s,visibility 0s .2s}
  body.nav-open .sidebar{transform:none;visibility:visible;box-shadow:0 0 40px rgba(0,0,0,.35);transition:transform .2s}
  body.nav-open .scrim{display:block;position:fixed;inset:0;background:rgba(10,16,24,.5);z-index:40}
  .main{margin-left:0}
  #menuBtn{display:inline-grid}
  .content{padding:.9rem}
  .g2,.g3{grid-template-columns:1fr}
}
@media (max-width:560px){
  body{font-size:15px}
  .g4{grid-template-columns:1fr 1fr}
  .stat .val{font-size:1.25rem}
  .hide-xs{display:none!important}
  .form-grid{grid-template-columns:1fr}
  .toolbar>div,.toolbar .btn{flex:1 1 100%}
  .toolbar .btn{width:100%}
  .kv{grid-template-columns:110px 1fr}
  .card{padding:.9rem}
  .topbar{padding-left:.7rem;padding-right:.7rem}
  /* responsive tables -> stacked cards */
  table.stack thead{display:none}
  table.stack,table.stack tbody,table.stack tr,table.stack td{display:block;width:100%}
  table.stack tr{border:1px solid var(--line);border-radius:10px;margin-bottom:.7rem;padding:.35rem .2rem;background:#fff}
  table.stack td{border:0;padding:.3rem .7rem;display:flex;justify-content:space-between;gap:1rem;text-align:right}
  table.stack td::before{content:attr(data-l);font-weight:600;color:var(--muted);font-size:.78rem;text-align:left;flex:0 0 34%;padding-top:.1rem}
  table.stack td .cv{flex:1;min-width:0;text-align:right;overflow-wrap:anywhere}
  table.stack td .cv input,table.stack td .cv select{max-width:100%}
  .hide-sm{display:none}
  table.stack td.nolabel::before{display:none}
  table.stack td.nolabel{justify-content:flex-end}
  table.stack tfoot{display:block}
  .lines.stack td{text-align:left}
  .lines.stack td .cv input{text-align:right}
  .lines.stack td .cv select{text-align:left}
  .inv-totals{width:100%}
  .invoice{padding:1rem}
}

/* ---------- Print ---------- */
@media print{
  body{background:#fff}
  .sidebar,.topbar,.foot,.no-print,.scrim,.flash{display:none!important}
  .main{margin:0}.content{padding:0}
  .invoice{border:0;max-width:none;padding:0;box-shadow:none;border-radius:0}
  .card{box-shadow:none;border:0;padding:0}
  @page{margin:10mm}
  body.print-thermal .invoice{max-width:80mm}
  body.print-thermal{width:80mm}
  table.stack thead{display:table-header-group!important}
  .hide-sm{display:table-cell!important}
}
