*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #f5f6f8;
  color: #222;
  font-size: 15px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: #fff;
  border-bottom: 1px solid #e2e4e8;
  flex-wrap: wrap;
  gap: 8px;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar .meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.user-chip {
  font-size: 13px;
  background: #eef5ff;
  color: #0a4d92;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 500;
}

.btn-link {
  background: none; border: none;
  color: #0a66c2; cursor: pointer;
  font-size: 13px; padding: 4px 6px;
}
.btn-link:hover { text-decoration: underline; }

.status { font-size: 12px; padding: 4px 10px; border-radius: 999px; font-weight: 500; }
.status.online  { background: #d4edda; color: #155724; }
.status.offline { background: #f8d7da; color: #721c24; }

.pending { font-size: 12px; color: #856404; background: #fff3cd; padding: 3px 8px; border-radius: 4px; }
.pending:empty { display: none; }
.cached-count { font-size: 12px; color: #6b7280; }
.cached-count:empty { display: none; }
#refreshBtn[disabled] { opacity: 0.5; cursor: wait; }

.sync-bar {
  background: #fff8e1; color: #6a4f00;
  padding: 8px 20px; font-size: 13px;
  border-bottom: 1px solid #ffe082;
  text-align: center;
}

main { max-width: 800px; margin: 0 auto; padding: 16px; }

.search-section { position: relative; margin-bottom: 16px; }
#search {
  width: 100%; padding: 12px 14px;
  font-size: 16px; border: 1px solid #cfd2d6;
  border-radius: 8px; background: #fff; outline: none;
}
#search:focus { border-color: #28a745; box-shadow: 0 0 0 3px rgba(40,167,69,0.15); }

.results {
  position: absolute; left: 0; right: 0;
  background: #fff; border: 1px solid #cfd2d6;
  border-radius: 0 0 8px 8px;
  max-height: 320px; overflow-y: auto;
  z-index: 20;
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}
.result { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid #eef0f2; }
.result:last-child { border-bottom: none; }
.result:hover { background: #f0f7ff; }
.result strong { display: block; font-weight: 600; }
.result small { display: block; color: #6b7280; font-size: 12px; margin-top: 2px; }

.list-section {
  background: #fff; border-radius: 8px; padding: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.list-header { display: flex; justify-content: space-between; align-items: center; padding: 4px 4px 8px; }
.item-count { color: #6b7280; font-size: 13px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 8px; text-align: left; border-bottom: 1px solid #eef0f2; vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; color: #6b7280; letter-spacing: 0.5px; }
td .code { display: block; font-size: 11px; color: #6b7280; margin-top: 2px; }

.qty-col { width: 100px; text-align: center; }
.rm-col  { width: 44px; text-align: right; }
.qty-input {
  width: 80px; padding: 6px 8px;
  border: 1px solid #cfd2d6; border-radius: 6px;
  font-size: 15px; text-align: center;
}
.qty-input:focus { border-color: #28a745; outline: none; }
.rm {
  background: #fdecea; color: #b71c1c; border: none;
  width: 28px; height: 28px; border-radius: 6px;
  cursor: pointer; font-size: 18px; line-height: 1;
}
.rm:hover { background: #f8d7da; }

.empty { padding: 20px; text-align: center; color: #6b7280; }

.actions { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 4px 4px; }
.btn-primary, .btn-secondary {
  padding: 10px 18px; border: none; border-radius: 6px;
  cursor: pointer; font-size: 15px; font-weight: 500;
}
.btn-primary { background: #28a745; color: #fff; }
.btn-primary:hover { background: #218838; }
.btn-secondary { background: #e9ecef; color: #333; }
.btn-secondary:hover { background: #dee2e6; }

/* ---- Modal (product not found) ------------------------------------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; animation: modal-fade 120ms ease-out;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal[hidden] { display: none; }
.modal-card {
  background: #fff; border-radius: 12px; max-width: 380px; width: 90%;
  padding: 28px 24px 22px; text-align: center;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
  animation: modal-pop 160ms ease-out;
}
@keyframes modal-pop {
  from { transform: scale(0.85); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.modal-icon {
  width: 60px; height: 60px; margin: 0 auto 14px;
  border-radius: 50%; background: #fdecea; color: #b71c1c;
  font-size: 36px; font-weight: bold; line-height: 60px;
  display: flex; align-items: center; justify-content: center;
}
.modal-card h2 { margin: 0 0 8px; font-size: 18px; color: #b71c1c; }
.modal-card p  { margin: 0 0 18px; color: #555; line-height: 1.4; }
.modal-card .btn-primary { width: 100%; padding: 11px; }

/* ---- Login page ----------------------------------------------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #28a745 0%, #1e7e34 100%);
  padding: 16px;
}
.login-card {
  background: #fff; padding: 32px 28px; border-radius: 12px;
  width: 100%; max-width: 360px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.18);
}
.login-card h1 {
  margin: 0 0 4px; font-size: 22px; text-align: center; color: #28a745;
}
.login-card .sub { text-align: center; color: #6b7280; margin: 0 0 22px; font-size: 13px; }
.login-card label { display: block; font-size: 12px; color: #555; margin: 12px 0 4px; }
.login-card input {
  width: 100%; padding: 10px 12px; font-size: 15px;
  border: 1px solid #cfd2d6; border-radius: 6px; outline: none;
}
.login-card input:focus { border-color: #28a745; box-shadow: 0 0 0 3px rgba(40,167,69,0.15); }
.login-card .btn-primary { width: 100%; margin-top: 18px; padding: 11px; }
.login-error {
  background: #fdecea; color: #b71c1c;
  padding: 10px; border-radius: 6px; font-size: 13px; margin-bottom: 8px;
}

@media (max-width: 480px) {
  .topbar { padding: 10px 12px; }
  .topbar h1 { font-size: 16px; }
  main { padding: 12px; }
  .qty-input { width: 64px; }
}

/* ---- Print: thermal receipt (80mm) --------------------------------- */
.print-only { display: none; }
@media print {
  /* hide everything, then show just the receipt */
  body * { visibility: hidden; }
  .print-only, .print-only * { visibility: visible; }
  .print-only {
    display: block !important;
    position: absolute; left: 0; top: 0;
    width: 80mm;
  }
  body { background: #fff; }
}
.receipt {
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12px; color: #000;
  width: 80mm; padding: 4mm 3mm;
  line-height: 1.35;
}
.receipt .r-header { text-align: center; }
.receipt .r-title { font-size: 16px; font-weight: bold; margin-bottom: 4px; }
.receipt .r-sub { font-size: 11px; }
.receipt hr {
  border: none; border-top: 1px dashed #000; margin: 6px 0;
}
.receipt .r-items { width: 100%; border-collapse: collapse; }
.receipt .r-items th, .receipt .r-items td {
  border: none; padding: 2px 0; vertical-align: top; font-size: 12px;
}
.receipt .r-items th { font-weight: bold; border-bottom: 1px solid #000; }
.receipt .r-name { text-align: left; }
.receipt .r-qty { text-align: right; width: 20mm; }
.receipt .r-code { font-size: 10px; color: #444; }
.receipt .r-totals {
  display: flex; justify-content: space-between; font-weight: bold;
  margin-top: 4px;
}
.receipt .r-footer { text-align: center; margin-top: 8px; font-size: 11px; }
@page { size: 80mm auto; margin: 0; }
