/**
 * Bridge: legacy styles.css + Tailwind (#stitch-root)
 * Sidebar active state, mobile drawer, Material Symbols
 *
 * Tailwind must NOT use important: '#stitch-root' (see tailwind-stitch-config.js).
 * .stitch-* helpers below guarantee Stitch reference contrast if utilities fail.
 */

html:has(#stitch-root) {
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
}

html:has(#stitch-root),
body.stitch-dashboard-body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  min-height: 100dvh;
  max-height: 100%;
  overflow: hidden;
  background-color: #f7f9fb;
  color: #191c1e;
  -webkit-tap-highlight-color: transparent;
}

@supports (height: 100dvh) {
  html:has(#stitch-root),
  body.stitch-dashboard-body {
    min-height: 100dvh;
  }
}

/* Lock app to viewport: prevents document scroll so top header + layout stay fixed; scroll happens inside main or wizard */
#stitch-root {
  --stitch-safe-top: env(safe-area-inset-top, 0px);
  --stitch-safe-bottom: env(safe-area-inset-bottom, 0px);
  --stitch-safe-left: env(safe-area-inset-left, 0px);
  --stitch-safe-right: env(safe-area-inset-right, 0px);
  --stitch-header-bar-h: calc(4rem + var(--stitch-safe-top));
  isolation: isolate;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Shell surfaces — beat legacy .sidebar / .app-shell__main where needed */
#stitch-root .app-shell {
  background: transparent;
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: row !important;
  overflow: hidden;
}

/* styles.css @media (max-width: 768px) sets .app-shell { flex-direction: column } — breaks fixed sidebar + main; keep row */
@media (max-width: 768px) {
  #stitch-root .app-shell {
    flex-direction: row !important;
    min-height: 0 !important;
  }
}

/* Main column shell: column flex so header stays at top and only <main> scrolls (no fixed header overlap). */
#stitch-root .app-shell__main {
  background-color: #f7f9fb !important;
  flex: 1 1 0%;
  min-width: 0;
  min-height: 0;
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch;
  align-content: flex-start;
}

#stitch-root aside.sidebar {
  background-color: #f9fafb !important;
  border-right: 1px solid rgba(229, 231, 235, 0.95) !important;
  /* Legacy styles.css .sidebar adds padding + gap — stacks with header/nav and creates huge vertical gaps */
  padding: 0 !important;
  gap: 0 !important;
}

/* Sidebar brand / logo row — flat blue tile (reference: #1a56db) */
#stitch-root .stitch-sidebar-brand:hover .stitch-sidebar-brand__mark {
  box-shadow: 0 6px 16px -4px rgba(26, 86, 219, 0.35);
}
#stitch-root .stitch-sidebar-brand:active .stitch-sidebar-brand__mark {
  transform: scale(0.98);
}
#stitch-root .stitch-sidebar-brand__mark {
  transition: box-shadow 0.2s ease, transform 0.15s ease;
}

/* Legacy buttons: replace pure white surface with tonal chips */
#stitch-root .btn:not(.btn-primary):not(.btn-outline):not(.btn-ghost) {
  background-color: #f2f4f6 !important;
  color: #191c1e !important;
  border-color: rgba(195, 198, 215, 0.35) !important;
}

#stitch-root .btn:not(.btn-primary):not(.btn-outline):not(.btn-ghost):hover {
  background-color: #e6e8ea !important;
}

#stitch-root .btn-outline {
  background-color: rgba(242, 244, 246, 0.6) !important;
  border-color: rgba(195, 198, 215, 0.45) !important;
  color: #191c1e !important;
}

#stitch-root .btn-outline:hover {
  background-color: #e6e8ea !important;
  border-color: rgba(37, 99, 235, 0.35) !important;
}

#stitch-root .btn-ghost:hover {
  background-color: rgba(226, 232, 240, 0.85) !important;
}

#stitch-root .btn-primary {
  background-color: #004ac6 !important;
  border-color: #004ac6 !important;
}

#stitch-root .btn-primary:hover {
  background-color: #1d4ed8 !important;
  border-color: #1d4ed8 !important;
}

