/* SPDX-FileCopyrightText: 2026 calendaring-jmap contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 *
 * Ports pycal.org's real design system (CC-BY-SA-4.0, fetched directly from
 * https://pycal.org/assets/css/style.css) onto pydata-sphinx-theme's own
 * --pst-color- and --pst-font-family- custom properties and matching
 * selectors: palette, fonts, the translucent/blurred sticky nav, button and
 * link hover states, focus-visible outline, text selection, external-link
 * markers, card hover lift/shadow, the back-to-top button, and the custom
 * scrollbar.
 *
 * pycal.org has no dark mode anywhere in its source (no prefers-color-scheme,
 * no data-theme, no dark variable block of any kind, confirmed by reading
 * its full stylesheet directly), so the dark variant below isn't a port of
 * an existing pycal dark mode, since none exists. It's a from-scratch
 * extension of pycal's own visual language: the same stone color family
 * inverted, the same type scale, radius, shadow style, and transition
 * timings, with a slightly lighter accent teal since pycal's literal
 * #0f766e is only 3.21:1 against a dark background, below the 4.5:1 WCAG AA
 * text threshold, where #0d9488 reaches 4.69:1.
 */

html[data-theme="light"] {
  --pst-color-primary: #0f766e;
  --pst-color-secondary: #0b5952;
  --pst-color-secondary-bg: #f0fbf9;
  --pst-color-accent: #0f766e;
  --pst-color-accent-bg: #f0fbf9;
  --pst-color-link: #0f766e;
  --pst-color-link-hover: #0b5952;
  --pst-color-link-higher-contrast: #0b5952;
  --pst-color-background: #ffffff;
  --pst-color-on-background: #ffffff;
  --pst-color-text-base: #111110;
  --pst-color-text-muted: #6b6760;
  --pst-color-border: #e8e6e0;
  --pst-color-border-muted: #e8e6e0;
  --pst-color-surface: #fafaf9;
  --pst-color-on-surface: #111110;
  --pst-color-shadow: rgb(0 0 0 / 0.06);
  --pst-color-inline-code: #292724;
  --pst-color-table: #111110;
  --pst-color-table-inner-border: #e8e6e0;
  --pst-color-primary-bg: #f0fbf9;
  --pst-color-blockquote-notch: #a8a49a;
  --pst-color-target: #fffbeb;
  --pst-color-table-row-hover-bg: #f5f4f0;
  /* Semantic colors (admonitions): pycal's own badge palette, the closest
     real precedent its design system has for status/severity color. */
  --pst-color-info: #1e40af;
  --pst-color-info-bg: #eff6ff;
  --pst-color-warning: #92400e;
  --pst-color-warning-bg: #fffbeb;
  --pst-color-success: #065f46;
  --pst-color-success-bg: #ecfdf5;
  --pst-color-danger: #991b1b;
  --pst-color-danger-bg: #fef2f2;
  --pcj-header-bg: rgb(255 255 255 / 0.92);
}

html[data-theme="dark"] {
  --pst-color-primary: #0d9488;
  --pst-color-secondary: #2dd4bf;
  --pst-color-secondary-bg: #102e2a;
  --pst-color-accent: #0d9488;
  --pst-color-accent-bg: #102e2a;
  --pst-color-link: #0d9488;
  --pst-color-link-hover: #2dd4bf;
  --pst-color-link-higher-contrast: #2dd4bf;
  --pst-color-background: #1a1917;
  --pst-color-on-background: #1a1917;
  --pst-color-text-base: #e8e6e0;
  --pst-color-text-muted: #a8a49a;
  --pst-color-border: #3a3835;
  --pst-color-border-muted: #3a3835;
  --pst-color-surface: #232220;
  --pst-color-on-surface: #e8e6e0;
  --pst-color-shadow: rgb(0 0 0 / 0.3);
  --pst-color-inline-code: #d4d1ca;
  --pst-color-table: #e8e6e0;
  --pst-color-table-inner-border: #3a3835;
  --pst-color-primary-bg: #102e2a;
  --pst-color-blockquote-notch: #6b6760;
  --pst-color-target: #3d3620;
  --pst-color-table-row-hover-bg: #2d2b28;
  /* Semantic colors (admonitions): same hues as light mode, lightened and
     paired with a dark tinted background instead of inverting flat. */
  --pst-color-info: #93c5fd;
  --pst-color-info-bg: #1e293b;
  --pst-color-warning: #fcd34d;
  --pst-color-warning-bg: #3d2e1a;
  --pst-color-success: #6ee7b7;
  --pst-color-success-bg: #1a2e24;
  --pst-color-danger: #fca5a5;
  --pst-color-danger-bg: #3a1e1e;
  --pcj-header-bg: rgb(26 25 23 / 0.92);
}

html {
  --pst-font-family-base: "Inter", system-ui, -apple-system, sans-serif;
  --pst-font-family-heading: "Playfair Display", Georgia, "Times New Roman", serif;
  --pst-font-family-monospace: "Cascadia Code", "Fira Code", ui-monospace, monospace;
}

