/**
 * Components - Magneto SPA
 * Shell components (header, account menu, footer), shared primitives (buttons,
 * cards, badges, tables, dialogs, code), and the view helpers the markup
 * relies on. Dark theme built on the tokens in tokens.css.
 */

/* ─── Base ─── */
body {
  margin: 0;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

code,
pre,
.code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.1em 0.4em;
  color: var(--color-text-secondary);
  overflow-wrap: anywhere;
}

pre.code {
  display: block;
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
  line-height: var(--leading-relaxed);
}

hr {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: var(--space-4) 0;
}

/* ─── Typography helpers ─── */

.text-center { text-align: center; }

.text-xs { font-size: var(--text-xs); }

/* ─── Header ─── */
.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: var(--color-bg-primary);
  border-bottom: 1px solid var(--color-border);
}

.product-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-primary);
  text-decoration: none;
}

.product-logo {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md);
}

.product-name {
  font-weight: var(--font-semi);
  letter-spacing: var(--tracking-wide);
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-5);
  font: inherit;
  font-weight: var(--font-medium);
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--color-brand);
  color: var(--color-text-inverse);
}

.btn--primary:hover {
  background: var(--color-brand-hover);
}

.btn--ghost {
  background: transparent;
  border-color: var(--color-border-strong);
  color: var(--color-text-primary);
}

.btn--ghost:hover {
  background: var(--color-bg-hover);
}

.btn--danger {
  background: var(--color-error-soft);
  color: var(--color-error);
  border-color: transparent;
}

.btn--danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.btn--sm { padding: var(--space-1) var(--space-3); font-size: var(--text-sm); min-height: unset; line-height: var(--leading-normal); }

/* ─── Cards ─── */
.card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

/* ─── Badges / chips ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.15em 0.6em;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  line-height: 1.4;
}

.badge--success { background: var(--color-success-soft); color: var(--color-brand-hover); }
.badge--warning { background: var(--color-warning-soft); color: var(--color-warning); }

.badge--neutral { background: var(--color-bg-hover); color: var(--color-text-muted); }

/* ─── Tables ─── */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th,
.table td {
  text-align: center;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

.table th:first-child,
.table td:first-child {
  text-align: left;
}

.table th {
  color: var(--color-text-muted);
  font-weight: var(--font-medium);
  text-transform: uppercase;
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-overline);
}

.table tr:last-child td { border-bottom: 0; }

.table-group-row td {
  padding-block: var(--space-2);
  background: var(--color-bg-hover);
}

.table-group-row .provider-cell { align-items: center; gap: var(--space-2); }
.table-group-row .provider-icon { width: 24px; height: 24px; }
.table-group-row .provider-icon svg { width: 14px; height: 14px; }
.table-group-row .provider-icon__img { width: 24px; height: 24px; padding: 2px; }
.table-group-row strong { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: var(--tracking-overline); color: var(--color-text-muted); }

.table--wrap { overflow-x: auto; border-radius: var(--radius-lg); }

/* ─── Skeleton / empty states ─── */

@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--color-text-muted);
}

/* ─── Footer ─── */
.app-footer {
  background: var(--color-bg-primary);
  border-top: 1px solid var(--color-border);
  margin-top: var(--space-16);
}

.app-footer__inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding-block: var(--space-6);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
}

.app-footer__signature {
  display: inline-flex;
  align-items: center;
}

.taidy-signature {
  height: 22px;
  width: auto;
  opacity: 0.8;
}

/* ─── Secondary text ─── */
.muted {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

/* ─── Redesign shell ─── */
body { min-width: 320px; }
button, a, input, select { min-height: 44px; }
.app-header { backdrop-filter: blur(14px); background: color-mix(in srgb, var(--color-bg-primary) 92%, transparent); }

.account-menu button { display: block; width: 100%; padding: var(--space-3); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text-primary); text-align: left; text-decoration: none; cursor: pointer; }
.account-menu button:hover { background: var(--color-bg-hover); }
.header-actions { display: flex; align-items: center; gap: var(--space-3); }
.mobile-nav-toggle { display: none; }
.banner { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-5); border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-bg-card); }

