// ========================================
// Shared Component Styles (cv-*)
// Pure CSS/HTML diagrams and visual components for documentation.
// Included automatically in all themes.
// Uses only CSS custom properties — no Sass variables except $phone-max-width
// which every theme must define before importing this partial.
// ========================================

.cv-visual {
  margin: 28px 0;
  max-width: 520px;

  &--wide { max-width: 100%; }
  &--center { margin-left: auto; margin-right: auto; }
}

.cv-caption {
  font-size: 0.82rem;
  color: var(--color-muted);
  text-align: center;
  margin: 10px 0 0;
  font-style: italic;
}

// Flow diagram — horizontal steps with arrows
.cv-flow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 16px;
  background: var(--background-raised);
  border: 1px solid var(--border-color);
  border-radius: 10px;

  @media (max-width: $phone-max-width) {
    flex-direction: column;
    gap: 4px;
  }

  &__step {
    text-align: center;
    min-width: 70px;
    padding: 10px 14px;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 8px;

    @media (max-width: $phone-max-width) {
      min-width: 0;
      width: 100%;
      display: flex;
      align-items: center;
      gap: 10px;
      padding: 8px 12px;
    }
  }

  &__step--accent {
    border-color: var(--accent-alpha-70);
    background: var(--accent-alpha-20);
  }

  &__step--green {
    border-color: rgba(52, 211, 153, .4);
    background: rgba(52, 211, 153, .1);
  }

  &__icon {
    font-size: 1.4rem;
    margin-bottom: 4px;

    @media (max-width: $phone-max-width) {
      font-size: 1.2rem;
      margin-bottom: 0;
    }
  }

  &__label {
    font-size: 0.78rem;
    color: var(--color-muted);
    line-height: 1.3;

    strong {
      color: var(--color);
      display: block;
      font-size: 0.82rem;
    }
  }

  &__arrow {
    color: var(--accent);
    font-size: 1.1rem;
    flex-shrink: 0;

    @media (max-width: $phone-max-width) {
      transform: rotate(90deg);
      font-size: 0.9rem;
    }
  }
}

// Layer stack — vertical layered diagram
.cv-layers {
  display: flex;
  flex-direction: column;
  gap: 0;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;

  &__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    background: var(--background-raised);

    &:last-child { border-bottom: none; }

    @media (max-width: $phone-max-width) {
      flex-wrap: wrap;
      gap: 8px;
      padding: 12px 14px;
    }
  }

  &__item--active {
    background: var(--accent-alpha-20);
    border-left: 3px solid var(--accent);
  }

  &__item--green {
    background: rgba(52, 211, 153, .08);
    border-left: 3px solid var(--accent-secondary);
  }

  &__num {
    font-family: "Space Grotesk", sans-serif;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-alpha-20);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  &__content {
    flex: 1;
    min-width: 0;
  }

  &__title {
    font-family: "Space Grotesk", sans-serif;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--color);
    margin: 0;
  }

  &__desc {
    font-size: 0.78rem;
    color: var(--color-muted);
    margin: 2px 0 0;
  }

  &__badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    flex-shrink: 0;
    font-family: ui-monospace, SFMono-Regular, monospace;

    @media (max-width: $phone-max-width) {
      flex-shrink: 1;
      font-size: 0.65rem;
      word-break: break-word;
    }
  }

  &__badge--blue {
    background: var(--accent-alpha-20);
    color: var(--accent);
  }

  &__badge--green {
    background: var(--accent-secondary-alpha-20);
    color: var(--accent-secondary);
  }
}

// File tree — visual directory structure
.cv-tree {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.82rem;
  background: var(--background-raised);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px 20px;
  overflow-x: auto;

  @media (max-width: $phone-max-width) {
    font-size: 0.75rem;
    padding: 12px 14px;
  }

  &__line {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    color: var(--color-muted);
    white-space: nowrap;

    &:hover { color: var(--color); }
  }

  &__prefix {
    color: var(--border-color);
    user-select: none;
  }

  &__icon {
    flex-shrink: 0;
    font-style: normal;
  }

  &__name {
    color: var(--color);
  }

  &__name--section {
    color: var(--accent);
    font-weight: 600;
  }

  &__name--page {
    color: var(--accent-secondary);
  }

  &__tag {
    font-family: "Public Sans", sans-serif;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 3px;
    margin-left: 4px;
  }

  &__tag--section {
    background: var(--accent-alpha-20);
    color: var(--accent);
  }

  &__tag--page {
    background: var(--accent-secondary-alpha-20);
    color: var(--accent-secondary);
  }

  &__tag--url {
    background: transparent;
    color: var(--color-muted);
    font-style: italic;
  }
}

// Comparison — side-by-side or stacked cards
.cv-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;

  @media (max-width: $phone-max-width) {
    grid-template-columns: 1fr;
  }

  &__card {
    padding: 16px;
    background: var(--background-raised);
    border: 1px solid var(--border-color);
    border-radius: 8px;

    @media (max-width: $phone-max-width) {
      padding: 12px;
    }
  }

  &__card--accent {
    border-color: var(--accent-alpha-70);
  }

  &__card--green {
    border-color: rgba(52, 211, 153, .4);
  }

  &__card--muted {
    opacity: 0.5;
  }

  &__title {
    font-family: "Space Grotesk", sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color);
    margin: 0 0 8px;
  }

  &__body {
    font-size: 0.8rem;
    color: var(--color-muted);
    line-height: 1.5;

    code {
      font-size: 0.78rem;
      padding: 1px 4px;
    }
  }
}

