/* ==========================================================================
   ShopSync design system — Light Slate + the ShopSync palette.
   Primary #1E88E5 · dark #1565C0 · success #43A047 · danger #E53935
   warn #FB8C00 · canvas #F5F7FA · card #FFF · ink #212121 · muted #757575
   border #E0E0E0. Touch targets >= 48px. RTL-ready.
   ========================================================================== */
:root {
  --blue: #1E88E5; --blue-dark: #1565C0; --green: #43A047; --red: #E53935;
  --warn: #FB8C00; --canvas: #F5F7FA; --card: #FFF; --ink: #212121;
  --muted: #757575; --border: #E0E0E0; --radius: 8px;
  --shadow: 0 1px 2px rgba(33,33,33,.06), 0 1px 8px rgba(33,33,33,.04);
  --pad: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body.app {
  background: var(--canvas); color: var(--ink);
  font-family: Inter, Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px; line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
}
body.rtl { direction: rtl; font-family: "Noto Nastaliq Urdu", Inter, Roboto, system-ui, sans-serif; }
h1, h2, h3 { font-weight: 700; margin: 0 0 8px; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 16px; }
a { color: var(--blue-dark); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .5px; }
.inline { display: inline; }

/* ---------------------------------------------------------------- topbar */
.topbar {
  position: sticky; top: 0; z-index: 30; background: var(--card);
  border-bottom: 1px solid var(--border); padding: 10px var(--pad);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  display: grid; place-items: center; width: 38px; height: 38px; flex: 0 0 38px;
  background: var(--blue); color: #fff; border-radius: var(--radius);
  font-weight: 800; letter-spacing: .5px;
}
.brand-mark--lg { width: 54px; height: 54px; flex-basis: 54px; font-size: 20px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { color: var(--muted); font-size: 12px; }
/* On a 375px phone the header chips squeeze the shop name into an ellipsis, so a
   shopkeeper cannot read the name of their own shop. Wrap to two lines and shrink
   the chips a little instead of truncating. */
@media (max-width: 430px) {
  .brand-text strong { font-size: 14px; white-space: normal; overflow-wrap: anywhere;
    line-height: 1.15; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .lang-toggle, .chip { padding: 6px 9px; font-size: 12px; }
}
.top-actions { display: flex; align-items: center; gap: 8px; }
.lang-toggle, .chip {
  border: 1px solid var(--border); border-radius: 999px; padding: 7px 12px;
  font-size: 12.5px; color: var(--ink); background: var(--canvas); white-space: nowrap;
}
.net-pill { border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 600; }
.net-pill--off { background: #FDECEA; color: var(--red); }
.net-pill--sync { background: #FFF4E5; color: #B26A00; }

/* ---------------------------------------------------------------- layout */
.wrap { padding: var(--pad) var(--pad) 110px; max-width: 1100px; margin: 0 auto; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--pad); margin-bottom: var(--pad); box-shadow: var(--shadow);
}
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.card-h h2 { margin: 0; }
.cols { display: grid; gap: var(--pad); }
@media (min-width: 860px) { .cols { grid-template-columns: 1fr 1fr; } }
.card--narrow { max-width: 560px; }

/* ---------------------------------------------------------------- stats */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: var(--pad); }
@media (min-width: 760px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  display: block; background: var(--card); border: 1px solid var(--border);
  border-left: 4px solid var(--blue); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); color: inherit;
}
body.rtl .stat { border-left: 1px solid var(--border); border-right: 4px solid var(--blue); }
.stat--green { border-left-color: var(--green); }
.stat--red { border-left-color: var(--red); }
.stat--warn { border-left-color: var(--warn); }
.stat-label { display: block; color: var(--muted); font-size: 12.5px; }
.stat-value { display: block; font-size: 20px; font-weight: 800; margin: 2px 0; }
.stat-sub { display: block; color: var(--muted); font-size: 12px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 48px; padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--card); color: var(--ink); font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.btn--primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn--success { background: var(--green); border-color: var(--green); color: #fff; }
.btn--danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn--ghost { background: var(--canvas); }
.btn--block { width: 100%; }
.btn--lg { min-height: 52px; font-size: 16px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: var(--pad); }
.link { background: none; border: 0; color: var(--blue-dark); font: inherit; font-weight: 600; cursor: pointer; padding: 4px; }
.link--danger { color: var(--red); }

/* ---------------------------------------------------------------- forms */
.form .field, .field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; }
label { font-size: 13px; font-weight: 600; color: var(--ink); }
.input {
  min-height: 48px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); color: var(--ink); font: inherit; width: 100%;
}
.input:focus { outline: 2px solid rgba(30,136,229,.35); border-color: var(--blue); }
.input--sm { min-height: 40px; padding: 6px 8px; }
.input--search { font-size: 16px; margin-bottom: 10px; }
.row { display: grid; gap: 10px; }
@media (min-width: 620px) { .row { grid-template-columns: 1fr 1fr; } }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; min-height: 48px; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-bar .input { width: auto; flex: 1 1 160px; }

/* ---------------------------------------------------------------- tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
body.rtl .tbl th, body.rtl .tbl td { text-align: right; }
.tbl th { color: var(--muted); font-size: 12.5px; text-transform: uppercase; letter-spacing: .3px; }
.tbl .num { text-align: right; white-space: nowrap; }
body.rtl .tbl .num { text-align: left; }
.tbl .actions { text-align: right; white-space: nowrap; }
.row--low td { background: #FFF9F0; }
.pill { display: inline-block; border-radius: 999px; padding: 3px 9px; font-size: 11.5px; font-weight: 700; }
.pill--green { background: #E8F5E9; color: #2E7D32; }
.pill--red { background: #FDECEA; color: #C62828; }
.pill--warn { background: #FFF4E5; color: #B26A00; }
.pill--grey { background: #EEEEEE; color: #555; }
.empty { color: var(--muted); padding: 10px 2px; }

/* ---------------------------------------------------------------- flashes */
.flash-list { margin-bottom: 10px; }
.flash { border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; font-size: 14px; }
.flash--ok { background: #E8F5E9; color: #2E7D32; }
.flash--warn { background: #FDECEA; color: #C62828; }
.flash--info { background: #E3F2FD; color: #1565C0; }

/* ---------------------------------------------------------------- bottom nav + fab */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--card);
  border-top: 1px solid var(--border); display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 8px 2px; min-height: 58px; color: var(--muted); font-size: 11.5px; font-weight: 600;
}
.tab-ico { font-size: 18px; line-height: 1; }
.tab.active { color: var(--blue-dark); }
.fab {
  position: fixed; right: 16px; bottom: 78px; z-index: 31; width: 62px; height: 62px;
  border-radius: 50%; background: var(--green); color: #fff; font-size: 32px; font-weight: 700;
  display: grid; place-items: center; box-shadow: 0 6px 16px rgba(67,160,71,.35); line-height: 1;
}
body.rtl .fab { right: auto; left: 16px; }
/* The day-close screen's one job is the Close button; the floating "+ new invoice"
   button would sit on top of the Expected / Difference figures on a 375px phone.
   A shopkeeper counting the drawer is not starting a sale. */
body.no-fab .fab { display: none; }
body.no-fab .wrap { padding-bottom: 90px; }
@media (min-width: 860px) { .bottomnav { display: none; } .fab { bottom: 24px; } .wrap { padding-bottom: 90px; } }

/* ---------------------------------------------------------------- POS */
.pos { display: grid; gap: var(--pad); }
@media (min-width: 900px) { .pos { grid-template-columns: 1.15fr .85fr; align-items: start; } }
.pick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 520px) { .pick-grid { grid-template-columns: repeat(3, 1fr); } }
.pick {
  display: flex; flex-direction: column; gap: 2px; text-align: left; min-height: 84px;
  padding: 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); cursor: pointer; font: inherit; color: inherit;
}
.pick:active { background: #E3F2FD; }
.pick--out { border-color: #EF9A9A; background: #FFF7F7; }
.pick-price { color: var(--green); font-weight: 700; }
.pick-stock { color: var(--muted); font-size: 12px; }
.cart-line {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px dashed var(--border);
}
.cart-line .cl-name { display: flex; flex-direction: column; grid-column: 1 / 2; }
.cart-line .cl-qty { display: flex; align-items: center; gap: 4px; grid-column: 1 / 2; }
.cart-line .cl-price { grid-column: 2 / 3; }
.cart-line .cl-price .input { width: 92px; }
.cart-line .cl-total { grid-column: 2 / 3; text-align: right; font-weight: 700; }
body.rtl .cart-line .cl-total { text-align: left; }
.cart-line .cl-del {
  grid-column: 2 / 3; justify-self: end; background: none; border: 0; color: var(--red);
  font-size: 22px; cursor: pointer; line-height: 1; padding: 2px 6px;
}
.qty-btn { width: 40px; height: 40px; border: 1px solid var(--border); background: var(--canvas); border-radius: var(--radius); font-size: 18px; font-weight: 700; cursor: pointer; }
.qty-in { width: 62px; min-height: 40px; text-align: center; border: 1px solid var(--border); border-radius: var(--radius); font: inherit; }
.method-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.method {
  min-height: 46px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); font: inherit; font-weight: 600; cursor: pointer;
}
.method.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.totals { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 8px; }
.totals > div { display: flex; justify-content: space-between; padding: 3px 0; font-size: 14px; }
.totals-grand { font-size: 19px !important; font-weight: 800; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 6px !important; }
.pos-actions { display: grid; gap: 8px; margin-top: 10px; }

/* ---------------------------------------------------------------- modal */
/* [hidden] must win over any class that sets a display value: without this the
   receipt modal stays clickable-but-invisible and the POS page goes dead. */
[hidden] { display: none !important; }
.modal { position: fixed; inset: 0; background: rgba(33,33,33,.45); display: grid; place-items: center; z-index: 60; padding: 16px; }
.modal-card { background: var(--card); border-radius: 12px; padding: 18px; width: 100%; max-width: 420px; }
.done-amount { font-size: 30px; font-weight: 800; margin: 6px 0; }

/* ---------------------------------------------------------------- auth */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; width: 100%; max-width: 430px; box-shadow: var(--shadow); }
.auth-head { text-align: center; margin-bottom: 16px; }
.auth-head h1 { margin: 8px 0 2px; }
.auth-card .btn { margin-top: 6px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 14px; }
.auth-shop { text-align: center; margin-bottom: 12px; }

