:root {
  --bg: var(--tg-theme-bg-color, #f3f5f7);
  --card: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1d2733);
  --muted: var(--tg-theme-hint-color, #6f7a86);
  --accent: var(--tg-theme-button-color, #1677ff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(127, 127, 127, .23);
  --danger: #c62828;
  --warning: #9a6400;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; }
button { min-height: 42px; border: 1px solid var(--border); border-radius: 10px; padding: 9px 13px; background: var(--card); color: var(--text); cursor: pointer; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 700; }
button.danger, .danger { background: var(--danger); color: white; border-color: transparent; }
button.warning-btn { background: #fff3cd; color: #664d03; border-color: #ffecb5; }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--card); color: var(--text); }
textarea { resize: vertical; }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
h1 { font-size: 19px; margin: 0; }
h2 { font-size: 18px; margin: 0 0 14px; }
.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }
.app-header { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--card); border-bottom: 1px solid var(--border); }
.logo { width: 46px; height: 46px; object-fit: contain; border-radius: 8px; }
.header-copy { flex: 1; min-width: 0; }
.icon-btn { width: 44px; padding: 0; font-size: 24px; }
main { width: min(100%, 1000px); margin: 0 auto; padding: 12px 12px 28px; }
.panel { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.summary-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.summary-card span { display: block; font-size: 12px; color: var(--muted); }
.summary-card strong { font-size: 24px; }
.summary-card.warning strong { color: var(--warning); }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: thin; }
.tab { flex: 0 0 auto; }
.tab.active { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.toolbar { display: grid; grid-template-columns: 1fr minmax(125px, 220px); gap: 8px; margin-bottom: 10px; }
.stock-list { display: grid; gap: 8px; }
.stock-item { width: 100%; text-align: left; display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 13px; }
.stock-item .name { font-weight: 750; font-size: 16px; }
.stock-item .type { color: var(--muted); font-size: 13px; }
.stock-item .qty { font-weight: 800; font-size: 20px; text-align: right; }
.status { display: inline-block; font-size: 11px; font-weight: 800; padding: 3px 7px; border-radius: 999px; margin-top: 5px; }
.status.ok { background: #e7f6ea; color: #166534; }
.status.low { background: #fff3cd; color: #7a4c00; }
.status.out { background: #fde8e8; color: #991b1b; }
.form-panel { display: grid; gap: 12px; max-width: 660px; margin-left: auto; margin-right: auto; }
.current-stock { font-weight: 700; padding: 10px; background: rgba(127,127,127,.08); border-radius: 10px; }
.button-row, .inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; }
.inline-form > label { min-width: 160px; flex: 1; }
.inline-form > input, .inline-form > select { width: auto; min-width: 150px; flex: 1; }
.table-wrap { overflow-x: auto; margin-top: 12px; }
table { width: 100%; border-collapse: collapse; min-width: 650px; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; font-size: 13px; }
th { font-weight: 750; }
.big-id { font-size: 25px; font-weight: 800; letter-spacing: .5px; padding: 12px; border: 1px dashed var(--border); border-radius: 10px; user-select: all; }
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 18px; overflow-y: auto; }
.modal-card { width: min(100%, 520px); background: var(--card); color: var(--text); border-radius: 16px; padding: 18px; position: relative; margin: auto; }
.modal-close { position: absolute; right: 10px; top: 10px; border: none; background: transparent; font-size: 26px; width: 40px; padding: 0; }
.item-image { width: 100%; max-height: 320px; object-fit: contain; border-radius: 12px; margin-bottom: 12px; background: rgba(127,127,127,.08); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); max-width: calc(100% - 24px); background: #20262d; color: white; border-radius: 10px; padding: 10px 14px; z-index: 150; box-shadow: 0 8px 30px rgba(0,0,0,.25); }
@media (max-width: 600px) {
  main { padding-left: 9px; padding-right: 9px; }
  .toolbar { grid-template-columns: 1fr; }
  .app-header { padding-left: 9px; padding-right: 9px; }
  .logo { width: 40px; height: 40px; }
  .summary-card { padding: 10px; }
  .summary-card strong { font-size: 20px; }
}
@media print {
  .app-header, .tabs, .summary-grid, .button-row, #reportInfo { display: none !important; }
  body, main, .panel { background: white; color: black; border: 0; }
  #page-reports { display: block !important; }
  .tab-page:not(#page-reports) { display: none !important; }
}

/* POS-style Stock product cards */
.stock-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 12px;
  align-items: stretch;
}
.stock-item.pos-card {
  min-width: 0;
  width: 100%;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.stock-item.pos-card:active {
  transform: scale(.985);
}
.product-media {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: rgba(127,127,127,.08);
  border-bottom: 1px solid var(--border);
}
.product-thumb {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.product-placeholder {
  display: grid;
  place-items: center;
  font-size: 48px;
  color: var(--muted);
}
.product-info {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
  padding: 11px;
}
.stock-item.pos-card .name {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 800;
  font-size: 15px;
  line-height: 1.25;
}
.stock-item.pos-card .type {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.stock-item.pos-card .other {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  min-height: 31px;
}
.product-bottom {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}
.stock-item.pos-card .status {
  margin-top: 0;
  max-width: 105px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.qty-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1;
}
.qty-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.stock-item.pos-card .qty {
  font-size: 22px;
  font-weight: 900;
  text-align: right;
  line-height: 1.1;
}
@media (max-width: 430px) {
  .stock-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .product-info { padding: 9px; }
  .stock-item.pos-card .name { font-size: 14px; }
  .stock-item.pos-card .qty { font-size: 20px; }
  .stock-item.pos-card .status { font-size: 9px; padding: 3px 5px; max-width: 86px; }
}
@media (max-width: 330px) {
  .stock-list { grid-template-columns: 1fr; }
}


/* POS quick stock-out actions */
.stock-item.pos-card {
  padding: 0;
}
.product-open {
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}
.product-open:active {
  transform: none;
  background: rgba(127,127,127,.05);
}
.quick-out-btn {
  width: calc(100% - 18px);
  margin: 0 9px 9px;
  min-height: 42px;
  border-radius: 10px;
  border-color: transparent;
  background: var(--danger);
  color: white;
  font-weight: 800;
}
.quick-out-btn:disabled {
  background: rgba(127,127,127,.2);
  color: var(--muted);
  cursor: not-allowed;
}
.quick-out-card {
  display: grid;
  gap: 12px;
}
.quick-out-image {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 12px;
  background: rgba(127,127,127,.06);
}
.quick-out-copy h2 {
  margin: 2px 0 5px;
}
.pos-action-label {
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .08em;
  color: var(--danger);
}
.qty-stepper {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 54px;
  gap: 8px;
  align-items: stretch;
}
.qty-stepper button {
  min-height: 52px;
  font-size: 24px;
  font-weight: 900;
}
.qty-stepper input {
  min-width: 0;
  text-align: center;
  font-size: 22px;
  font-weight: 900;
}
.quick-out-confirm {
  min-height: 52px;
  font-size: 16px;
}
@media (max-width: 430px) {
  .quick-out-btn {
    min-height: 40px;
    font-size: 13px;
  }
}

/* v1.9 image performance */
.stock-item.pos-card {
  content-visibility: auto;
  contain-intrinsic-size: 320px;
}
.product-media {
  position: relative;
}
.product-thumb {
  background: rgba(127,127,127,.06);
}
.stock-load-more {
  grid-column: 1 / -1;
  text-align: center;
  padding: 10px 8px 16px;
  min-height: 36px;
}
.stock-empty {
  grid-column: 1 / -1;
}
.stock-load-more[type="button"] {
  width: 100%;
  background: var(--card);
  color: var(--muted);
  border: 1px dashed var(--border);
}
