:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #14161a;
  --text-2: #767b85;
  --border: #e7e8ec;
  --blue: #005bff;
  --blue-text: #ffffff;
  --green: #16a34a;
  --green-tint: rgba(22, 163, 74, 0.12);
  --orange: #b45309;
  --orange-tint: rgba(245, 158, 11, 0.16);
  --red: #ef4444;
  --red-tint: rgba(239, 68, 68, 0.1);
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 6px rgba(16, 24, 40, 0.04);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0c0d10;
  --surface: #1a1b1f;
  --surface-2: #232428;
  --text: #f2f3f5;
  --text-2: #93979f;
  --border: #2c2d32;
  --blue: #2f7cff;
  --blue-text: #ffffff;
  --green: #34d072;
  --green-tint: rgba(52, 208, 114, 0.14);
  --orange: #f5a524;
  --orange-tint: rgba(245, 165, 36, 0.16);
  --red: #f8695a;
  --red-tint: rgba(248, 105, 90, 0.14);
  --shadow: none;
  color-scheme: dark;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

button, input, select { font-family: inherit; }

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

#shopSelect {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.topbar button {
  flex: none;
  border: none;
  border-radius: 12px;
  width: 40px;
  height: 40px;
  font-size: 17px;
  line-height: 1;
  background: var(--surface-2);
  color: var(--text);
}

.topbar button#refreshBtn {
  background: var(--blue);
  color: var(--blue-text);
}

.settings {
  padding: 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.settings .row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.settings label { color: var(--text-2); font-size: 12.5px; min-width: 110px; }

.settings select, .settings input {
  flex: 1;
  height: 36px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
}

.settings > .row button {
  flex: none;
  border: none;
  border-radius: 10px;
  height: 36px;
  padding: 0 14px;
  background: var(--blue);
  color: var(--blue-text);
  font-size: 13px;
  font-weight: 600;
}

.settings button.danger {
  display: block;
  margin: 4px 0 0 auto;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 12.5px;
  padding: 4px 2px;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.search-bar {
  padding: 12px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.search-bar input {
  height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.filter-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.filter-tabs::-webkit-scrollbar { display: none; }

.filter-tabs button {
  flex: none;
  white-space: nowrap;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
}

.filter-tabs button.active {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--blue-text);
}

#statusLine {
  font-size: 12px;
  color: var(--text-2);
  padding: 0 2px;
}

.empty, .empty-filter {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
}

.empty-filter { list-style: none; }

.product-list {
  list-style: none;
  margin: 0;
  padding: 8px 12px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.product-item.low { background: var(--orange-tint); border-color: transparent; }
.product-item.off { background: var(--surface-2); }

.product-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.product-thumb {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.product-thumb-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  opacity: 0.5;
}

.product-info { flex: 1; min-width: 0; }

.product-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 3px;
  word-break: break-word;
  line-height: 1.35;
}

.product-offer {
  font-size: 12px;
  color: var(--text-2);
}

.badge {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 9px 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
  margin-top: 1px;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-active { background: var(--green-tint); color: var(--green); }
.badge-low { background: var(--orange-tint); color: var(--orange); }
.badge-off { background: var(--surface-2); color: var(--text-2); }

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

.stepper {
  display: flex;
  align-items: stretch;
  background: var(--surface-2);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.stepper button {
  border: none;
  background: transparent;
  color: var(--text);
  width: 36px;
  height: 36px;
  font-size: 15px;
  font-weight: 600;
}

.stepper button:active { background: var(--blue); color: var(--blue-text); }

.stock-input {
  width: 50px;
  height: 36px;
  text-align: center;
  border: none;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
}

.off-btn {
  margin-left: auto;
  background: var(--red-tint) !important;
  color: var(--red) !important;
  border: none !important;
  border-radius: 12px !important;
  height: 36px !important;
  padding: 0 14px !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
}

.off-btn.confirm {
  background: var(--red) !important;
  color: #fff !important;
}

.hidden { display: none !important; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 14, 0.5);
  display: flex;
  align-items: flex-end;
  z-index: 100;
}

.modal {
  background: var(--surface);
  width: 100%;
  border-radius: 22px 22px 0 0;
  padding: 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
}

.modal h3 { margin: 0 0 14px; color: var(--text); font-size: 16px; }

.modal input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  margin-bottom: 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
  box-sizing: border-box;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
}

.modal .modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.modal .modal-actions button {
  flex: 1;
  height: 44px;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
}

.modal .btn-primary { background: var(--blue); color: var(--blue-text); }
.modal .btn-secondary { background: var(--surface-2); color: var(--text); }

.user-list {
  max-height: 40vh;
  overflow-y: auto;
  margin-bottom: 10px;
}

.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.user-row:last-child { border-bottom: none; }

.user-name { font-size: 14px; font-weight: 600; }
.user-id { font-size: 12px; color: var(--text-2); }

.user-row-empty {
  padding: 12px 0;
  color: var(--text-2);
  font-size: 13px;
  text-align: center;
}

.btn-remove-user {
  border: none;
  background: var(--red-tint);
  color: var(--red);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
}

.user-add {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  margin-top: 2px;
}