/* Sticky nav: translucent + blurred, matching pycal's own header exactly. */
.bd-header {
  background-color: var(--pcj-header-bg) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Buttons (search, theme switch, copy, prev/next): pycal's own transition
   timing and radius instead of the theme's defaults. */
.btn,
.copybtn {
  transition: all 0.15s;
  border-radius: 8px;
}

.search-button__button:hover,
.theme-switch-button:hover {
  background: var(--pst-color-surface);
}

/* sphinx-copybutton ships its own hardcoded button.copybtn{color:#57606a}.
   pydata-sphinx-theme overrides the resting color correctly, with
   var(--pst-color-muted), but its hover override reads
   var(--pst-color-text), a variable name that doesn't exist anywhere in
   this theme (the real ones are --pst-color-text-base/-muted), so the
   hover color silently resolves to nothing. Both rules are matched here,
   at equal or higher specificity, rather than relying on source order. */
div.highlight button.copybtn:not(.success) {
  color: var(--pst-color-text-muted);
  background-color: var(--pst-color-surface);
  border-color: var(--pst-color-border);
}

div.highlight button.copybtn:hover:not(.success) {
  color: var(--pst-color-accent);
  background-color: var(--pst-color-border);
}

/* Blanket link-state override: the browser's own built-in :visited purple
   otherwise wins over the theme's --pst-color-link on plain, unclassed
   links (e.g. the sidebar's "Show Source"/"Edit on GitHub"), since that
   link only goes through --pst-color-link indirectly and visited-link
   styling is handled specially by browsers. Setting color directly here,
   last in the cascade and without relying on inheritance, fixes it.
   This also covers every other hover case (a.nav-link, a.reference, the
   prev-next-area title), since a:hover matches any anchor. */
a:link,
a:visited {
  color: var(--pst-color-link);
}

a:hover,
a:visited:hover {
  color: var(--pst-color-link-hover);
}

/* Theme-switch dropdown (System Settings/Light/Dark): the theme's own
   dropdown-item color override only targets a.nav-link.dropdown-item (the
   navbar's "More" menu), not these button.dropdown-item elements, which
   otherwise stay on raw, un-themed Bootstrap colors in both modes. */
button.dropdown-item {
  color: var(--pst-color-text-muted);
}

button.dropdown-item:hover {
  color: var(--pst-color-link-hover);
}

/* External links: pycal marks them with a small arrow, not just an icon. */
a.reference.external::after {
  content: " \2197";
  font-size: 0.85em;
  opacity: 0.7;
}

/* Card-like surfaces (grid cards, admonitions): pycal's hover lift + shadow. */
.sd-card,
.admonition {
  transition: transform 0.15s, box-shadow 0.15s;
  border-radius: 8px;
}

.sd-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--pst-color-shadow);
}

/* Focus-visible outline, matching pycal's own 2px solid offset. */
:focus-visible {
  outline: 2px solid var(--pst-color-accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Text selection, matching pycal's own fixed dark-on-light selection. */
::selection {
  background: var(--pst-color-text-base);
  color: var(--pst-color-surface);
}

/* Scrollbar: Firefox. */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--pst-color-border) var(--pst-color-surface);
}

/* Scrollbar: WebKit/Blink/Chromium, matching pycal's 8px + ring inset. */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--pst-color-surface);
}

::-webkit-scrollbar-thumb {
  background: var(--pst-color-border);
  border-radius: 4px;
  border: 2px solid var(--pst-color-surface);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--pst-color-text-muted);
}

/* Back-to-top button, matching pycal's own floating circular button. */
#pst-back-to-top {
  border-radius: 50%;
  border: 1px solid var(--pst-color-border);
  background: var(--pst-color-surface);
  color: var(--pst-color-text-muted);
  box-shadow: 0 2px 8px var(--pst-color-shadow);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

#pst-back-to-top:hover {
  background: var(--pst-color-border);
  color: var(--pst-color-text-base);
}

/* Bootstrap tooltips (navbar icon labels): fixed dark-on-light bubble in
   both modes, since a tooltip is meant to pop over its surroundings,
   matching pycal's own fixed-color ::selection in the same spirit. */
.tooltip {
  --bs-tooltip-bg: var(--pst-color-text-base);
  --bs-tooltip-color: var(--pst-color-background);
}

/* Footer: pycal's own border-top + off-background surface + muted links
   that brighten on hover, instead of the theme's plain default bar. */
.bd-footer {
  border-top: 1px solid var(--pst-color-border);
  background: var(--pst-color-surface);
}

.bd-footer .footer-item,
.bd-footer .footer-item p {
  color: var(--pst-color-text-muted);
  font-size: 0.85rem;
}

/* Inline prose links (the NLnet acknowledgment sentence), not a nav list:
   pycal's own equivalent for "a link inside a sentence" is .prose a, an
   underline that darkens on hover, not the undecorated .footer-col ul a
   nav-list style, which would otherwise be indistinguishable from the
   surrounding plain text here. */
.bd-footer .footer-item a {
  color: var(--pst-color-text-muted);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: var(--pst-color-text-muted);
  transition: text-decoration-color 0.15s, color 0.15s;
}

.bd-footer .footer-item a:hover {
  color: var(--pst-color-accent);
  text-decoration-color: var(--pst-color-accent);
}

/* Read the Docs' "Show diff" PR preview overlay (.doc-diff-added/-removed
   on plain <ins>/<del> tags). RTD ships no theme-aware default for these,
   just light-mode-tuned colors, which read as a muddy, low-contrast block
   against a dark background. Reusing the same success/danger tokens the
   admonitions already use keeps it legible and on-theme in both modes. */
ins.doc-diff-added {
  background-color: var(--pst-color-success-bg);
  color: var(--pst-color-text-base);
  text-decoration: none;
}

del.doc-diff-removed {
  background-color: var(--pst-color-danger-bg);
  color: var(--pst-color-text-base);
}
