/* FeedSync base layer - reset, element defaults, and the shared component
   vocabulary (the app shell + sidebar, buttons, forms, cards, tables, pills,
   flashes, the impersonation banner). Makes the merchant /app and agency /admin
   look like one product on the light canvas. Consumes tokens.css only - every
   colour/space/radius/shadow is a var(--...), nothing hard-coded.

   S.C.R.A.P.S. physicality lives here: buttons rest with a lip and LIFT on hover;
   inputs SINK (inset) and rise on focus; cards/sidebar carry real depth. Motion is
   tactile and purposeful, disabled under prefers-reduced-motion.

   Load order on every surface: tokens.css -> base.css -> <surface>.css */

/* reset */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, p, figure, ul, ol { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }
/* The `hidden` attribute must win over component `display` rules (e.g. .notice /
   .alert set display:flex, which would otherwise override the UA [hidden] rule
   and leave "hidden" state blocks visible). */
[hidden] { display: none !important; }
a { color: var(--color-link); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--shadow-focus); border-radius: var(--radius-sm); }

/* typography */
h1 { font-family: var(--font-display); font-size: var(--text-2xl); line-height: var(--leading-tight); color: var(--color-ink); font-weight: var(--weight-bold); letter-spacing: -0.02em; }
h2 { font-family: var(--font-display); font-size: var(--text-xl); line-height: var(--leading-snug); color: var(--color-ink); font-weight: var(--weight-semibold); letter-spacing: -0.012em; }
h3 { font-size: var(--text-md); color: var(--color-ink); font-weight: var(--weight-semibold); }

.muted, .sub { color: var(--color-muted); }
.sub { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.stack > * + * { margin-top: var(--space-4); }

code, .code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--color-surface-2);
  color: var(--color-ink);
  padding: 0.12em 0.4em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  word-break: break-word;
}

/* layout */
.container { width: 100%; max-width: var(--container); margin: 0 auto; padding: var(--space-6) var(--space-5); }
.container--wide { max-width: var(--container-wide); }

/* app shell (shared by /app + /admin): white left rail + content
   The sidebar is a clean white rail with a hairline + soft shadow; the content
   canvas sits on the faint off-white, so cards read as floating (Sentry-style
   light elevation). */
.shell { display: flex; align-items: flex-start; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  flex: none;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  height: 100vh;
  overflow-y: auto;
  background: var(--color-sidebar);
  border-right: 1px solid var(--color-border);
  box-shadow: var(--shadow-xs);
  padding: var(--space-5) var(--space-3) var(--space-4);
}
/* a faint blue glow bleeds down from the top of the rail */
.sidebar::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 140px;
  background: var(--brand-glow); opacity: 0.5; pointer-events: none;
}

.sidebar__head { position: relative; padding: 0 var(--space-2) var(--space-4); }
.sidebar__brand { display: inline-flex; align-items: center; }
.sidebar__brand:hover { text-decoration: none; }
/* the logo asset is a white plate: shown as a rounded tile so its corners never
   read as a raw rectangle on the rail or in dark mode */
.sidebar__brand img, .brand-logo {
  height: 36px; width: auto; padding: 3px 6px; box-sizing: content-box;
  border-radius: 10px; border: 1px solid var(--color-border); background: #fff; box-shadow: var(--shadow-xs);
}
.sidebar__brand img { margin-left: -2px; }
.sidebar__context {
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-muted);
  line-height: var(--leading-snug);
  word-break: break-word;
}
.sidebar__context strong { color: var(--color-ink); font-weight: var(--weight-semibold); }

.sidebar__label {
  padding: 0 var(--space-2) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-faint);
}
.sidebar__nav { position: relative; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0.5rem var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--color-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}
.nav-item svg { width: 18px; height: 18px; flex: none; }
.nav-item:hover { background: var(--color-sidebar-hover); color: var(--color-ink); text-decoration: none; }
.nav-item.is-active { background: var(--color-primary-soft); color: var(--color-primary); font-weight: var(--weight-semibold); }
.nav-item.is-active::before {
  content: ""; position: absolute; left: -1px; top: 7px; bottom: 7px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--color-primary);
}

.sidebar__foot {
  margin-top: auto;
  padding: var(--space-4) var(--space-2) 0;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  font-size: var(--text-sm);
}
.sidebar__user { color: var(--color-muted); font-size: var(--text-xs); word-break: break-word; }

.shell__main { flex: 1; min-width: 0; }

