/* ============================================================================
 * MCOS App Dark Mode
 * ----------------------------------------------------------------------------
 * App-only dark theme. The Capacitor shell adds `mcos-app` + `mcos-dark` to
 * <html> at document-start when the user enables "Dunkles Design" in the
 * native settings; web browsers never get these classes, so every rule below
 * is a no-op for regular visitors.
 *
 * Enqueued LAST (after style.min.css, the per-page CSS and mobile-shell.css)
 * so it wins on equal specificity; the `html.mcos-dark` prefix plus targeted
 * `!important` overrides the theme's hard-coded light colours.
 *
 * Palette derived from the theme's own tokens (assets/sass/common/_colors.scss),
 * mapped light -> dark:
 *   page bg     #f1f1f1 / #f6f6f6 / #fff      -> #111817
 *   surface     white cards                   -> #1b2624
 *   surface-2   tiles / inputs / header       -> #243331
 *   border      #dce0df / #c5d2cd / #d0d8d5    -> #33403d
 *   text        #274446 / #203839 / #0b4033   -> #e8eeec ($green17)
 *   text-muted  #637575 ($greenGrey)          -> #9fb3ac (~$green0)
 *   brand green #407360 ($green1) as TEXT     -> #85e7aa ($green22) for contrast
 *   accent link                               -> #85e7aa
 * Filled brand-green buttons keep #407360 bg + white text (still high contrast).
 * Images / logos / product photos are never filtered (no `invert`).
 * ========================================================================== */

html.mcos-dark {
  --d-bg: #111817;
  --d-surface: #1b2624;
  --d-surface-2: #243331;
  --d-border: #33403d;
  --d-text: #e8eeec;
  --d-text-muted: #9fb3ac;
  --d-green: #85e7aa;
  --d-green-soft: #8ac7b6;
  --d-brand: #407360;
  color-scheme: dark;
}

/* ---- Base ---------------------------------------------------------------- */
html.mcos-dark,
html.mcos-dark body {
  background-color: var(--d-bg) !important;
  color: var(--d-text) !important;
}

/* ---- Surfaces ------------------------------------------------------------ *
 * The theme paints light backgrounds on a wide range of structural and
 * component wrappers. Darken them broadly, but exclude interactive accents
 * (buttons/badges/pills/toggles) and media so they keep their own colours. */
html.mcos-dark :is(
  main, section, article, aside, header, footer,
  .site-content, .site-header, #masthead, #primary, #secondary,
  .box, .info-box, .entry-content, .page-content,
  [class*="card"], [class*="-box"], [class*="wrap"], [class*="inner"],
  [class*="container"], [class*="content"], [class*="panel"], [class*="block"],
  [class*="tile"], [class*="overview"], [class*="dash"], [class*="section"],
  [class*="modal"], [class*="popup"], [class*="overlay"], [class*="drawer"],
  [class*="accordion"], [class*="list-item"], [class*="row"],
  details, [class*="item"], [class*="faq"], [class*="question"],
  [class*="answer"], [class*="pages"], [class*="pagination"], [class*="field"],
  [class*="group"], [class*="table"], [class*="summary"], [class*="detail"]
):not([class*="btn"]):not([class*="button"]):not([class*="badge"]):not([class*="pill"]):not([class*="chip"]):not([class*="tag"]):not([class*="status"]):not([class*="toggle"]):not(img):not(svg):not([class*="icon"]):not([class*="gradient"]):not([class*="image"]):not([class*="photo"]):not([class*="thumb"]):not([class*="avatar"]):not([class*="logo"]):not([class*="picture"]) {
  background-color: var(--d-surface) !important;
  /* Drop decorative light gradients the theme layers via background-image
   * (e.g. .faq-page__hero's linear-gradient(#f9fbfa …)) — they paint over the
   * background-color above and show as pale bands on the dark surface. Content
   * images use <img>, so they're unaffected (and media classes are excluded). */
  background-image: none !important;
  /* Also light text: many components (e.g. .info-box, .accordion-header) set a
   * dark-green color directly on the container, which the element-list text
   * rule below doesn't match. The 11 :not() guards inflate this selector's
   * specificity well past the theme's class rules, so the container — and any
   * descendant text that inherits from it — becomes readable. Links, buttons
   * and status pills set their own colour on their own element and still win. */
  color: var(--d-text) !important;
  border-color: var(--d-border) !important;
}

