:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f766e;
  --primary-hover: #0d625b;
  --primary-soft: #ccfbf1;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warning-soft: #fef3c7;
  --warning: #b45309;
  --radius: 12px;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.03em;
}

.brand-name {
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 0.78rem;
  color: var(--muted);
}

.nav-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.nav-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 8px 14px;
  border-radius: 9px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-btn:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #99f6e4;
}

/* Main */
.main-content {
  padding: 20px 24px 32px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* POS Layout */
.pos-layout {
  display: grid;
  grid-template-columns: 1fr 400px;
  gap: 20px;
  align-items: start;
}

.pos-catalog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-height: 74vh;
}

.panel-toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1;
  min-width: 220px;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="email"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 0.92rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.select-compact {
  width: auto;
  min-width: 120px;
}

.category-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.cat-pill {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--muted);
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.cat-pill.active {
  background: var(--text);
  color: #fff;
  border-color: var(--text);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
  gap: 12px;
}

.product-card {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 13px;
  background: var(--surface);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  text-align: left;
}

.product-card:hover {
  border-color: var(--primary);
  box-shadow: 0 6px 14px rgba(15, 118, 110, 0.1);
  transform: translateY(-1px);
}

.product-card:active {
  transform: scale(0.98);
}

.prod-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.prod-sku {
  font-size: 0.72rem;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.prod-stock-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
}

.prod-stock-badge.low {
  background: var(--warning-soft);
  color: var(--warning);
}

.prod-stock-badge.out {
  background: var(--danger-soft);
  color: var(--danger);
}

.prod-card-name {
  font-weight: 700;
  font-size: 0.94rem;
  line-height: 1.3;
}

.prod-card-price {
  font-weight: 800;
  font-size: 1.08rem;
  color: var(--primary);
}

/* Cart */
.pos-cart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 82px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cart-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.customer-box label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  margin-bottom: 5px;
}

.customer-row {
  display: flex;
  gap: 8px;
}

.customer-row select {
  flex: 1;
}

.cart-items {
  max-height: 300px;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 8px 0;
}

.cart-empty {
  text-align: center;
  padding: 26px 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.cart-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 10px;
  padding: 9px 4px;
  border-bottom: 1px dashed var(--border);
}

.cart-item:last-child {
  border-bottom: none;
}

.cart-item-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.cart-item-price {
  font-size: 0.78rem;
  color: var(--muted);
}

.cart-item-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-btn {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-weight: 700;
  cursor: pointer;
}

.qty-btn:hover {
  background: #e2e8f0;
}

.qty-input {
  width: 48px !important;
  padding: 3px 5px !important;
  text-align: center;
  font-weight: 700;
  font-size: 0.86rem !important;
}

.cart-item-total {
  font-weight: 700;
  font-size: 0.92rem;
  text-align: right;
  min-width: 68px;
}

.remove-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 4px;
}

.remove-btn:hover {
  color: var(--danger);
}

.cart-summary {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.94rem;
}

.summary-row.inline-input input {
  width: 110px;
  text-align: right;
  padding: 5px 8px;
}

.summary-row.grand-total {
  font-size: 1.25rem;
  padding-top: 8px;
  border-top: 2px solid var(--border);
}

.payment-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-alt);
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.payment-methods {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.pay-pill {
  border: 1px solid var(--border);
  background: #fff;
  padding: 7px 6px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.pay-pill.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.cash-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: center;
}

.field-compact label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 3px;
}

.change-display {
  text-align: right;
  background: #fff;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.change-display span {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.change-display strong {
  font-size: 1.05rem;
  color: var(--primary);
}

/* Buttons */
.btn {
  border: none;
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: #e2e8f0;
}

.btn-danger-outline {
  background: #fff;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
}

.btn-checkout {
  width: 100%;
  padding: 13px;
  font-size: 1rem;
}

.btn-link {
  border: none;
  background: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
}

.btn-link.danger {
  color: var(--danger);
}

/* Stats & Tables */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.stat-value {
  display: block;
  margin-top: 4px;
  font-size: 1.4rem;
  font-weight: 800;
}