/* responsive: the rail folds up into a horizontal top bar (no JS needed) */
@media (max-width: 64rem) {
  .shell { display: block; }
  .sidebar {
    position: static; width: auto; height: auto; flex-direction: row; align-items: center;
    gap: var(--space-3); overflow-x: auto; overflow-y: visible;
    border-right: none; border-bottom: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-4);
  }
  .sidebar::before { display: none; }
  .sidebar__head { padding: 0; }
  .sidebar__context { display: none; }
  .sidebar__label { display: none; }
  .sidebar__nav { flex-direction: row; gap: var(--space-1); flex: 1; }
  .nav-item { white-space: nowrap; }
  .nav-item.is-active::before { left: 8px; right: 8px; top: auto; bottom: -1px; width: auto; height: 3px; border-radius: 3px 3px 0 0; }
  .sidebar__foot { margin-top: 0; margin-left: auto; padding: 0; border-top: none; flex-direction: row; align-items: center; }
  .sidebar__user { display: none; }
}

/* brand mark (auth card / marketing) */
.brand { display: inline-flex; align-items: center; gap: var(--space-3); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand-logo { height: 30px; }

/* language switcher (HU/EN) - ISO country flags, shared */
.lang-switch { display: inline-flex; align-items: center; gap: var(--space-2); }
.lang-switch__opt { display: inline-flex; padding-bottom: 3px; line-height: 0; opacity: 0.45; border-bottom: 2px solid transparent; transition: opacity 0.15s var(--ease), border-color 0.15s var(--ease); }
.lang-switch__opt:hover { opacity: 1; text-decoration: none; }
.lang-switch__opt.is-active { opacity: 1; border-bottom-color: var(--color-primary); }
.lang-flag { display: block; width: 22px; height: 15px; object-fit: cover; border-radius: 2px; }

/* sidebar tools row: language flags + the light/dark toggle, side by side */
.sidebar__tools { display: flex; align-items: center; gap: var(--space-3); }

/* light/dark switch - shows the moon in light mode, the sun in dark mode */
.theme-toggle {
  display: inline-grid; place-items: center; width: 30px; height: 30px; flex: none;
  padding: 0; border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-strong); background: var(--color-surface);
  color: var(--color-muted); cursor: pointer; box-shadow: var(--shadow-xs);
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.theme-toggle:hover { color: var(--color-primary); border-color: var(--color-primary); background: var(--color-primary-soft); }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* failure reason under a status pill (feed sources, shared app + admin) */
.status-detail { margin-top: var(--space-1); font-size: var(--text-xs); color: var(--color-danger); max-width: 40ch; line-height: var(--leading-snug); }

/* key/value grid (shop info on /app/settings + /admin) - shared so both
   surfaces render the two-column layout, not a raw browser <dl> */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); align-items: baseline; }
.kv dt { color: var(--color-muted); font-size: var(--text-sm); }
.kv dd { margin: 0; color: var(--color-ink); }

/* error pages (404 / 500) - self-contained, centered, any surface */
.errorpage { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--space-6) var(--space-5); }
.errorpage__card { width: 100%; max-width: 30rem; text-align: center; }
.errorpage__brand { justify-content: center; margin-bottom: var(--space-5); }
.errorpage__code { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: var(--weight-bold); line-height: 1; color: var(--color-primary); letter-spacing: -0.02em; }
.errorpage h1 { margin-top: var(--space-3); }
.errorpage p { color: var(--color-muted); margin-top: var(--space-3); }
.errorpage__actions { margin-top: var(--space-5); }
.errorpage__ref { margin-top: var(--space-5); font-size: var(--text-xs); color: var(--color-faint); }

/* buttons (tactile: rest with a lip, LIFT on hover) */
.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  font-family: inherit; font-size: var(--text-sm); font-weight: var(--weight-semibold); line-height: 1.1;
  padding: 0.6rem 1.05rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), background-color 0.15s var(--ease), border-color 0.15s var(--ease), color 0.15s var(--ease);
}
.btn:hover, button:hover { text-decoration: none; }

.btn--primary, button:not([class]), button[type="submit"]:not([class]) {
  background: var(--color-primary-fill); color: var(--color-on-brand); border-color: transparent;
  box-shadow: var(--shadow-btn);
}
.btn--primary:hover, button:not([class]):hover, button[type="submit"]:not([class]):hover {
  background: var(--color-primary-fill-strong); transform: translateY(-1px); box-shadow: var(--shadow-btn-hover);
}
.btn--primary:active, button:not([class]):active { transform: translateY(0); box-shadow: var(--shadow-btn); }

