/* Damal POS - simple, large, clear */
:root {
  --bg: #f4f6f5; --card: #ffffff; --ink: #14201d; --muted: #5f6f6a; --line: #dfe5e3;
  --primary: #0f766e; --primary-ink: #ffffff; --success: #15803d; --danger: #b91c1c; --warn: #b45309;
  --blue: #1d4ed8; --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --nav-h: 64px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 17px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .6rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.big { font-size: 1.3rem; font-weight: 700; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 14px; padding-top: calc(8px + env(safe-area-inset-top)); background: var(--primary); color: #fff; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.1rem; min-width: 0; }
.brand #shopName { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand.big { font-size: 1.6rem; color: var(--primary); justify-content: center; margin-bottom: 8px; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: #fde68a; color: #0f3d39; font-weight: 900; flex: none; }
.top-actions { display: flex; gap: 6px; align-items: center; flex: none; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.45); background: transparent; }
.pill { display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 99px; padding: 6px 10px; font: inherit; font-size: .8rem; font-weight: 700; background: rgba(255,255,255,.18); color: #fff; cursor: pointer; }
.pill .dot { width: 9px; height: 9px; border-radius: 50%; background: #4ade80; }
.pill.off .dot { background: #f87171; }
.pill #pendingText:not(:empty) { background: #fde68a; color: #422006; border-radius: 99px; padding: 1px 7px; }

/* Navigation: top on big screens, bottom on phones */
.mainnav { display: flex; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 52px; z-index: 15; }
.mainnav a { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 6px; text-decoration: none; color: var(--muted); font-weight: 700; border-bottom: 3px solid transparent; }
.mainnav a.on { color: var(--primary); border-bottom-color: var(--primary); }
.ni { font-size: 1.2rem; }
main { max-width: 1200px; margin: 0 auto; padding: 14px; }
@media (max-width: 760px) {
  .mainnav { position: fixed; top: auto; bottom: 0; left: 0; right: 0; border-top: 1px solid var(--line); border-bottom: 0; padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -2px 10px rgba(0,0,0,.06); }
  .mainnav a { flex-direction: column; gap: 2px; font-size: .75rem; padding: 8px 2px; border-bottom: 0; border-top: 3px solid transparent; }
  .mainnav a.on { border-top-color: var(--primary); }
  main { padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
  .top-actions .btn.small { padding: 6px 9px; }
}

/* Buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 48px; padding: 10px 18px; border-radius: 12px; border: 1.5px solid transparent;
  font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; background: #e7ecea; color: var(--ink); user-select: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); color: var(--primary-ink); }
.btn.success { background: var(--success); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn.icon { font-size: 1.2rem; }
.btn.xl { min-height: 60px; font-size: 1.2rem; padding: 12px 22px; }
.btn.block { display: flex; width: 100%; }
input, select { font: inherit; width: 100%; min-height: 50px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); }
input:focus, select:focus { outline: 3px solid rgba(15,118,110,.25); border-color: var(--primary); }
label { display: block; font-weight: 600; }
label > input, label > select, label > .inline { margin-top: 6px; }
.form { display: grid; gap: 14px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline { display: flex; gap: 8px; }
.inline .btn { flex: none; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }
.actions.wrap { flex-wrap: wrap; justify-content: stretch; }
.actions.wrap .btn { flex: 1 1 140px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.alert { padding: 12px 14px; border-radius: 12px; font-weight: 600; margin: 0 0 10px; }
.alert.danger { background: #fee2e2; color: #7f1d1d; }
.alert.warn { background: #fef3c7; color: #78350f; }
.alert.ok { background: #dcfce7; color: #14532d; }
#banner { max-width: 1200px; margin: 10px auto 0; }
#banner a { color: inherit; }

/* Dashboard */
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
@media (max-width: 900px) { .cards { grid-template-columns: 1fr 1fr; } }
.stat .label { color: var(--muted); font-weight: 600; font-size: .9rem; }
.stat .value { font-size: 1.9rem; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; word-break: break-word; }
.stat .sub { color: var(--muted); font-size: .85rem; }
.stat { border-top: 5px solid var(--line); }
.stat.green { border-top-color: var(--success); } .stat.blue { border-top-color: var(--blue); }
.stat.gray { border-top-color: #64748b; } .stat.red { border-top-color: var(--danger); }
.list { display: grid; gap: 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: #fff; border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow); }
.row .t { font-weight: 700; }
.row .s { color: var(--muted); font-size: .88rem; }
button.row { width: 100%; border: 0; font: inherit; text-align: left; cursor: pointer; color: inherit; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: .8rem; font-weight: 800; white-space: nowrap; }
.badge.low { background: #fef3c7; color: #78350f; }
.badge.out { background: #fee2e2; color: #7f1d1d; }
.badge.ok { background: #dcfce7; color: #14532d; }
.badge.wait { background: #e0e7ff; color: #1e3a8a; }

/* Sell */
.sell-grid { display: grid; grid-template-columns: 1fr 360px; gap: 14px; align-items: start; }
@media (max-width: 900px) { .sell-grid { grid-template-columns: 1fr; } }
.sell-right { position: sticky; top: 130px; display: grid; gap: 12px; }
@media (max-width: 900px) { .sell-right { position: static; } }
.scanbar { display: flex; gap: 8px; margin-bottom: 10px; }
.scan-input { font-size: 1.2rem; min-height: 60px; border-width: 2px; border-color: var(--primary); }
.btn.cam { min-height: 60px; flex: none; }
@media (max-width: 480px) { .btn.cam span { display: none; } }
.results { background: #fff; border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.12); margin-bottom: 10px; overflow: hidden; }
.results button { display: flex; width: 100%; justify-content: space-between; gap: 10px; padding: 14px; border: 0; border-bottom: 1px solid var(--line); background: #fff; font: inherit; text-align: left; cursor: pointer; }
.results button:last-child { border-bottom: 0; }
.results button:hover, .results button:focus { background: #f0fdfa; }
.lastscan { background: #ecfdf5; border: 2px solid #34d399; border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 1.15rem; }
.lastscan strong { font-size: 1.5rem; }
.lastscan.bad { background: #fef2f2; border-color: #f87171; flex-wrap: wrap; }
.cart { display: grid; gap: 8px; }
.cart-empty { text-align: center; color: var(--muted); padding: 40px 10px; border: 2px dashed var(--line); border-radius: var(--radius); }
.citem { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; background: #fff; border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
.citem .nm { font-weight: 700; font-size: 1.05rem; }
.citem .pr { color: var(--muted); }
.citem .lt { font-weight: 800; font-size: 1.15rem; text-align: right; }
.citem .warn { color: var(--warn); font-size: .85rem; font-weight: 600; grid-column: 1 / -1; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 48px; height: 48px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-size: 1.5rem; font-weight: 800; cursor: pointer; }
.qty input { width: 76px; text-align: center; font-weight: 800; font-size: 1.15rem; min-height: 48px; padding: 6px; }
.qty .rm { color: var(--danger); margin-left: 6px; font-size: 1.2rem; }
.tot-row { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; font-size: 1.1rem; }
.big-total { font-size: 2.2rem; color: var(--primary); font-variant-numeric: tabular-nums; }
.tot-row.change strong { font-size: 1.7rem; color: var(--success); }
.paid-input { font-size: 1.6rem; font-weight: 800; min-height: 62px; text-align: right; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; }
.quick button { flex: 1 1 70px; min-height: 44px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; font: inherit; font-weight: 700; cursor: pointer; }

.mobile-bar { display: none; }
@media (max-width: 900px) {
  .mobile-bar:not(.hidden) { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 14; gap: 10px; align-items: center;
    padding: 10px 14px; background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(0,0,0,.08); }
  .mobile-bar .btn { flex: 1; min-height: 56px; }
  .mb-total { border: 0; background: transparent; font: inherit; text-align: left; display: grid; cursor: pointer; padding: 0; color: var(--ink); }
  .mb-total small { color: var(--muted); font-weight: 600; }
  .mb-total strong { font-size: 1.6rem; color: var(--primary); }
  #view-sell { padding-bottom: 90px; }
}
@media (max-width: 760px) { .mobile-bar:not(.hidden) { bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); } }

/* Products */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 0 16px; min-height: 46px; font: inherit; font-weight: 700; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--primary); color: #fff; }
.table-wrap { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.ptable { width: 100%; border-collapse: collapse; }
.ptable th, .ptable td { padding: 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.ptable th { font-size: .85rem; color: var(--muted); background: #f8faf9; }
.ptable td.num, .ptable th.num { text-align: right; }
.ptable tr.lowrow td { background: #fffbeb; } .ptable tr.outrow td { background: #fef2f2; }
.ptable .pn { font-weight: 700; } .ptable .bc { color: var(--muted); font-size: .8rem; }
.ptable .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.ptable .acts .btn { min-height: 40px; padding: 6px 12px; font-size: .9rem; }
.found { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; border: 2px solid #34d399; }
.found .price { font-size: 2rem; font-weight: 800; color: var(--primary); }
@media (max-width: 640px) {
  .ptable thead { display: none; }
  .ptable tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px 8px; padding: 12px; border-bottom: 1px solid var(--line); }
  .ptable td { border: 0; padding: 0; }
  .ptable td:first-child, .ptable td:last-child { grid-column: 1 / -1; }
  .ptable td.num { text-align: left; }
  .ptable td.num::before { content: attr(data-l); display: block; font-size: .72rem; color: var(--muted); }
  .ptable tr.lowrow, .ptable tr.outrow { background: inherit; }
  .ptable tr.lowrow { background: #fffbeb; } .ptable tr.outrow { background: #fef2f2; }
  .ptable tr.lowrow td, .ptable tr.outrow td { background: transparent; }
  .two { grid-template-columns: 1fr; }
}
.date-input { max-width: 220px; }

/* Dialogs */
.modal { border: 0; border-radius: 18px; padding: 18px; width: min(520px, calc(100vw - 20px)); max-height: calc(100vh - 30px); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal::backdrop { background: rgba(10,20,18,.55); }
.modal h2 { margin-top: 0; }
.cam-modal #camReader { width: 100%; min-height: 240px; background: #000; border-radius: 12px; overflow: hidden; margin: 8px 0 12px; }
.cam-modal #camReader video { width: 100% !important; }
.receipt-preview { background: #fafafa; border: 1px dashed #c8d0cd; border-radius: 10px; padding: 12px; margin: 0 0 12px; max-height: 55vh; overflow: auto; display: flex; justify-content: center; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 28px); transform: translateX(-50%) translateY(20px); background: #14201d; color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 700; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-box { width: min(400px, 100%); background: #fff; padding: 26px; border-radius: 18px; box-shadow: var(--shadow); display: grid; gap: 14px; }

/* Receipt (screen preview + print) */
.receipt { font-family: "Courier New", ui-monospace, monospace; color: #000; background: #fff; font-size: 13px; line-height: 1.35; width: 72mm; padding: 2mm; }
.receipt.w58 { width: 48mm; font-size: 11px; }
.receipt.a4 { width: 120mm; font-size: 14px; font-family: system-ui, Arial, sans-serif; padding: 6mm; border: 1px solid #ddd; }
.receipt .c { text-align: center; }
.receipt .shop { font-size: 1.35em; font-weight: 800; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.receipt table { width: 100%; border-collapse: collapse; }
.receipt td { padding: 2px 0; vertical-align: top; }
.receipt td.r { text-align: right; white-space: nowrap; }
.receipt .tot td { font-weight: 800; font-size: 1.2em; }
.receipt .meta { display: flex; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
#printArea { display: none; }

@media print {
  html, body { background: #fff !important; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block !important; }
  .receipt { padding: 0 1mm; }
  .receipt.a4 { border: 0; margin: 0 auto; width: 100%; max-width: 170mm; }
}