/* Form controls — soft fill on grey canvas */
#stitch-root .input,
#stitch-root .textarea,
#stitch-root select {
  background-color: #f2f4f6 !important;
  border-color: rgba(195, 198, 215, 0.4) !important;
  color: #191c1e !important;
}

#stitch-root .input:focus,
#stitch-root .textarea:focus,
#stitch-root select:focus {
  background-color: #eceef0 !important;
}

#stitch-root #view-builder [data-step-pane='6'] .toolbar--summary .toolbar__btn {
  background-color: #f2f4f6 !important;
  border-color: rgba(195, 198, 215, 0.4) !important;
}

#stitch-root #view-builder [data-step-pane='6'] .toolbar--summary .toolbar__btn:hover {
  background-color: #e6e8ea !important;
}

#stitch-root .icon-button:hover {
  background-color: rgba(226, 232, 240, 0.9) !important;
}

/* Views fill main width — stretch full row (prevents flex quirks pushing content to a corner) */
#stitch-root main.app-main > .view {
  width: 100% !important;
  max-width: none !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  align-self: stretch !important;
  box-sizing: border-box;
}

#stitch-root #view-builder {
  max-width: min(100%, 112rem);
}

/* Create Resume — fill main column height; form scrolls under fixed header strip */
#stitch-root main.app-main > #view-builder.view--active {
  flex: 1 1 0%;
  min-height: 0;
}

/* Create Resume: shell column doesn’t grow past viewport — only .wizard-body--scroll scrolls */
#stitch-root .app-shell__main:has(#view-builder.view--active) {
  overflow: hidden;
  min-height: 0;
}

#stitch-root #view-builder.view--active {
  display: flex !important;
  flex-direction: column;
  flex: 1 1 0%;
  min-height: 0;
  max-height: 100%;
  overflow: hidden;
}

#stitch-root #view-builder.view--active .layout-grid--wizard {
  flex: 1 1 0%;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  align-items: stretch;
  grid-template-rows: minmax(0, 1fr);
}

#stitch-root #view-builder.view--active .layout-grid--wizard > * {
  min-height: 0;
}

/* Base glyph rules live in styles.css so icons work even if bridge order changes */
#stitch-root .material-symbols-outlined {
  vertical-align: middle;
}

/* Resume Chat — scrollbar (stitch/ai_resume_chat/code.html) */
#stitch-root .chat-scroll::-webkit-scrollbar {
  width: 4px;
}
#stitch-root .chat-scroll::-webkit-scrollbar-track {
  background: transparent;
}
#stitch-root .chat-scroll::-webkit-scrollbar-thumb {
  background: #e0e3e5;
  border-radius: 10px;
}

/* Resume Chat — guaranteed contrast (fixes white-on-white when bg-primary/text-white fail) */
#stitch-root .resume-chat-user-bubble {
  background: linear-gradient(135deg, #004ac6 0%, #2563eb 100%) !important;
  color: #ffffff !important;
  border: none !important;
}
#stitch-root .resume-chat-user-bubble p {
  color: #ffffff !important;
}
#stitch-root #resumeChatSend.stitch-resume-chat-send {
  background: linear-gradient(135deg, #004ac6 0%, #2563eb 100%) !important;
  color: #ffffff !important;
  border: none !important;
}
#stitch-root #resumeChatSend.stitch-resume-chat-send .material-symbols-outlined {
  color: #ffffff !important;
}

/* Main: offset for fixed top bar + gutters aligned with header (prevents content under navbar). */
#stitch-root main.app-main.app-main--dashboard {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  gap: 0 !important;
  align-items: stretch;
  align-content: flex-start;
  justify-content: flex-start;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  padding-top: calc(var(--stitch-header-bar-h) + 1rem) !important;
  padding-bottom: max(1.5rem, var(--stitch-safe-bottom)) !important;
  padding-left: max(1rem, var(--stitch-safe-left)) !important;
  padding-right: max(1rem, var(--stitch-safe-right)) !important;
  scroll-padding-top: calc(var(--stitch-header-bar-h) + 0.75rem);
}

@media (min-width: 1024px) {
  #stitch-root main.app-main.app-main--dashboard {
    padding-top: calc(var(--stitch-header-bar-h) + 1.25rem) !important;
    padding-bottom: max(2rem, var(--stitch-safe-bottom)) !important;
    padding-left: max(2rem, var(--stitch-safe-left)) !important;
    padding-right: max(2rem, var(--stitch-safe-right)) !important;
  }
}