.btn--ghost { background: var(--color-surface); color: var(--color-primary); border-color: var(--color-border-strong); box-shadow: var(--shadow-xs); }
.btn--ghost:hover { border-color: var(--color-primary); background: var(--color-primary-soft); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn--ghost:active { transform: translateY(0); box-shadow: var(--shadow-xs); }

.btn--danger { background: var(--color-danger-fill); color: var(--color-on-brand); border-color: transparent; box-shadow: var(--shadow-btn); }
.btn--danger:hover { background: var(--color-danger-fill-strong); transform: translateY(-1px); box-shadow: var(--shadow-btn-hover); }
.btn--danger:active { transform: translateY(0); box-shadow: var(--shadow-btn); }

/* An unsized icon still claims the flex gap, which reads as lopsided padding. */
.btn svg { width: 16px; height: 16px; flex: none; }
.btn--sm { padding: 0.35rem 0.7rem; font-size: var(--text-xs); }
.btn:disabled, button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* forms (tactile: inputs SINK, rise to white on focus) */
label { display: block; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--color-ink); }

input[type="text"], input[type="url"], input[type="email"], input[type="password"],
input[type="search"], input[type="number"], select, textarea {
  width: 100%; max-width: 28rem; font: inherit; font-size: var(--text-sm);
  color: var(--color-ink);
  background: var(--color-sunken);
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-inset);
  transition: background-color 0.15s var(--ease), border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  /* background-color longhand (not the `background` shorthand): the shorthand
     resets background-image, which would strip the select chevron on focus. */
  background-color: var(--color-surface);
  border-color: var(--color-primary);
  box-shadow: var(--shadow-focus);
}
input[type="file"] { font: inherit; font-size: var(--text-sm); color: var(--color-muted); }
::placeholder { color: var(--color-faint); }

/* one styled dropdown chevron for every <select> (replaces the native OS arrow).
   -moz-appearance is required too, else Firefox draws its own arrow alongside. */
select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 2rem;
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 1rem;
}

/* block rhythm: shared blocks (base.css components) that get server-concatenated
   as siblings should never touch. .card + .card / .field + .field own their own
   seams and are deliberately excluded, so nothing double-stacks. */
.card + .table-wrap, .table-wrap + .card, .table-wrap + .table-wrap { margin-top: var(--space-4); }

.field + .field { margin-top: var(--space-4); }
.field > label { margin-bottom: var(--space-2); }
.form-row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: flex-end; }
form.inline { display: inline; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* cards (real depth; interactive cards lift) */
.card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: var(--space-5); }
.card + .card { margin-top: var(--space-4); }
.card__title { font-size: var(--text-xs); font-weight: var(--weight-semibold); letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-muted); margin-bottom: var(--space-3); }

/* section headings */
.section-title { font-size: var(--text-lg); color: var(--color-ink); font-weight: var(--weight-semibold); margin: var(--space-6) 0 var(--space-3); padding-bottom: var(--space-2); border-bottom: 1px solid var(--color-border); }

/* progressive disclosure (native <details>) */
details.disclose { border: 1px solid var(--color-border); border-radius: var(--radius); background: var(--color-surface); box-shadow: var(--shadow-xs); }
details.disclose > summary {
  list-style: none; cursor: pointer; padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--color-ink);
  display: flex; align-items: center; gap: var(--space-2);
}
details.disclose > summary::-webkit-details-marker { display: none; }
details.disclose > summary::before {
  content: ""; width: 0.5rem; height: 0.5rem; border-right: 2px solid var(--color-muted); border-bottom: 2px solid var(--color-muted);
  transform: rotate(-45deg); transition: transform 0.15s var(--ease); margin-right: var(--space-1);
}
details.disclose[open] > summary::before { transform: rotate(45deg); }
details.disclose > summary:hover { color: var(--color-primary); }
details.disclose > .disclose__body { padding: 0 var(--space-4) var(--space-4); }

/* tables */
.table-wrap { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
thead th { background: var(--color-surface-2); color: var(--color-muted); font-size: var(--text-xs); font-weight: var(--weight-semibold); letter-spacing: 0.04em; text-transform: uppercase; text-align: left; }
th, td { padding: 0.6rem 0.8rem; border-bottom: 1px solid var(--color-border); text-align: left; vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color 0.12s var(--ease); }
tbody tr:hover td { background: var(--color-primary-softer); }

/* pills / status badges */
.pill { display: inline-block; padding: 0.15rem 0.55rem; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); line-height: 1.5; background: var(--color-surface-2); color: var(--color-muted); border: 1px solid var(--color-border); white-space: nowrap; }
.pill-completed, .pill-active, .pill-approved, .pill-ok { background: var(--color-success-bg); color: var(--color-success); border-color: var(--color-success-border); }
.pill-failed, .pill-rejected, .pill-unpaid, .pill-suspended, .pill-uninstalled, .pill-terminated, .pill-error, .pill-past_due { background: var(--color-danger-bg); color: var(--color-danger-text); border-color: var(--color-danger-border); }
.pill-uploaded, .pill-parsing, .pill-writing, .pill-mapping, .pill-running, .pill-trialing, .pill-pending_review { background: var(--color-info-bg); color: var(--color-info); border-color: var(--color-info-border); }
/* an actively-working run pulses gently so it reads as live, not stuck */
@media (prefers-reduced-motion: no-preference) {
  .pill.is-working { animation: pill-pulse 1.6s var(--ease) infinite; }
  @keyframes pill-pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--color-info-border); }
    50% { box-shadow: 0 0 0 4px var(--color-info-border); }
  }
}

