/* ==========================================================================
   Depots — review-source sync UI
   Styled on MUS: --mus-* tokens come from the stylesheet linked before this
   one; cards, buttons and the URL field follow the MUS CSS recipes.
   Self-hosted Roboto (MUS names the font but doesn't load it), no build step.
   ========================================================================== */

/* --- Self-hosted Roboto (latin + latin-ext for Czech diacritics) ---------- */
@font-face {
  font-family: 'Roboto'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('/static/fonts/roboto-400-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Roboto'; font-style: normal; font-weight: 400; font-display: swap;
  src: url('/static/fonts/roboto-400-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'Roboto'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('/static/fonts/roboto-700-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Roboto'; font-style: normal; font-weight: 700; font-display: swap;
  src: url('/static/fonts/roboto-700-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* --- Local tokens: only what MUS doesn't define ---------------------------- */
:root {
  --logo-size: 2.5rem;
}

/* MUS recipes assume border-box. */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

body {
  font-family: var(--mus-font-family);
  color: var(--mus-color-dark);
  background: var(--mus-color-white);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--mus-spacing-4) var(--mus-spacing-3);
  -webkit-font-smoothing: antialiased;
}

.page { width: 100%; max-width: 560px; }

/* --- Header ---------------------------------------------------------------- */
.page-header { text-align: left; margin-bottom: var(--mus-spacing-5); }

.app-logo { margin: 0; line-height: 0; }

.app-logo img {
  display: block;
  height: 40px;
  width: auto;
}

/* MUS Typography "description". */
.subtitle {
  margin-top: var(--mus-spacing-3);
  font-size: var(--mus-font-size-md);
  font-weight: var(--mus-font-weight-normal);
  color: var(--mus-color-gray);
  line-height: var(--mus-line-height-normal);
}

/* --- Source cards ---------------------------------------------------------- */
.sources { display: flex; flex-direction: column; gap: var(--mus-spacing-2); }

/* Reviews / Statistics groups: title sits tight above its cards, groups get
   a little extra air between them. */
.source-group { display: flex; flex-direction: column; gap: var(--mus-spacing-1); }
.source-group .source-card + .source-card { margin-top: var(--mus-spacing-1); }
.source-group + .source-group { margin-top: var(--mus-spacing-1); }

.source-group-title {
  font-size: var(--mus-font-size-sm);
  font-weight: var(--mus-font-weight-bold);
  color: var(--mus-color-gray);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* MUS Panel: hairline border, no fill. Hover lifts it with the MUS resting
   elevation (the hover one is too strong for a non-clickable card). */
.source-card {
  display: flex;
  align-items: center;
  gap: var(--mus-spacing-2);
  padding: var(--mus-spacing-2);
  border: 1px solid var(--mus-color-border);
  border-radius: var(--mus-radius-md);
  line-height: var(--mus-line-height-small);
  transition: border-color var(--mus-duration-medium) var(--mus-easing-standard),
    box-shadow var(--mus-duration-medium) var(--mus-easing-standard);
}

.source-card:hover { box-shadow: var(--mus-shadow); }

/* On/off visuals are driven by the checkbox itself (:checked), not by a server
   re-render — so a toggle updates instantly and the slider keeps its animation
   (no card swap to re-parent it). data-state="failing" keeps its own amber
   treatment below and must win while on, hence the :not() guard. The amber
   rules also require :checked so that switching a failing source off greys it
   out immediately, like any other disabled source. */
.source-card:not([data-state="failing"]):has(.sync-toggle:checked) {
  border-color: var(--mus-color-primary);
}

.source-card[data-state="failing"]:has(.sync-toggle:checked) {
  border-color: var(--mus-color-warning);
}

/* Logo tile: CSS monogram is the always-present baseline; the MUS service logo
   layers on top and is hidden by JS (.logo-broken) if it fails to load. */
.source-logo {
  position: relative;
  flex: none;
  width: var(--logo-size);
  height: var(--logo-size);
}

.monogram {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--mus-font-size-lg);
  font-weight: var(--mus-font-weight-bold);
  color: var(--mus-color-secondary);
}

/* Monogram is only a fallback: hide it whenever a healthy logo image is shown
   (the image precedes it in the DOM). It reappears if the image is missing or
   fails to load (.logo-broken), since then the rule no longer matches. */
.source-logo img:not(.logo-broken) + .monogram { display: none; }

.source-logo img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: var(--mus-spacing-0_5);
}

.source-logo img.logo-broken { display: none; }

/* Not connected in Mergado Keychain: grey out the logo so it reads as
   unavailable at a glance. Applies to both the image and the monogram fallback. */
.source-card[data-state="unavailable"] .source-logo img,
.source-card[data-state="unavailable"] .monogram {
  filter: grayscale(100%);
  opacity: 0.45;
}

.source-info { flex: 1; min-width: 0; }

/* MUS Panel title: truncates so a long name can't push the switch out. */
.source-info h3 {
  font-size: var(--mus-font-size-md);
  font-weight: var(--mus-font-weight-bold);
  color: var(--mus-color-dark);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* MUS Panel description, but wrapping: it holds setup hints and the failure
   tooltip, which truncation would cut off. */
.source-status {
  margin-top: var(--mus-spacing-0_5);
  font-size: var(--mus-font-size-sm);
  color: var(--mus-color-gray);
  transition: color var(--mus-duration-medium) var(--mus-easing-standard);
}

.source-card:not([data-state="failing"]):has(.sync-toggle:checked) .source-status { color: var(--mus-color-primary); font-weight: var(--mus-font-weight-bold); }
.source-card[data-state="failing"]:has(.sync-toggle:checked) .source-status { color: var(--mus-color-warning-darkest); font-weight: var(--mus-font-weight-bold); }

/* Status label tracks the checkbox so it flips with no round-trip. Both phrases
   are rendered (and translated) server-side; CSS reveals the live one. */
.source-status .status-on { display: none; }
.source-card:has(.sync-toggle:checked) .source-status .status-on { display: inline; }
.source-card:has(.sync-toggle:checked) .source-status .status-off { display: none; }

/* --- Failure reasons (MUS TooltipWrapper "With Icon") ----------------------- */
.failure-tooltip-wrapper {
  position: relative;
  display: inline-flex;
  vertical-align: -2px;
  margin-left: var(--mus-spacing-0_5);
  padding: 2px;              /* enlarges the hover/focus target around the icon */
}

.failure-icon { display: block; color: var(--mus-color-warning); }

.failure-tooltip {
  position: absolute;
  bottom: calc(100% + var(--mus-spacing-0_5));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: max-content;
  max-width: 250px;
  padding: var(--mus-spacing-1);
  background: var(--mus-color-dark);
  color: var(--mus-color-white);
  box-shadow: 0 2px 8px var(--mus-color-dark);
  border-radius: var(--mus-radius-sm);
  font-size: var(--mus-font-size-sm);
  font-weight: var(--mus-font-weight-normal);
  line-height: var(--mus-line-height-normal);
  text-align: left;
  overflow-wrap: break-word;
  visibility: hidden;
  transition: visibility 0s;
}

/* Radix-style arrow: 10px wide, 5px tall, same fill as the box. */
.failure-tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--mus-color-dark);
  border-bottom: none;
}

.failure-tooltip-wrapper:hover .failure-tooltip,
.failure-tooltip-wrapper:focus-visible .failure-tooltip {
  visibility: visible;
  transition-delay: var(--mus-duration-medium);  /* MUS delayDuration before showing */
}

.failure-tooltip-reason { display: block; }
.failure-tooltip-reason + .failure-tooltip-reason { margin-top: var(--mus-spacing-2); }

/* --- Toggle switch (accessible: real focusable checkbox) ------------------- */
/* MUS has no CSS recipe for Toggler. Track colors carry fallbacks: the switch
   is the one control whose state is color-only, so it must survive a failed
   token load. */
.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex: none;
}