/* Shared inner shell — same pattern as My Resumes (use Tailwind max-w-6xl / max-w-7xl on the element for width cap). */
#stitch-root .dashboard-view-inner {
  width: 100%;
  margin-left: 0 !important;
  margin-right: 0 !important;
  box-sizing: border-box;
  align-self: flex-start;
}

/* Non-dashboard pages that reuse .app-main without --dashboard keep bridge defaults below */
#stitch-root main.app-main:not(.app-main--dashboard) {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  gap: 0 !important;
  align-items: stretch;
  padding: 1rem max(1rem, var(--stitch-safe-right)) max(1.5rem, var(--stitch-safe-bottom)) max(1rem, var(--stitch-safe-left)) !important;
}

@media (min-width: 1024px) {
  #stitch-root main.app-main:not(.app-main--dashboard) {
    padding: 1.25rem max(2rem, var(--stitch-safe-right)) max(2rem, var(--stitch-safe-bottom)) max(2rem, var(--stitch-safe-left)) !important;
  }
}

/* Tall views (builder, chat) consume remaining viewport height; others size to content */
#stitch-root main.app-main > .view.view--active:not(#view-resume-chat):not(#view-builder) {
  flex: 0 0 auto;
}

#stitch-root main.app-main > #view-resume-chat.view--active,
#stitch-root main.app-main > #view-builder.view--active {
  flex: 1 1 0%;
  min-height: 0;
}

/* Create Resume: main doesn’t scroll — #view-builder + .wizard-body--scroll owns vertical scroll */
#stitch-root main.app-main:has(#view-builder.view--active) {
  overflow: hidden !important;
  overflow-y: hidden !important;
}

#stitch-root #view-resume-chat.view--active {
  display: flex !important;
  flex-direction: column;
  min-height: 0 !important;
  overflow: hidden !important;
  height: auto !important;
  max-height: none !important;
}

#stitch-root #view-resume-chat .resume-chat-layout {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
  width: 100%;
  max-width: 100% !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  align-self: stretch;
}

/* Template gallery: legacy styles.css adds outer padding + flex gap — strips double frame & border clash with Tailwind */
#stitch-root .template-gallery-card.card {
  padding: 0 !important;
  gap: 0 !important;
}

#stitch-root .template-gallery-card__header {
  align-items: flex-start !important;
  justify-content: space-between !important;
}

/* Template gallery — legacy .template-grid is 3 columns everywhere; make it responsive */
@media (max-width: 639px) {
  #stitch-root .template-grid {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 1rem !important;
  }
}

@media (min-width: 640px) and (max-width: 1023px) {
  #stitch-root .template-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 1.25rem !important;
  }
}

/* Template gallery view — match ATS / Settings cards */
#stitch-root #view-templates .template-card {
  border-color: rgba(195, 198, 215, 0.45) !important;
  border-radius: 0.875rem !important;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.05) !important;
}

#stitch-root #view-templates .template-card:hover {
  border-color: rgba(0, 74, 198, 0.38) !important;
  box-shadow: 0 12px 32px rgba(0, 74, 198, 0.1) !important;
  transform: translateY(-2px);
}

#stitch-root #view-templates .template-card.is-selected {
  border-color: #004ac6 !important;
  box-shadow: 0 0 0 3px rgba(0, 74, 198, 0.2), 0 12px 32px rgba(0, 74, 198, 0.12) !important;
}

#stitch-root #view-templates .template-card.is-selected::after {
  background: linear-gradient(135deg, #004ac6 0%, #2563eb 100%) !important;
}

#stitch-root #view-templates .template-card__preview {
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%) !important;
  border-bottom-color: rgba(195, 198, 215, 0.35) !important;
}

#stitch-root #view-templates .template-card__body h3 {
  font-size: 1rem !important;
  font-weight: 700 !important;
  color: #191c1e !important;
}

#stitch-root #view-templates .template-card__body p {
  font-size: 0.8125rem !important;
  line-height: 1.45 !important;
  color: #475569 !important;
}

#stitch-root #view-templates .template-card__cta-pill .material-symbols-outlined {
  color: #004ac6 !important;
}

