/*
 * RiderMates core styles: design tokens, base and site header.
 *
 * Rules for this file
 *  - Mobile first: base rules are for phones; wider screens add rules with min-width.
 *  - Two breakpoints only: 768px (tablet and up) and 1024px (desktop).
 *  - Colours, spacing, radii and type come from the tokens below, never from raw values.
 *  - No !important, except in the "App overrides" section at the end, where it is needed to
 *    beat inline style="" attributes written by the exported app templates.
 */

/* ---------------------------------------------------------------------------
   1. Tokens
   --------------------------------------------------------------------------- */
:root {
  /* colour (light) */
  --rm-color-bg: #fff;
  --rm-color-surface: #f7f7f7;
  --rm-color-ink: #1b1b1b;
  --rm-color-muted: #5f5f5f;
  --rm-color-line: #e5e5e5;
  --rm-color-accent: #bf3f17;
  --rm-color-accent-hover: #a33512;
  --rm-color-on-accent: #fff;
  --rm-color-link: #1f7a70;
  --rm-color-tint: #e3f1ef;
  --rm-logo-bg: transparent;

  /* space */
  --rm-space-1: 4px;
  --rm-space-2: 8px;
  --rm-space-3: 12px;
  --rm-space-4: 16px;
  --rm-space-5: 24px;
  --rm-space-6: 32px;
  --rm-space-7: 48px;

  /* shape and depth */
  --rm-radius-sm: 8px;
  --rm-radius-md: 12px;
  --rm-radius-lg: 20px;
  --rm-radius-pill: 999px;
  --rm-shadow-pop: 0 12px 28px rgb(0 0 0 / 0.2);

  /* layout */
  --rm-shell-max: 1140px;
  --rm-tap: 44px;

  /* type */
  --rm-font-sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --rm-font-display: "Inter Tight", Inter, system-ui, sans-serif;
}

/* colour (dark): set by the colour-mode toggle, or by the OS when the visitor has not chosen */
html[data-theme="dark"] {
  color-scheme: dark;
  --rm-color-bg: #080808;
  --rm-color-surface: #151515;
  --rm-color-ink: #ededed;
  --rm-color-muted: #b7b7b7;
  --rm-color-line: #2a2a2a;
  --rm-color-accent: #e0592b;
  --rm-color-accent-hover: #ee6d40;
  --rm-color-link: #5fc0b3;
  --rm-color-tint: #14302c;
  --rm-logo-bg: #fff;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) {
    color-scheme: dark;
    --rm-color-bg: #080808;
    --rm-color-surface: #151515;
    --rm-color-ink: #ededed;
    --rm-color-muted: #b7b7b7;
    --rm-color-line: #2a2a2a;
    --rm-color-accent: #e0592b;
    --rm-color-accent-hover: #ee6d40;
    --rm-color-link: #5fc0b3;
    --rm-color-tint: #14302c;
    --rm-logo-bg: #fff;
  }
}

/* ---------------------------------------------------------------------------
   2. Site header  (markup: functions.php, "One independent header")
   --------------------------------------------------------------------------- */

/* Phone: logo, colour toggle and a Menu button; the links open in a drawer. */
#rm-site-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--rm-color-bg);
  color: var(--rm-color-ink);
  border-bottom: 1px solid var(--rm-color-line);
  font: 550 14px/20px var(--rm-font-sans);
}

#rm-site-header *,
#rm-site-header *::before,
#rm-site-header *::after {
  box-sizing: border-box;
}

#rm-site-header :is(a, summary, button) {
  color: inherit;
  font: inherit;
  text-decoration: none;
}

#rm-site-header :is(a, summary, button):focus-visible {
  outline: 3px solid var(--rm-color-accent);
  outline-offset: 3px;
}

/* WordPress admin bar is 46px tall on small screens, 32px from 783px */
.admin-bar #rm-site-header {
  top: 46px;
}

#rm-site-header .rmsh-row {
  display: flex;
  align-items: center;
  gap: var(--rm-space-2);
  height: 56px;
  max-width: var(--rm-shell-max);
  margin-inline: auto;
  padding-inline: max(14px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-right));
}

#rm-site-header .rmsh-logo {
  display: flex;
  align-items: center;
  flex: none;
  width: min(148px, 42vw);
}

#rm-site-header .rmsh-logo img {
  display: block;
  width: 100%;
  height: 42px;
  object-fit: contain;
  background: var(--rm-logo-bg);
  border-radius: 5px;
}

/* Colour toggle sits next to the Menu button, both pushed right */
#rm-site-header .rmsh-actions {
  display: flex;
  align-items: center;
  gap: var(--rm-space-2);
  margin-left: auto;
  order: 1;
}

#rm-site-header .rmsh-mode {
  display: grid;
  place-items: center;
  width: var(--rm-tap);
  height: var(--rm-tap);
  padding: 0;
  background: transparent;
  border: 1px solid var(--rm-color-line);
  border-radius: 50%;
  font-size: 20px;
  cursor: pointer;
}

#rm-site-header .rmsh-menu {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  order: 2;
  min-height: var(--rm-tap);
  padding: 0 var(--rm-space-3);
  background: transparent;
  border: 1px solid var(--rm-color-line);
  border-radius: var(--rm-radius-sm);
  cursor: pointer;
}