.card-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th {
  text-align: left;
  padding: 10px 10px;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

td {
  padding: 11px 10px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

th.num, td.num {
  text-align: right;
}

th.actions-col, td.actions-col {
  text-align: right;
  white-space: nowrap;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-ok {
  background: var(--primary-soft);
  color: var(--primary);
}

.badge-cancel {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-muted {
  background: #e2e8f0;
  color: #475569;
}

/* Forms & Settings */
.settings-grid {
  max-width: 780px;
}

.form-panel h2 {
  margin-top: 0;
}

.brand-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
  background: #fff;
}

.logo-uploader {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 11px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.logo-preview-box {
  width: 120px;
  height: 68px;
  border-radius: 9px;
  border: 1px dashed var(--border);
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 4px;
}

.logo-preview-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.logo-placeholder {
  font-size: 0.78rem;
  color: var(--muted);
}

.logo-uploader-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.logo-uploader-title {
  font-size: 0.88rem;
  font-weight: 600;
}

.logo-uploader-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text);
}

.field.full {
  grid-column: 1 / -1;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 22px 0;
}

.help-text {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 0;
}

.detected-urls {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.form-actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 540px;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

.modal-lg {
  max-width: 760px;
}

.modal-receipt-dialog {
  max-width: 540px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
}

.modal-close {
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.modal-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.history-body {
  overflow-y: auto;
}

.history-meta {
  font-size: 0.88rem;
  color: var(--muted);
  margin-bottom: 12px;
}

/* Printable Receipt */
.receipt-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.receipt-preview-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: #e2e8f0;
  padding: 16px;
  border-radius: 10px;
  display: block;
}

.receipt-paper {
  background: #fff;
  color: #000;
  padding: 16px 14px;
  margin: 0 auto;
  height: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.38;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.receipt-paper.size-80mm {
  width: 302px; /* ~80mm */
}

.receipt-paper.size-58mm {
  width: 218px; /* ~58mm */
  font-size: 11px;
  padding: 12px 10px;
}

.receipt-paper.size-letter {
  width: 100%;
  max-width: 680px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  padding: 24px;
}

.rc-center { text-align: center; }
.rc-logo {
  display: block;
  max-width: 130px;
  max-height: 62px;
  margin: 0 auto 6px;
  object-fit: contain;
}
.rc-title { font-size: 1.2em; font-weight: 800; margin: 0; }
.rc-sub { margin: 2px 0; font-size: 0.92em; }
.rc-hr { border: none; border-top: 1px dashed #000; margin: 8px 0; }
.rc-row { display: flex; justify-content: space-between; gap: 8px; }
.rc-items { width: 100%; border-collapse: collapse; margin: 4px 0; }
.rc-items th {
  font-size: 0.85em;
  text-transform: uppercase;
  border-bottom: 1px dashed #000;
  padding: 4px 2px;
  color: #000;
}
.rc-items td {
  padding: 4px 2px;
  border-bottom: none;
  vertical-align: top;
}
.rc-items .num { text-align: right; white-space: nowrap; }
.rc-total-big { font-size: 1.25em; font-weight: 800; margin-top: 4px; }
.rc-qr {
  margin: 10px auto 6px;
  display: flex;
  justify-content: center;
}
.rc-qr svg {
  width: 126px;
  height: 126px;
  display: block;
}
.rc-url {
  font-size: 0.75em;
  word-break: break-all;
  color: #334155;
}
.rc-cancelled {
  border: 2px solid #000;
  padding: 4px;
  font-weight: 800;
  text-align: center;
  margin: 6px 0;
}

.receipt-online-bar {
  margin-top: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.receipt-online-bar input {
  font-size: 0.8rem;
  background: var(--surface-alt);
}

.receipt-wa-bar {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.receipt-wa-bar input {
  font-size: 0.85rem;
}

.btn-whatsapp {
  background: #16a34a;
  color: #fff;
  white-space: nowrap;
}

.btn-whatsapp:hover:not(:disabled) {
  background: #15803d;
}

.receipt-wa-hint {
  margin-top: 5px;
  font-size: 0.78rem;
  color: var(--muted);
}

.receipt-wa-hint a {
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.wa-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.wa-qr-box {
  margin-top: 16px;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: var(--surface-alt);
  text-align: center;
}

.wa-qr-box svg {
  width: 220px;
  height: 220px;
  display: block;
  margin: 0 auto 10px;
  background: #fff;
  padding: 8px;
  border-radius: 10px;
}

.wa-user-info {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.88rem;
  font-weight: 600;
}

.wa-actions-row {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* Login Screen */
.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
}

.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.1);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-brand {
  text-align: center;
}

.login-brand h1 {
  margin: 10px 0 4px;
  font-size: 1.35rem;
}

.login-brand p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.login-logo-box {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.2rem;
  overflow: hidden;
}

.login-logo-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.login-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 0.86rem;
  font-weight: 600;
}

.login-hint {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--surface-alt);
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px dashed var(--border);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 600;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.2);
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 960px) {
  .pos-layout {
    grid-template-columns: 1fr;
  }
  .pos-cart {
    position: static;
  }
}

@media (max-width: 600px) {
  .main-content {
    padding: 12px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* Print Styles */
@media print {
  @page {
    margin: 4mm;
  }
  body {
    background: #fff !important;
  }
  .no-print {
    display: none !important;
  }
  .modal-backdrop {
    position: static !important;
    background: transparent !important;
    padding: 0 !important;
    display: block !important;
  }
  .modal-receipt-dialog {
    box-shadow: none !important;
    max-width: none !important;
    width: auto !important;
    padding: 0 !important;
    max-height: none !important;
  }
  .receipt-preview-scroll {
    background: transparent !important;
    padding: 0 !important;
    overflow: visible !important;
    display: block !important;
  }
  .receipt-paper {
    box-shadow: none !important;
    padding: 0 !important;
  }
  .receipt-paper.size-80mm {
    width: 72mm !important;
  }
  .receipt-paper.size-58mm {
    width: 50mm !important;
  }
  .receipt-paper.size-letter {
    width: 100% !important;
    max-width: none !important;
  }
}