/* flashes / alerts */
.flash, .alert { display: flex; gap: var(--space-3); padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); border: 1px solid var(--color-warning-border); border-left: 4px solid var(--color-warning); background: var(--color-warning-bg); color: var(--color-ink); font-size: var(--text-sm); box-shadow: var(--shadow-xs); }
.alert--info, .flash--info { border-color: var(--color-info-border); border-left-color: var(--color-info); background: var(--color-info-bg); }
.alert--success, .flash--success { border-color: var(--color-success-border); border-left-color: var(--color-success); background: var(--color-success-bg); }
.alert--danger, .flash--danger { border-color: var(--color-danger-border); border-left-color: var(--color-danger); background: var(--color-danger-bg); }

/* impersonation banner (safety-critical - unmistakable, spans the shell) */
.banner {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  padding: 0.65rem clamp(var(--space-4), 4vw, var(--space-6));
  background: var(--color-banner-bg); color: var(--color-on-brand);
  font-size: var(--text-sm);
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: var(--shadow-sm);
}
.banner a { color: var(--color-on-brand); }
.banner__icon { display: inline-grid; place-items: center; width: 1.9rem; height: 1.9rem; flex: none; border-radius: var(--radius-sm); background: rgba(255, 255, 255, 0.14); }
.banner__icon svg { width: 18px; height: 18px; }
.banner__title { display: inline-flex; flex-direction: column; line-height: 1.25; }
.banner__eyebrow { font-family: var(--font-mono); font-size: 0.62rem; letter-spacing: 0.16em; text-transform: uppercase; color: rgba(255, 255, 255, 0.7); }
.banner__shop { font-weight: var(--weight-semibold); }
.banner__mode { display: inline-flex; align-items: center; padding: 0.12rem 0.6rem; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-bold); letter-spacing: 0.05em; text-transform: uppercase; background: rgba(255, 255, 255, 0.18); color: var(--color-on-brand); }
.banner__reason { color: rgba(255, 255, 255, 0.72); font-size: var(--text-sm); }
.banner__spacer { margin-left: auto; }
.banner__elevate { display: inline-flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.banner__elevate input { width: auto; max-width: 7rem; padding: 0.3rem 0.5rem; box-shadow: none; background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.4); color: var(--color-on-brand); }
.banner__elevate input::placeholder { color: rgba(255, 255, 255, 0.7); }
.banner__err { font-size: var(--text-xs); font-weight: var(--weight-medium); }
.banner button, .banner .btn { background: rgba(255, 255, 255, 0.16); border-color: rgba(255, 255, 255, 0.45); color: var(--color-on-brand); box-shadow: none; font-weight: var(--weight-semibold); }
.banner button:hover, .banner .btn:hover { background: rgba(255, 255, 255, 0.28); transform: translateY(-1px); text-decoration: none; }
/* Stop is the distinct "exit" action - a solid light button, set apart from the
   translucent navigation links. */
.banner .banner__stop { background: #fff; color: var(--color-banner-bg); border-color: transparent; }
.banner .banner__stop:hover { background: rgba(255, 255, 255, 0.88); }

/* WRITE mode: the dangerous state - escalate to a pulsing danger-red bar with a
   high-contrast mode pill, so it reads as more alarming than READ-ONLY. */
.banner--write { background: var(--color-danger-fill); border-bottom-color: var(--color-danger-fill-strong); animation: banner-pulse 1.8s var(--ease) infinite; }
.banner--write .banner__icon { background: rgba(255, 255, 255, 0.24); }
/* safety-critical WRITE pill: pin a constant dark red (the token flips too light
   in dark mode); white bg is intentional - the banner bar is always dark. */
.banner--write .banner__mode { background: #fff; color: #b51f1f; }
@keyframes banner-pulse { 0%, 100% { box-shadow: var(--shadow-sm); } 50% { box-shadow: 0 0 0 3px rgba(217, 45, 45, 0.5), var(--shadow-md); } }

@media (prefers-reduced-motion: reduce) {
  .banner--write { animation: none; }
  *, *::before, *::after { transition: none !important; }
  .btn:hover, button:hover, .btn--ghost:hover, .banner button:hover { transform: none; }
}
