:root {
  color-scheme: light;
  --surface: #fff;
  --surface-soft: #f3f2ec;
  --accent-text: #b83b1b;
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --cream: #141715;
  --ink: #f2f1e9;
  --muted: #b0b8b1;
  --line: #343c35;
  --green: #a0cfab;
  --surface: #1d231f;
  --surface-soft: #272f29;
  --accent-text: #ffab8f;
}
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  font: 650 12px var(--body);
}
.theme-toggle:hover { background: var(--surface-soft); }
.theme-toggle svg { width: 18px; height: 18px; flex-shrink: 0; }
.profile-header-actions { display: flex; align-items: center; gap: 18px; }
.access-theme { position: absolute; top: 20px; right: 20px; }
.access-screen { position: relative; }
.theme-toggle:focus-visible { outline: 3px solid #df8d50; outline-offset: 3px; }

/* Common surfaces, including dialogs and dynamically rendered content. */
html[data-theme="dark"] body,
html[data-theme="dark"] .access-screen { background: var(--cream); color: var(--ink); }
html[data-theme="dark"] :is(.cart-top,.search,.product-card,.cart-panel,.cart-heading,.icon-button,.fulfillment label,.message-preview,.loyalty-panel,.admin-sidebar,.admin-topbar,.stat-box,.table-panel,.settings-card,.edit-dialog,.simple-card,.access-card,.admin-coupon,.wallet-info,.profile-coupon,.profile-empty,.wallet-ledger,.profile-order,.profile-form,.profile-access,.profile-refresh,.upload-button,.edit-button,.store-section-nav button) {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
html[data-theme="dark"] :is(input:not([type="checkbox"]):not([type="radio"]),textarea,select) {
  background: var(--surface) !important;
  color: var(--ink);
  border-color: var(--line) !important;
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #a2aca4; opacity: 1; }
html[data-theme="dark"] :is(.tip-card,.category-pill,.cart-trust,.empty-illustration,.cart-heading h2 span,.section-title>span,.registered-reference,.registered-message,.coupon-code,.order-note,.order-badge,.status-toggle.off,.stat-box i) {
  background: var(--surface-soft);
  color: var(--muted);
  border-color: var(--line);
}
html[data-theme="dark"] .hero { background: var(--surface-soft); }
html[data-theme="dark"] :is(.admin-table th,.orders-table th) { background: #252d27; color: var(--muted); }
html[data-theme="dark"] :is(.admin-table td,.orders-table td,.admin-table th,.orders-table th,.table-toolbar,.table-footer,.admin-footer,.editor-form fieldset,.product-options-editor,.option-editor-group,.option-editor-row,.import-list>div,.checklist li,.order-detail-items>div,.order-amounts,.order-history,.coupon-value) { border-color: var(--line); }
html[data-theme="dark"] :is(.hero-copy p,.hero-note,.image-note,.admin-brand small,.store-mini small,.nav-caption,.admin-sidebar nav button,.tip-card p,.sidebar-bottom .signout,.breadcrumb,.admin-top-actions>span,.view-header p,.stat-box>span,.admin-table td,.admin-table th,.admin-product small,.table-footer,.admin-footer span,.settings-card>p,.settings-form label small,.editor-form label small,.checkbox-line span,.checklist li,.settings-actions p,.edit-dialog>div>p,.admin-empty,.simple-card p,.access-card p,.back-link,.photo-note,.color-field span,.import-help,.import-list span,.option-editor-group summary small,.orders-filters label,.orders-table td,.orders-table td small,.orders-pagination,.order-detail-grid p,.order-detail-items p,.order-amounts p,.order-payment,.order-history small,.loyalty-list-title>span,.admin-coupon p,#loading-state) { color: var(--muted); }
html[data-theme="dark"] :is(.breadcrumb b,.admin-product b,.admin-table .price-cell,.admin-empty h3,.order-detail-grid h3,.order-section-heading,.order-detail-grid p b,.order-amounts strong,.wallet-info>strong) { color: var(--ink); }
html[data-theme="dark"] :is(.store-mini>span,.admin-sidebar nav button.selected,.admin-sidebar nav button>b,.add-button,.cart-top b,.fulfillment label:has(input:checked),.store-section-nav button:hover) { background: #3d2c24; color: var(--accent-text); }
html[data-theme="dark"] :is(.orange,.strip-icon,.profile-tabs button[aria-pressed="true"],.loyalty-heading>a,#loyalty-signin>a,.coupon-copy>a,.coupon-code button,.choice-selected,.admin-link,.quantity button,.featured-mark,.danger-button,.settings-section-number,#store-information dd a) { color: var(--accent-text); }
html[data-theme="dark"] .category { color: var(--ink); }
html[data-theme="dark"] .category.active { background: #edebe0; color: #20271f; border-color: #edebe0; }
html[data-theme="dark"] .category.active svg { color: #20271f; }
html[data-theme="dark"] .empty-illustration:after { border-color: var(--surface); }
html[data-theme="dark"] .loyalty-code-field button { background: #e2e8dd; color: #20271f; }
html[data-theme="dark"] :is(.setup-banner,.config-warning,.notice-error,.profile-adjustment,.status-pending) { background: #3d321d; color: #f0cc87; border-color: #695533; }
html[data-theme="dark"] :is(.form-error,.status-cancelled) { background: #422725; color: #f2b2a8; }
html[data-theme="dark"] :is(.status-toggle:not(.off),.status-completed,.notice-success,.profile-order-status) { background: #253d2d; color: #abd6b4; }
html[data-theme="dark"] :is(.credit,.checklist li.complete,#loyalty-earned,.summary-line.discount) { color: #abd6b4; }
html[data-theme="dark"] .debit { color: #edb788; }
html[data-theme="dark"] :is(.orders-help,.status-confirmed) { background: #223540; color: #b0d3ec; }
html[data-theme="dark"] .status-preparing { background: #402e22; color: #edb788; }
html[data-theme="dark"] .status-ready { background: #332d46; color: #c9bcec; }
html[data-theme="dark"] :is(.coupon-value,.admin-coupon code,#profile-avatar,#loyalty-feedback) { background: #393326; color: #e8d5a6; border-color: #645a42; }
html[data-theme="dark"] .wallet-main { background: #293c2e; }
html[data-theme="dark"] #toast { background: #e2e8dd; color: #20271f; }
html[data-theme="dark"] .primary,
html[data-theme="dark"] .hero-cta { background: color-mix(in srgb, var(--orange) 80%, #000); }
html[data-theme="dark"] .media-preview { background: var(--surface-soft); }
html[data-theme="dark"] .search kbd { border-color: var(--line); }

/* Flexible children must be able to shrink without widening the page. */
.topbar,.topbar nav,.brand,.brand>span:last-child,.menu-main,.admin-main,.admin-workspace,
.settings-layout>*,.loyalty-admin-grid>*,.profile-identity,.profile-identity>div,
.wallet-layout>*,.field-grid>label,.profile-field-grid>label { min-width: 0; }
input,textarea,select { max-width: 100%; }
.table-scroll,.categories,.profile-tabs,.store-section-nav,#admin-nav { overscroll-behavior-inline: contain; }
.table-scroll { max-width: 100%; }
.cart-item-header>div { min-width: 0; }
.cart-item-header h4,.simple-card h3,.admin-coupon h3,.profile-greeting { overflow-wrap: anywhere; }
.product-submit { bottom: 0; }

@media (max-width: 1000px) and (min-width: 761px) {
  .topbar { padding-inline: 26px; gap: 18px; }
  .topbar nav { gap: 14px; }
  .topbar .theme-label { display: none; }
  .topbar .brand [data-brand-name] { max-width: 210px; }
  .topbar .brand-sub { letter-spacing: 1px; }
}
@media (min-width: 761px) {
  .admin-sidebar { overflow-y: auto; }
}

@media (max-width: 760px) {
  body:has(.cart-panel.open) { overflow: hidden; }
  .theme-toggle { padding: 10px; }
  .theme-label { display: none; }
  .topbar { height: auto; min-height: 112px; padding: 16px 20px 12px; flex-wrap: wrap; gap: 12px; }
  .topbar>.brand { width: 100%; }
  .topbar .brand [data-brand-name] { max-width: calc(100vw - 105px); }
  .topbar nav { width: 100%; justify-content: flex-end; gap: 10px; }
  .topbar .profile-link { width: auto; min-height: 44px; margin-right: auto; gap: 7px; font-size: 12px; }
  .topbar .profile-link>span:last-child { display: inline; }
  .topbar nav>.text-button { display: inline-flex; align-items: center; min-height: 44px; font-size: 12px; }
  .topbar .text-button>span { margin-left: 7px; }
  .cart-top { min-width: 44px; min-height: 44px; }
  .hero h1 { font-size: clamp(40px,11vw,58px); }
  .hero-image { height: clamp(200px,57vw,300px); }
  .hero-copy { padding: 25px 22px; }
  .hero-cta { min-height: 46px; }
  .store-strip { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 16px 12px; }
  .store-strip>div:nth-child(2) { grid-column: 1; }
  .store-strip .round-button { grid-column: 2; grid-row: 1 / 3; width: 44px; height: 44px; }
  .store-strip b { font-size: 12px; }
  .store-strip small { font-size: 11px; }
  .store-strip .strip-icon { display: grid; width: 34px; height: 34px; flex-shrink: 0; }
  .search { min-height: 48px; }
  .search input { font-size: 16px; }
  .category { min-height: 44px; font-size: 12px; }
  .categories { scrollbar-width: none; }
  .product-photo { height: clamp(135px,36vw,235px); }
  .product-body .product-description { font-size: 12px; }
  .product-body .product-name { font-size: 16px; }
  .product-bottom { flex-wrap: wrap; gap: 8px; font-size: 14px; }
  .add-button { width: 32px; height: 32px; }
  .mobile-cart { min-height: 58px; bottom: calc(12px + env(safe-area-inset-bottom,0px)); padding: 13px 16px; }
  .cart-panel { max-height: 90dvh; padding-bottom: env(safe-area-inset-bottom,0px); overscroll-behavior: contain; }
  .cart-panel.open { display: flex; flex-direction: column; }
  .cart-panel .cart-heading { flex-shrink: 0; }
  .cart-content { max-height: none; min-height: 0; flex: 1 1 auto; }
  .cart-bottom,.cart-trust { flex-shrink: 0; }
  .quantity button,.product-submit .quantity button { min-width: 44px; min-height: 44px; }
  .icon-button { width: 44px; height: 44px; }
  dialog { max-width: calc(100% - 20px); max-height: 92dvh; }
  .product-detail-copy,.checkout-dialog,.edit-dialog { padding: 24px 20px; }
  .product-submit { bottom: 0; gap: 10px; padding-bottom: calc(14px + env(safe-area-inset-bottom,0px)); }
  .product-submit .primary { font-size: 12px; gap: 5px; padding-inline: 12px; }
  .product-detail-copy h3 small { float: none; display: block; margin-top: 6px; }
  .option-row { min-height: 48px; font-size: 14px; }
  .choice-group .option-row { gap: 10px; }
  .choice-group .option-row>span:last-child { min-width: 76px; font-size: 12px; }
  .choice-description { font-size: 12px; }
  .choice-options-scroll { max-height: 32dvh; }
  .choice-group legend small { font-size: 12px; }
  .field-grid { grid-template-columns: minmax(0,1fr); }
  input:not([type="checkbox"]):not([type="radio"]),textarea,select,
  .settings-form input,.settings-form textarea,.settings-form select,
  .editor-form input,.editor-form textarea,.editor-form select,
  .orders-filters input,.orders-filters select,.admin-search input { font-size: 16px !important; }
  .primary,.edit-button,.upload-button,.profile-refresh,.profile-back { min-height: 44px; }
  .loyalty-code-field button { min-height: 44px; }
  .checkout-dialog .checkout-header { padding-top: 15px; padding-right: 26px; }
  .checkout-header h2 { font-size: 30px; overflow-wrap: anywhere; }
  .fulfillment label { font-size: 14px; }
  .checkout-dialog form>label,.field-grid>label { font-size: 14px; }
  .profile-header { flex-wrap: wrap; padding: 20px; gap: 14px; }
  .profile-header>.brand { width: 100%; }
  .profile-header .brand>span:last-child { max-width: calc(100vw - 95px); }
  .profile-header-actions { width: 100%; justify-content: space-between; gap: 12px; }
  .profile-back { display: inline-flex; align-items: center; font-size: 12px; }
  .profile-welcome { flex-wrap: wrap; }
  .profile-identity { max-width: 100%; }
  .profile-welcome p { max-width: none; }
  .profile-tabs { gap: 22px; }
  .profile-tabs button { min-height: 44px; }
  .profile-section-title { flex-wrap: wrap; gap: 10px; }
  .profile-order summary { align-items: flex-start; flex-wrap: wrap; font-size: 13px; }
  .profile-order summary>span:last-child { text-align: left; }
  .profile-order-items>div>strong { float: none; display: block; margin: 8px 0; }
  .coupon-code button { min-height: 44px; min-width: 44px; }
  .profile-footer { margin-inline: 20px; flex-wrap: wrap; }
  .admin-sidebar { max-width: 100%; }
  .admin-sidebar nav button { min-height: 48px; font-size: 12px; }
  .admin-topbar { height: auto; min-height: 64px; padding: 12px 16px; flex-wrap: wrap; gap: 10px; }
  .admin-top-actions { gap: 10px; }
  .admin-top-actions>a { display: inline-flex; align-items: center; min-height: 44px; font-size: 11px; }
  .breadcrumb { font-size: 12px; }
  .breadcrumb>span { margin-inline: 8px; }
  .view-header { flex-wrap: wrap; align-items: flex-start; }
  .view-header>div:first-child { min-width: 0; max-width: 100%; }
  .view-header p { max-width: none; font-size: 12px; }
  .view-header .primary { min-height: 44px; font-size: 12px; }
  .view-header .catalog-actions { flex-direction: row; flex-wrap: wrap; align-items: center; }
  .stats-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .stat-box>span { font-size: 11px; line-height: 1.6; }
  .stat-box b { font-size: 25px; overflow-wrap: anywhere; }
  .stat-box i { display: none; }
  .table-toolbar { flex-wrap: wrap; }
  .admin-search { flex-basis: 100%; max-width: none; }
  .table-toolbar select { max-width: 100%; width: 100%; }
  .admin-table th,.admin-table td { padding: 12px; font-size: 12px; }
  .admin-product b { font-size: 13px; max-width: 150px; }
  .admin-table .price-cell { font-size: 12px; }
  .status-toggle,.edit-button { min-height: 44px; font-size: 12px; }
  .table-scroll { scrollbar-width: thin; }
  .settings-actions,.editor-actions { flex-wrap: wrap; }
  .settings-actions .primary { font-size: 12px; }
  .settings-actions p { flex-basis: 100%; font-size: 11px; }
  .settings-form label,.editor-form label,.checkbox-line span { font-size: 13px; }
  .settings-form label small,.editor-form label small { font-size: 11px; }
  .checkbox-line { min-height: 44px; }
  .settings-form .field-grid,.editor-form .field-grid { grid-template-columns: minmax(0,1fr); }
  .store-page-heading .primary { margin-top: 0; }
  .store-section-nav button { min-height: 44px; font-size: 12px; }
  .admin-coupon { flex-wrap: wrap; gap: 15px; }
  .admin-coupon>div { min-width: 0; max-width: 100%; }
  .coupon-admin-actions { flex-direction: row; flex-wrap: wrap; }
  .admin-coupon code { overflow-wrap: anywhere; }
  .orders-filters label { min-width: 0; flex-basis: calc(50% - 10px); }
  .orders-filters .order-search { min-width: 0; flex-basis: 100%; }
  .order-item-heading { flex-wrap: wrap; }
  .order-detail-grid p { font-size: 13px; }
  #order-status-form>label { min-width: 0; flex-basis: 100%; }
  .access-screen { padding-top: 85px; }
  .access-card { min-width: 0; }
  .access-card h1 { font-size: clamp(34px,11vw,44px); }
}

@media (max-width: 420px) {
  .products { grid-template-columns: minmax(0,1fr); }
  .product-photo { height: 200px; }
  .product-body { padding: 17px; }
  .product-body .product-name { font-size: 18px; }
  .product-body .product-description { font-size: 13px; }
  .product-bottom { font-size: 16px; }
  .wallet-layout { grid-template-columns: minmax(0,1fr); }
  .profile-main { padding-inline: 16px; }
  .wallet-info>strong { margin-top: 15px; }
  .coupon-value { width: 72px; font-size: 24px; }
  .coupon-copy { padding: 15px; }
  .profile-access { padding: 24px; }
  .profile-access h1 { font-size: 38px; }
  .product-submit { flex-wrap: wrap; }
  .product-submit>.primary { flex: 1; width: auto; min-width: 145px; }
  .info-dialog { padding: 34px 22px; }
}
@media (max-width: 360px) {
  .topbar .profile-link { width: 44px; justify-content: center; flex-shrink: 0; }
  .topbar .profile-link>span:last-child { display: none; }
  .topbar nav>.text-button { white-space: nowrap; font-size: 11px; }
}
