/* ============================================================
   kasirin — application shell & screens
   ============================================================ */

html, body.app-body { height: 100%; }
body.app-body { overflow: hidden; }

.app {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr) 372px;
  height: 100dvh;
}

/* ---------- sidebar ---------- */
.sidebar {
  display: flex; flex-direction: column; gap: 14px;
  padding: 16px 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  min-height: 0;
}
.sb-brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 10px; }
.sb-brand img { width: 32px; height: 32px; border-radius: 9px; }
.sb-brand .word { font-size: 1.1rem; font-weight: 800; letter-spacing: -.045em; }
.sb-brand .word b { color: var(--accent-500); }
.sb-nav { display: flex; flex-direction: column; gap: 3px; }
.navitem {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--r-md);
  font-size: .9rem; font-weight: 600; color: var(--ink-2);
  transition: background .16s var(--ease), color .16s var(--ease);
  text-align: left; width: 100%;
}
.navitem svg { width: 19px; height: 19px; color: var(--muted); flex: none; }
.navitem:hover { background: var(--surface-3); color: var(--ink); }
.navitem[aria-current="page"] {
  background: var(--brand-50); color: var(--brand-700);
}
.navitem[aria-current="page"] svg { color: var(--brand-600); }
[data-theme="dark"] .navitem[aria-current="page"] { color: var(--brand-300); }
.navitem .count {
  margin-left: auto; font-size: .72rem; font-weight: 800;
  background: var(--surface-3); color: var(--muted); border-radius: var(--r-pill);
  padding: 2px 7px; min-width: 22px; text-align: center;
}
.navitem[aria-current="page"] .count { background: var(--brand-100); color: var(--brand-700); }
[data-theme="dark"] .navitem[aria-current="page"] .count { background: #12483A; color: var(--brand-200); }

.sb-store {
  margin-top: auto; padding: 12px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.sb-store .av {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: .9rem;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700)); color: #fff;
  overflow: hidden;
}
.sb-store .av img { width: 100%; height: 100%; object-fit: cover; }
.sb-store .nm { font-size: .84rem; font-weight: 700; line-height: 1.2; }
.sb-store .sub { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.sb-foot { display: flex; gap: 6px; }
.sb-foot .btn { flex: 1; }

/* ---------- workspace ---------- */
.workspace { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: transparent; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  backdrop-filter: blur(10px);
  flex: none;
}
.topbar .mobile-brand { display: none; }
.search-wrap {
  position: relative; flex: 1; max-width: 520px;
}
.search-wrap svg.ic {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  width: 17px; height: 17px; color: var(--muted-2); pointer-events: none;
}
.search-wrap input {
  width: 100%; height: 42px; padding: 0 74px 0 40px;
  border-radius: var(--r-pill); border: 1px solid var(--line-strong);
  background: var(--surface); font-size: .92rem;
}
.search-wrap input:focus { outline: none; border-color: var(--brand-500); box-shadow: var(--ring); }
.search-wrap .hint {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  display: flex; gap: 4px; pointer-events: none;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
}
.icon-btn:hover { border-color: var(--line-strong); }
.icon-btn svg { width: 18px; height: 18px; }

.view {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
  padding: 20px 22px 34px;
  scrollbar-gutter: stable;
}
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.view-head h1 { font-size: 1.5rem; letter-spacing: -.03em; }
.view-head .sub { font-size: .86rem; color: var(--muted); margin-top: 3px; }

/* ---------- category rail ---------- */
.cat-rail {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 26px 10px 2px; margin-bottom: 12px;
  scrollbar-width: none; scroll-padding-right: 26px;
}
.cat-rail::-webkit-scrollbar { display: none; }

/* ---------- product grid ---------- */
.pgrid {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
}
.pcard {
  display: flex; flex-direction: column; gap: 6px; text-align: left;
  padding: 10px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line);
  transition: transform .13s var(--ease), box-shadow .18s var(--ease), border-color .18s var(--ease);
  position: relative; overflow: hidden;
}
.pcard:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--brand-200); }
.pcard:active { transform: scale(.985); }
.pcard .thumb {
  height: 64px; border-radius: var(--r-sm); display: grid; place-items: center;
  font-size: 1.5rem; background: var(--tint, var(--surface-3));
  position: relative; overflow: hidden;
}
.pcard .thumb .ini { font-family: var(--font-ui); font-weight: 800; font-size: 1.1rem; color: var(--tint-ink, var(--brand-700)); }
.pcard .pname { font-size: .84rem; font-weight: 700; line-height: 1.28; min-height: 2.1em; }
.pcard .pmeta { font-size: .72rem; color: var(--muted); }
.pcard .pprice { font-size: .92rem; font-weight: 800; letter-spacing: -.02em; margin-top: auto; }
.pcard .stocktag {
  position: absolute; bottom: 6px; right: 6px; font-size: .62rem; font-weight: 800;
  padding: 2px 6px; border-radius: var(--r-pill); background: rgba(255,255,255,.9); color: var(--ink-2);
  border: 1px solid var(--line);
}
.pcard .stocktag.low { background: var(--accent-400); color: #2A1B00; border-color: transparent; }
.pcard .stocktag.out { background: var(--danger-500); color: #fff; border-color: transparent; }
.pcard.is-out { opacity: .62; }
.pcard .addhint {
  position: absolute; inset: auto 0 0 0; padding: 6px; text-align: center;
  font-size: .7rem; font-weight: 800; color: #fff;
  background: linear-gradient(180deg, transparent, rgba(10,92,70,.92));
  opacity: 0; transition: opacity .16s var(--ease);
}
.pcard:hover .addhint { opacity: 1; }

/* compact row layout */
.pgrid.rows { grid-template-columns: 1fr; }
.pgrid.rows .pcard {
  flex-direction: row; align-items: center; gap: 12px; padding: 9px 12px;
}
.pgrid.rows .pcard .thumb { width: 44px; height: 44px; flex: none; font-size: 1.1rem; }
.pgrid.rows .pcard .pname { min-height: 0; flex: 1; }
.pgrid.rows .pcard .pmeta { display: none; }
.pgrid.rows .pcard .pprice { margin: 0; }
.pgrid.rows .pcard .stocktag { position: static; }
.pgrid.rows .pcard .addhint { display: none; }

/* ---------- cart ---------- */
.cart-panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--surface); border-left: 1px solid var(--line);
}
.cart-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 14px 16px 10px; flex: none;
}
.cart-head h2 { font-size: 1rem; }
.cart-head .sub { font-size: .76rem; color: var(--muted); }
.cart-lines { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 4px 10px 8px; }
.cline {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 8px;
  padding: 9px 8px; border-radius: var(--r-md);
  transition: background .14s var(--ease);
}
.cline:hover { background: var(--surface-2); }
.cline + .cline { border-top: 1px dashed var(--line); border-radius: 0; }
.cline .nm { font-size: .84rem; font-weight: 700; line-height: 1.3; }
.cline .meta { font-size: .74rem; color: var(--muted); }
.cline .lt { font-size: .86rem; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.qty { display: inline-flex; align-items: center; gap: 2px; grid-column: 1 / -1; margin-top: 2px; }
.qty button {
  width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line-strong);
  display: grid; place-items: center; font-weight: 800; font-size: .9rem; color: var(--ink-2);
  background: var(--surface);
}
.qty button:hover { border-color: var(--brand-400); color: var(--brand-700); }
.qty .v {
  min-width: 30px; text-align: center; font-size: .84rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.qty .del { margin-left: auto; border: 0; color: var(--muted); width: 30px; }
.qty .del:hover { color: var(--danger-500); background: var(--danger-50); }
.cart-empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.cart-empty .ic {
  width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 16px;
  background: var(--surface-3); display: grid; place-items: center;
}
.cart-foot { flex: none; padding: 12px 14px 16px; border-top: 1px solid var(--line); background: var(--surface); }
.sumrow { display: flex; justify-content: space-between; font-size: .85rem; padding: 3px 2px; color: var(--ink-2); }
.sumrow.disc { color: var(--brand-700); }
.sumrow.total {
  font-size: 1.15rem; font-weight: 800; letter-spacing: -.03em; color: var(--ink);
  border-top: 1px dashed var(--line-strong); margin-top: 6px; padding-top: 9px;
}
.cart-foot .btn-pay { margin-top: 10px; }
.pay-methods { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0 4px; }
.pay-methods button {
  padding: 9px 4px; border-radius: var(--r-sm); border: 1px solid var(--line-strong);
  font-size: .76rem; font-weight: 700; color: var(--ink-2); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.pay-methods button svg { width: 16px; height: 16px; }
.pay-methods button[aria-pressed="true"] {
  border-color: var(--brand-600); background: var(--brand-600); color: var(--on-brand);
  box-shadow: var(--shadow-sm);
}
.pay-methods button[aria-pressed="true"] svg { color: currentColor; }

/* mobile cart bar */
.cartbar { display: none; }

/* ---------- tables / lists ---------- */
.list-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.lrow {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border-bottom: 1px solid var(--line); cursor: pointer; transition: background .14s var(--ease);
  width: 100%; text-align: left;
}
.lrow:last-child { border-bottom: 0; }
.lrow:hover { background: var(--surface-2); }
.lrow .av {
  width: 38px; height: 38px; border-radius: 12px; flex: none; display: grid; place-items: center;
  font-weight: 800; font-size: .88rem; background: var(--brand-50); color: var(--brand-700);
}
[data-theme="dark"] .lrow .av { color: var(--brand-300); }
.lrow .main { flex: 1; min-width: 0; }
.lrow .t { font-size: .9rem; font-weight: 700; }
.lrow .s { font-size: .78rem; color: var(--muted); margin-top: 1px; }
.lrow .amt { font-weight: 800; font-size: .92rem; text-align: right; white-space: nowrap; }

/* kpi */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 14px 16px; position: relative; overflow: hidden;
}
.kpi-card .lab { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.kpi-card .val { font-size: 1.42rem; font-weight: 800; letter-spacing: -.035em; margin-top: 4px; }
.kpi-card .delta { font-size: .75rem; font-weight: 700; margin-top: 3px; color: var(--brand-600); }
.kpi-card .delta.neg { color: var(--danger-500); }
.kpi-card.hero { background: linear-gradient(140deg, var(--brand-600), var(--brand-700)); border-color: transparent; color: #fff; }
.kpi-card.hero .lab { color: rgba(255,255,255,.72); }
.kpi-card.hero .delta { color: #CFF5E5; }

/* chart */
.chart-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px; }
.chart { display: flex; align-items: flex-end; gap: 8px; height: 150px; margin-top: 14px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; height: 100%; }
.chart .bar {
  width: 100%; max-width: 44px; border-radius: 6px 6px 3px 3px; min-height: 3px;
  background: linear-gradient(180deg, var(--brand-400), var(--brand-600));
  transition: height .5s var(--ease); position: relative;
}
.chart .col.today .bar { background: linear-gradient(180deg, var(--accent-400), var(--accent-500)); }
.chart .col span { font-size: .68rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.chart .bar:hover::after {
  content: attr(data-v); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--surface); font-size: .68rem; font-weight: 700;
  padding: 3px 7px; border-radius: 6px; white-space: nowrap;
}

/* settings */
.set-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.set-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.set-card .hd {
  padding: 13px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2);
  font-size: .72rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; color: var(--muted);
}
.set-row {
  display: flex; align-items: center; gap: 12px; padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.set-row:last-child { border-bottom: 0; }
.set-row .txt { flex: 1; min-width: 0; }
.set-row .txt .t { font-size: .88rem; font-weight: 700; }
.set-row .txt .s { font-size: .76rem; color: var(--muted); margin-top: 2px; line-height: 1.45; }
.set-row .ctl { flex: none; }

/* receipt */
.receipt {
  background: #fff; color: #111; font-family: var(--font-mono); font-size: 11px; line-height: 1.5;
  padding: 14px 12px; border-radius: 4px; max-width: 300px; margin: 0 auto;
  box-shadow: 0 1px 0 rgba(0,0,0,.06);
}
.receipt .c { text-align: center; }
.receipt .b { font-weight: 700; }
.receipt hr { border: 0; border-top: 1px dashed #999; margin: 7px 0; }
.receipt .li { display: flex; justify-content: space-between; gap: 6px; }
.receipt .li .n { flex: 1; }
.receipt .tooth {
  height: 8px; margin-top: 10px;
  background: radial-gradient(circle at 4px -2px, transparent 4px, #fff 4px) 0 0/8px 8px repeat-x;
}

/* misc app bits */
.banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--brand-50); border: 1px solid var(--brand-100); color: var(--brand-800);
  font-size: .85rem; margin-bottom: 14px;
}
[data-theme="dark"] .banner { color: var(--brand-200); border-color: #17453A; }
.banner svg { width: 18px; height: 18px; flex: none; }
.banner .btn { margin-left: auto; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }

.progress { height: 7px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: var(--brand-500); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: 210px minmax(0, 1fr) 330px; }
}
@media (max-width: 1020px) {
  .app { grid-template-columns: 72px minmax(0, 1fr); }
  .sidebar { padding: 14px 10px; align-items: center; }
  .sb-brand .word, .navitem span.lbl, .sb-store .txt, .sb-foot { display: none; }
  .navitem { justify-content: center; padding: 12px 0; }
  .navitem .count { display: none; }
  .sb-store { padding: 8px; }
  .cart-panel {
    position: fixed; inset: auto 0 0 0; z-index: 60;
    border-left: 0; border-top: 1px solid var(--line);
    border-radius: var(--r-xl) var(--r-xl) 0 0;
    box-shadow: 0 -18px 44px -22px rgba(10,40,30,.35);
    transform: translateY(calc(100% - 0px)); transition: transform .28s var(--ease);
    max-height: 84dvh; height: auto;
  }
  .cart-panel.open { transform: none; }
  .cart-panel .cart-lines { max-height: 46dvh; }
  .cartbar {
    display: flex; align-items: center; gap: 12px;
    position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 61;
    padding: 10px 12px 10px 16px; border-radius: var(--r-lg);
    background: linear-gradient(180deg, var(--brand-500), var(--brand-700));
    color: #fff; box-shadow: 0 18px 40px -18px rgba(10,60,45,.7);
  }
  .cartbar .info { flex: 1; min-width: 0; }
  .cartbar .info small { display: block; font-size: .7rem; opacity: .8; }
  .cartbar .info b { font-size: 1.05rem; letter-spacing: -.02em; }
  .cartbar .btn { --btn-bg: rgba(255,255,255,.16); --btn-fg: #fff; --btn-border: rgba(255,255,255,.35); }
  .view { padding-bottom: 96px; }
  .cart-panel .close-sheet { display: grid; }
}
@media (min-width: 1021px) {
  .cart-panel .close-sheet { display: none; }
  .cartbar { display: none !important; }
}
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: auto 0 0 0; z-index: 65;
    flex-direction: row; justify-content: space-around; gap: 2px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    border-right: 0; border-top: 1px solid var(--line);
    background: var(--surface);
  }
  .sb-brand, .sb-store, .sb-foot { display: none; }
  .sb-nav { flex-direction: row; width: 100%; justify-content: space-around; }
  .navitem { flex-direction: column; gap: 3px; padding: 6px 4px; border-radius: 10px; flex: 1; }
  .navitem .lbl { display: block !important; font-size: .66rem; font-weight: 700; }
  .navitem[aria-current="page"] { background: var(--brand-50); }
  .topbar { padding: 10px 12px; }
  .topbar .mobile-brand { display: inline-flex; align-items: center; gap: 7px; }
  .topbar .mobile-brand img { width: 26px; height: 26px; border-radius: 7px; }
  .topbar .mobile-brand span { font-size: .95rem; font-weight: 800; letter-spacing: -.04em; display: none; }
  .search-wrap input { padding-right: 40px; }
  .search-wrap .hint { display: none; }
  .view { padding: 14px 12px 150px; }
  .view-head h1 { font-size: 1.25rem; }
  .pgrid { grid-template-columns: repeat(auto-fill, minmax(122px, 1fr)); gap: 8px; }
  .pcard .thumb { height: 58px; font-size: 1.25rem; }
  .pcard .pname { font-size: .78rem; }
  .pcard .pprice { font-size: .86rem; }
  .cartbar { bottom: calc(64px + env(safe-area-inset-bottom)); }
  .kpi-card .val { font-size: 1.2rem; }
}
@media (max-width: 400px) {
  .pgrid { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- print ---------- */
@media print {
  body.app-body { overflow: visible; }
  .app, .topbar, .sidebar, .cartbar, .toast-host, .modal-root:not(.printing) { display: none !important; }
  .modal-root.printing { position: static; display: block; padding: 0; }
  .modal-root.printing .modal-backdrop, .modal-root.printing .modal-head,
  .modal-root.printing .modal-foot { display: none !important; }
  .modal-root.printing .modal { box-shadow: none; border: 0; width: 58mm; max-width: 58mm; max-height: none; }
  .modal-root.printing .modal-body { padding: 0; overflow: visible; }
  .receipt { box-shadow: none; max-width: 58mm; padding: 0; font-size: 10.5px; }
  @page { margin: 4mm; size: 58mm auto; }
}
