/*
 * Spark application shell — sidebar, drawer, topbar, account menu, theme toggle,
 * navigation, skip link and focus ring. Shared by the portal and the platform admin.
 *
 * Rules: class-scoped selectors only (no element resets), tokens from tokens.css,
 * rule order preserved from the original spark.css so the portal cascade is unchanged.
 * Breakpoints: >= 1300px wide, <= 1100px compact, <= 900px drawer, <= 560px phone.
 * The drawer breakpoint (900px) must match the media query in spark.js.
 */

.spark-sidebar,
.spark-sidebar *,
.spark-topbar,
.spark-topbar *,
.sidebar-scrim,
.skip-link {
  box-sizing: border-box;
}

/* Focus and utility */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

[hidden] {
  display: none !important; /* `hidden` must win over component display values. */
}

::selection {
  background: #FF751A;
  color: #14171A;
}

.skip-link {
  position: fixed;
  top: -100px;
  left: 16px;
  z-index: 100;
  background: var(--surface);
  padding: 12px;
}

.skip-link:focus {
  top: 10px;
}

/* Sidebar */
.spark-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 246px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 34px 18px 18px;
  display: flex;
  flex-direction: column;
  z-index: 40;
  overflow: auto;
}

.spark-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 22px;
  font-family: var(--font-display);
  font-weight: 700;
  text-decoration: none;
  margin: 0 10px 26px;
}

.brand-mark {
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #14171A;
  width: 33px;
  height: 33px;
  border-radius: 10px;
  box-shadow: 0 8px 22px -10px rgba(255, 117, 26, .55);
}

.brand-pos {
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
  margin-left: -5px;
  align-self: end;
  margin-bottom: 6px;
}

/* Official supplied Spark artwork on a transparent background: the black wordmark
   is swapped for the white variant in the dark theme. */
.spark-logo {
  display: block;
  width: 164px;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.spark-logo-dark,
[data-theme=dark] .spark-logo-light {
  display: none;
}

[data-theme=dark] .spark-logo-dark {
  display: block;
}

.sidebar-caption {
  font-size: 9px;
  letter-spacing: 1.4px;
  padding: 0 14px;
  margin: 0 0 14px;
}

.spark-navigation {
  display: block;
  margin-bottom: 28px;
}

.nav-link,
.nav-group > summary {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  margin: 4px 0;
  border-radius: 10px;
  color: var(--text);
  font-weight: 550;
  font-size: 12px;
  text-decoration: none;
  cursor: pointer;
  list-style: none;
}

.nav-group > summary::-webkit-details-marker {
  display: none;
}

.nav-link:hover,
.nav-group > summary:hover {
  background: var(--surface-alt);
  text-decoration: none;
}

.nav-link.active,
.nav-group > summary.active {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 8px 22px -12px rgba(255, 117, 26, .45);
}

.nav-icon {
  width: 17px;
  text-align: center;
  font-size: 17px;
  line-height: 1;
}

.chevron {
  margin-left: auto;
}

.nav-group[open] .chevron {
  transform: rotate(180deg);
}

.nav-children {
  border-left: 1px solid var(--line);
  margin: 5px 0 10px 21px;
  padding-left: 9px;
}

.nav-children .nav-link {
  font-size: 12px;
  font-weight: 450;
  padding: 9px 10px;
}

.nav-children .nav-link.active {
  background: var(--surface-alt);
  color: var(--text);
  font-weight: 700;
  box-shadow: none;
  border-left: 2px solid var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 18px 12px;
  font-size: 12px;
  background: var(--surface);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.sidebar-footer small {
  display: block;
  max-width: 150px;
  overflow-wrap: anywhere;
}

.avatar {
  border-radius: 50%;
  background: var(--surface-alt);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
}

/* Topbar */
.spark-topbar {
  min-height: 76px;
  padding: 18px 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid transparent;
  background: var(--canvas);
}

.topbar-location,
.topbar-actions {
  display: flex;
  gap: 16px;
  align-items: center;
  min-width: 0;
}

/* Account menu (also the base of the portal scope menu). */
.account-menu {
  position: relative;
  font-size: 12px;
}

.account-menu summary {
  cursor: pointer;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--surface-alt);
  box-shadow: none;
}

.account-menu > div {
  position: absolute;
  right: 0;
  top: 48px;
  background: var(--surface);
  box-shadow: var(--popover-shadow);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 18px;
  min-width: 190px;
  z-index: 30;
}

.account-menu a,
.account-menu strong {
  display: block;
  margin-bottom: 12px;
}

.account-menu form {
  margin: 0;
}

/* Drawer controls */
.menu-toggle {
  display: none;
}

.sidebar-scrim {
  position: fixed;
  inset: 0;
  background: #0007;
  border-radius: 0;
  z-index: 35;
}

@media (prefers-reduced-motion: no-preference) {
  .nav-link,
  .nav-group > summary {
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
  }
}

@media (min-width: 1300px) {
  .spark-topbar {
    padding-left: 44px;
    padding-right: 44px;
  }
}

@media (max-width: 1100px) {
  .spark-topbar {
    padding: 18px 24px;
  }

  .topbar-actions,
  .topbar-location {
    gap: 8px;
  }
}

@media (max-width: 900px) {
  .spark-sidebar {
    transform: translateX(-100%);
    width: 250px;
    top: 76px;
  }

  .spark-topbar {
    height: 76px;
    min-height: 76px;
    padding: 12px 18px;
    position: relative;
    z-index: 45;
  }

  .menu-toggle {
    display: block;
  }

  .menu-open .spark-sidebar {
    transform: translateX(0);
  }

  .menu-open {
    overflow: hidden;
  }

  .menu-open .spark-topbar {
    position: sticky;
    top: 0;
  }

  .sidebar-scrim {
    top: 76px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .theme-toggle {
    font-size: 11px !important; /* Overrides the generic control size in both portal and admin. */
    padding: 9px !important;
  }
}

@media (max-width: 560px) {
  .spark-topbar {
    padding: 12px;
  }

  .account-menu summary {
    max-width: 130px;
    overflow-wrap: anywhere;
  }

  .account-menu:not(.scope-menu) summary {
    max-width: 70px;
    font-size: 11px;
  }

  /* Icon-only theme toggle on phones; the accessible name stays in aria-label. */
  .theme-toggle.quiet {
    font-size: 0 !important;
    width: 40px;
    min-width: 40px;
  }

  .theme-toggle::before {
    content: '☾';
    font-size: 18px;
  }

  [data-theme=dark] .theme-toggle::before {
    content: '☀';
  }
}