/* Drawer: slides in from the right under the header */
#rm-site-header .rmsh-nav {
  position: absolute;
  inset: 100% 0 auto auto;
  display: flex;
  flex-direction: column;
  gap: var(--rm-space-1);
  width: min(320px, 88vw);
  max-height: calc(100dvh - 104px);
  padding: var(--rm-space-3);
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--rm-color-bg);
  border: 1px solid var(--rm-color-line);
  border-radius: 0 0 0 var(--rm-radius-md);
  box-shadow: var(--rm-shadow-pop);
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateX(100%);
  transition: transform 0.22s ease, opacity 0.22s ease, visibility 0s linear 0.22s;
}

#rm-site-header .rmsh-nav[data-open] {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
  transform: none;
  transition-delay: 0s;
}

#rm-site-header .rmsh-nav > a,
#rm-site-header .rmsh-nav summary {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--rm-tap);
  padding: var(--rm-space-2) var(--rm-space-3);
  background: var(--rm-color-surface);
  border-radius: var(--rm-radius-sm);
  white-space: nowrap;
  list-style: none;
  cursor: pointer;
}

#rm-site-header summary::-webkit-details-marker {
  display: none;
}

#rm-site-header summary::after {
  content: "⌄";
  font-size: 12px;
}

#rm-site-header .rmsh-panel {
  margin: var(--rm-space-1) 0 var(--rm-space-1) var(--rm-space-3);
  padding: 0 var(--rm-space-1);
}

#rm-site-header .rmsh-panel a {
  display: flex;
  align-items: center;
  min-height: var(--rm-tap);
  padding: var(--rm-space-3);
  border-radius: var(--rm-radius-sm);
}

#rm-site-header .rmsh-panel a:hover {
  background: var(--rm-color-surface);
}

#rm-site-header .rmsh-search {
  display: flex;
  align-items: center;
  margin: var(--rm-space-1) 0 0;
}

#rm-site-header .rmsh-search input {
  width: 100%;
  height: 32px;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  border: 0;
  border-bottom: 1px solid var(--rm-color-line);
  border-radius: 0;
  box-shadow: none;
  outline: 0;
  appearance: none;
}

#rm-site-header .rmsh-search input:focus {
  border-bottom-color: var(--rm-color-accent);
}

@media (prefers-reduced-motion: reduce) {
  #rm-site-header .rmsh-nav {
    transition: none;
  }
}

/* Tablet and up: links sit in the bar, dropdowns float */
@media (min-width: 768px) {
  #rm-site-header .rmsh-row {
    height: 64px;
    gap: var(--rm-space-5);
    padding-inline: var(--rm-space-5);
  }

  #rm-site-header .rmsh-logo {
    width: 180px;
  }

  #rm-site-header .rmsh-logo img {
    height: 44px;
  }

  #rm-site-header .rmsh-menu {
    display: none;
  }

  #rm-site-header .rmsh-nav {
    position: static;
    flex: 1;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 20px;
    width: auto;
    max-height: none;
    padding: 0;
    overflow: visible;
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: none;
    transition: none;
  }

  #rm-site-header .rmsh-nav > a,
  #rm-site-header .rmsh-nav summary {
    padding: 10px var(--rm-space-1);
    background: none;
    border-radius: 0;
  }

  #rm-site-header .rmsh-nav > details {
    position: relative;
  }

  #rm-site-header .rmsh-panel {
    position: absolute;
    top: 100%;
    left: -14px;
    min-width: 205px;
    margin: 0;
    padding: var(--rm-space-2);
    background: var(--rm-color-bg);
    border: 1px solid var(--rm-color-line);
    border-radius: var(--rm-radius-md);
    box-shadow: var(--rm-shadow-pop);
  }

  #rm-site-header .rmsh-panel a {
    white-space: nowrap;
  }

  #rm-site-header .rmsh-search {
    margin: 0;
  }

  #rm-site-header .rmsh-search input {
    width: 150px;
  }
}

@media (min-width: 783px) {
  .admin-bar #rm-site-header {
    top: 32px;
  }
}

/* ---------------------------------------------------------------------------
   3. App overrides
   !important is allowed in this section only. Each rule beats an inline style="" written by the
   exported app templates, or hides legacy markup that those templates still render.
   --------------------------------------------------------------------------- */

/* Hide the old app header, the WordPress-template header and the topic strip: the shared
   #rm-site-header above replaces all three. */
header[data-rm-hdr],
header.site-header,
.category-strip {
  display: none !important;
}

/* Catalogue search button: no decorative arrow (moves to the catalogue part of the migration) */
.rm-catalog-filters button[type="submit"]::after {
  content: none !important;
}

/* Header guards. Each one beats a global !important rule or inline style that is not part of the
   header. Root causes, to fix at source (then delete the guard):
   - an inline <style> underlines every link: a:not([style*="display"]):not([style*="background"])
   - an inline <style> gives every input in [data-theme] a 24px radius and a paper background
   - a script sets style="display:none" on the "Buy & sell" <details> after load */
#rm-site-header :is(a, summary) {
  text-decoration: none !important;
}

#rm-site-header .rmsh-search input {
  height: 32px !important;
  background: transparent !important;
  border-radius: 0 !important;
}

#rm-site-header .rmsh-nav > details {
  display: block !important;
}
