/* ------------------------------------------------------------------ *
 * Webperf Cloud — premium (authenticated app) skin over Pico CSS.
 * Shares the marketing site's teal accent so the product feels like one
 * thing. Vanilla CSS, no framework beyond Pico. WCAG-minded.
 * ------------------------------------------------------------------ */

:root {
  --pico-primary: #0a6e5e;
  --pico-primary-background: #0d7c6b;
  --pico-primary-hover-background: #0a6253;
  --pico-primary-hover: #084f43;
  --pico-primary-focus: rgba(13, 124, 107, 0.3);
  --pico-primary-underline: rgba(10, 110, 94, 0.5);
  --pico-border-radius: 0.5rem;

  --wp-accent: #0d7c6b;
  /* Accent used as TEXT/foreground. A touch darker than --wp-accent so it clears
     WCAG 2.1 AA 4.5:1 on light accent tints (e.g. the active nav link's #e2efed
     background, where #0d7c6b is only 4.32:1). Lightened again for dark mode
     (below). Backgrounds, borders and badges keep --wp-accent (white text passes). */
  --wp-accent-fg: #0a6e5e;
}

/* Our brand-green primary above is set on :root (specificity 0,1,0). Pico's
   system-dark palette uses :root:not([data-theme]) (0,2,0) so it wins and shows
   Pico's blue, but explicit [data-theme="dark"] (0,1,0) ties with our :root and
   loses to it by source order — making "Dark" look green-tinted, unlike the
   System-dark the user prefers. Restore Pico's dark blue for explicit dark so
   the two match. Values mirror pico.min.css [data-theme=dark]. */
[data-theme="dark"] {
  --pico-primary: #01aaff;
  --pico-primary-background: #0172ad;
  --pico-primary-hover-background: #017fc0;
  --pico-primary-hover: #79c0ff;
  --pico-primary-focus: rgba(1, 170, 255, 0.375);
  --pico-primary-underline: rgba(1, 170, 255, 0.5);
  /* Brand green #0d7c6b as text on dark surfaces is only ~3:1 (fails AA). Use a
     lighter teal for accent text. ~6:1 on the dark sidebar/card background. */
  --wp-accent-fg: #4db6a4;
  /* Pico's dark muted (#7b8495) is only 4.27:1 on the dark card background
     (#181c25), so muted UI text — disclosure summaries, stat labels, hints —
     fails WCAG AA. Lift it to ~5:1 on the card surface. */
  --pico-muted-color: #8b94a6;
}
/* Same lightened accent + muted text for System-dark (no data-theme attribute). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --wp-accent-fg: #4db6a4;
    --pico-muted-color: #8b94a6;
  }
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

main#main {
  flex: 1 0 auto;
  padding-block: 1.5rem 3rem;
}

/* ---- Skip link ---------------------------------------------------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 1000;
  padding: 0.5rem 1rem;
  background: var(--wp-accent);
  color: #fff;
  border-radius: 0 0 var(--pico-border-radius) 0;
}
.skip-link:focus { left: 0; }

/* ---- App shell: left sidebar (logged in) -------------------------- */
.app-shell {
  display: flex;
  flex: 1 0 auto;
  align-items: stretch;
}
.app-sidebar {
  flex: 0 0 220px;
  border-right: 1px solid var(--pico-muted-border-color);
  background: var(--pico-card-background-color);
  padding: 1rem 0.6rem;
}
.app-sidebar nav ul { list-style: none; margin: 0; padding: 0; }
.app-sidebar li { margin-bottom: 0.15rem; }
.app-sidebar a:not([role="button"]) {
  display: block;
  padding: 0.5rem 0.7rem;
  border-radius: var(--pico-border-radius);
  text-decoration: none;
  color: var(--pico-color);
}
.app-sidebar a:not([role="button"]):hover {
  background: color-mix(in srgb, var(--wp-accent) 8%, transparent);
  color: var(--wp-accent-fg);
}
.app-sidebar a[aria-current="page"] {
  background: color-mix(in srgb, var(--wp-accent) 12%, transparent);
  color: var(--wp-accent-fg);
  font-weight: 600;
}
.app-sidebar details.dropdown { margin: 0.15rem 0 0; }
.app-sidebar details.dropdown summary { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0.7rem; border-radius: var(--pico-border-radius); }
/* In the narrow sidebar the floated chevron wraps to a new line; flex keeps it
   inline. Reset Pico's float so it behaves as a flex item beside the text. */
.app-sidebar details.dropdown summary::after { float: none; margin: 0; }
.app-sidebar details.dropdown ul { padding-left: 0.5rem; }
/* Content disclosures (e.g. "Testresultat"). Pico floats the chevron to the far
   right of a full-width summary, so it reads as plain text. Give it a bordered,
   tinted control look with the marker sitting right next to the label. */
