/* ==========================================================================
   Depots — review-source sync UI
   Styling built on the Mergado brand palette.
   Self-hosted Roboto (no third-party font CDN), pure CSS, 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: 500; font-display: swap;
  src: url('/static/fonts/roboto-500-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: 500; font-display: swap;
  src: url('/static/fonts/roboto-500-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;
}

/* --- Design tokens --------------------------------------------------------
   Spacing is authored in px on an 8px grid; root font-size stays at 16px. */
:root {
  /* Brand */
  --color-primary: #0c7d3e;
  --color-secondary: #353433;
  --color-success: #02c956;
  --color-warning: #eca51d;
  --color-error: #d03660;
  /* Neutrals */
  --color-dark: #353433;
  --color-gray: #9b9a9a;
  --color-light: #f2f2f5;
  --color-border: #d1d5db;
  --color-white: #ffffff;
  /* Text */
  --text-primary: #353433;
  --text-secondary: #9b9a9a;
  /* Surfaces */
  --bg: #ffffff;
  --card-bg: #ffffff;
  /* Soft / derived (color-mix with solid fallbacks where functional) */
  --primary-soft: #e1f0e6;
  --primary-soft: color-mix(in srgb, var(--color-primary) 10%, white);
  --warning-text: #946608;
  --warning-text: color-mix(in srgb, var(--color-warning), black 28%);
  --warning-soft: #fbf0d8;
  --warning-soft: color-mix(in srgb, var(--color-warning) 14%, white);
  --track-off: #d1d5db;
  /* Spacing (8px grid) */
  --space-0_5: 4px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 40px;
  --space-6: 48px;
  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  /* Shadow (MUS-tinted, modern soft) */
  --shadow: 0 10px 30px -14px rgba(53, 52, 51, 0.12);
  --shadow-hover: 0 16px 36px -16px rgba(53, 52, 51, 0.22);
  /* Motion */
  --t-fast: 150ms;
  --t: 200ms;
  --t-slow: 300ms;
  --font: 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--text-primary);
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4) var(--space-3);
  -webkit-font-smoothing: antialiased;
}

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

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

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

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

.subtitle {
  margin-top: var(--space-3);
  font-size: 16px;
  font-weight: 400;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 46ch;
}

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

.source-card {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--card-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  transition: box-shadow var(--t) ease, border-color var(--t) ease;
}

.source-card:hover { box-shadow: var(--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(--color-primary);
}

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

/* Logo tile: CSS monogram is the always-present baseline; the <img> layers
   on top and is hidden by JS (.logo-broken) if it fails to load. */
.source-logo {
  position: relative;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: transparent;
  overflow: hidden;
}

.monogram {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: var(--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: 4px;
  background: transparent;
}

.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; }

.source-info h2 {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-primary);
}

.source-status {
  margin-top: var(--space-0_5);
  font-size: 14px;
  color: var(--text-secondary);
  transition: color var(--t) ease;
}

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

/* 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(--space-0_5);
  padding: 2px;              /* enlarges the hover/focus target around the icon */
}

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

.failure-tooltip {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: max-content;
  max-width: 250px;
  padding: var(--space-1);
  background: var(--color-dark);
  color: var(--color-white);
  box-shadow: 0 2px 8px var(--color-dark);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.45;
  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(--color-dark);
  border-bottom: none;
}

.failure-tooltip-wrapper:hover .failure-tooltip,
.failure-tooltip-wrapper:focus-visible .failure-tooltip {
  visibility: visible;
  transition-delay: 200ms;              /* MUS delayDuration before showing */
}

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

/* --- Toggle switch (accessible: real focusable checkbox) ------------------- */
.switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}

/* 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(--track-off);
  border-radius: var(--radius-pill);
  transition: background 250ms cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.slider::before {
  content: "";
  position: absolute;
  height: 24px;
  width: 24px;
  left: 3px;
  top: 3px;
  background: var(--color-white);
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(53, 52, 51, 0.25);
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Functional on-state fill: solid first, then on-brand override */
.switch input:checked + .slider { background: #0c7d3e; background: var(--color-primary); }
.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(--color-warning); }

.switch input:focus-visible + .slider {
  outline: 2px solid var(--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" link for unavailable sources ------------------------------- */
/* Outlined button: green border + text, fills green on hover. */
.source-cta {
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--color-primary);
  background: transparent;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius-sm);
  padding: 6px 16px;
  white-space: nowrap;
  text-decoration: none;
  transition: color var(--t-fast) ease, background var(--t-fast) ease,
    border-color var(--t-fast) ease;
}

.source-cta:hover,
.source-cta:focus-visible {
  color: var(--color-white);
  background: var(--color-primary);
}

.source-cta:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

/* --- Footer summary -------------------------------------------------------- */
.page-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  margin-top: var(--space-4);
  font-size: 14px;
  color: var(--text-secondary);
}

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

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--track-off);
  transition: background var(--t) ease, box-shadow var(--t) ease;
}

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

/* --- Toast (light variant: dark text on the color's gradient) ------------- */
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--color-dark);
  font-size: 14px;
  line-height: 1.45;
  text-align: left;
  animation: toast-in 180ms ease-out;
}

/* 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 160ms ease-in 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: 700; }

.toast__close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: var(--space-1);
  border-radius: var(--radius-sm);
  color: inherit;
  transition: background var(--t-fast) ease;
}

.toast__close svg { width: 14px; height: 14px; }
.toast__close:hover { background: rgba(53, 52, 51, 0.08); }

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

/* Error toast (base #d03660) */
.toast--error { background-image: linear-gradient(180deg, #f7dbe2 0%, #fcf1f4 100%); }
.toast--error .toast__icon { color: var(--color-error); }

/* Warning toast (base #eca51d) */
.toast--warning { background-image: linear-gradient(180deg, #fcefd6 0%, #fef9ef 100%); }
.toast--warning .toast__icon { color: var(--color-warning); }

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

/* --- Loading skeleton ------------------------------------------------------ */
.skeleton {
  height: 98px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: linear-gradient(100deg,
    var(--card-bg) 30%,
    var(--color-light) 50%,
    var(--card-bg) 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-card { padding: 16px 18px; gap: 14px; }
  .source-cta { padding: 6px 12px; }
}

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