/* Visually hidden but focusable (do NOT use display:none) */
.switch input {
  position: absolute;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.slider {
  position: absolute;
  inset: 0;
  background: var(--mus-color-border, #d1d5db);
  border-radius: 2rem;
  transition: background var(--mus-duration-medium) var(--mus-easing-standard);
  pointer-events: none;
}

.slider::before {
  content: "";
  position: absolute;
  height: 24px;
  width: 24px;
  left: 3px;
  top: 3px;
  background: var(--mus-color-white, #ffffff);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(53, 52, 51, 0.25);
  transition: transform var(--mus-duration-medium) var(--mus-easing-standard);
}

.switch input:checked + .slider { background: var(--mus-color-primary, #0c7d3e); }
.switch input:checked + .slider::before { transform: translateX(22px); }

/* Failing source toggled on → amber track so health trouble stays visible */
.source-card[data-state="failing"] .switch input:checked + .slider { background: var(--mus-color-warning, #eca51d); }

.switch input:focus-visible + .slider {
  outline: 2px solid var(--mus-color-primary);
  outline-offset: 3px;
}

/* In-flight: lock interaction without removing focus (no `disabled`) */
.source-card.htmx-request .switch { pointer-events: none; }
.source-card.htmx-request { opacity: 0.7; }

/* --- Connect / Save buttons (MUS Button, outlined) ------------------------- */
/* Focus shares the hover fill, as in the recipe. */
.source-cta,
.feed-url-save {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: var(--mus-spacing-1) var(--mus-spacing-2);
  border: 1px solid var(--mus-color-primary);
  border-radius: var(--mus-radius-sm);
  background-color: inherit;
  color: var(--mus-color-primary);
  font-family: var(--mus-font-family);
  font-size: var(--mus-font-size-md);
  font-weight: var(--mus-font-weight-bold);
  line-height: normal;
  white-space: nowrap;
  text-decoration: none;
  appearance: none;
  outline: 0;
  cursor: pointer;
  transition:
    color var(--mus-duration-short),
    background-color var(--mus-duration-short),
    border-color var(--mus-duration-short);
}

.source-cta:hover,
.source-cta:focus-visible,
.feed-url-save:hover,
.feed-url-save:focus-visible {
  color: var(--mus-color-primary-contrast);
  background-color: var(--mus-color-primary);
}

/* --- Availability-feed URL field ------------------------------------------- */
/* Lives under the card's status line until Mergado Keychain holds the feed. */
.feed-url-form {
  display: flex;
  gap: var(--mus-spacing-1);
  margin-top: var(--mus-spacing-1);
}

/* MUS Form control (input). A URL must read exactly as typed: opt out of the
   page's uppercase. */
.feed-url-input {
  flex: 1;
  min-width: 0;
  height: var(--mus-form-control-min-height);
  padding: var(--mus-spacing-1);
  border: 1px solid var(--mus-color-border);
  border-radius: var(--mus-radius-sm);
  background-color: var(--mus-color-white);
  color: var(--mus-color-dark);
  font-family: var(--mus-font-family);
  font-size: var(--mus-font-size-md);
  line-height: normal;
  text-transform: none;
  letter-spacing: normal;
  appearance: none;
  outline: none;
  transition: all var(--mus-duration-short);
}

.feed-url-input::placeholder { color: var(--mus-color-gray); }
.feed-url-input:not(:disabled):hover { border-color: var(--mus-color-border-darken); }

.feed-url-input:focus {
  border-color: var(--mus-color-primary);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--mus-color-primary) 12.5%, transparent);
}

.source-card.htmx-request .feed-url-form { pointer-events: none; }

/* --- Footer summary -------------------------------------------------------- */
.page-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--mus-spacing-1);
  margin-top: var(--mus-spacing-4);
  font-size: var(--mus-font-size-sm);
  color: var(--mus-color-gray);
}

.page-footer[hidden] { display: none; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--mus-color-border);
  transition: background var(--mus-duration-medium) var(--mus-easing-standard),
    box-shadow var(--mus-duration-medium) var(--mus-easing-standard);
}

.page-footer.has-active .dot {
  background: var(--mus-color-success);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--mus-color-success) 18%, transparent);
}