.dialog-backdrop { position: fixed; inset: 0; display: grid; place-items: center; padding: var(--space-4); background: rgba(0,0,0,.7); z-index: var(--z-modal-backdrop); }
/* Border-box sizing so the declared width already covers the padding and border: with content-box a
   narrow viewport puts the card 50px wider than the backdrop can hold, hanging both edges and the
   fields inside them off screen. */
.dialog { box-sizing: border-box; width: min(100%, 960px); padding: var(--space-6); border: 1px solid var(--color-border-strong); border-radius: var(--radius-xl); background: var(--color-bg-card); box-shadow: var(--shadow-xl); }
/* A dialog holding a table, not a short form: at the base width the member list's email column is cut
   off behind a horizontal scrollbar, so the roster cannot be read without scrolling sideways. */

.dialog__actions { display: flex; justify-content: flex-end; gap: var(--space-3); margin-top: var(--space-6); }
.field { display: flex; flex-direction: column; gap: var(--space-2); }
/* Stacked fields need air between them, or each label reads as a caption of the control above it.
   Scoped to the dialog because the page-level forms that stack fields sit in a flex column that
   already carries a gap. */
.dialog .field + .field { margin-top: var(--space-4); }
/* Same border-box reasoning as `.dialog`: `width: 100%` has to mean the container's width, padding
   and border included, so the control lands inside the container's own padding. */
.field input, .field select, .field textarea { box-sizing: border-box; width: 100%; padding: var(--space-3); border: 1px solid var(--color-border-strong); border-radius: var(--radius-md); background: var(--color-bg-tertiary); color: var(--color-text-primary); font: inherit; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline: 2px solid var(--color-focus); outline-offset: 2px; }
.field__hint { font-size: var(--text-xs); margin: 0; }
.table--responsive { overflow-x: auto; }
.table--responsive table { min-width: 680px; }

/* Grouped sidebar layout */
.app-layout {
  display: flex;
  flex: 1 0 auto;
  width: 100%;
}

.app-sidebar {
  box-sizing: border-box;
  width: var(--sidebar-width);
  flex-shrink: 0;
  border-right: 1px solid var(--color-border);
  padding: 20px 16px;
  background: var(--color-bg-primary);
  transition: width var(--transition-normal);
}

/* Muted until hovered, so the control reads as part of the sidebar chrome rather than as a button
   competing with the links under it. */
.sidebar-collapse { display: flex; align-items: center; justify-content: center; width: 28px; height: 28px; min-height: 28px; margin: 0 0 var(--space-2) auto; padding: 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--color-text-muted); opacity: .55; cursor: pointer; }
.sidebar-collapse:hover { opacity: 1; background: var(--color-bg-hover); }

/* Collapsed rail: the icons stay, everything needing the full width goes. Scoped above the breakpoint
   where a sidebar exists at all, since below it the nav is a dropdown that wants its labels whatever
   the rail was set to on a wider screen. */
@media (min-width: 761px) {
  .app-sidebar.is-collapsed { width: var(--sidebar-width-collapsed); }
  .app-sidebar.is-collapsed .sidebar-collapse svg { transform: rotate(180deg); }
  .app-sidebar.is-collapsed .nav-group__label,
  .app-sidebar.is-collapsed .nav-link span { display: none; }
  .app-sidebar.is-collapsed .nav-link { justify-content: center; padding-inline: 0; }

  /* Collapsing hands the rail's width to the content rather than to the empty margin beside it: without
     this the page frame stays pinned at its cap and the reclaimed space is simply never used. */
  .app-sidebar.is-collapsed ~ .app-main .page-frame {
    max-width: calc(var(--page-max-width) + var(--sidebar-width) - var(--sidebar-width-collapsed));
  }
}

