/* iwant2eat — theme tokens
 * 5 named themes, switched by the data-theme attribute on <body>.
 * Default (no attribute) = market.
 *
 * Drop-in: <link rel="stylesheet" href="css/themes.css" /> BEFORE app.css.
 * Then in MainLayout.razor: <body data-theme="@(currentUser?.Theme ?? "market")">
 */

/* Opt out of the browser darkening this page for us.
 *
 * Android is the reason. Chrome's "auto dark theme for web contents" and the
 * WebView's algorithmic darkening both kick in for any page that hasn't said
 * which schemes it supports, and they are not a clean inversion: text gets
 * forced light while gradient and image backgrounds are frequently left alone.
 * That is how the top-nav chip ended up white-on-cream and unreadable in the
 * Android app — nothing in our own CSS could produce it, which is exactly the
 * signature of a repaint happening after our stylesheet has had its say.
 *
 * Declaring color-scheme is the documented opt-out, and it has to be on the
 * ROOT to cover the page; #blazor-error-ui already carried a local `light only`
 * from the last time this bit someone.
 *
 * Our themes are CSS, not UA-driven, so this doesn't constrain them — it only
 * tells the browser which palette its own furniture (form controls, scrollbars,
 * the canvas behind us) should match. Midnight overrides it below. */
:root { color-scheme: light; }
[data-theme="midnight"] { color-scheme: dark; }

:root,
[data-theme="market"] {
  --bg:          #fff8ef;
  --surface:     #ffffff;
  --surface-2:   #fff2e0;
  --text:        #1d2419;
  --text-2:      #5a6155;
  /* WCAG 1.4.3: #8a8f85 read at 3.3:1 on white, #0a8a3f at 4.4:1; these pass
     4.5:1 on --bg, --surface and --surface-2 (axe, legal audit F1, 2026-11-06). */
  --muted:       #6b7066;
  --border:      #ecdfc8;
  --primary:     #077a36;
  --primary-2:   #0d6f34;
  --primary-ink: #ffffff;
  --accent:      #ff6b1f;
  --accent-2:    #f59e0b;
  --success:     #077a36;
  --danger:      #c43a2a;
  --chip-bg:     #fff2e0;
  --chip-text:   #7a3a0a;
  --chip-border: #f5d8b4;
  --shadow-sm:   0 1px 2px rgba(34,28,18,.06), 0 2px 6px rgba(34,28,18,.05);
  --shadow-md:   0 6px 20px rgba(34,28,18,.10);
  --font-display: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-body:    'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, monospace;
  --display-weight: 700;
  --display-tracking: -0.02em;

  /* Tweak knobs — bake your chosen values from the prototype here. */
  --radius: 10px;
  --pad: 0.85rem;
  --gap: 0.9rem;
  --card-pad: 1rem;
  --font-scale: 1;
}

[data-theme="editorial"] {
  --bg:          #f7f3ec;
  --surface:     #ffffff;
  --surface-2:   #efe9dc;
  --text:        #1a1a1a;
  --text-2:      #4a4a4a;
  --muted:       #6e685e;
  --border:      #e2dccd;
  --primary:     #1a1a1a;
  --primary-2:   #000000;
  --primary-ink: #ffffff;
  --accent:      #b85728;
  --accent-2:    #7a5b2a;
  --success:     #3a7a3a;
  --danger:      #a13822;
  --chip-bg:     #efe9dc;
  --chip-text:   #3a3a3a;
  --chip-border: #d8d0bd;
  --shadow-sm:   0 1px 2px rgba(0,0,0,.06);
  --shadow-md:   0 8px 24px rgba(0,0,0,.10);
  --font-display: 'DM Serif Display', 'Times New Roman', serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, monospace;
  --display-weight: 400;
  --display-tracking: -0.01em;
}

[data-theme="modern"] {
  --bg:          #ffffff;
  --surface:     #ffffff;
  --surface-2:   #f6f6f5;
  --text:        #0f0f0e;
  --text-2:      #3d3d3a;
  --muted:       #6b6b66;
  --border:      #ececea;
  --primary:     #0f0f0e;
  --primary-2:   #000000;
  --primary-ink: #ffffff;
  --accent:      #22a559;
  --accent-2:    #0f0f0e;
  --success:     #22a559;
  --danger:      #d9402a;
  --chip-bg:     #f4f4f2;
  --chip-text:   #1a1a18;
  --chip-border: #e6e6e2;
  --shadow-sm:   0 0 0 1px rgba(0,0,0,.04);
  --shadow-md:   0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --font-display: 'Helvetica Neue', Helvetica, 'Inter', sans-serif;
  --font-body:    'Helvetica Neue', Helvetica, 'Inter', sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, monospace;
  --display-weight: 600;
  --display-tracking: -0.025em;
}