/* Views: prevent horizontal overflow from long URLs / pre blocks */
#stitch-root main.app-main > .view {
  min-width: 0;
  max-width: 100%;
}

#stitch-root main.app-main table {
  word-break: break-word;
}

/* Sidebar: clip nav so active highlight does not bleed past the rail */
#stitch-root aside.sidebar,
#stitch-root .sidebar__nav {
  overflow-x: hidden;
  contain: layout;
}

#stitch-root .sidebar__nav .sidebar__item {
  max-width: 100%;
  box-sizing: border-box;
}

/* Sidebar nav — Stitch active rail */
#stitch-root .sidebar__item.is-active {
  border-left: 4px solid #1d4ed8;
  background: rgba(226, 232, 240, 0.55);
  color: #1d4ed8;
  font-weight: 600;
}

#stitch-root .sidebar__item:not(.is-active):hover {
  color: #2563eb;
  background: rgba(226, 232, 240, 0.45);
}

/* Mobile: overlay sidebar */
@media (max-width: 900px) {
  #stitch-root .sidebar {
    transform: translateX(-100%);
    transition: transform 0.2s ease-out, box-shadow 0.2s ease-out;
    box-shadow: none;
    padding-bottom: var(--stitch-safe-bottom);
  }

  #stitch-root .sidebar.is-open {
    transform: translateX(0);
    box-shadow: 0 0 0 999px rgba(15, 23, 42, 0.35);
  }

  #stitch-root .app-shell__main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  #stitch-root .stitch-header-bar {
    margin-left: 0 !important;
    max-width: 100% !important;
  }

  #stitch-root .stitch-progress-fixed {
    left: 0 !important;
  }
}

/* Create Resume / wizard — Stitch-style layout (copy trimmed in dashboard_view.php) */
#stitch-root #view-builder .stitch-builder-wizard.wizard.card {
  background: #ffffff;
  border: 1px solid rgba(195, 198, 215, 0.2);
  border-radius: 0.875rem;
  box-shadow: 0 12px 40px rgba(0, 74, 198, 0.06);
  overflow: hidden;
}

/* Split: stepper strip vs scrollable form + pinned footer */
#stitch-root #view-builder .stitch-builder-wizard.wizard.card.stitch-builder-wizard--split {
  display: flex;
  flex-direction: column;
  flex: 1 1 0%;
  min-height: 0;
  padding: 0;
}

#stitch-root #view-builder .wizard-header.wizard-header--split {
  flex-shrink: 0;
  margin-bottom: 0;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  border-radius: 0.875rem 0.875rem 0 0;
  box-shadow: 0 10px 28px -18px rgba(15, 23, 42, 0.14);
}

@media (min-width: 900px) {
  #stitch-root #view-builder .wizard-header.wizard-header--split {
    align-items: center;
  }
}

#stitch-root #view-builder .wizard-header--split .wizard-steps.stitch-wizard-steps {
  margin-bottom: 0;
}

#stitch-root #view-builder .wizard-main {
  flex: 1 1 0%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#stitch-root #view-builder .wizard-body.wizard-body--scroll {
  flex: 1 1 0%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  /* allow wheel to scroll this region when focus is inside inputs (contain traps scroll in some browsers) */
  overscroll-behavior-y: auto;
  touch-action: pan-y;
}

#stitch-root #view-builder .wizard-header {
  background: linear-gradient(180deg, rgba(242, 244, 246, 0.9) 0%, rgba(255, 255, 255, 0.95) 100%);
  border-bottom: 1px solid rgba(195, 198, 215, 0.22);
  padding: 0.75rem 1rem 1rem;
}

/* Create Resume — Stitch-style horizontal stepper (icons + connectors, resume_builder pattern) */
#stitch-root #view-builder .wizard-steps.stitch-wizard-steps {
  display: block;
  gap: 0;
  flex-wrap: nowrap;
  padding-right: 0;
  margin-bottom: 0.75rem;
  align-items: stretch;
}

#stitch-root #view-builder .stitch-wizard-steps {
  position: relative;
}