.app-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  width: 100%;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.nav-group__label {
  font-size: var(--text-xs);
  font-weight: var(--font-semi);
  text-transform: uppercase;
  letter-spacing: var(--tracking-overline);
  color: var(--color-text-muted);
  margin: 20px 0 6px;
  padding-inline: 10px;
}

.nav-group:first-child .nav-group__label {
  margin-top: 0;
}

.nav-group__items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-group__items svg, .app-nav svg, .sidebar-collapse svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 38px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: var(--text-sm);
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.nav-link:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-hover);
}

.nav-link.active,
.nav-link[aria-current="page"] {
  color: var(--color-text-inverse);
  background: var(--color-brand);
  font-weight: var(--font-medium);
}

.nav-link.active svg,
.nav-link[aria-current="page"] svg {
  stroke: var(--color-text-inverse);
}

.app-main {
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.page-frame {
  width: 100%;
  max-width: var(--page-max-width);
  padding: var(--space-6) var(--space-8) var(--space-12);
  box-sizing: border-box;
}

.app-layout:not(.has-sidebar) .page-frame {
  max-width: 580px;
  margin-inline: auto;
}

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: var(--header-height);
  padding-inline: var(--space-6);
  gap: var(--space-5);
  width: 100%;
  box-sizing: border-box;
}
.account-area { position: relative; }
.account-menu { position: relative; }
.account-trigger { display: inline-flex; align-items: center; gap: var(--space-2); min-height: 36px; padding: 6px 10px; border: 1px solid var(--color-border); border-radius: var(--radius-pill); background: var(--color-bg-card); color: var(--color-text-primary); font-size: var(--text-sm); cursor: pointer; }
.account-trigger svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.account-dropdown { position: absolute; right: 0; top: calc(100% + 8px); min-width: 240px; padding: var(--space-2); border: 1px solid var(--color-border-strong); border-radius: var(--radius-lg); background: var(--color-bg-card); box-shadow: var(--shadow-pop); z-index: var(--z-dropdown); }
.account-dropdown button { display: block; width: 100%; padding: var(--space-3); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text-primary); text-align: left; cursor: pointer; }
.account-dropdown button:hover { background: var(--color-bg-hover); }
.account-summary { display: flex; flex-direction: column; gap: var(--space-1); padding: var(--space-3); border-bottom: 1px solid var(--color-border); }
.account-summary small, .account-summary span { color: var(--color-text-muted); font-size: var(--text-xs); }
.account-section { display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--color-border); }
.account-section__label { display: flex; align-items: center; justify-content: space-between; font-size: var(--text-xs); color: var(--color-text-muted); }
.segmented-control { display: flex; background: var(--color-bg-tertiary); border: 1px solid var(--color-border); border-radius: var(--radius-pill); padding: 2px; gap: 2px; }
.account-dropdown .segmented-control button, .segmented-control__btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1); padding: 4px 8px; min-height: 28px; border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--color-text-muted); font-size: var(--text-xs); font-weight: var(--font-medium); text-align: center; cursor: pointer; transition: all 0.15s ease; }
.account-dropdown .segmented-control button:hover, .segmented-control__btn:hover { color: var(--color-text-primary); background: var(--color-bg-hover); }
.account-dropdown .segmented-control button.is-active, .segmented-control__btn.is-active { background: var(--color-bg-card); color: var(--color-text-primary); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); font-weight: var(--font-semi); }
.account-footer { padding: var(--space-2) var(--space-3); border-top: 1px solid var(--color-border); text-align: center; }
.app-version { color: var(--color-text-muted); font-size: var(--text-xs); font-family: var(--font-mono); opacity: 0.75; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: var(--space-2) var(--space-4); border: 1px solid transparent; border-radius: var(--radius-pill); font: inherit; font-weight: var(--font-medium); text-decoration: none; cursor: pointer; }
.btn--primary { background: var(--color-brand); color: var(--color-text-inverse); }
.btn--primary:hover { background: var(--color-brand-hover); }
.btn--secondary { border-color: var(--color-border-strong); background: transparent; color: var(--color-text-primary); }
.btn--secondary:hover { background: var(--color-bg-hover); }
.status { display: inline-flex; align-items: center; gap: var(--space-1); padding: .2em .65em; border-radius: var(--radius-pill); font-size: var(--text-xs); }

