* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f4f5f7;
  color: #1a1a2e;
}

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #1a1a2e;
}
.login-card {
  background: #fff;
  padding: 32px;
  border-radius: 12px;
  width: 320px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.login-card h1 { font-size: 20px; margin: 0 0 20px; text-align: center; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.login-card input {
  width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 8px; font-size: 15px;
}
.login-card button {
  margin-top: 20px; width: 100%; padding: 12px; border: none; border-radius: 8px;
  background: #1a1a2e; color: #fff; font-weight: 600; font-size: 15px; cursor: pointer;
}
.login-card button:hover { background: #2a2a4a; }

.install-buttons { display: flex; gap: 10px; margin-top: 16px; width: 320px; }
.install-btn {
  flex: 1; padding: 10px; border: 1px solid rgba(255,255,255,0.3); border-radius: 8px;
  background: transparent; color: #fff; font-weight: 600; font-size: 13px; cursor: pointer;
}
.install-btn:hover { background: rgba(255,255,255,0.1); }
.install-note { margin-top: 10px; width: 320px; color: #c9c9d8; font-size: 12px; text-align: center; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: #1a1a2e; color: #fff;
  display: flex; flex-direction: column; padding: 20px 0; flex-shrink: 0;
}
.brand { font-size: 18px; font-weight: 700; padding: 0 20px 20px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  color: #c9c9d8; text-decoration: none; padding: 12px 20px; font-size: 14px; font-weight: 500;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.08); color: #fff; }
.sidebar nav a.active { background: rgba(255,255,255,0.12); color: #fff; border-left: 3px solid #4caf50; }
.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.1); }
.user-name { font-size: 13px; color: #c9c9d8; margin-bottom: 8px; }
.link-button {
  background: none; border: none; color: #ff8080; padding: 0; font-size: 13px;
  font-weight: 600; cursor: pointer;
}

.content { flex: 1; padding: 32px 40px; max-width: 900px; }
.content h1 { margin-top: 0; font-size: 22px; }

/* Flash */
.flash { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.flash-success { background: #e6f6ea; color: #0a7d32; }
.flash-error { background: #fdeaea; color: #c62828; }

/* Offline selling status (worker_offline.js) */
.sync-bar { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 14px; font-weight: 600; }
.sync-bar:empty { display: none; }
.sync-ok { background: #e6f6ea; color: #0a7d32; }
.sync-warn { background: #fff4e0; color: #9a5b00; }
.sync-offline { background: #e8ecf5; color: #2b3a67; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 600; vertical-align: middle; }
.tag-wait { background: #fff4e0; color: #9a5b00; }
.tag-offline { background: #e8ecf5; color: #2b3a67; }
.tag-conflict { background: #fdeaea; color: #c62828; }
.pending-row td { opacity: .75; }

/* Dashboard cards */
.cards { display: flex; gap: 16px; margin-top: 20px; }
.stat-card {
  background: #fff; border-radius: 12px; padding: 20px 28px; text-decoration: none;
  color: inherit; box-shadow: 0 1px 3px rgba(0,0,0,0.08); min-width: 140px;
}
.stat-number { font-size: 28px; font-weight: 700; }
.stat-label { font-size: 13px; color: #666; margin-top: 4px; }

/* Forms */
.panel-form {
  background: #fff; padding: 20px; border-radius: 12px; margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.form-row { display: flex; gap: 16px; margin-bottom: 4px; }
.form-row > div { flex: 1; }
.panel-form label { display: block; font-size: 13px; font-weight: 600; margin: 8px 0 4px; }
.panel-form input, .panel-form select {
  width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 8px; font-size: 14px;
}
.panel-form button {
  margin-top: 16px; padding: 10px 20px; border: none; border-radius: 8px;
  background: #1a1a2e; color: #fff; font-weight: 600; cursor: pointer;
}
.panel-form button:hover { background: #2a2a4a; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.data-table th, .data-table td { text-align: left; padding: 12px 16px; font-size: 14px; border-bottom: 1px solid #eee; }
.data-table th { background: #fafafa; font-weight: 600; color: #555; }
.data-table .empty { text-align: center; color: #999; padding: 24px; }
.data-table form { margin: 0; }
.link-button-danger { color: #c62828; }
.link-button-danger:hover { text-decoration: underline; }
.transfer-form { display: flex; gap: 6px; align-items: center; }
.transfer-form select { padding: 6px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px; }
.transfer-form input[type="number"] { width: 60px; padding: 6px 8px; border: 1px solid #ccc; border-radius: 6px; font-size: 13px; }
.transfer-form button {
  padding: 6px 12px; border: none; border-radius: 6px; background: #1a1a2e; color: #fff;
  font-size: 13px; font-weight: 600; cursor: pointer;
}
.transfer-form button:hover { background: #2a2a4a; }
.empty-inline { font-size: 12px; color: #999; }
.row-actions { display: flex; gap: 12px; align-items: center; }
.row-actions a.link-button { color: #1a1a2e; text-decoration: none; font-weight: 600; font-size: 13px; }
.row-actions a.link-button:hover { text-decoration: underline; }
.cancel-link { margin-left: 12px; font-size: 13px; color: #666; text-decoration: none; }
.cancel-link:hover { text-decoration: underline; }

/* Reports */
.report-tabs { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.report-tab {
  padding: 8px 16px; border-radius: 100px; font-size: 13px; font-weight: 600;
  background: #fff; color: #555; text-decoration: none; border: 1px solid #ddd;
}
.report-tab:hover { border-color: #1a1a2e; color: #1a1a2e; }
.report-tab.active { background: #1a1a2e; color: #fff; border-color: #1a1a2e; }
.filter-form { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.filter-form label { font-size: 13px; font-weight: 600; color: #555; }
.filter-form select { padding: 8px 12px; border: 1px solid #ccc; border-radius: 8px; font-size: 13px; }
.chart-card {
  background: #fcfcfb; border-radius: 12px; padding: 20px; margin: 16px 0 28px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.chart-title { font-size: 14px; font-weight: 700; color: #0b0b0b; margin: 0 0 16px; }
.chart-wrap { position: relative; height: 260px; }

/* Search */
.search-result-card {
  background: #fff; border-radius: 12px; padding: 20px; margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.search-result-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 14px; }
.search-result-name { font-size: 17px; font-weight: 700; }
.search-result-sub { font-size: 13px; color: #666; margin-top: 2px; }
.search-result-price { font-size: 18px; font-weight: 700; color: #0a7d32; }

/* Notifications */
.notification-unread { background: #f0f6ff; font-weight: 600; }

/* Worker panel (mobile-first, no sidebar) */
.worker-body { max-width: 480px; margin: 0 auto; }
.worker-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; background: #1a1a2e; color: #fff; position: sticky; top: 0; z-index: 10;
}
.worker-brand { font-weight: 700; font-size: 16px; }
.worker-header-right { display: flex; align-items: center; gap: 12px; }
.worker-name { font-size: 13px; color: #c9c9d8; }
.worker-header .link-button { color: #ff8080; font-size: 13px; font-weight: 600; }
.worker-tabs { display: flex; background: #fff; border-bottom: 1px solid #eee; position: sticky; top: 49px; z-index: 9; }
.worker-tab { flex: 1; text-align: center; padding: 12px; font-size: 13px; font-weight: 600; color: #666; text-decoration: none; }
.worker-tab.active { color: #1a1a2e; border-bottom: 2px solid #1a1a2e; }
.worker-content { padding: 16px; }
.worker-content h1 { font-size: 19px; margin-top: 0; }

.scan-card {
  background: #fff; border-radius: 12px; padding: 16px; margin-bottom: 16px;
  text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.scan-card button { width: 100%; padding: 12px; background: #1a1a2e; color: #fff; border: none; border-radius: 8px; font-weight: 600; }
#scan-video { width: 100%; border-radius: 8px; margin-bottom: 10px; display: none; background: #000; }
#scan-canvas { display: none; }
#scan-status { margin-top: 8px; word-break: break-all; }

/* Seller transfer page: one card per product at the seller's market */
.stock-cards { display: flex; flex-direction: column; gap: 10px; }
.stock-card { background: #fff; border: 1px solid #eee; border-radius: 10px; padding: 12px; }
.stock-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.stock-card-name { font-weight: 700; font-size: 14px; }
.stock-card-sub { font-size: 12px; color: #666; margin-top: 2px; }
.stock-card-qty { font-weight: 700; font-size: 14px; white-space: nowrap; }
.stock-card .transfer-form { flex-wrap: wrap; }
.stock-card .transfer-form select { flex: 1; min-width: 0; font-size: 16px; }
.stock-card .transfer-form input[type="number"] { font-size: 16px; }
.report-tab.export-tab { margin-left: auto; background: #0a7d32; color: #fff; border-color: #0a7d32; }
.report-tab.export-tab:hover { background: #086024; color: #fff; }

/* Exact-day calendar filter (worker reports) */
.date-filter { display: flex; align-items: center; gap: 10px; margin: 0 0 20px; flex-wrap: wrap; }
.date-filter-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px;
  font-weight: 600; color: #555; cursor: pointer; }
.date-filter-label.active { color: #0a7d32; }
.date-filter-icon { flex: none; }
.date-filter input[type="date"] { padding: 8px 12px; border: 1px solid #ccc; border-radius: 8px;
  font-size: 13px; color: #1a1a2e; background: #fff; cursor: pointer; }
.date-filter input[type="date"]:focus { outline: none; border-color: #0a7d32; }
.date-filter-clear { font-size: 13px; color: #b0203a; text-decoration: none; }
.date-filter-clear:hover { text-decoration: underline; }
.section-title { font-size: 16px; margin: 28px 0 12px; }

/* QR Code Generator */
.form-note { font-size: 12px; color: #888; margin: 10px 0 0; }
.qr-print-area { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; margin: 20px 0; }
/* Labels are sized in real mm (--lw/--lh set by admin_qrcode.php) so the screen
   preview matches the XP-246B sticker exactly. Black on white only — thermal. */
:root { --lw: 58mm; --lh: 40mm; }
.label-item { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.qr-box {
  --pad: 1.5mm;
  width: var(--lw); height: var(--lh); box-sizing: border-box; overflow: hidden;
  /* The head prints ~54 mm, so 58/60 mm stickers keep content inside that width. */
  padding: var(--pad) max(var(--pad), (var(--lw) - 54mm) / 2); display: flex; align-items: center; gap: 1.5mm;
  background: #fff; color: #000; border: 1px dashed #bbb; border-radius: 2mm;
  font-size: calc(var(--lh) * 0.085); line-height: 1.2;
}
.qr-canvas {
  flex: none; width: calc(min(var(--lh) - 2 * var(--pad), var(--lw) * 0.48));
  aspect-ratio: 1;
}
.qr-canvas img, .qr-canvas canvas { width: 100% !important; height: 100% !important; display: block; image-rendering: pixelated; }
.qr-text { flex: 1; min-width: 0; text-align: left; }
/* The 14-char code must stay on one line, so its size follows the text column width. */
.qr-label-id { font-family: monospace; font-weight: 700; white-space: nowrap; font-size: calc(min(0.85em, (var(--lw) * 0.52 - 4.5mm) / 8.6)); }
.qr-label-name {
  font-weight: 700; margin-top: 0.4em; overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.qr-label-sub { font-size: 0.85em; margin-top: 0.2em; }
body.label-stacked .qr-box { flex-direction: column; justify-content: center; }
body.label-stacked .qr-canvas { width: calc(min(var(--lh) * 0.6, var(--lw) - 2 * var(--pad))); }
body.label-stacked .qr-text { flex: none; width: 100%; text-align: center; }
body.label-stacked .qr-label-id { font-size: calc(min(0.85em, (var(--lw) - 4mm) / 8.6)); }
.label-toolbar .form-row > div { flex: 1; }

/* Quick templates */
.templates-box { margin-bottom: 16px; }
.templates-hint { font-size: 12px; color: #888; margin-bottom: 8px; }
.templates-empty { font-size: 13px; color: #999; }
.templates-list { display: flex; flex-wrap: wrap; gap: 8px; }
.template-chip {
  display: inline-flex; align-items: stretch; background: #fff; border: 1px solid #ddd;
  border-radius: 100px; overflow: hidden;
}
.template-fill {
  border: none; background: none; padding: 8px 14px; font-size: 13px; font-weight: 600;
  color: #1a1a2e; cursor: pointer;
}
.template-fill:hover { background: #f2f2f7; }
.template-delete-form { margin: 0; display: flex; }
.template-delete {
  border: none; border-left: 1px solid #eee; background: none; padding: 8px 12px;
  color: #c62828; font-weight: 700; cursor: pointer; font-size: 14px; line-height: 1;
}
.template-delete:hover { background: #fdeaea; }

/* Responsive: this system runs mostly on phones, so treat the phone layout as the
   primary target (wide breakpoint) rather than a narrow fallback for desktop. */
@media (max-width: 900px) {
  .login-card, .install-buttons, .install-note { width: 90vw; max-width: 320px; }

  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; align-items: center;
    padding: 8px 12px; overflow-x: auto; white-space: nowrap;
  }
  .brand { padding: 0 12px 0 0; }
  .sidebar nav { flex-direction: row; flex: none; gap: 2px; }
  .sidebar nav a { padding: 10px 12px; white-space: nowrap; border-radius: 8px; }
  .sidebar-footer { margin-left: auto; padding: 0 0 0 12px; border: none; display: flex; align-items: center; gap: 10px; }
  .user-name { margin-bottom: 0; }

  .content { padding: 14px; max-width: 100%; }
  .content h1 { font-size: 19px; }
  .cards { flex-wrap: wrap; gap: 10px; }
  .stat-card { flex: 1 1 calc(50% - 5px); min-width: 0; padding: 16px; }

  .form-row { flex-direction: column; gap: 0; }

  /* Inputs/selects at 16px prevent iOS Safari's auto-zoom-on-focus */
  .panel-form input, .panel-form select, .login-card input,
  .transfer-form select, .transfer-form input[type="number"],
  .date-filter input[type="date"],
  .filter-form select { font-size: 16px; }

  /* Comfortable tap targets (Apple HIG / Material minimum ~44px) */
  .panel-form button, .login-card button, .report-tab, .data-table .link-button,
  .row-actions a.link-button, .transfer-form button { min-height: 40px; }

  .data-table { display: block; overflow-x: auto; white-space: nowrap; }
  .data-table thead, .data-table tbody, .data-table tr { display: table; width: 100%; table-layout: fixed; }

  .search-result-head { flex-direction: column; gap: 6px; }
  .transfer-form { flex-wrap: wrap; }
}

@media (max-width: 420px) {
  .stat-card { flex-basis: 100%; }
  .content { padding: 12px; }
}

@media print {
  .sidebar, .panel-form, .data-table, .section-title, h1, .flash, .no-print, .templates-box { display: none !important; }
  html, body { background: #fff; margin: 0; padding: 0; }
  .layout { display: block; min-height: 0; }
  .content { padding: 0; margin: 0; max-width: none; }
  /* One label per page: @page is sized to the sticker by admin_qrcode.php. */
  .qr-print-area { display: block; margin: 0; padding: 0; }
  .label-item { display: block; break-after: page; page-break-after: always; }
  .label-item:last-child { break-after: auto; page-break-after: auto; }
  body.print-single .label-item { display: none; }
  body.print-single .label-item.print-this { display: block; break-after: auto; page-break-after: auto; }
  /* A hair under the page height, or rounding pushes a blank sticker out after each label. */
  .qr-box { border: none; border-radius: 0; height: calc(var(--lh) - 0.5mm); break-inside: avoid; page-break-inside: avoid; }
}