// Code mockup — styled code block visual
.cv-code {
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  background: var(--background-raised);

  &__bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--background);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.75rem;
    color: var(--color-muted);
  }

  &__dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;

    &--red { background: #f87171; }
    &--yellow { background: #fbbf24; }
    &--green { background: #34d399; }
  }

  &__filename {
    margin-left: 8px;
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 0.75rem;
  }

  &__body {
    padding: 14px 18px;
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    overflow-x: auto;
  }

  &__line {
    color: var(--color-muted);

    &--key { color: var(--accent); }
    &--value { color: var(--accent-secondary); }
    &--comment { color: var(--color-muted); opacity: 0.5; font-style: italic; }
    &--highlight { background: var(--accent-alpha-20); margin: 0 -18px; padding: 0 18px; display: block; }
  }
}

// Cascade/override diagram
.cv-cascade {
  display: flex;
  flex-direction: column;
  gap: 0;

  &__level {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--background-raised);
    border: 1px solid var(--border-color);
    border-bottom: none;
    position: relative;

    &:first-child { border-radius: 10px 10px 0 0; }
    &:last-child { border-bottom: 1px solid var(--border-color); border-radius: 0 0 10px 10px; }

    @media (max-width: $phone-max-width) {
      flex-wrap: wrap;
      gap: 8px;
      padding: 12px 14px;
    }
  }

  &__level--winner {
    background: rgba(52, 211, 153, .08);
    border-color: rgba(52, 211, 153, .3);

    & + .cv-cascade__level { border-top-color: rgba(52, 211, 153, .3); }
  }

  &__priority {
    font-family: "Space Grotesk", sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex-shrink: 0;
    width: 48px;
  }

  &__label {
    flex: 1;
    font-size: 0.85rem;
    color: var(--color);

    code { font-size: 0.8rem; }
  }

  &__badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    flex-shrink: 0;
  }

  &__badge--wins {
    background: var(--accent-secondary-alpha-20);
    color: var(--accent-secondary);
  }

  &__badge--default {
    background: var(--accent-alpha-20);
    color: var(--accent);
  }
}

// Chip list
.cv-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px;
  background: var(--background-raised);
  border: 1px solid var(--border-color);
  border-radius: 10px;

  &__chip {
    padding: 5px 14px;
    background: var(--background);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 0.82rem;
    color: var(--accent);
    font-weight: 600;

    &--green { color: var(--accent-secondary); border-color: rgba(52, 211, 153, .3); }
    &--muted { color: var(--color-muted); font-family: "Public Sans", sans-serif; font-weight: 400; font-style: italic; border: none; }
  }
}

// ========================================
// Feed Banner
// ========================================

.feed-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  margin: 24px 0;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: var(--background-raised);
  color: var(--color-muted);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s, border-color 0.2s, background 0.2s;

  &:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-alpha-20);
  }

  svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
  }
}

// ========================================
// Search
// ========================================

// .search-toggle is styled via .navbar__icon-link (see _structure.scss)

.search-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;

  &[hidden] { display: none; }

  &__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
  }

  &__dialog {
    position: relative;
    width: 90%;
    max-width: 560px;
    background: var(--background-raised);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
    overflow: hidden;
  }

  &__header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
  }

  &__icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--color-muted);
  }

  &__input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-size: 1rem;
    color: var(--color);
    font-family: inherit;

    &::placeholder { color: var(--color-muted); }
  }

  &__kbd {
    font-size: 0.7rem;
    padding: 2px 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--color-muted);
    background: var(--background);
    font-family: ui-monospace, SFMono-Regular, monospace;
  }

  &__status {
    padding: 4px 18px;
    font-size: 0.75rem;
    color: var(--color-muted);

    &:empty { display: none; }
  }

  &__results {
    max-height: 50vh;
    overflow-y: auto;
    padding: 4px;
  }

  &__result {
    display: block;
    padding: 12px 14px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--color);
    transition: background 0.15s;

    &:hover,
    &--selected {
      background: var(--accent-alpha-20);
    }

    mark {
      background: var(--accent-alpha-20);
      color: var(--accent);
      border-radius: 2px;
      padding: 0 2px;
    }
  }

  &__result-title {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 2px;

    mark {
      font-weight: 700;
    }
  }

  &__result-url {
    font-size: 0.75rem;
    color: var(--color-muted);
    margin-bottom: 4px;
    font-family: ui-monospace, SFMono-Regular, monospace;
    opacity: 0.7;
  }

  &__result-snippet {
    font-size: 0.8rem;
    color: var(--color-muted);
    line-height: 1.4;
  }

  &__empty {
    padding: 24px 18px;
    text-align: center;
    color: var(--color-muted);
    font-size: 0.9rem;
  }
}

// ========================================
// Theme Switcher
// ========================================

.theme-switcher {
  position: relative;
  display: flex;
  align-items: center;

  &__btn {
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    // Reset button defaults to exactly match <a> navbar__right-btn
    background: none;
    color: var(--color-muted);
    border: 1px solid var(--border-color);
    padding: 6px 14px;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: inherit;
    line-height: 1.54;
    box-sizing: border-box;
  }

  &__chevron {
    width: 14px;
    height: 14px;
    transition: transform 0.2s;
  }

  // Rotate chevron when menu is open
  &:has(&__menu:not([hidden])) &__chevron {
    transform: rotate(180deg);
  }

  &__menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--background-raised);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 4px;
    z-index: 100;
    min-width: 130px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  }

  &__option {
    display: block;
    width: 100%;
    padding: 7px 14px;
    border: none;
    background: none;
    color: var(--color);
    cursor: pointer;
    text-align: left;
    border-radius: 5px;
    font-size: 0.82rem;
    font-family: ui-monospace, SFMono-Regular, monospace;
    transition: background 0.15s;

    &:hover { background: var(--accent-alpha-20); }
    &.active {
      color: var(--accent);
      font-weight: 600;
      background: var(--accent-alpha-20);
    }
  }
}