/* --- Toast (MUS light variant: dark text on the color's light gradient) ---- */
.toast {
  display: flex;
  align-items: center;
  gap: var(--mus-spacing-2);
  padding: var(--mus-spacing-2);
  border-radius: var(--mus-radius-md);
  color: var(--mus-color-dark);
  font-size: var(--mus-font-size-sm);
  line-height: var(--mus-line-height-normal);
  text-align: left;
  animation: toast-in var(--mus-duration-medium) var(--mus-easing-decelerate);
}

/* Smooth enter (on insert) and close (.toast--closing added by JS on dismiss).
   Disabled under prefers-reduced-motion by the global rule below; the dismiss
   JS then removes the node immediately instead of waiting for animationend. */
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to   { opacity: 0; transform: translateY(-6px); }
}

.toast--closing { animation: toast-out var(--mus-duration-short) var(--mus-easing-standard) forwards; }

.toast__icon { flex-shrink: 0; display: inline-flex; line-height: 0; }
.toast__icon svg { width: 22px; height: 22px; }

.toast__content { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.toast__title { font-weight: var(--mus-font-weight-bold); }

.toast__close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: var(--mus-spacing-1);
  border-radius: var(--mus-radius-sm);
  color: inherit;
  transition: background var(--mus-duration-short) var(--mus-easing-standard);
}

.toast__close svg { width: 14px; height: 14px; }
.toast__close:hover { background: color-mix(in srgb, var(--mus-color-dark) 8%, transparent); }

.toast__close:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 1px;
}

.toast--error { background-image: var(--mus-color-error-light-gradient); }
.toast--error .toast__icon { color: var(--mus-color-error); }

.toast--warning { background-image: var(--mus-color-warning-light-gradient); }
.toast--warning .toast__icon { color: var(--mus-color-warning); }

/* The error banner just holds a toast (409); take no space when empty. */
#error-banner:not(:empty) { margin-bottom: var(--mus-spacing-2); }

/* --- Loading skeleton ------------------------------------------------------ */
/* Card height: logo + padding + the two 1px borders. */
.skeleton {
  height: calc(var(--logo-size) + 2 * var(--mus-spacing-2) + 2px);
  border-radius: var(--mus-radius-md);
  border: 1px solid var(--mus-color-border);
  background: linear-gradient(100deg,
    var(--mus-color-white) 30%,
    var(--mus-color-light) 50%,
    var(--mus-color-white) 70%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* --- Responsive ------------------------------------------------------------ */
@media (max-width: 480px) {
  .app-logo img { height: 34px; }
  .source-cta { padding: var(--mus-spacing-1); }
}

/* --- Reduced motion -------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
