:root {
  --primary: #D95D00;
  --primary-hover: #B84D00;
  --primary-soft: #FFF7ED;
  --accent: #141414;
  --bg: #F3F4F6;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --muted: #6B7280;
  --ok: #15803D;
  --ok-bg: #DCFCE7;
  --warn: #B45309;
  --warn-bg: #FEF3C7;
  --danger: #B91C1C;
  --danger-bg: #FEE2E2;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.45;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* Top Navigation Bar */
.topbar {
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 3px solid var(--primary);
}
.brand-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
}
.brand-logo {
  height: 34px;
  width: auto;
  border-radius: 6px;
  background: #fff;
  padding: 2px 6px;
}
.brand-title { font-weight: 800; font-size: 15px; letter-spacing: 0.3px; }
.brand-sub { font-size: 11px; color: #FDBA74; display: block; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #E5E7EB;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}
.nav-link:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-link.active { background: var(--primary); color: #fff; }

/* Account Dropdown Menu (Safe Logout & Close App placement) */
.account-menu-wrap { position: relative; }
.account-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #fff;
  padding: 6px 11px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
}
.account-trigger:hover { background: rgba(255,255,255,0.18); }
.account-popup {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 260px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 32px rgba(0,0,0,0.22);
  padding: 8px;
  z-index: 60;
}
.popup-header {
  padding: 6px 10px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.popup-section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  padding: 4px 10px;
}
.popup-item {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.popup-item:hover { background: #F3F4F6; }
.popup-item.active-mode { background: var(--primary-soft); color: var(--primary); }
.popup-divider {
  height: 1px;
  background: var(--border);
  margin: 10px 4px;
}
.popup-item-danger {
  color: #B91C1C;
  margin-top: 2px;
}
.popup-item-danger:hover { background: #FEE2E2; }

/* Containers & Cards */
.container {
  max-width: 1420px;
  margin: 0 auto;
  padding: 14px 16px 28px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  margin-bottom: 14px;
}
.card h3, .card h4 { margin: 0 0 10px; font-size: 15px; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.page-head h2 { margin: 0; font-size: 19px; }

/* KPI & Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.kpi-title { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kpi-val { font-size: 20px; font-weight: 800; margin-top: 4px; color: var(--accent); }

.pos-grid {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 14px;
  align-items: start;
}
@media (max-width: 980px) {
  .pos-grid { grid-template-columns: 1fr; }
}

/* Forms & Inputs */
.form-grid {
  display: grid;
  gap: 10px;
}
label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #374151;
}
input[type="text"], input[type="number"], input[type="password"], input[type="date"], input[type="datetime-local"], input[type="month"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #D1D5DB;
  border-radius: 7px;
  font-size: 13.5px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(217, 93, 0, 0.14);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 13px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 700;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-dark { background: var(--accent); color: #fff; }
.btn-dark:hover:not(:disabled) { background: #27272A; }
.btn-outline { background: #fff; border-color: #D1D5DB; color: var(--text); }
.btn-outline:hover:not(:disabled) { background: #F9FAFB; border-color: #9CA3AF; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #991B1B; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-lg { padding: 12px 16px; font-size: 15px; }
.btn-block { width: 100%; }

/* Tables & Pills */
.table-wrap { width: 100%; overflow-x: auto; }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  background: #F9FAFB;
  color: #374151;
  font-weight: 700;
  text-align: left;
  padding: 9px 10px;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:hover td { background: #FFFBF7; }

.table-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 10px;
}
.table-toolbar > input, .table-toolbar > select { width: auto; min-width: 150px; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-danger { background: var(--danger-bg); color: var(--danger); }
.pill-muted { background: #E5E7EB; color: #374151; }

@keyframes blinkPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.blink-danger { animation: blinkPulse 1.2s infinite; }

/* Banners */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  font-weight: 600;
  border: 1px solid transparent;
}
.alert-ok { background: var(--ok-bg); color: var(--ok); border-color: #86EFAC; }
.alert-warn { background: var(--warn-bg); color: var(--warn); border-color: #FCD34D; }
.alert-danger { background: var(--danger-bg); color: var(--danger); border-color: #FCA5A5; }

/* Quick Non-Barcode Packaged Bulk Panel */
.bulk-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 8px;
  max-height: 250px;
  overflow-y: auto;
  padding-right: 4px;
}
.bulk-item-btn {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: left;
  background: #FFFBF7;
  border: 1px solid #FDBA74;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}
.bulk-item-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateY(-1px);
}
.bulk-item-name { font-weight: 700; font-size: 12.5px; color: var(--text); }
.bulk-item-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; font-size: 11.5px; }

/* POS Total & Change Display */
.pos-total-box {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  padding: 12px 14px;
  margin: 10px 0;
}
.pos-total-row { display: flex; justify-content: space-between; align-items: center; }
.pos-grand-val { font-size: 28px; font-weight: 900; color: #FB923C; }

.change-banner {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 800;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}
.change-banner.short { background: var(--danger-bg); color: var(--danger); border: 1px solid #FCA5A5; }
.change-banner.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #86EFAC; }

.shortcut-strip {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.shortcut-chip {
  background: #F3F4F6;
  border: 1px solid #D1D5DB;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}
.shortcut-chip:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 18px 20px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.3);
}
.modal-box.modal-lg { max-width: 780px; }
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 12px;
}
.modal-head h4 { margin: 0; font-size: 16px; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* Tabs */
.tab-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-bottom: 2px solid var(--border);
  margin-bottom: 14px;
  padding-bottom: 6px;
}
.tab-btn {
  padding: 7px 14px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
}
.tab-btn.active { background: var(--primary); color: #fff; }

/* Inline Edit Details */
.inline-edit-form {
  margin-top: 6px;
  padding: 10px;
  background: #FFFBF7;
  border: 1px solid #FDBA74;
  border-radius: 8px;
  display: grid;
  gap: 6px;
  min-width: 220px;
}

/* Footer */
.app-footer {
  text-align: center;
  padding: 14px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: #fff;
}
.app-footer a { color: var(--primary); font-weight: 700; text-decoration: none; }

/* ============================================================================
   PRINT STYLES — Fixed #thermalReceipt & Multi-Paper Support (58mm/80mm/A5/A4/F4)
   ============================================================================ */
#printAreaHost { display: none; }

@media print {
  body * { visibility: hidden !important; }
  #printAreaHost, #printAreaHost *,
  #thermalReceipt, #thermalReceipt * {
    visibility: visible !important;
  }
  #printAreaHost {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    background: #fff !important;
    color: #000 !important;
  }
  #thermalReceipt {
    margin: 0 auto;
    color: #000 !important;
    background: #fff !important;
    font-family: 'Courier New', Courier, monospace;
  }
  #thermalReceipt.paper-58mm { width: 54mm; font-size: 11px; line-height: 1.3; }
  #thermalReceipt.paper-80mm { width: 76mm; font-size: 12px; line-height: 1.35; }
  #thermalReceipt.paper-A5_HALF,
  #thermalReceipt.paper-A4,
  #thermalReceipt.paper-F4 {
    width: 100%;
    max-width: 195mm;
    font-family: 'Segoe UI', Arial, sans-serif;
    font-size: 12px;
    padding: 8mm;
  }
}
