* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #772432;
  --primary-dark: #5a1a26;
  --primary-soft: #f7ecee;
  --bg: #ffffff;
  --card: #ffffff;
  --text: #141414;
  --text-muted: #6b6b6b;
  --border: #e6e6e6;
  --success: #16794f;
  --danger: #b3261e;
  --radius: 12px;
  --app-bar-h: 56px;
  --sidebar-w: min(84vw, 300px);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', 'Noto Sans Khmer', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  padding-top: calc(var(--app-bar-h) + env(safe-area-inset-top, 0px));
  overflow-x: hidden;
}

/* ===================== App shell ===================== */
.app-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  height: calc(var(--app-bar-h) + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 10px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 3px solid var(--primary);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(20, 20, 20, 0.06);
}

/* Language picker and actions inside the top bar (customer pages without sidebar) */
.app-bar-logo {
  flex: 0 0 auto;
  display: block;
  height: 30px;
  width: auto;
}
.app-bar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-bar-link {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.app-bar-link:active { background: var(--primary-soft); }
/* Member-only top bar actions (Profile / Logout) sit between Home and the
   language picker, so they use tighter spacing to fit narrow phones. */
.app-bar .app-bar-link-compact {
  padding: 6px 9px;
  font-size: 13px;
  font-family: inherit;
}
.app-bar .app-bar-picker {
  flex: 0 0 auto;
  width: auto;
}
.app-bar-picker .lang-current {
  padding: 7px 10px;
  font-size: 14px;
}
.app-bar-picker .lang-menu {
  top: calc(100% + 8px);
  bottom: auto;
  left: auto;
  right: 0;
  width: max-content;
  box-shadow: 0 6px 22px rgba(20, 20, 20, 0.14);
}
.app-bar-picker .lang-option {
  width: auto;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

/* Landing page */
.landing {
  padding: 8px 0 32px;
}
.landing-card {
  padding: 22px 18px;
  text-align: center;
}
.landing-card h1 {
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.35;
}
.landing-desc {
  margin: 0 0 18px;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
}
/* The landing CTA sits in the middle of its card. */
.landing .landing-cta {
  display: block;
  width: fit-content;
  min-width: 200px;
  margin: 0 auto;
  text-decoration: none;
}

/* Custom select (replaces native dropdown popup) */
.cselect {
  position: relative;
  width: 100%;
  min-width: 0;
}
.cselect-native {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}
.cselect-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s;
}
.cselect-btn:focus,
.cselect-btn[aria-expanded="true"] {
  border-color: var(--primary);
  outline: none;
}
.cselect-btn:disabled {
  background: #f5f5f5;
  color: var(--text-muted);
  cursor: not-allowed;
}
.cselect-label {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.cselect-label-text {
  display: inline-block;
  white-space: nowrap;
  will-change: transform;
}
.cselect-chevron {
  flex: 0 0 auto;
  color: var(--text-muted);
  transition: transform 0.18s;
}
.cselect-btn[aria-expanded="true"] .cselect-chevron {
  transform: rotate(180deg);
}
.cselect-menu {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(20, 20, 20, 0.14);
}
.cselect-menu[hidden] {
  display: none;
}
.cselect-option {
  display: block;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  white-space: normal;
  cursor: pointer;
}
.cselect-option:hover {
  background: var(--primary-soft);
}
.cselect-option.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-weight: 600;
}

/* Configurator sections */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}
.section-title::before {
  content: '';
  flex: 0 0 auto;
  width: 3px;
  height: 15px;
  border-radius: 2px;
  background: var(--primary);
}
.calc-btn {
  margin-top: 4px;
  box-shadow: 0 6px 16px rgba(119, 36, 50, 0.22);
}

