/* ============================================================
   Components
   ============================================================ */

/* ── Cards ── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--gap-lg);
}
.card-pressable {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--gap-lg);
  transition: background .15s, transform .1s;
  cursor: pointer;
  user-select: none;
}
.card-pressable:hover { background: var(--card-hover); }
.card-pressable:active { transform: scale(0.98); }
.card-pressable.is-selected {
  background: var(--accent-dim);
  border-color: var(--accent);
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  padding: 10px 16px;
  border-radius: var(--r-md);
  font-weight: 600;
  font-size: 14px;
  transition: background .15s, transform .1s, opacity .15s;
  cursor: pointer;
  user-select: none;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #1A1810;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-light); }

.btn-secondary {
  background: var(--surface-light);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--card-hover); }

.btn-outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-outline:hover:not(:disabled) { background: var(--accent-dim); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-light);
  color: var(--text-primary);
}

.btn-success { background: var(--success); color: #0D1A12; }
.btn-success:hover:not(:disabled) { filter: brightness(1.1); }

.btn-danger  { background: var(--danger);  color: #1F0E0E; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.1); }

.btn-info    { background: var(--info);    color: #0E1828; }
.btn-info:hover:not(:disabled) { filter: brightness(1.1); }

.btn-icon {
  width: 40px; height: 40px;
  border-radius: var(--r-md);
  background: var(--surface-light);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--card-hover); color: var(--text-primary); }
.btn-icon.is-active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent); }

/* Cart icon button in app-bar — always visible with counter badge */
.cart-icon-btn {
  position: relative;
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}
.cart-icon-btn:hover { background: var(--accent); color: #1A1810; }
.cart-icon-count {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--danger, #E04545);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  border: 2px solid var(--surface);
  letter-spacing: -0.3px;
}

.btn-block { width: 100%; }
.btn-lg { padding: 14px 20px; font-size: 15px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }

/* ── Inputs ── */
.input {
  display: block;
  width: 100%;
  padding: 12px 14px;
  background: var(--surface-light);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s;
}
.input::placeholder { color: var(--text-muted); }
.input:focus { border-color: var(--accent); }

/* ── Material Symbols icon helper ── */
.icon {
  font-family: 'Material Symbols Rounded';
  font-weight: normal;
  font-style: normal;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-feature-settings: 'liga';
  -webkit-font-smoothing: antialiased;
  user-select: none;
}
.icon-sm { font-size: 16px; }
.icon-md { font-size: 20px; }
.icon-lg { font-size: 24px; }
.icon-xl { font-size: 32px; }

/* ── App shell (Scaffold equivalent) ── */
.app-shell {
  display: flex;
  flex-direction: column;
  /* Calculate available height: 100dvh minus 44px topbar (set by wrapper index.html).
     #app-root already accounts for topbar via padding-top, so we use its content height. */
  height: 100%;
  min-height: 0;     /* allows children to shrink */
  overflow: hidden;
}

.app-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--gap-lg);
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  flex-shrink: 0;
}
/* On mobile/narrow phones — compact app-bar so all buttons fit */
@media (max-width: 480px) {
  .app-bar {
    padding: 0 8px;
    gap: 4px;
    height: 52px;
  }
  .app-bar h1 {
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
  }
  .app-bar .btn-icon,
  .app-bar .back-btn {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
  }
  .app-bar .icon-md { font-size: 20px; }
}
.app-bar-bottom {
  background: var(--surface-light);
  border-bottom: 1px solid var(--border);
  padding: 8px var(--gap-lg);
  flex-shrink: 0;
}
.app-bar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.app-bar .back-btn {
  width: 40px; height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-primary);
  border-radius: var(--r-md);
  cursor: pointer;
}
.app-bar .back-btn:hover { background: var(--surface-light); }

.app-body {
  flex: 1;
  min-height: 0;        /* CRITICAL: allows children to overflow & scroll properly inside flex parent */
  overflow: hidden;
  display: flex;
  position: relative;
}

.app-bottom-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: var(--gap-md) var(--gap-lg);
  flex-shrink: 0;
}