#stitch-root #view-builder .stitch-wizard-steps .stitch-wizard-steps__scroll {
  display: flex;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.25rem 0 0.35rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step {
  flex: 0 0 auto;
  min-width: 3.25rem;
  max-width: 5.5rem;
  padding: 0;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  font: inherit;
  color: inherit;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step:focus-visible {
  outline: 2px solid #004ac6;
  outline-offset: 3px;
  border-radius: 0.5rem;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 999px;
  border: 2px solid #cbd5e1;
  background: #ffffff;
  color: #64748b;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
  transition:
    background-color 0.2s ease,
    border-color 0.2s ease,
    color 0.2s ease,
    box-shadow 0.2s ease;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step__icon .material-symbols-outlined {
  font-size: 1.25rem;
  line-height: 1;
  font-variation-settings: 'FILL' 0, 'wght' 500, 'GRAD' 0, 'opsz' 24;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step__label {
  display: block;
  margin-top: 0.35rem;
  padding: 0 0.15rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  line-height: 1.15;
  color: #64748b;
  white-space: normal;
  word-break: break-word;
  transition: color 0.2s ease;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step:not(.is-active):not(.is-complete) .wizard-step__label {
  opacity: 0.88;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step.is-active .wizard-step__label,
#stitch-root #view-builder .stitch-wizard-steps .wizard-step.is-complete .wizard-step__label {
  opacity: 1;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step.is-complete .wizard-step__icon {
  background: rgba(219, 234, 254, 0.95);
  border-color: #2563eb;
  color: #1d4ed8;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step.is-complete .wizard-step__label {
  color: #1e40af;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step.is-active .wizard-step__icon {
  background: linear-gradient(135deg, #004ac6 0%, #2563eb 100%);
  border-color: #004ac6;
  color: #ffffff;
  box-shadow: 0 8px 20px -6px rgba(0, 74, 198, 0.45);
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step.is-active .wizard-step__icon .material-symbols-outlined {
  color: #ffffff !important;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step.is-active .wizard-step__label {
  color: #0f172a;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step-connector {
  flex: 1 1 1.25rem;
  min-width: 0.75rem;
  max-width: 3rem;
  height: 3px;
  align-self: flex-start;
  margin-top: 1.125rem;
  border-radius: 999px;
  background: #e2e8f0;
  transition: background-color 0.25s ease;
}

#stitch-root #view-builder .stitch-wizard-steps .wizard-step-connector.is-complete {
  background: linear-gradient(90deg, #004ac6 0%, #3b82f6 100%);
}

@media (min-width: 1280px) {
  #stitch-root #view-builder .stitch-wizard-steps .wizard-step {
    max-width: 6.5rem;
  }
}

/* Match wizard-header horizontal padding (1rem) so form card aligns with template/stepper strip above */
#stitch-root #view-builder .wizard-body {
  padding: 1.25rem 1rem 1.5rem;
  background: #f7f9fb;
}

@media (min-width: 1024px) {
  #stitch-root #view-builder .wizard-body {
    padding: 1.5rem 1rem 2rem;
  }
}

#stitch-root #view-builder .wizard-pane__header {
  margin: 0 0 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(195, 198, 215, 0.2);
}

#stitch-root #view-builder .wizard-pane__header h2 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #191c1e;
}

#stitch-root #view-builder .wizard-card {
  background: #ffffff !important;
  border: 1px solid rgba(195, 198, 215, 0.22) !important;
  border-radius: 0.75rem !important;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.05);
  margin-bottom: 1rem;
}

#stitch-root #view-builder .wizard-card__title {
  background: rgba(241, 245, 249, 0.7);
  border-bottom: 1px solid rgba(195, 198, 215, 0.18);
  border-radius: 0.75rem 0.75rem 0 0;
}

#stitch-root #view-builder .wizard-card__title h3 {
  font-size: 0.95rem;
  font-weight: 600;
}

/* Collapsed repeaters — ensure body hides under Stitch card rules (higher specificity) */
#stitch-root #view-builder .experience-card--collapsed > .wizard-grid,
#stitch-root #view-builder .experience-card--collapsed > .wizard-card__footer,
#stitch-root #view-builder .education-card--collapsed > .wizard-grid,
#stitch-root #view-builder .education-card--collapsed > .wizard-card__footer,
#stitch-root #view-builder .project-card--collapsed > .wizard-grid,
#stitch-root #view-builder .project-card--collapsed > .wizard-card__footer,
#stitch-root #view-builder .certification-card--collapsed > .wizard-grid,
#stitch-root #view-builder .certification-card--collapsed > .wizard-card__footer {
  display: none !important;
}