#app { display: flex; flex-direction: column; min-height: 100vh; }

:where(a, button, input, select, summary):focus-visible { outline: 2px solid var(--color-focus); outline-offset: 3px; }

@media (max-width: 760px) {
  .app-bar {
    min-height: var(--header-height-mobile);
    padding-inline: var(--container-padding-mobile);
    gap: var(--space-2);
  }
  
  .mobile-nav-toggle { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; padding: 0; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-bg-card); color: var(--color-text-primary); cursor: pointer; }
  .mobile-nav-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
  .app-layout { flex-direction: column; width: 100%; }
  .app-sidebar { display: contents; }
  .sidebar-collapse { display: none; }
  .app-nav { display: none; }
  .app-nav.is-open {
    position: absolute;
    left: var(--container-padding-mobile);
    right: var(--container-padding-mobile);
    top: calc(var(--header-height-mobile) + 8px);
    display: flex;
    flex-direction: column;
    padding: var(--space-4);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    background: var(--color-bg-card);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    width: auto;
    max-height: calc(100vh - var(--header-height-mobile) - 24px);
    overflow-y: auto;
  }
  .page-frame {
    padding: var(--space-3) var(--container-padding-mobile) var(--space-8);
  }
  
  .account-name { display: none; }
}

/* ─── Help hint ───────────────────────────────────────────────────────────
   A "?" any view can attach to a label (see view-state.js `helpHint`). `position: relative` on the
   wrapper is what lets the bubble anchor to this one trigger instead of the table cell or header row
   it sits inside. */
.help-hint { position: relative; display: inline-flex; vertical-align: middle; }

.help-hint__trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 1.125rem;
  height: 1.125rem;
  /* The shell gives every control a 44px touch target, which would stretch this into a capsule.
     A hint is read, never tapped, so it opts out and stays the circle the glyph needs. */
  min-height: 0;
  padding: 0;
  border: 1px solid var(--color-border-strong);
  border-radius: 50%;
  background: var(--color-bg-hover);
  color: var(--color-text-muted);
  font-size: var(--text-xs);
  line-height: 1;
  cursor: help;
}

.help-hint__trigger:focus-visible {
  background: var(--color-brand-soft);
  color: var(--color-brand-hover);
  border-color: var(--color-brand-border);
}

.help-hint:hover .help-hint__trigger {
  color: var(--color-text-primary);
  border-color: var(--color-brand-border);
}

/* `display: none` rather than a hidden-but-laid-out box: these hints sit inside a horizontally
   scrolling table, and an absolutely positioned box counts toward its ancestor's scroll width even
   when invisible, which is enough to put a scrollbar under a table that otherwise fits exactly.
   Opening below the trigger for the same family of reason: a scroll container clips its own
   overflow, so a bubble rising above a header row at the top of that container is cut off by it. */
.help-hint__bubble {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: var(--z-tooltip);
  width: max-content;
  max-width: 16rem;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-bg-card);
  color: var(--color-text-secondary);
  font-size: var(--text-xs);
  font-weight: var(--font-normal);
  line-height: var(--leading-relaxed);
  box-shadow: var(--shadow-pop);
  text-align: left;
  white-space: normal;
}

.help-hint__bubble--end { left: auto; right: 0; }

.help-hint:hover .help-hint__bubble,
.help-hint__trigger:focus-visible + .help-hint__bubble {
  display: block;
}