/* Elevated micro-surfaces: stat tiles, inputs-on-cards, table heads, header. */
html.mcos-dark :is(
  .site-header, #masthead, .dash-stat, .key-value,
  [class*="stat"], [class*="suggestions"], thead, .table-head
):not([class*="btn"]):not([class*="button"]):not([class*="status"]) {
  background-color: var(--d-surface-2) !important;
  border-color: var(--d-border) !important;
}

/* ---- Text ---------------------------------------------------------------- *
 * Force readable text everywhere, then re-assert accents below. */
html.mcos-dark :is(
  h1, h2, h3, h4, h5, h6, p, span, li, dt, dd, label, legend,
  strong, b, em, i, small, sub, sup, th, td, figcaption, blockquote,
  .key, .value, .title, [class*="title"], [class*="heading"], [class*="label"],
  [class*="text"], [class*="desc"]
) {
  color: var(--d-text) !important;
}

/* Muted / secondary text (theme #637575). */
html.mcos-dark :is(
  .text-muted, .secondary-text, small, .key,
  [class*="muted"], [class*="secondary"], [class*="subtitle"], [class*="caption"],
  [class*="hint"], [class*="placeholder"], [class*="disclaimer"],
  [class*="strength"], .gfield_description, [class*="gfield_description"],
  [class*="-note"], [class*="helper"]
) {
  color: var(--d-text-muted) !important;
}

/* ---- Links & brand-green text -------------------------------------------- *
 * Brand green (#407360 / #346452 / #368f77) is unreadable on dark, so any
 * link or explicitly-green text element is brightened to the accent green. */
/* :not() guards both keep filled CTAs out (handled below) and raise
 * specificity above the theme's component link colours (e.g. .faq-page__nav-link
 * was rendering a dim #5f8c7b). */