.app-main details:not(.dropdown) {
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  margin-bottom: var(--pico-spacing);
}
.app-main details:not(.dropdown) summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  font-weight: 600;
  color: var(--wp-accent-fg);
  background: color-mix(in srgb, var(--wp-accent) 6%, transparent);
  border-radius: var(--pico-border-radius);
  cursor: pointer;
}
.app-main details:not(.dropdown)[open] summary {
  border-bottom: 1px solid var(--pico-muted-border-color);
  border-end-start-radius: 0;
  border-end-end-radius: 0;
}
.app-main details:not(.dropdown) summary:hover {
  background: color-mix(in srgb, var(--wp-accent) 12%, transparent);
}
/* Reset Pico's float so the chevron sits beside the label instead of far right. */
.app-main details:not(.dropdown) summary::after {
  float: none;
  margin: 0;
  order: -1;
}
.app-main details:not(.dropdown) > :not(summary) {
  margin-inline: 0.85rem;
}
.app-main details:not(.dropdown) > :not(summary):first-of-type { margin-top: 0.85rem; }
.app-main details:not(.dropdown) > :last-child { margin-bottom: 0.85rem; }
/* Selector must out-specify `main#main { flex: 1 0 auto }` above, otherwise
   the content column won't shrink and overflows the sidebar. flex-basis 0 +
   shrink + min-width:0 lets it fit beside the sidebar and shrink below the
   intrinsic width of wide children (charts, grids). */
main#main.app-main {
  flex: 1 1 0%;
  min-width: 0;
  padding-inline: clamp(1rem, 3vw, 2rem);
  padding-block: 1.5rem 3rem;
}
/* Keep wide dashboard widgets within the content column. */
.app-main #myDiv,
.app-main .js-plotly-plot { max-width: 100%; }

/* Hamburger (mobile only) */
.sidebar-toggle {
  display: none;
  width: auto;
  margin: 0;
  padding: 0.2rem 0.55rem;
  background: none;
  border: none;
  /* Pico redefines --pico-color to white on buttons, so use the contrast
     colour explicitly or the icon would be white-on-white. */
  color: var(--pico-contrast);
  cursor: pointer;
}
.sidebar-toggle svg { display: block; stroke: currentColor; }
.sidebar-overlay { display: none; }

@media (max-width: 768px) {
  .sidebar-toggle { display: inline-flex; align-items: center; }
  /* Stack the two nav groups: row 1 = hamburger + brand, row 2 = nav items */
  .app-header nav.container-fluid { flex-direction: column; align-items: stretch; gap: 0.4rem; }
  .app-header nav.container-fluid > .app-nav {
    justify-content: flex-start;
    flex-wrap: wrap;
    column-gap: 0.9rem;
    row-gap: 0.25rem;
  }
  .app-nav > li { padding-inline: 0; }
  .app-shell { display: block; }
  .app-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    width: 260px;
    max-width: 84vw;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    overflow-y: auto;
    box-shadow: 0 0 24px rgba(0, 0, 0, 0.18);
  }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 150;
    background: rgba(0, 0, 0, 0.4);
  }
}
@media (prefers-reduced-motion: reduce) {
  .app-sidebar { transition: none; }
}

/* ---- Header / nav ------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--pico-background-color) 90%, transparent);
  backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--pico-muted-border-color);
}
.app-header nav { padding-block: 0.3rem; }

/* Slimmer top bar when logged in. Pico spaces each nav <li> by
   --pico-nav-element-spacing-vertical (1rem default); cutting it ~⅓
   shrinks the header height without touching the marketing pages. */
.is-authed .app-header nav { --pico-nav-element-spacing-vertical: 0.1rem; padding-block: 0.1rem; }
.brand {
  font-size: 1.1rem;
  text-decoration: none;
  color: var(--pico-color);
  white-space: nowrap;
}
.brand strong { color: var(--wp-accent-fg); }
.brand-sep { margin: 0 0.25rem; color: var(--pico-muted-color); }

.app-nav {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.1rem 0.25rem;
}
.app-nav a:not([role="button"]) {
  text-decoration: none;
  color: var(--pico-color);
  padding: 0.4rem 0.6rem;
  border-radius: var(--pico-border-radius);
  display: inline-block;
}
.app-nav a:not([role="button"]):hover { color: var(--wp-accent-fg); }
.app-nav a[aria-current="page"] {
  color: var(--wp-accent-fg);
  font-weight: 600;
}
.logout-btn { --pico-color: #fff; padding-block: 0.35rem; }

/* Pico dropdowns inside the nav (site switcher, admin group) */
.app-nav details.dropdown { margin-bottom: 0; }
.app-nav details.dropdown summary { padding: 0.4rem 0.6rem; }

/* Language switch */
.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-left: 0.4rem;
  color: var(--pico-muted-color);
  font-size: 0.85rem;
}
.lang-switch a { text-decoration: none; color: var(--pico-muted-color); }
.lang-switch a[aria-current="true"] { color: var(--wp-accent-fg); font-weight: 700; }

/* ---- Generic content niceties ------------------------------------- */
.page-breadcrumb,
.page-title { margin-bottom: 0.5rem; }
.page-title { font-size: 1.6rem; letter-spacing: -0.01em; }