#stitch-root #view-builder .contacts-required-divider,
#stitch-root #view-builder .contacts-optional-divider {
  grid-column: 1 / -1;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #64748b;
  margin: 0.75rem 0 0.35rem;
  padding-top: 0.5rem;
}

#stitch-root #view-builder .contacts-optional-divider {
  border-top: 1px dashed rgba(195, 198, 215, 0.45);
  margin-top: 1rem;
}

#stitch-root #view-builder .stitch-builder-add {
  margin-top: 0.35rem;
  display: inline-flex;
  align-items: center;
  font-weight: 600;
  color: #004ac6 !important;
}

#stitch-root #view-builder .wizard-footer {
  flex-shrink: 0;
  border-top: 1px solid rgba(195, 198, 215, 0.2);
  background: #ffffff;
  padding: 1rem 1rem;
}

#stitch-root #view-builder .wizard-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 1rem;
  margin-bottom: 1rem;
  background: #ffffff;
  border: 1px solid rgba(195, 198, 215, 0.22);
  border-radius: 0.75rem;
}

#stitch-root #view-builder .wizard-card__header h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0;
}

#stitch-root #view-builder .wizard-card--summary-editor {
  border: 1px solid rgba(195, 198, 215, 0.22) !important;
}

#stitch-root #view-builder .finalize-card {
  border: 1px solid rgba(195, 198, 215, 0.2) !important;
  border-radius: 0.75rem;
  background: #ffffff !important;
}

#stitch-root .builder-preview {
  background: transparent;
  border: none;
  box-shadow: none;
}

/* Preview column matches form column height; inner frame fills (drop fixed 100vh cap) */
#stitch-root #view-builder.view--active .layout-grid--wizard > .builder-preview {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

#stitch-root #view-builder.view--active .builder-preview__header {
  flex-shrink: 0;
}

#stitch-root #view-builder.view--active .builder-preview__frame {
  flex: 1 1 0%;
  min-height: 0;
  max-height: none !important;
}

@media (max-width: 900px) {
  #stitch-root #view-builder.view--active .layout-grid--wizard {
    grid-template-rows: none;
    grid-auto-rows: minmax(0, auto);
  }

  #stitch-root #view-builder .wizard-main {
    max-height: min(70dvh, 780px);
  }
}

/* Tables & cards in secondary views */
#stitch-root .view .card {
  background: #ffffff;
  border: 1px solid rgba(195, 198, 215, 0.12);
  border-radius: 0.75rem;
  box-shadow: 0 12px 40px rgba(0, 74, 198, 0.04);
}

/* AI rewrite / secondary panels — avoid harsh #f9fafb-only blocks */
#stitch-root .rewrite-output {
  background-color: #f2f4f6 !important;
  border-color: rgba(195, 198, 215, 0.35) !important;
}

#stitch-root .view .card.placeholder-view {
  background: #eceef0 !important;
  border-color: rgba(195, 198, 215, 0.28) !important;
  color: #434655 !important;
  box-shadow: none;
}

/* Top bar: fixed to main column (sidebar is separate fixed rail). Main uses padding-top to clear this. */
#stitch-root .stitch-header-bar.app-header {
  background-color: rgba(255, 255, 255, 0.92) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(195, 198, 215, 0.18) !important;
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 0.75rem !important;
  padding: var(--stitch-safe-top) max(1rem, var(--stitch-safe-right)) 0 max(1rem, var(--stitch-safe-left)) !important;
  box-sizing: border-box !important;
  position: fixed !important;
  top: 0 !important;
  right: 0 !important;
  left: 16rem !important;
  width: auto !important;
  min-height: var(--stitch-header-bar-h) !important;
  height: auto !important;
  flex-shrink: 0 !important;
  z-index: 40 !important;
}

@media (max-width: 900px) {
  #stitch-root .stitch-header-bar.app-header {
    left: 0 !important;
  }
}