html.mcos-dark a:not([class*="btn"]):not([class*="button"]):not([class*="cta"]):is(#i#i#i#i.c.c.c, *),
html.mcos-dark a :is(span, strong, p, h1, h2, h3, h4) {
  color: var(--d-green) !important;
}
html.mcos-dark a:hover {
  color: #a8f0c4 !important;
}

/* ---- Buttons ------------------------------------------------------------- *
 * Filled brand-green CTAs stay green with white text (high contrast on dark).
 * Outline/secondary buttons get a readable light border + accent text. */
html.mcos-dark :is(
  .btn-primary, .button.alt, .wc-block-components-button,
  input[type="submit"], button.checkout-button, .button-redirect,
  .community-profile-gate .btn-mod,
  [class*="btn-primary"], [class*="cta"]
):is(#i#i#i#i.c.c.c, *) {
  background-color: var(--d-brand) !important;
  /* white text, forced past the theme's ID-scoped green via the specificity
   * borrow (see the form-controls note) so CTAs never render green-on-green */
  color: #ffffff !important;
  border-color: var(--d-brand) !important;
}
html.mcos-dark :is(.btn-secondary, .button:not(.alt), .button-outline) {
  background-color: transparent !important;
  color: var(--d-green) !important;
  border-color: var(--d-border) !important;
}

/* Segmented toggles (e.g. pharmacy "Apotheken anzeigen | Karte anzeigen"):
 * the inactive segment is transparent with dark theme text — unreadable on
 * the dark surface, so give it light text. The active segment keeps its white
 * pill, so its text stays dark. */
html.mcos-dark :is([class*="view-btn"], [class*="view-toggle"] button, [class*="segment"] button) {
  color: var(--d-text) !important;
}
html.mcos-dark :is([class*="view-btn"], [class*="segment"] button).active {
  color: #203839 !important;
}

/* Ghost / link-style buttons that aren't filled CTAs (e.g. Gravity Forms
 * "Angaben speichern und später fortfahren") render dim brand-green on the dark
 * surface; use the brighter accent so they clear contrast. Filled CTAs keep
 * white (their rule's specificity borrow wins); active segments stay dark. */
html.mcos-dark :is(button, [class*="btn"], [class*="button"]):not(.active):not([class*="btn-primary"]):not([class*="cta"]):not([type="submit"]):not([class*="view-btn"]) {
  color: var(--d-green) !important;
}

/* Tab bar of the embedded product widget (.tabset → "Bestbewertet" /
 * "Günstigste", used in blog posts, archives and manufacturer pages). The theme
 * paints the tabs with light $green14/#f0f4f3 fills that the surface rule skips
 * (they're <button>s), so with the ghost-button rule above they end up green on
 * light. Darken them: the inactive tab sits on the elevated surface, the
 * selected tab matches the (already darkened) .tab-panels below it so it reads
 * as connected. The borrow lifts specificity above the ghost rule's (0,7,1). */
html.mcos-dark .tab-buttons button:is(#i#i#i#i.c.c.c, *) {
  background-color: var(--d-surface-2) !important;
  color: var(--d-text-muted) !important;
}
html.mcos-dark .tab-buttons button[aria-selected="true"]:is(#i#i#i#i.c.c.c, *) {
  background-color: var(--d-surface) !important;
  color: var(--d-text) !important;
}

/* ---- Form controls ------------------------------------------------------- *
 * The theme paints inputs #f6f6f6/#f1f1f1 with a #658b7d border and #637575
 * placeholder. Several search/date inputs are styled by ID with !important,
 * e.g.  #search-container-archive .search-wrapper-archive #search-bar-archive
 *       { background:#f6f6f6 !important; color:#346452 }   (specificity 2,2,0)
 * which is exactly the unreadable green-on-white the user reported. The worst
 * offender chains three IDs (#archive-wrapper ... #search-container-archive ...
 * #search-bar-archive, specificity 3,3,0 !important), so a plain `input`
 * selector — even with !important — can't win.
 *
 * The `:is(#i#i#i#i.c.c.c, *)` below matches *every* element (via `*`) yet
 * borrows the (4,3,0) specificity of the never-matching `#i#i#i#i.c.c.c`
 * compound, lifting the rule above the theme's ID rules without enumerating
 * each offending id.
 * Combined with `html.mcos-dark` and the `:not([type=...])` guards it lands at
 * a high specificity while staying scoped to text-like inputs, so buttons,
 * checkboxes, radios and toggles keep their own colours. */
html.mcos-dark
  input:not([type="submit"]):not([type="button"]):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):is(#i#i#i#i.c.c.c, *),
html.mcos-dark textarea:is(#i#i#i#i.c.c.c, *),
html.mcos-dark select:is(#i#i#i#i.c.c.c, *),
html.mcos-dark .form-control:is(#i#i#i#i.c.c.c, *) {
  background-color: var(--d-surface-2) !important;
  color: var(--d-text) !important;
  -webkit-text-fill-color: var(--d-text) !important;
  border-color: var(--d-border) !important;
}
html.mcos-dark input:is(#i#i#i#i.c.c.c, *):focus,
html.mcos-dark textarea:is(#i#i#i#i.c.c.c, *):focus,
html.mcos-dark select:is(#i#i#i#i.c.c.c, *):focus {
  border-color: var(--d-green) !important;
  outline-color: var(--d-green) !important;
}
html.mcos-dark input:is(#i#i#i#i.c.c.c, *)::placeholder,
html.mcos-dark textarea:is(#i#i#i#i.c.c.c, *)::placeholder {
  color: var(--d-text-muted) !important;
  -webkit-text-fill-color: var(--d-text-muted) !important;
  opacity: 1;
}
/* Native dropdown options */
html.mcos-dark option {
  background-color: var(--d-surface-2) !important;
  color: var(--d-text) !important;
}

/* Search inputs sit inside a rounded pill wrapper (the header overlay, the
 * product-archive search, the pharmacy name/location filters, the case search)
 * that already carries the field's surface, border and radius. The generic
 * form-control rule above paints the bare <input> --d-surface-2, which is
 * lighter than the pill's --d-surface, so it shows as a pale rectangle floating
 * inside the pill. Make these inputs transparent so the pill reads as one
 * uniform field. The five-id borrow (#i#i#i#i#i.c.c.c.c → specificity (5,4,0))
 * outranks the form rule's four-id (4,…) input selector that would otherwise
 * re-assert the surface. */
html.mcos-dark :is(
  .search-wrapper, .search-wrapper-archive,
  .search-name-wrap, .search-location-wrap, .case-search-wrapper
) input:is(#i#i#i#i#i.c.c.c.c, *) {
  background-color: transparent !important;
}

/* ---- Borders, dividers, shadows ------------------------------------------ */
html.mcos-dark :is(hr, .separator, [class*="divider"], [class*="border"]) {
  border-color: var(--d-border) !important;
  background-color: var(--d-border) !important;
}

/* ---- Tables -------------------------------------------------------------- */
html.mcos-dark :is(table, th, td) {
  border-color: var(--d-border) !important;
  color: var(--d-text) !important;
}
html.mcos-dark tr:nth-child(even) :is(td, th) {
  background-color: var(--d-surface-2) !important;
}

/* ---- Status / feedback colours (kept legible, not inverted) -------------- */
html.mcos-dark :is(.woocommerce-error, .error-msg, [class*="error"]) {
  color: #e88f8f !important;
}
/* Status pills (e.g. dashboard "inaktiv" .dash-status-pill) keep their light
 * tinted background (#fef2e6), so their text stays dark and legible. */
html.mcos-dark :is([class*="status"], [class*="pill"]) {
  color: #203839 !important;
}
/* Badges/chips/tags here use a translucent brand-green fill over the (now dark)
 * surface — dark text on them is unreadable, so render the label in accent
 * green (e.g. dashboard .dash-bonus__badge "Bonus 1"). */
html.mcos-dark :is([class*="badge"], [class*="chip"], [class*="tag"]):not([class*="status"]):not([class*="pill"]) {
  color: var(--d-green) !important;
}

/* ---- Pagination ---------------------------------------------------------- *
 * Non-current page numbers ( <li> ) carry a white background in the theme;
 * darken them so the light number text is legible. The current page keeps its
 * green highlight. */
html.mcos-dark :is(.pagination-links, [class*="pagination"], .infinite-pages) li:not(.current-page) {
  background-color: var(--d-surface-2) !important;
  border-color: var(--d-border) !important;
}

/* ---- Dashboard specifics ------------------------------------------------- */
html.mcos-dark :is(.dash-overview, .claim-id, .box) {
  background-color: var(--d-surface) !important;
  border-color: var(--d-border) !important;
}
html.mcos-dark .key { color: var(--d-text-muted) !important; }
html.mcos-dark .value { color: var(--d-text) !important; }

/* Dashboard quota legend: the inline subtitle spans (.dash-quota__hint /
 * __caption) are caught by the surface rule's [class*="dash"] and painted
 * --d-surface, which is DARKER than their elevated --d-surface-2 row, so the
 * subtitle shows inside a darker box. They're inline labels, not surfaces — drop
 * the fill. The borrow clears the surface rule's high (~0,13,1) specificity. */
html.mcos-dark :is(.dash-quota__hint, .dash-quota__caption):is(#i#i#i#i.c.c.c, *) {
  background-color: transparent !important;
}

/* ---- Single product page ------------------------------------------------- *
 * The product template paints several panels with the theme's light $white2
 * (#dce0df) fill that the broad surface rule misses (their class names —
 * ingredients-info, attributes-row, price-info, chart — match none of its
 * patterns). With the text forced light they render light-on-light, so darken
 * them to the elevated surface. */
html.mcos-dark :is(
  .ingredients-info p, .attributes-row, .price-info, .price-info_upper, .chart
) {
  background-color: var(--d-surface-2) !important;
  border-color: var(--d-border) !important;
}

/* Aroma / terpene / effect tiles keep their light $green0 fill (a deliberate
 * brand accent that holds a dark glyph or letter — the image glyphs are tinted,
 * not flat monochrome, so inverting them mangles their colour). The img tiles
 * already read fine (dark glyph on light green); only the letter labels break,
 * because the global text rule forces them light → light-on-light. Re-assert a
 * dark label colour so they read on the light tile, matching the glyph tiles. */
html.mcos-dark .card-info_icons .icon-desc span {
  color: #203839 !important;
}

/* ---- Scrollbars ---------------------------------------------------------- */
html.mcos-dark ::-webkit-scrollbar-track { background-color: var(--d-surface) !important; }
html.mcos-dark ::-webkit-scrollbar-thumb { background-color: var(--d-border) !important; }

/* ---- Header logo --------------------------------------------------------- *
 * The default header logo (assets/img/medcan-logo.png) has a dark "MedCanOneStop"
 * wordmark that disappears on the dark header. Swap it for the white variant the
 * theme already ships (assets/img/mcos-logo-lg-white.svg). `content: url()`
 * replaces the rendered image of the <img> in WebKit/Blink (the app WebView)
 * with no markup change; object-fit keeps the original aspect ratio in its
 * 150x48 box. (.logo-sm is display:none, so only .logo-lg needs swapping.) */
html.mcos-dark a[aria-label="Home"] .logo-lg {
  content: url("../img/mcos-logo-lg-white.svg") !important;
  object-fit: contain !important;
}

/* ---- UI icons (systematic) ---------------------------------------------- *
 * The theme ships ~180 monochrome SVG glyphs painted in its dark ink (#274446 /
 * brand green) — invisible on dark surfaces (header search, account, accordion
 * chevrons, the id-stepper, nav, card/legend glyphs, distance/delivery marks …).
 * Rather than chase each, treat every SVG <img> as a UI glyph and force it to a
 * light tone: brightness(0) flattens any hue to black, invert(0.9) lifts it to a
 * near-white mark. Raster <img>s (product photos, brand/manufacturer logos,
 * uploads) are NOT matched, so the `filter: none` media rule below still keeps
 * them — only vector glyphs recolour. Specificity (0,2,2) clears that media
 * rule's (0,1,2). */
html.mcos-dark img[src*=".svg"] {
  filter: brightness(0) invert(0.9) !important;
}
/* Re-assert the original rendering where colour carries meaning (rating stars,
 * payment-method + brand/social marks, logos) or where the glyph sits on a light
 * tile (aroma/terpene .icon-desc), which would otherwise become light-on-light. */
html.mcos-dark :is(
  .icon-desc img,
  img[src*="star"], img[src*="rating"],
  img[src*="card"], img[src*="paypal"], img[src*="klarna"], img[src*="google"], img[src*="method-"],
  img[src*="delivery"], img[src*="service"], img[src*="logistic"], img[src*="truck"],
  img[src*="dpd"], img[src*="hermes"], img[src*="dhl"], img[src*="pickup"],
  img[src*="telegram"], img[src*="linkedin"], img[src*="instagram"], img[src*="demecan"], img[src*="copeia"],
  img[src*="logo"], img[src*="DHV"], img[src*="about-page"],
  /* self-contained graphics (own light fill / circle), placeholders and
   * decorative art — not glyphs, so flattening them to a light blob breaks them */
  img[src*="back-to-top"], img[src*="scroll-top"], img[src*="placeholder"], img[src*="bild"],
  img[src*="coupon"], img[src*="hero"], img[src*="dark-flower"], img[src*="bottom-right"]
) {
  filter: none !important;
}

/* Inline header SVGs (account glyph + its dropdown chevron) hard-code the dark
 * theme stroke (#274446); repaint their strokes to the light text colour. The
 * `filter: none` media rule doesn't touch <svg>, so there's no conflict. */
html.mcos-dark :is(.user-icon, .arrow-wrap svg) :is(path, circle, rect, line, polyline) {
  stroke: var(--d-text) !important;
}

/* The search overlay reuses the dark-wordmark logo (.search-logo); swap it for
 * the white variant exactly like the header .logo-lg above (inverting a colour
 * logo would look wrong). */
html.mcos-dark .search-logo {
  content: url("../img/mcos-logo-lg-white.svg") !important;
  object-fit: contain !important;
}

/* ---- Manufacturer landing (/marke, /manufacturer-landing) ---------------- *
 * This co-branded template paints its product cards with a light .single-product
 * fill and renders a white .google-link reviews card — neither matches a surface
 * pattern, so the text (forced light) sits invisibly on white. Darken both. */
html.mcos-dark .single-product {
  background-color: var(--d-surface) !important;
  border-color: var(--d-border) !important;
}
html.mcos-dark .google-link {
  background-color: var(--d-surface-2) !important;
  border-color: var(--d-border) !important;
}
/* "Mehr laden" pagination button ships a light #f1f1f1 fill; darken it so its
 * accent-green label (from the ghost-button rule) reads. */
html.mcos-dark .load-more {
  background-color: var(--d-surface-2) !important;
  border-color: var(--d-border) !important;
}

/* ---- Complianz cookie banner --------------------------------------------- *
 * The cookie consent banner is a self-contained light component whose classes
 * (.cmplz-*) match no surface pattern, so the broad rules skip it and it stays a
 * white panel with green-on-white buttons. Dark-theme the panel, its text and
 * the secondary buttons; the green accept button keeps its fill, and inline
 * .cmplz-link links stay accent green with no box. */
html.mcos-dark :is(.cmplz-cookiebanner, .cmplz-categories, .cmplz-category) {
  background-color: var(--d-surface) !important;
  border-color: var(--d-border) !important;
}
html.mcos-dark .cmplz-cookiebanner :is(
  .cmplz-title, .cmplz-body, .cmplz-text, p, h1, h2, h3, h4, h5, label, span, li, .cmplz-close
) {
  color: var(--d-text) !important;
}
html.mcos-dark .cmplz-cookiebanner .cmplz-btn:not(.cmplz-accept):not(.cmplz-accept-all):not(.cmplz-deny) {
  background-color: var(--d-surface-2) !important;
  color: var(--d-text) !important;
  border-color: var(--d-border) !important;
}
html.mcos-dark .cmplz-cookiebanner :is(.cmplz-accept, .cmplz-accept-all) {
  background-color: var(--d-brand) !important;
  color: #ffffff !important;
  border-color: var(--d-brand) !important;
}
html.mcos-dark .cmplz-cookiebanner .cmplz-deny {
  background-color: transparent !important;
  color: var(--d-green) !important;
  border-color: var(--d-border) !important;
}
html.mcos-dark .cmplz-cookiebanner .cmplz-link {
  color: var(--d-green) !important;
}

/* Social share buttons (.social-share-buttons) carry a light #f1f1f1 chip fill
 * the surface rule misses; darken so the icons read on the dark page. */
html.mcos-dark .social-share-buttons :is(a, button) {
  background-color: var(--d-surface-2) !important;
  border-color: var(--d-border) !important;
}

/* ---- Media: never filter logos / product photos ------------------------- */
html.mcos-dark :is(img, video, picture, canvas) { filter: none !important; }
