:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #166534;
  --primary-hover: #14532d;
  --primary-soft: #f0fdf4;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #991b1b; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 18px; font-size: 15px; width: 100%; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px;
}
.login-brand {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 4px 0;
}
.login-sub {
  font-size: 13px;
  color: var(--muted);
  margin: 0 0 20px 0;
}
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}
.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
.input:focus { outline: 2px solid #bbf7d0; border-color: var(--primary); }
.error-box {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* Main App Layout */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.topbar {
  height: 54px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--primary);
  margin-right: 6px;
}
.status-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}
.status-dot.online { background: var(--primary-soft); color: var(--primary); border-color: #bbf7d0; }
.status-dot.offline { background: var(--danger-soft); color: var(--danger); border-color: #fecaca; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.queue-btn {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: #fde68a;
}

/* Workspace Split */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 380px;
  overflow: hidden;
}

/* Left Catalog */
.catalog-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px 16px;
  gap: 10px;
}
.search-row {
  display: flex;
  gap: 8px;
}
.cats-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  flex-shrink: 0;
}
.cat-pill {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.cat-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.product-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(156px, 1fr));
  gap: 10px;
  align-content: start;
  padding-right: 4px;
}
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  min-height: 92px;
  transition: border-color 0.15s ease, background-color 0.15s ease;
  text-align: left;
}
.product-card:hover { border-color: var(--primary); background: #f8fafc; }
.product-card:active { background: var(--primary-soft); }
.product-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.product-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px;
}
.product-price { font-size: 13px; font-weight: 700; color: var(--primary); }
.product-code { font-size: 11px; color: var(--muted); }

/* Right Cart */
.cart-pane {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.cart-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cart-header h2 { margin: 0; font-size: 14px; font-weight: 700; }
.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px;
}
.cart-empty {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 13px;
}
.cart-line {
  padding: 10px 0;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.cart-line-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.cart-line-name { font-weight: 600; font-size: 13px; }
.cart-line-sub { font-weight: 700; font-size: 13px; }
.cart-line-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.qty-box {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.qty-btn {
  width: 28px;
  height: 26px;
  border: none;
  background: #f8fafc;
  font-weight: 700;
  cursor: pointer;
}
.qty-btn:hover { background: #e2e8f0; }
.qty-val {
  min-width: 32px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}
.disc-input {
  width: 58px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  text-align: right;
}

.cart-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: #fafafa;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.total-label { font-size: 14px; font-weight: 600; color: var(--muted); }
.total-amount { font-size: 22px; font-weight: 800; color: var(--text); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 20px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.pm-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.pm-btn {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
}
.pm-btn.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
}
.quick-cash {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.change-box {
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  margin-bottom: 14px;
}

.list-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.list-item.active { border-color: var(--primary); background: var(--primary-soft); }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 5px;
}
.badge-synced { background: var(--primary-soft); color: var(--primary); }
.badge-pending { background: var(--warn-soft); color: var(--warn); }

/* Print Area (Hidden on screen, 48mm thermal on print) */
#print-area { display: none; }

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr 290px; }
  .cart-pane { border-left: none; border-top: 1px solid var(--border); }
  .topbar { overflow-x: auto; }
}

@media print {
  @page { margin: 0 !important; padding: 0 !important; }
  html, body {
    margin: 0 !important;
    padding: 0 !important;
    width: 48mm !important;
    height: auto !important;
    overflow: visible !important;
    background: #ffffff !important;
  }
  .app-shell, .login-wrap, .modal-backdrop { display: none !important; }
  #print-area {
    display: block !important;
    width: 48mm !important;
    margin: 0 !important;
    padding: 0 !important;
    font-family: "Courier New", Courier, monospace;
    font-size: 11px;
    line-height: 1.3;
    color: #000000 !important;
  }
  #receipt-content::after {
    content: '.';
    display: block;
    padding-top: 12mm;
    font-size: 6px;
    line-height: 6px;
    color: #000000;
  }
  .rc-center { text-align: center; }
  .rc-bold { font-weight: 700; }
  .rc-sep { border-top: 1px dashed #000; margin: 4px 0; }
  .rc-row { display: flex; justify-content: space-between; gap: 4px; }
  .rc-item { margin-bottom: 3px; }
}