/* ---------------------------------------------------------------- reports */
.report-list { display: grid; gap: 6px; }
.report-line { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px dashed var(--border); padding: 6px 0; }
.report-line strong { white-space: nowrap; }
/* a figure that wraps ("-Rs / 240.00") reads like a typo; the label may wrap, the money may not */
.report-line > span:last-child { white-space: nowrap; }
.range-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.range-tabs a {
  border: 1px solid var(--border); border-radius: 999px; padding: 8px 12px;
  background: var(--card); color: var(--ink); font-size: 13px; font-weight: 600;
}
.range-tabs a.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ---------------------------------------------------------------- receipt */
.receipt-wrap { display: grid; place-items: start center; }
.receipt {
  background: #fff; color: #000; padding: 8px 6px; border: 1px solid var(--border);
  font-family: ui-monospace, "Courier New", monospace; font-size: 12px; line-height: 1.35;
  width: 58mm; max-width: 100%;
}
.receipt--80 { width: 80mm; }
.receipt .r-center { text-align: center; }
.receipt .r-shop { font-size: 15px; font-weight: 800; }
.receipt hr { border: 0; border-top: 1px dashed #000; margin: 5px 0; }
.receipt table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.receipt th, .receipt td { padding: 1px 0; }
.receipt .r-right { text-align: right; }
.receipt .r-total { font-size: 14px; font-weight: 800; }
.receipt .r-foot { margin-top: 6px; text-align: center; font-size: 10.5px; }

@media print {
  .topbar, .bottomnav, .fab, .no-print, .flash-list, .btn-row { display: none !important; }
  body.app { background: #fff; padding: 0; }
  .wrap { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; padding: 0; margin: 0; }
  .receipt { border: 0; }
  @page { margin: 3mm; }
}
