:root {
  --primary: #1565C0;
  --primary-container: #D6E4FF;
  --on-primary-container: #001B3E;
  --secondary: #00695C;
  --bg: #F7F9FC;
  --surface: #FFFFFF;
  --surface-variant: #E8EDF5;
  --text: #111827;
  --text-muted: #6B7280;
  --border: #E5E7EB;
  --green: #2E7D32;
  --green-bg: #DDF5DF;
  --amber: #EF6C00;
  --amber-bg: #FFECD6;
  --red: #C62828;
  --red-bg: #FFDAD6;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #90CAF9;
    --primary-container: #1B2A3D;
    --on-primary-container: #D6E4FF;
    --bg: #111418;
    --surface: #1B2028;
    --surface-variant: #262C36;
    --text: #F3F4F6;
    --text-muted: #9CA3AF;
    --border: #2F3744;
    --green: #66BB6A;
    --green-bg: rgba(46, 125, 50, 0.22);
    --amber: #FFA726;
    --amber-bg: rgba(239, 108, 0, 0.22);
    --red: #EF5350;
    --red-bg: rgba(198, 40, 40, 0.22);
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}

.app-root {
  min-height: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}

/* Top App Bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px 12px;
  background: var(--primary-container);
  color: var(--on-primary-container);
  box-shadow: var(--shadow);
}

.topbar.plain {
  background: var(--surface);
  color: var(--text);
  border-bottom: 1px solid var(--border);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-subtitle {
  font-size: 12px;
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: inherit;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
}

.icon-btn:active {
  background: rgba(128, 128, 128, 0.18);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot.green { background: var(--green); }
.dot.red { background: var(--red); }

/* Page Content */
.page {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 14px;
  gap: 12px;
}

/* Home 2x3 Tile Grid */
.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tile-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 112px;
  padding: 14px 10px;
  border: none;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.08s ease;
}

.tile-btn:active {
  transform: scale(0.97);
}

.tile-icon {
  width: 32px;
  height: 32px;
}

.tile-blue { background: #E3F2FD; color: #1565C0; }
.tile-green { background: #E8F5E9; color: #2E7D32; }
.tile-teal { background: #E0F7FA; color: #00695C; }
.tile-amber { background: #FFF3E0; color: #EF6C00; }
.tile-red { background: #FFEBEE; color: #C62828; }
.tile-purple { background: #F3E5F5; color: #6A1B9A; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  background: var(--primary);
  color: #FFFFFF;
}

@media (prefers-color-scheme: dark) {
  .btn {
    color: #0B192C;
  }
}

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

.btn-sync {
  width: 100%;
  min-height: 60px;
  border-radius: 14px;
  font-size: 16px;
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--border);
}

.btn-text {
  background: transparent;
  color: var(--primary);
  padding: 8px 12px;
}

.btn-danger {
  background: var(--red);
  color: #FFFFFF;
}

.btn-sm {
  padding: 7px 12px;
  font-size: 13px;
  border-radius: 10px;
}

.spacer {
  flex: 1;
}

/* Cards & Inputs */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.card-clickable {
  cursor: pointer;
}

.card-clickable:active {
  opacity: 0.9;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.input {
  width: 100%;
  padding: 11px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  outline: none;
}

.input:focus {
  border-color: var(--primary);
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.col {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-green { background: var(--green); color: #fff; }
.badge-amber { background: var(--amber); color: #fff; }
.badge-red { background: var(--red); color: #fff; }
.badge-muted { background: var(--surface-variant); color: var(--text-muted); }

/* Home Bottom Info Card */
.home-footer-card {
  padding: 10px 12px;
}

.home-wh-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-user-title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-sync-row {
  font-size: 12px;
  color: var(--text-muted);
}

/* Login Screen */
.login-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 20px;
  gap: 16px;
}

.login-logo {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--primary-container);
  color: var(--on-primary-container);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
}

.dropdown-list {
  max-height: 210px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.dropdown-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

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

.dropdown-item:active {
  background: var(--surface-variant);
}

/* Filter chips */
.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.filter-chip.active {
  background: var(--primary-container);
  color: var(--on-primary-container);
  border-color: var(--primary);
}

/* Order Item Colors */
.order-item-green { background: var(--green-bg); border-color: var(--green); }
.order-item-amber { background: var(--amber-bg); border-color: var(--amber); }
.order-item-red { background: var(--red-bg); border-color: var(--red); }

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

.modal-backdrop.sheet {
  align-items: flex-end;
  padding: 0;
}

.modal-box {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  color: var(--text);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 88vh;
  overflow-y: auto;
}

.modal-backdrop.sheet .modal-box {
  max-width: 560px;
  border-radius: 20px 20px 0 0;
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
}

.info-tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.info-tile {
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--surface-variant);
}

.info-tile.stock-ok {
  background: rgba(46, 125, 50, 0.14);
  border: 1px solid rgba(46, 125, 50, 0.45);
  color: var(--green);
}

.info-tile.stock-zero {
  background: rgba(198, 40, 40, 0.14);
  border: 1px solid rgba(198, 40, 40, 0.45);
  color: var(--red);
}

.info-tile-label {
  font-size: 11px;
  opacity: 0.85;
}

.info-tile-val {
  font-size: 15px;
  font-weight: 700;
}

.stock-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-radius: 10px;
}

.stock-bar.stock-ok {
  background: rgba(46, 125, 50, 0.14);
  border: 1px solid rgba(46, 125, 50, 0.45);
  color: var(--green);
}

.stock-bar.stock-zero {
  background: rgba(198, 40, 40, 0.14);
  border: 1px solid rgba(198, 40, 40, 0.45);
  color: var(--red);
}

/* Camera view */
#qr-reader {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  background: #000;
}

/* Snackbar */
.snackbar {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  background: #222933;
  color: #FFFFFF;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  max-width: 92vw;
  text-align: center;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
  font-size: 13px;
}

.divider {
  height: 1px;
  background: var(--border);
  width: 100%;
}

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-variant);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.badge-blue { background: #1565C0; color: #fff; }

/* ---------- Device-adaptive layout: Mobile (iPhone) vs Desktop (PC) ---------- */
body.device-mobile .app-root {
  max-width: 520px;
}

body.device-desktop {
  font-size: 16px;
}

body.device-desktop .app-root {
  max-width: 1120px;
  box-shadow: 0 0 32px rgba(0, 0, 0, 0.12);
}

body.device-desktop .topbar {
  padding: 14px 24px;
}

body.device-desktop .topbar-title {
  font-size: 21px;
}

body.device-desktop .page {
  padding: 22px 24px;
  gap: 16px;
}

body.device-desktop .tile-grid {
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

body.device-desktop .tile-btn {
  min-height: 142px;
  font-size: 17px;
  gap: 12px;
  border-radius: 18px;
}

body.device-desktop .btn-sync {
  min-height: 68px;
  font-size: 18px;
}

body.device-desktop .cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

body.device-desktop .input {
  padding: 13px 14px;
  font-size: 16px;
}

body.device-desktop .modal-backdrop.sheet {
  align-items: center;
  padding: 20px;
}

body.device-desktop .modal-backdrop.sheet .modal-box,
body.device-desktop .modal-box {
  max-width: 540px;
  border-radius: 18px;
}

body.device-desktop .login-wrap {
  max-width: 460px;
  margin: 0 auto;
  width: 100%;
}