/* ── Dialog / Modal ── */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  /* Push the backdrop start below the demo topbar so dialogs never appear behind it */
  top: 44px;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--gap-lg);
  animation: fadeIn .15s ease;
}
.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  max-width: 480px;
  width: 100%;
  max-height: calc(100dvh - 44px - 32px);  /* viewport minus topbar minus padding */
  max-height: calc(100vh - 76px);          /* fallback */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: dialogIn .2s ease;
}
@media (max-width: 480px) {
  .dialog-backdrop {
    padding: 8px;
    /* On mobile, allow dialog to use full available height comfortably */
  }
  .dialog {
    max-height: calc(100dvh - 44px - 16px);
    border-radius: 14px;
  }
  .dialog-header { padding: 14px 16px; gap: 10px; }
  .dialog-body { padding: 14px 16px; }
  .dialog-footer { padding: 12px 16px; gap: 8px; flex-wrap: wrap; }
  .dialog-footer .btn { flex: 1; min-width: 0; }
}
.dialog-header {
  padding: var(--gap-lg);
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  border-bottom: 1px solid var(--border);
}
.dialog-body {
  padding: var(--gap-lg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.dialog-footer {
  padding: var(--gap-md) var(--gap-lg);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--gap-md);
  justify-content: flex-end;
}

/* ── Bottom Sheet ── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  top: 44px;  /* respect demo topbar */
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn .15s ease;
}
.sheet {
  background: var(--surface);
  border-top-left-radius: var(--r-xl);
  border-top-right-radius: var(--r-xl);
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 44px - 8px);   /* viewport minus topbar minus small spacer */
  max-height: calc(100vh - 52px);          /* fallback */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: sheetIn .25s cubic-bezier(0.16, 1, 0.3, 1);
  padding-bottom: env(safe-area-inset-bottom, 0px);  /* iPhone home indicator */
}
@media (max-width: 480px) {
  .sheet-header { padding: 4px 14px 10px; }
  .sheet-body   { padding: 0 14px 14px; }
  .sheet-footer { padding: 10px 14px; gap: 8px; flex-wrap: wrap; }
  .sheet-footer .btn { flex: 1; min-width: 0; }
}
.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 8px;
  flex-shrink: 0;
}
.sheet-header {
  padding: 8px var(--gap-lg) var(--gap-md);
  display: flex;
  align-items: center;
  gap: var(--gap-md);
  flex-shrink: 0;
}
.sheet-body {
  padding: 0 var(--gap-lg) var(--gap-lg);
  overflow-y: auto;
  flex: 1;
}
.sheet-footer {
  padding: var(--gap-md) var(--gap-lg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
/* Cart panel action buttons — both share row equally, text wraps gracefully */
.cp-actions { display: flex; gap: 10px; }
.cp-action-btn {
  flex: 1;
  min-width: 0;
  white-space: normal;     /* allow text wrap if needed */
  text-align: center;
  padding: 12px 10px;
  font-size: 13px;
  line-height: 1.2;
}
.cp-action-btn .icon { flex-shrink: 0; }
@media (max-width: 380px) {
  .cp-action-btn { font-size: 12px; padding: 11px 8px; gap: 4px; }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes dialogIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}
@keyframes sheetIn {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

/* ── Snackbar / Toast ── */
.snackbar-host {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  align-items: center;
  pointer-events: none;
}
.snackbar {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 16px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  animation: snackIn .25s ease, snackOut .25s ease 2.6s forwards;
  pointer-events: auto;
  max-width: 90vw;
}
.snackbar.is-success { border-color: var(--success); }
.snackbar.is-danger  { border-color: var(--danger); }
@keyframes snackIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes snackOut {
  to { opacity: 0; transform: translateY(20px); }
}

/* ── Welcome banner (demo-only) ── */
.demo-banner {
  background: linear-gradient(90deg, var(--accent-dim), var(--surface-light));
  border-bottom: 1px solid var(--accent);
  padding: 6px var(--gap-lg);
  font-size: 11px;
  color: var(--accent-light);
  text-align: center;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--gap-sm);
  flex-shrink: 0;
  flex-shrink: 0;
}
.demo-banner .reset-btn {
  margin-left: auto;
  background: transparent;
  color: var(--accent-light);
  border: 1px solid var(--accent);
  padding: 2px 8px;
  border-radius: var(--r-sm);
  font-size: 10px;
  cursor: pointer;
}
.demo-banner .reset-btn:hover { background: var(--accent); color: #1A1810; }

/* ──────────────────────────────────────────────────────────
   Help Dialog — mobile-first, scrollable, properly bounded
   ────────────────────────────────────────────────────────── */

/* Title bar */
.hd-titlebar {
  background: linear-gradient(135deg, var(--accent-dim), var(--surface));
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.hd-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--info));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #1A1810;
  font-size: 16px;
  flex-shrink: 0;
}
.hd-title {
  margin: 0;
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hd-subtitle {
  margin-top: 2px;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hd-close-btn {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
}

/* Tabs row — horizontal scroll with smooth touch */
.hd-tabs-wrap {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: relative;
}
.hd-tabs {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;             /* Firefox */
}
.hd-tabs::-webkit-scrollbar { display: none; }  /* WebKit/Blink */
.hd-tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 12px 14px;
  color: var(--text-secondary);
  font-weight: 400;
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
  font-family: inherit;
  transition: color .15s;
}
.hd-tab.is-active {
  border-bottom-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.hd-tab:hover { color: var(--text-primary); }

/* Body — scrolls independently */
.hd-body {
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ── Mobile (≤480px) — compact everything ── */
@media (max-width: 480px) {
  .hd-titlebar { padding: 10px 12px; gap: 10px; }
  .hd-logo { width: 36px; height: 36px; font-size: 15px; border-radius: 8px; }
  .hd-title { font-size: 15px; }
  .hd-subtitle { font-size: 11.5px; }
  .hd-tab {
    padding: 10px 12px;
    font-size: 12.5px;
    gap: 4px;
  }
  .hd-tab .icon-sm { font-size: 14px; }
  .hd-body { padding: 12px; }
  /* Hint that there's more — small fade on the right edge */
  .hd-tabs-wrap::after {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--surface));
    pointer-events: none;
  }
}

/* ── Very small phones (≤359px) — even tighter ── */
@media (max-width: 359px) {
  .hd-tab { padding: 9px 10px; font-size: 12px; }
  .hd-tab-label { display: none; }     /* show only icons */
  .hd-tab .icon-sm { font-size: 16px; }
}