@media (min-width: 1024px) {
  #stitch-root .stitch-header-bar.app-header {
    padding-left: max(2rem, var(--stitch-safe-left)) !important;
    padding-right: max(2rem, var(--stitch-safe-right)) !important;
  }
}

#stitch-root .stitch-header-bar .app-header__title h1 {
  margin: 0 !important;
}

#stitch-root .stitch-header-bar .app-header__actions {
  margin-left: 0 !important;
}

#stitch-root .stitch-header-bar .app-header__user {
  margin-left: 0 !important;
}

/* Mobile: legacy dashboard hides .app-header__actions — keep Stitch CTAs */
@media (max-width: 768px) {
  #stitch-root .stitch-header-bar .app-header__actions {
    display: flex !important;
  }
}

/* ========== Stitch dashboard_overview/code.html — guaranteed contrast ========== */

/* Header CTAs (match: bg-surface-container-high + on-primary-fixed-variant; gradient Upgrade) */
#stitch-root .stitch-header-bar .stitch-btn-new {
  background-color: #e6e8ea !important;
  color: #003ea8 !important;
  border: 1px solid rgba(195, 198, 215, 0.45) !important;
  font-weight: 600 !important;
}

#stitch-root .stitch-header-bar .stitch-btn-new:hover {
  background-color: #d8dce0 !important;
  color: #002d7a !important;
}

/* Gradient Upgrade CTA — anywhere in #stitch-root (header was the only place styled before; ATS / Settings buttons need the same contrast). */
#stitch-root .stitch-btn-upgrade {
  background: linear-gradient(135deg, #004ac6 0%, #2563eb 100%) !important;
  color: #ffffff !important;
  border: none !important;
  font-weight: 700 !important;
  box-shadow: 0 10px 25px -5px rgba(0, 74, 198, 0.25) !important;
}

#stitch-root .stitch-btn-upgrade:hover {
  filter: brightness(1.05);
}

#stitch-root .stitch-btn-upgrade .material-symbols-outlined {
  color: #ffffff !important;
}

/* ATS check stat card — solid + gradient fallback (Stitch: bg-primary + gradient) */
#stitch-root .stitch-ats-check-card {
  background: linear-gradient(135deg, #004ac6 0%, #2563eb 100%) !important;
  color: #ffffff !important;
  border: none !important;
}

#stitch-root .stitch-ats-check-card h4 {
  color: #ffffff !important;
}

#stitch-root .stitch-ats-check-card .stitch-ats-check-card__sub {
  color: #dbeafe !important;
}

#stitch-root .stitch-ats-check-card .stitch-ats-check-card__cta {
  color: #ffffff !important;
  border-color: rgba(255, 255, 255, 0.45) !important;
  background-color: rgba(255, 255, 255, 0.22) !important;
}

#stitch-root .stitch-ats-check-card .stitch-ats-check-card__cta:hover {
  background-color: rgba(255, 255, 255, 0.32) !important;
}

/* Sidebar PRO box */
#stitch-root .stitch-sidebar-upgrade-btn {
  background-color: #004ac6 !important;
  color: #ffffff !important;
  border: none !important;
  font-weight: 700 !important;
}

#stitch-root .stitch-sidebar-upgrade-btn:hover {
  background-color: #1d4ed8 !important;
}

/* Featured document row */
#stitch-root .stitch-btn-featured-primary {
  background-color: #004ac6 !important;
  color: #ffffff !important;
  border: none !important;
  font-weight: 700 !important;
  box-shadow: 0 10px 25px -5px rgba(0, 74, 198, 0.2) !important;
}

#stitch-root .stitch-btn-featured-primary:hover {
  background-color: #1d4ed8 !important;
}

#stitch-root .stitch-btn-featured-secondary {
  background-color: #e6e8ea !important;
  color: #191c1e !important;
  border: 1px solid rgba(195, 198, 215, 0.35) !important;
  font-weight: 700 !important;
}

#stitch-root .stitch-btn-featured-secondary:hover {
  background-color: #d8dce0 !important;
}

/* ATS widget bottom button */
#stitch-root .stitch-ats-full-cta {
  background-color: #dbe1ff !important;
  color: #003ea8 !important;
  border: none !important;
  font-weight: 700 !important;
}