[data-theme="midnight"] {
  --bg:          #0e1110;
  --surface:     #181c1a;
  --surface-2:   #22272a;
  --text:        #f3eee2;
  --text-2:      #bfb9aa;
  --muted:       #85807a;
  --border:      #2c322f;
  --primary:     #fb923c;
  --primary-2:   #f97316;
  --primary-ink: #1d1108;
  --accent:      #84cc16;
  --accent-2:    #facc15;
  --success:     #84cc16;
  --danger:      #f87171;
  --chip-bg:     #22272a;
  --chip-text:   #e8dfc8;
  --chip-border: #373d3a;
  --shadow-sm:   0 1px 2px rgba(0,0,0,.4);
  --shadow-md:   0 12px 32px rgba(0,0,0,.5);
  --font-display: 'DM Sans', system-ui, sans-serif;
  --font-body:    'DM Sans', system-ui, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, monospace;
  --display-weight: 700;
  --display-tracking: -0.02em;
}

/* Per-theme tweaks that affect more than just colors — same overrides
 * the prototype uses. Keep this section here so themes.css is the single
 * source of theme truth. */

[data-theme="editorial"] .section-title,
[data-theme="editorial"] .hero-eyebrow {
  border-top: 2px solid var(--text);
  padding-top: 0.5rem;
}

/* Midnight theme — the binder-paper backdrops on /recipes/{id} and
 * /r/{token} hard-code a cream `background-color` that doesn't react
 * to the dark palette, so the light --text disappears against it.
 * Force the paper darker (and the printed-form lined background to
 * vanish) only for these themes so the body text stays legible. */
[data-theme="midnight"] .printable-recipe,
[data-theme="midnight"] .rs-paper {
  background-color: var(--surface);
  color: var(--text);
  background-image: none;
}

/* Same problem on the static legal pages (/dmca, /terms, /privacy,
 * /data-deletion). Each renders three callouts with hard-coded light
 * backgrounds — agent-box, address, legal-warn. Map them to the dark
 * surface palette so the inherited light --text reads. */