/* Map common legacy helpers so un-reskinned pages stay readable until
   they're converted individually. */
.white-box {
  background: var(--pico-card-background-color);
  border: 1px solid var(--pico-muted-border-color);
  border-radius: var(--pico-border-radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}
.message, .bg-info {
  border-left: 4px solid var(--wp-accent);
  background: var(--pico-card-background-color);
  padding: 0.8rem 1rem;
  border-radius: var(--pico-border-radius);
  margin-bottom: 1rem;
}
/* Felmeddelanden ska sticka ut tydligt mot de gröna info-meddelandena. */
.message-error {
  border-left-width: 6px;
  border-left-color: #c0392b;
  background: color-mix(in srgb, #c0392b 12%, var(--pico-card-background-color));
  font-weight: 600;
}
.text-muted { color: var(--pico-muted-color); }
.text-center { text-align: center; }
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

/* ---- Dashboard (start) ------------------------------------------- */
.analytics-info h3,
.score-card h3 {
  font-size: 1rem;
  color: var(--pico-muted-color);
  margin-bottom: 0.6rem;
}
.circle-svg {
  display: block;
  max-width: 160px;
  margin: 0 auto;
}
.circle-svg .around {
  fill: none;
  stroke: var(--pico-muted-border-color);
  stroke-width: 2.2;
}
.circle-svg .percent {
  fill: none;
  stroke: var(--wp-accent);
  stroke-width: 2.2;
  stroke-linecap: round;
}
.circle-svg text {
  fill: var(--pico-color);
  font-weight: 600;
}
.score-grid {
  grid-template-columns: repeat(4, 1fr);
}
.score-card { text-align: center; }
.score-card .score {
  font-size: 2.2rem;
  font-weight: 700;
  color: var(--wp-accent-fg);
}
@media (max-width: 768px) {
  .score-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ---- Account (mitt-konto) ----------------------------------------- */
.account-grid { grid-template-columns: 1fr 2fr; align-items: start; }
.user-card .user-avatar { font-size: 4rem; display: block; line-height: 1; }
.user-card dt { font-weight: 600; color: var(--pico-muted-color); margin-top: 0.6rem; }
.user-card dd { margin-left: 0; }
@media (max-width: 768px) {
  .account-grid { grid-template-columns: 1fr; }
}

/* Two-column split (filter sidebar + content). */
.split-grid { grid-template-columns: 1fr 3fr; align-items: start; }
@media (max-width: 768px) {
  .split-grid { grid-template-columns: 1fr; }
}

/* Simple badges (pico has none). */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 1rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  background: var(--pico-muted-color);
}
.badge-danger  { background: #b3261e; }
.badge-warning { background: #9c5b00; } /* darker amber: white text ~5.4:1 (AA) */
.badge-info    { background: var(--wp-accent); }
.badge-success { background: #1f7a4d; }

/* Destructive buttons */
button.danger, .danger[role="button"], input[type="submit"].danger {
  background: #b3261e;
  border-color: #b3261e;
  color: #fff;
}
button.danger:hover, .danger[role="button"]:hover {
  background: #8f1e17;
  border-color: #8f1e17;
}

/* Favorite star buttons (sites list) */
.star-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  width: auto;
  font-size: 1.2rem;
  line-height: 1;
  color: #d4a017;
  cursor: pointer;
}
.star-btn.star-empty { color: var(--pico-muted-color); }
.star-btn:disabled { cursor: not-allowed; opacity: 0.5; }

/* Opt out of Pico's square `ul li` bullets for utility lists (buttons,
   tabs, etc.). The selector targets `li` directly so it beats `ul li`. */
.list-plain { margin: 0; padding: 0; }
.list-plain > li { list-style: none; }

/* Bootstrap-style inline lists (e.g. the CrUX metric-card KPI rows). */
.list-inline { margin: 0; padding: 0; list-style: none; }
.list-inline > li { list-style: none; display: inline-block; }

/* ---- Error pages -------------------------------------------------- */
.error-box {
  max-width: 32rem;
  margin: 3rem auto;
  text-align: center;
}
.error-code {
  font-size: clamp(3.5rem, 12vw, 6rem);
  font-weight: 800;
  line-height: 1;
  color: var(--wp-accent-fg);
  margin-bottom: 0.5rem;
}

/* ---- Footer ------------------------------------------------------- */
.app-footer {
  flex-shrink: 0;
  padding-block: 1.5rem;
  border-top: 1px solid var(--pico-muted-border-color);
  background: var(--pico-card-background-color);
  text-align: center;
  font-size: 0.9rem;
  color: var(--pico-muted-color);
}
.app-footer a { text-decoration: none; }

/* ---- Language dialog --------------------------------------------- */
dialog.lang-dialog article { max-width: 26rem; }
.lang-options { display: grid; gap: 0.6rem; margin-block: 1rem; }

/* ---- Focus & motion ----------------------------------------------- */
:where(a, button, [role="button"], input, summary, select, textarea):focus-visible {
  outline: 3px solid var(--wp-accent);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .app-header { backdrop-filter: none; }
}