#stitch-root .stitch-ats-full-cta:hover {
  background-color: #b4c5ff !important;
  color: #00174b !important;
}

/* Helper / secondary copy — stronger than default on-surface-variant */
#stitch-root .text-stitch-muted {
  color: #475569 !important;
}

#stitch-root .text-stitch-caption {
  color: #64748b !important;
}

/* Recent Activity — vertical timeline (reference: connected spine + ring nodes) */
#stitch-root ul.stitch-activity-timeline {
  position: relative;
  margin: 0;
  padding: 0.35rem 0 0.5rem;
  list-style: none;
}

#stitch-root ul.stitch-activity-timeline::before {
  content: "";
  position: absolute;
  left: 10px;
  top: 0.85rem;
  bottom: 0.85rem;
  width: 1px;
  background: linear-gradient(to bottom, rgba(226, 232, 240, 0.2), #e2e8f0 8%, #e2e8f0 92%, rgba(226, 232, 240, 0.2));
  z-index: 0;
  pointer-events: none;
}

#stitch-root .stitch-activity-timeline__dot {
  position: relative;
  z-index: 1;
  display: block;
  width: 11px;
  height: 11px;
  flex-shrink: 0;
  border-radius: 9999px;
  background: #ffffff;
  border: 2px solid #cbd5e1;
  box-shadow: 0 0 0 3px #ffffff;
}

#stitch-root .stitch-activity-timeline__dot--active {
  border-color: #2563eb;
  border-width: 2px;
  box-shadow: 0 0 0 3px #ffffff, 0 0 0 1px rgba(37, 99, 235, 0.15);
}

/* Resume builder — Stitch resume_builder reference (scroll + preview column) */
#stitch-root .stitch-scrollbar::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
#stitch-root .stitch-scrollbar::-webkit-scrollbar-thumb {
  background: rgba(195, 198, 215, 0.95);
  border-radius: 999px;
}
#stitch-root .stitch-scrollbar {
  scrollbar-width: thin;
  scrollbar-color: rgba(195, 198, 215, 0.95) transparent;
}

#stitch-root .stitch-builder-layout {
  align-items: stretch;
}

#stitch-root .stitch-builder-preview .builder-preview__frame {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#stitch-root .wizard-pane__lead {
  color: #434655;
}

/* Very small screens: slightly tighter main gutters (dashboard main uses bridge padding) */
@media (max-width: 380px) {
  #stitch-root main.app-main.app-main--dashboard {
    padding-left: max(0.75rem, var(--stitch-safe-left)) !important;
    padding-right: max(0.75rem, var(--stitch-safe-right)) !important;
  }
}

/* ATS checker — score bar on gradient hero (readable on blue) */
#stitch-root #view-ats .stitch-ats-score-progress {
  height: 0.5rem !important;
  margin-top: 0 !important;
  background: rgba(255, 255, 255, 0.22) !important;
}

#stitch-root #view-ats .stitch-ats-score-progress .progress-bar__value,
#stitch-root #view-ats .stitch-ats-score-progress__value {
  background: linear-gradient(90deg, #ffffff 0%, #bfdbfe 55%, #38bdf8 100%) !important;
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.35);
}

#stitch-root #view-ats .ats-score-card__value {
  font-size: 3rem !important;
  font-weight: 900 !important;
  margin: 0 !important;
  line-height: 1 !important;
}

#stitch-root #view-ats .ats-breakdown__list {
  margin: 0 !important;
}

#stitch-root #view-ats .ats-recommendations {
  list-style: none !important;
  padding-left: 0 !important;
}

/* Settings — in-page nav pills (active state matches Stitch primary) */
#stitch-root .settings-nav__link.settings-nav__link--active {
  border-color: rgba(0, 74, 198, 0.45) !important;
  background: linear-gradient(135deg, rgba(219, 234, 254, 0.95) 0%, rgba(241, 245, 249, 0.98) 100%) !important;
  color: #003ea8 !important;
  box-shadow: 0 0 0 2px rgba(0, 74, 198, 0.12);
}

#stitch-root .settings-nav__link.settings-nav__link--active .material-symbols-outlined {
  color: #004ac6 !important;
}

/* Marketing pages: stitch-root inside main */
#stitch-root .topbar {
  position: relative;
  z-index: 20;
}