[data-theme="midnight"] .legal-page .agent-box,
[data-theme="midnight"] .legal-page address,
[data-theme="midnight"] .legal-page .legal-warn {
  background-color: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
/* Inline `<code>` snippets on the legal + help pages have their own
 * light pill background (#f2f2f0 / #f4f4f4). Switch to the chip
 * palette which is already theme-aware. */
[data-theme="midnight"] .legal-page code,
[data-theme="midnight"] .help-page code {
  background-color: var(--chip-bg);
  color: var(--chip-text);
}
/* Help page's lead paragraph forces `color: #333`, which renders as
 * dark grey on the dark background — barely visible. Reset to the
 * theme's primary text color for midnight so it matches body weight. */
[data-theme="midnight"] .help-page .lead {
  color: var(--text);
}

/* Form inputs default to white-on-dark-text via the browser stylesheet
 * (or .form-control's hard-coded `background: #fff` in app.css). Looks
 * completely out of place on the dark theme — re-skin every input /
 * textarea / select and the recipe-editor contenteditable to use the
 * surface palette. !important is needed because themes.css loads BEFORE
 * app.css (so legacy selectors win on regular themes), but here we
 * explicitly want the dark palette to override. */
[data-theme="midnight"] .form-control,
[data-theme="midnight"] input[type="text"],
[data-theme="midnight"] input[type="email"],
[data-theme="midnight"] input[type="password"],
[data-theme="midnight"] input[type="search"],
[data-theme="midnight"] input[type="number"],
[data-theme="midnight"] input[type="tel"],
[data-theme="midnight"] input[type="url"],
[data-theme="midnight"] textarea,
[data-theme="midnight"] select,
[data-theme="midnight"] .recipe-editor {
  background-color: var(--surface) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}
[data-theme="midnight"] .form-control::placeholder,
[data-theme="midnight"] input::placeholder,
[data-theme="midnight"] textarea::placeholder,
[data-theme="midnight"] .recipe-editor:empty::before {
  color: var(--muted) !important;
}

/* AdminUsers grid — admin-row tint and totals-row tint hard-code light
 * green; in midnight that flips to "white-on-white"-style invisibility.
 * Re-skin both with the dark surface palette. */
[data-theme="midnight"] .users-table tr.row-admin td {
  background-color: var(--surface-2);
  color: var(--text);
}
[data-theme="midnight"] .users-table .summary-body .summary-row td {
  background-color: var(--surface-2);
  color: var(--text);
  border-top-color: var(--border);
}

/* The rest of the hard-coded light palette, found by a contrast scan of every
 * signed-in page in the new look's dark tone (which is this theme) on
 * 2026-11-21, plus the admin pages read by hand. Two kinds of fault:
 *   - text written #fff on --primary, which here is amber, or a light
 *     background with the inherited --text, which here is light;
 *   - dark text (#444, #555, a dark green) with no background of its own.
 * A rule here maps the colour to a token and leaves everything else. */
[data-theme="midnight"] .btn-primary,
[data-theme="midnight"] .btn-primary:hover,
[data-theme="midnight"] .topbar nav > a.nav-tab.active:not(.help-link),
[data-theme="midnight"] .topbar nav > a:not(.user-badge):not(.help-link):hover,
[data-theme="midnight"] .topbar nav .user-badge .user-badge-initials,
[data-theme="midnight"] .topbar nav > a.nav-tab.active .nav-ic,
[data-theme="midnight"] .topbar nav > a.nav-tab:hover .nav-ic,
[data-theme="midnight"] .trial-banner-cta,
[data-theme="midnight"] .terms-banner-cta,
[data-theme="midnight"] .sort-switch button.active,
[data-theme="midnight"] .collections-toggle.active,
[data-theme="midnight"] .grid-xlate.active,
[data-theme="midnight"] .tag-chip.active,
[data-theme="midnight"] .tag-chip:not(.active):hover,
[data-theme="midnight"] .collection-card-owner-initials,
[data-theme="midnight"] .share-attest-actions .btn-accept,
[data-theme="midnight"] .sl-people-circle,
[data-theme="midnight"] .add-drop-banner,
[data-theme="midnight"] .install-prompt-action,
[data-theme="midnight"] .recipe-toolbar .copy-recipe-btn:hover:not(:disabled),
[data-theme="midnight"] .translate-upsell-cta,
[data-theme="midnight"] .translate-btn:hover:not(:disabled),
[data-theme="midnight"] .translate-btn.on,
[data-theme="midnight"] .cook-btn:hover,
[data-theme="midnight"] .split-section-btn:hover:not(:disabled),
[data-theme="midnight"] .split-all-btn:hover:not(:disabled),
[data-theme="midnight"] .format-switch button.active,
[data-theme="midnight"] .swap-modal .swap-option.is-on,
[data-theme="midnight"] .tag-delete-confirm .btn-yes,
[data-theme="midnight"] .delete-confirm .btn-yes,
[data-theme="midnight"] .settings-pane .btn-primary,
[data-theme="midnight"] .account-links a:hover,
[data-theme="midnight"] .account-admin-link,
[data-theme="midnight"] .fv-avatar-initials,
[data-theme="midnight"] .fo-avatar-initials,
[data-theme="midnight"] .fl-avatar-initials,
[data-theme="midnight"] .ask-done-mark,
[data-theme="midnight"] .hh-bought-chip:hover,
[data-theme="midnight"] .sl-view-toggle button.active,
[data-theme="midnight"] .subscribe-badge,
[data-theme="midnight"] .thumb-badge,
[data-theme="midnight"] .save-badge,
[data-theme="midnight"] .fmt-toggle.on,
[data-theme="midnight"] .fv-invite-plus,
[data-theme="midnight"] .act-period.is-on,
[data-theme="midnight"] .sub-confirm .btn-yes {
  color: var(--primary-ink);
}
[data-theme="midnight"] .ext-promo-banner strong,
[data-theme="midnight"] .ext-promo-banner a,
[data-theme="midnight"] .ios-promo-banner strong,
[data-theme="midnight"] .ios-promo-banner a {
  color: var(--primary) !important;
}
[data-theme="midnight"] .ext-promo-banner a:hover,
[data-theme="midnight"] .ios-promo-banner a:hover {
  color: var(--accent-2) !important;
}
[data-theme="midnight"] .email-list .chip.verified,
[data-theme="midnight"] .settings-pane .chip.verified {
  color: var(--success);
}
[data-theme="midnight"] .fv-all-now.is-none { color: var(--accent-2); }
[data-theme="midnight"] .pricing-card li,
[data-theme="midnight"] .pricing-appstore-note,
[data-theme="midnight"] .get-ext-page .lede,
[data-theme="midnight"] .cs-description,
[data-theme="midnight"] .cs-notes p,
[data-theme="midnight"] .cs-cta-body,
[data-theme="midnight"] .recipe-description,
[data-theme="midnight"] .reprocess-modal p {
  color: var(--text-2);
}
[data-theme="midnight"] .serves-stepper .serves-value,
[data-theme="midnight"] .recipe-nutrition-cell strong,
[data-theme="midnight"] .sl-view-toggle button:hover:not(.active) {
  color: var(--text);
}
[data-theme="midnight"] .plan-toolbar .btn-print:hover,
[data-theme="midnight"] .sl-topbar .btn-print:hover {
  background: var(--primary) !important;
  color: var(--primary-ink) !important;
}
/* Recipe notes: the paper colour is a recipe-format fallback (#faf8f0). */
[data-theme="midnight"] {
  --rf-notes-bg: var(--surface-2);
  --rf-notes-fg: var(--text-2);
}
[data-theme="midnight"] .paprika-import,
[data-theme="midnight"] .paprika-result,
[data-theme="midnight"] .legal-page pre,
[data-theme="midnight"] .guide-body code,
[data-theme="midnight"] .recipe-ai-history,
[data-theme="midnight"] .original-text-edit,
[data-theme="midnight"] .recipe-tag-row,
[data-theme="midnight"] .mep-steps > li,
[data-theme="midnight"] .photo-delete-confirm,
[data-theme="midnight"] .account-danger-panel,
[data-theme="midnight"] .recipe-collection-row,
[data-theme="midnight"] .nc-original {
  background: var(--surface-2) !important;
  color: var(--text);
}
[data-theme="midnight"] .photo-delete-confirm span { color: var(--danger); }
[data-theme="midnight"] .ctx-menu .ctx-item-danger:hover:not(:disabled) {
  background: color-mix(in oklab, var(--danger) 18%, var(--surface));
}
[data-theme="midnight"] .recipe-drop-zone.drag-over,
[data-theme="midnight"] .card.drag-over,
[data-theme="midnight"] .card.tag-drop-hover {
  background: color-mix(in oklab, var(--primary) 14%, var(--surface));
}
[data-theme="midnight"] .tag-chip.editing,
[data-theme="midnight"] .recipe-title-input:hover,
[data-theme="midnight"] .recipe-title-input:focus,
[data-theme="midnight"] .recipe-subtitle-input:hover,
[data-theme="midnight"] .recipe-subtitle-input:focus,
[data-theme="midnight"] .sl-name-input:hover,
[data-theme="midnight"] .sl-name-input:focus {
  background: var(--surface) !important;
  color: var(--text);
}

/* Household list (/shopping-lists/household). */
[data-theme="midnight"] .hh-viewtoggle button,
[data-theme="midnight"] .hh-undo-btn,
[data-theme="midnight"] .hh-pick,
[data-theme="midnight"] .hh-chip:not(.is-active),
[data-theme="midnight"] .hh-suggest {
  background: var(--surface);
  color: var(--text-2);
}
[data-theme="midnight"] .hh-step,
[data-theme="midnight"] .hh-section-title,
[data-theme="midnight"] .hh-section-title.is-collapsed {
  background: var(--surface-2);
  color: var(--text);
}
[data-theme="midnight"] .hh-section-title:hover,
[data-theme="midnight"] .hh-suggest li:hover,
[data-theme="midnight"] .hh-mic.is-ready:hover,
[data-theme="midnight"] .hh-item:active {
  background: color-mix(in oklab, var(--primary) 14%, var(--surface));
}
[data-theme="midnight"] .hh-item.editing,
[data-theme="midnight"] .hh-toast.is-warn {
  background: var(--surface-2);
}
[data-theme="midnight"] .hh-store-header { color: var(--text-2); }
[data-theme="midnight"] .hh-pick.is-set { color: var(--success); }

/* Fridge ideas (Ask AI → what can I cook). Its rules are scoped CSS, whose
 * attribute selector adds a class's weight: body[...] outweighs it. */
body[data-theme="midnight"] .fridge-lead { color: var(--text-2); }
body[data-theme="midnight"] .fridge-chip { background: var(--chip-bg); color: var(--chip-text); }
body[data-theme="midnight"] .fridge-idea-tolist { background: var(--surface); }

/* Admin pages. Badges with a light fill AND their own dark text (the plan
 * pills, strike chips) read fine and are left alone; what is fixed is a
 * light fill under inherited light text. */
[data-theme="midnight"] .users-table th.th-sortable:hover,
[data-theme="midnight"] .users-search-clear:hover,
[data-theme="midnight"] .early-toggle:hover,
[data-theme="midnight"] .admin-toggle:hover {
  background: var(--surface-2);
  color: var(--text);
}
[data-theme="midnight"] .user-email-btn:hover,
[data-theme="midnight"] .notes-toggle:hover,
[data-theme="midnight"] .notes-toggle.is-open {
  background: var(--surface-2);
}
[data-theme="midnight"] .users-table tr.row-notes-open td,
[data-theme="midnight"] .users-table tr.row-notes-panel td,
[data-theme="midnight"] .users-table tr.over-cap,
[data-theme="midnight"] .users-table tr.subaccount-row > td {
  background: color-mix(in oklab, var(--accent-2) 8%, var(--surface));
  color: var(--text);
}
[data-theme="midnight"] .users-table tr.row-needs-trial-email td {
  background: color-mix(in oklab, var(--accent) 18%, var(--surface));
  color: var(--text);
}
[data-theme="midnight"] .notes-textarea {
  background: var(--surface) !important;
  color: var(--text) !important;
}
[data-theme="midnight"] .user-subof { color: #b3a6f0; }
[data-theme="midnight"] .chip-unverified,
[data-theme="midnight"] .sub-pill--canceled,
[data-theme="midnight"] .admin-toggle.is-self {
  background: var(--surface-2);
  color: var(--text-2);
}
[data-theme="midnight"] .cr-form,
[data-theme="midnight"] .cr-step td,
[data-theme="midnight"] .email-history,
[data-theme="midnight"] .tmpl-sub code,
[data-theme="midnight"] .tmpl-list-item.active,
[data-theme="midnight"] .settings-table,
[data-theme="midnight"] .settings-table tr.editing > td,
[data-theme="midnight"] .sa-context pre,
[data-theme="midnight"] .sa-in {
  background: var(--surface-2);
  color: var(--text);
}
[data-theme="midnight"] .sa-out { background: color-mix(in oklab, var(--success) 16%, var(--surface)); color: var(--text); }
[data-theme="midnight"] .email-history-title,
[data-theme="midnight"] .email-history li { color: var(--text-2); }
[data-theme="midnight"] .email-row:hover td { background: var(--surface-2); }
[data-theme="midnight"] .email-row.from-user td { background: color-mix(in oklab, #6aa0ff 10%, var(--surface)); }
[data-theme="midnight"] .email-row.from-user:hover td { background: color-mix(in oklab, #6aa0ff 18%, var(--surface)); }
[data-theme="midnight"] .email-row-title,
[data-theme="midnight"] .email-row.from-user .email-inapp-kind { color: #8fb8ff; }
[data-theme="midnight"] .email-modal-x:hover { color: var(--text); }
[data-theme="midnight"] .events-table tr.evt-complained,
[data-theme="midnight"] .events-table tr.evt-failed,
[data-theme="midnight"] .events-table tr.evt-rejected { background: color-mix(in oklab, var(--danger) 12%, var(--surface)); }
[data-theme="midnight"] .events-table tr.evt-delivered { background: color-mix(in oklab, var(--success) 10%, var(--surface)); }

/* Recipe-grid sticky-note cards hard-code `background-color: #fdfaf0`
 * (cream paper) and rely on `color: inherit` for the title — which
 * becomes the light --text on midnight, leaving title text invisible.
 * Re-skin the card to the dark surface so the title and meta read. */
[data-theme="midnight"] .card {
  background-color: var(--surface);
  color: var(--text);
}

/* === COLLECTION THEMES ==========================================
   A collection theme (see CollectionThemeCss) redefines the tokens above on
   <body data-theme>. Colours, fonts and weights therefore need no rules here —
   every component already reads them.

   --heading-color is the exception: nothing consumed it before, because the
   account themes tint headings with --text. Both source sites disagree with
   that. saucy-gourmet sets its recipe h1 in orange (#EF5623) and
   oliveyourlife sets its post title in blue (#26619A) — in each case the title
   colour is the most recognisable thing on the page, so a theme has to be able
   to say it.

   Defaults to `inherit`, so an account theme (which never sets the property) is
   completely unaffected — these rules are inert until a collection theme
   supplies a value. */
body[data-theme] .page-title,
body[data-theme] .recipe-header .recipe-title,
body[data-theme] .recipe-title-input,
body[data-theme] .rs-title {
  color: var(--heading-color, inherit);
}
/* The display face too — the account themes only apply --font-display to a
   few chrome elements, but a collection theme choosing a brush script means it
   for the recipe title above all. */
body[data-theme] .recipe-header .recipe-title,
body[data-theme] .recipe-title-input {
  font-family: var(--font-display);
  font-weight: var(--display-weight);
}