.icon-btn {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.icon-btn:active {
  background: var(--primary-soft);
}

.page-head {
  max-width: 480px;
  margin: 0 auto;
  padding: 18px 16px 0;
}
.page-head h1 {
  font-size: 21px;
  line-height: 1.3;
  font-weight: 700;
  color: var(--text);
  overflow-wrap: break-word;
}
.page-head p {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(20, 20, 20, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.26s ease, visibility 0.26s ease;
}
.sidebar-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 71;
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-top: 4px solid var(--primary);
  box-shadow: 6px 0 26px rgba(20, 20, 20, 0.16);
  transform: translateX(-104%);
  visibility: hidden;
  transition: transform 0.28s cubic-bezier(0.2, 0.7, 0.3, 1), visibility 0.28s;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sidebar.open {
  transform: translateX(0);
  visibility: visible;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 14px 14px;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  height: 30px;
  width: auto;
  max-width: calc(100% - 54px);
  display: block;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 10px;
  overflow-y: auto;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 12px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.sidebar-link svg {
  flex: 0 0 auto;
  color: var(--text-muted);
}
.sidebar-link:active {
  background: var(--primary-soft);
}
.sidebar-link.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}
.sidebar-link.active svg {
  color: var(--primary);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
}
.sidebar-label {
  flex: 0 0 auto;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}
/* Language picker: menu expands upward so it stays visible at the bottom */
.lang-picker {
  position: relative;
  flex: 1;
  min-width: 0;
}
.lang-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 11px 12px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.lang-current:focus {
  outline: none;
  border-color: var(--primary);
}
.lang-chevron {
  flex: 0 0 auto;
  color: var(--text-muted);
  transition: transform 0.2s;
}
/* AI assistant dock: pinned to the viewport bottom, collapsible.
   The expanded panel never exceeds half of the viewport height. */
.ai-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  max-height: calc(50vh - 1px); /* -1px absorbs sub-pixel rounding of vh */
  overflow: hidden;
  background: var(--card);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}
.ai-toggle {
  width: 100%;
  height: 45px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ai-chevron {
  flex: 0 0 auto;
  transition: transform 0.2s;
}
.ai-dock.open .ai-chevron {
  transform: rotate(180deg);
}
/* Keep page content clear of the collapsed dock bar. */
body:has(.ai-dock) .container {
  padding-bottom: 64px;
}
.ai-card {
  display: none;
  flex-direction: column;
  gap: 8px;
  /* The whole dock (toggle bar + this panel) stays within 50vh. */
  max-height: calc(50vh - 48px);
  margin: 0;
  padding: 0 12px 10px;
  border: none;
  border-radius: 0;
  box-shadow: none;
  overflow: hidden;
}
.ai-dock.open .ai-card {
  display: flex;
}
.ai-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.ai-clear {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.ai-clear:active {
  color: var(--danger);
  border-color: var(--danger);
}
.ai-kb-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.ai-kb-chip {
  border: 1px solid var(--primary);
  background: var(--primary-soft);
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.ai-kb-chip:active {
  background: var(--primary);
  color: #fff;
}
.ai-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafafa;
}
.ai-msg {
  max-width: 88%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.ai-msg.user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-msg.bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.ai-prompt {
  align-self: stretch;
  background: #fff;
  border: 1px dashed var(--primary);
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
}
.ai-input-row {
  display: flex;
  gap: 8px;
}
.ai-input-row input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
}
.ai-input-row input:focus {
  outline: none;
  border-color: var(--primary);
}
.ai-input-row .btn {
  flex: 0 0 auto;
}

/* Flag of the selected language shown on the collapsed picker button */
.lang-flag {
  flex: 0 0 auto;
  width: 26px;
  height: 17px;
  object-fit: cover;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(20, 20, 20, 0.12);
}
.lang-current[aria-expanded="true"] .lang-chevron {
  transform: rotate(180deg);
}
.lang-menu {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 -6px 22px rgba(20, 20, 20, 0.14);
}
.lang-menu[hidden] {
  display: none;
}
.lang-option {
  width: 100%;
  padding: 11px 12px;
  text-align: left;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.lang-option:hover {
  background: #f5f5f5;
}
.lang-option.active {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 14px 16px calc(24px + env(safe-area-inset-bottom, 0px));
}
.scope-notice {
  background: var(--primary-soft);
  border: 1px solid #ecd3d8;
  color: var(--primary-dark);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.field { margin-bottom: 14px; min-width: 0; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus, .field select:focus {
  border-color: var(--primary);
}
.row { display: flex; gap: 10px; }
.row .field { flex: 1; min-width: 0; }
.phone-row { display: grid; grid-template-columns: 1.4fr 1fr; gap: 10px; }
.phone-row > * { min-width: 0; }
@media (max-width: 640px) { .phone-row { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: auto;
  padding: 10px 20px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  white-space: nowrap;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:active { opacity: 0.85; }
.btn-secondary {
  background: var(--border);
  color: var(--text);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
  padding: 8px 12px;
  font-size: 13px;
  width: auto;
}
.btn-sm {
  width: auto;
  padding: 7px 14px;
  font-size: 13px;
}

/* Action buttons align to the right edge of their card/form. */
.card > .btn-primary:not(.btn-add):not(.landing-cta) {
  display: flex;
  width: fit-content;
  margin-left: auto;
}
/* Login and register submit buttons are centered in their forms. */
#loginForm .btn-primary,
#registerForm > .btn-primary {
  display: flex;
  width: fit-content;
  margin-left: auto;
  margin-right: auto;
}
/* "Add new" buttons align left instead. */
.btn-add {
  margin-left: 0;
  margin-right: auto;
}

.result-card {
  border-left: 4px solid var(--primary);
}
.result-card h3 {
  font-size: 16px;
  margin-bottom: 10px;
  color: var(--primary-dark);
}
.spec-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 12px;
  font-size: 13px;
}
.spec-grid .label { color: var(--text-muted); }
.spec-grid .value { font-weight: 600; text-align: right; }

.price-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.price-row:last-child { border-bottom: none; }
.price-row.total {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary-dark);
  border-top: 2px solid var(--primary);
  border-bottom: none;
  margin-top: 8px;
  padding-top: 12px;
}

.calc-summary {
  background: var(--primary-soft);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.calc-summary h4 {
  font-size: 13px;
  color: var(--primary-dark);
  margin-bottom: 8px;
}

.notes {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}
.notes li { margin-left: 16px; margin-bottom: 4px; }

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  background: var(--border);
  padding: 4px;
  border-radius: 10px;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.tab-btn.active {
  background: #fff;
  color: var(--primary-dark);
}

.product-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}
.product-item .row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}
.product-item h4 { font-size: 15px; margin-bottom: 4px; }
.product-item .meta { font-size: 12px; color: var(--text-muted); }

/* Catalog filters and progressive 8-per-page loading (staff + member pages) */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}
.filter-field {
  flex: 1 1 150px;
  min-width: 0;
  max-width: 220px;
}
.filter-range-field {
  flex: 1 1 240px;
  max-width: 300px;
}
.filter-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 5px;
}
.filter-field input,
.filter-field select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.filter-field input:focus,
.filter-field select:focus {
  border-color: var(--primary);
}
.filter-field .cselect-btn {
  padding: 9px 10px;
  font-size: 13px;
  border-radius: 8px;
}
.filter-range {
  display: flex;
  gap: 6px;
}
.filter-actions {
  flex: 0 0 auto;
  max-width: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-left: auto;
}
.filter-actions .btn {
  width: auto;
  padding: 10px 22px;
}
.filter-footer {
  flex: 1 1 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.filter-footer .btn {
  width: auto;
  padding: 9px 18px;
}
.show-more-wrap {
  display: flex;
  justify-content: center;
  margin: 12px 0 4px;
}
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 12px 0 4px;
}
.pager .btn {
  width: auto;
  padding: 8px 16px;
}
.pager .btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.pager-info {
  font-size: 13px;
  color: var(--text-muted);
}
.status-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
}
.status-badge.on_sale { background: #eef7f2; color: var(--success); }
.status-badge.discontinued { background: #fbf1f0; color: var(--danger); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal-overlay.active { display: flex; }
.modal {
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal.modal-wide { max-width: 1100px; }
.modal h2 {
  font-size: 18px;
  margin-bottom: 14px;
}
.modal .actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
.phone-pick-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.phone-pick-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: #fff;
}
.phone-pick-item.selected { border-color: var(--primary); background: var(--primary-soft); }
.phone-pick-item input { margin: 0; }
.phone-pick-item .phone-pick-code { font-weight: 600; }

.chip-group { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  cursor: pointer;
  background: #fff;
  color: var(--text-muted);
}
.chip.selected {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 16px;
  font-size: 14px;
}

.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--success);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 200;
  display: none;
}
.toast.show { display: block; }

/* ===================== RBAC / admin ===================== */
.container-wide {
  max-width: 480px;
}
.card-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 14px;
}
.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.user-name {
  font-weight: 700;
}
.role-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  background: #eff6ff;
  color: #2563eb;
  vertical-align: middle;
}
.role-super_admin { background: #f5f3ff; color: #7c3aed; }
.role-sales_manager { background: #eff6ff; color: #2563eb; }
.role-salesperson { background: #ecfdf5; color: #059669; }
.role-member { background: var(--primary-soft); color: var(--primary-dark); }

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.sub-tabs { margin-bottom: 0; }
.inline-hint {
  font-size: 12px;
  color: var(--text-muted);
}
.price-line {
  color: var(--primary-dark);
  font-weight: 600;
  margin-top: 4px;
}
.account-item h4 .role-badge,
.account-item h4 .status-badge {
  margin-left: 6px;
}

.approval-item {
  border-left: 4px solid var(--border);
}
.approval-pending { border-left-color: var(--primary); }
.approval-approved { border-left-color: var(--success); }
.approval-rejected { border-left-color: var(--danger); }
.approval-cancelled { border-left-color: var(--text-muted); }
.approval-badge.pending { background: var(--primary-soft); color: var(--primary-dark); }
.approval-badge.approved { background: #eef7f2; color: var(--success); }
.approval-badge.rejected { background: #fbf1f0; color: var(--danger); }
.approval-badge.cancelled { background: #f4f4f4; color: var(--text-muted); }

/* ===================== Member portal ===================== */
.auth-card {
  max-width: 480px;
  margin: 0 auto 14px;
}
.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 12px;
  color: var(--text-muted);
  font-size: 13px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.google-btn {
  display: flex;
  justify-content: flex-end;
  min-height: 44px;
  max-width: 100%;
  overflow: hidden;
}
.google-btn iframe {
  margin: 0;
  max-width: 100%;
}
.auth-switch {
  text-align: center;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.link-btn {
  background: none;
  border: none;
  color: var(--primary-dark);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.segment {
  display: flex;
  gap: 4px;
  background: var(--border);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 14px;
}
.segment button {
  flex: 1;
  padding: 9px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.segment button.active {
  background: #fff;
  color: var(--primary-dark);
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.range-box {
  background: linear-gradient(135deg, #fdf7f8, #f4e2e6);
  border: 1px solid #ecd3d8;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.range-box h3 {
  font-size: 14px;
  color: var(--primary-dark);
  margin-bottom: 6px;
}
.range-values {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.range-amount {
  font-size: 26px;
  font-weight: 800;
  color: var(--primary-dark);
}
.range-sep { color: var(--primary-dark); font-weight: 700; }
.range-meta {
  font-size: 12px;
  color: var(--primary-dark);
  opacity: 0.75;
  margin-top: 4px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.metric {
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}
.metric .label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.metric .value {
  font-size: 16px;
  font-weight: 700;
}

.candidate-group { margin-top: 12px; }
.candidate-group h4 {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.candidate {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  cursor: pointer;
  background: #fff;
}
.candidate.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}
.candidate .price {
  font-weight: 600;
  color: var(--primary-dark);
  white-space: nowrap;
}
.candidate .price-wrap {
  display: flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex-shrink: 0;
}
.candidate .qty-input {
  width: 48px;
  padding: 3px 5px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  text-align: center;
  color: var(--text);
  background: #fff;
}
.candidate .qty-input:focus {
  border-color: var(--primary);
  outline: none;
}
.candidate .qty-x {
  color: var(--text-muted);
  font-weight: 600;
}
.candidate-main { min-width: 0; }
.candidate-main strong { display: block; font-size: 13px; }
.candidate-main span { color: var(--text-muted); }

.select-note {
  font-size: 12px;
  color: var(--text-muted);
  margin: 4px 0 8px;
}
.select-note.autonomy-warn {
  color: var(--danger);
  background: #fbf1f0;
  border: 1px solid #edd0cb;
  border-radius: 8px;
  padding: 8px 10px;
  font-weight: 600;
  line-height: 1.5;
}
.flag-icon {
  width: 20px;
  height: 14px;
  object-fit: cover;
  border-radius: 2px;
  vertical-align: -2px;
  margin: 0 2px;
}
.cta-box {
  background: var(--primary-soft);
  border: 1px dashed var(--primary);
  border-radius: 10px;
  padding: 12px;
  margin-top: 12px;
}
.cta-box p {
  font-size: 13px;
  margin-bottom: 8px;
}
.pbp-card {
  background: #f2f9f5;
  border: 1px solid #cfe9dd;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
}
.pbp-card h3 {
  font-size: 14px;
  color: var(--success);
  margin-bottom: 8px;
}
.pbp-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px dashed #cfe9dd;
}
.pbp-row:last-child { border-bottom: none; }
.pbp-row strong { color: var(--success); }
.catalog-grid,
#productList, #accountList, #approvalList, #flowList, #caseList {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
#approvalList, #flowList, #caseList {
  /* Non-product/account cards can be a touch wider for readability */
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.catalog-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: #fff;
}
.catalog-card h4 { font-size: 14px; margin-bottom: 4px; }
.catalog-card .meta { font-size: 12px; color: var(--text-muted); }
.catalog-card .price { font-size: 14px; font-weight: 700; color: var(--primary-dark); margin-top: 6px; }
.quote-error {
  background: #fbf1f0;
  color: var(--danger);
  border-radius: 10px;
  padding: 12px;
  font-size: 13px;
}

.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--primary);
  background: #fff;
  color: var(--primary-dark);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
  vertical-align: middle;
}
.tip-body {
  font-size: 13px;
  line-height: 1.8;
  color: var(--text);
  margin-bottom: 6px;
}

/* Scenario load checklist */
.load-builder {
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
  background: #fafafa;
}
.load-builder-head {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.load-builder-head h3 { font-size: 15px; margin: 0; }
.load-builder-tools { display: flex; align-items: center; gap: 8px; }
.load-row {
  display: grid;
  grid-template-columns: 1.7fr 0.9fr 0.5fr 0.8fr 0.8fr 0.7fr 32px;
  gap: 6px;
  align-items: end;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.load-row label { display: block; font-size: 10px; color: var(--text-muted); margin-bottom: 2px; }
.load-row input[type="text"], .load-row input[type="number"] {
  width: 100%;
  padding: 7px 8px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}
.load-row input[type="text"]:focus, .load-row input[type="number"]:focus { border-color: var(--primary); }
.load-row .load-name {
  height: 32px;
  display: flex;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.load-row .critical-cell { height: 32px; display: flex; align-items: center; }
.load-row .critical-cell input { width: 18px; height: 18px; }
.load-row .del-load {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: #fbe3e1;
  color: var(--danger);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
@media (max-width: 640px) {
  .load-row { grid-template-columns: 1fr 1fr; }
  .load-row .name-cell { grid-column: 1 / -1; }
  .load-row .del-load { width: 100%; }
}

/* ===================== App polish ===================== */
.field input,
.field select,
.field textarea,
.load-row input,
.candidate .qty-input {
  font-size: 16px;
}
.card {
  border-radius: 16px;
  padding: 16px;
}
.btn {
  border-radius: 12px;
  -webkit-tap-highlight-color: transparent;
}
.segment button,
.tab-btn {
  padding: 10px 6px;
  font-size: 12px;
}
.tabs {
  border-radius: 12px;
}
.catalog-grid,
#productList, #accountList, #approvalList, #flowList, #caseList {
  grid-template-columns: 1fr;
}
@media (min-width: 520px) {
  .catalog-grid,
  #productList, #accountList, #approvalList, #flowList, #caseList {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
  #approvalList, #flowList, #caseList {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  }
}
@media (max-width: 400px) {
  .page-head h1 { font-size: 19px; }
}

