/* ==========================================
   BENEFIQ — ADVISOR PAGE
   The main search experience
   ========================================== */

@layer pages {

  /* ==========================================
     ADVISOR CONTAINER
     ========================================== */
  .advisor {
    padding-top: var(--space-2);
  }

  .advisor-video-bg {
    display: none;
  }

  /* ==========================================
     PRE-SEARCH: CONVEYOR BELT LAYOUT
     Centers search bar vertically with ghost
     text above and below
     ========================================== */
  .advisor-conveyor {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: calc(80vh - var(--nav-height));
    padding: var(--space-8) 0;
    gap: 0;
    position: relative;
    z-index: 1;
  }

  /* Active state: search at top, categories below */
  .advisor-conveyor--active {
    justify-content: flex-start;
    min-height: auto;
    padding-top: var(--space-6);
  }

  /* Ghost text — previous/next examples with bokeh blur */
  .advisor-ghost {
    font-family: var(--font-display);
    font-size: var(--text-xl);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    opacity: 0.6;
    height: 1.6em;
    display: flex;
    align-items: center;
    overflow: hidden;
    pointer-events: none;
    user-select: none;
    filter: blur(2px);
    width: 100%;
    max-width: 630px;
    padding-left: var(--space-8);
  }

  .advisor-ghost-text {
    display: inline-block;
    white-space: nowrap;
  }

  /* ==========================================
     SEARCH ROW — Input + branded search button
     ========================================== */
  .advisor-search-row {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    width: 100%;
    max-width: 630px;
    margin: var(--space-3) 0;
  }

  .advisor-search {
    position: relative;
    flex: 1;
  }

  .advisor-search-input {
    width: 100%;
    height: 64px;
    padding: 0 var(--space-8);
    font-size: var(--text-xl);
    font-weight: var(--weight-medium);
    color: var(--text);
    background: var(--bg-elevated);
    border: 2px solid var(--border);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-md);
    transition: all var(--transition-base);
    caret-color: var(--primary);
  }

  .advisor-search-input:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-lg), 0 0 0 4px var(--primary-light);
    outline: none;
  }

  .advisor-search-input::placeholder {
    color: var(--text-muted);
    font-weight: var(--weight-medium);
    font-size: 0.85em;
  }

  /* Conveyor text overlay inside input — shows cycling example */
  .advisor-conveyor-text {
    position: absolute;
    left: var(--space-8);
    top: 0;
    bottom: 0;
    right: var(--space-8);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    pointer-events: none;
    overflow: hidden;
  }

  .advisor-conveyor-text span {
    font-size: var(--text-xl);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    white-space: nowrap;
    text-align: left;
  }

  .advisor-search-clear {
    position: absolute;
    right: var(--space-5);
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--bg-sunken);
    color: var(--text-muted);
    font-weight: var(--weight-semibold);
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition-base);
  }

  .advisor-search-input:not(:placeholder-shown) ~ .advisor-search-clear {
    opacity: 1;
  }

  .advisor-search-clear:hover {
    background: var(--danger-light);
    color: var(--danger);
  }

  /* Branded search icon button — coral orange */
  .advisor-search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: var(--radius-xl);
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    flex-shrink: 0;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
  }

  .advisor-search-btn:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
  }

  .advisor-search-btn:active {
    transform: scale(0.97);
  }

  .advisor-search-btn svg {
    width: 26px;
    height: 26px;
  }

  /* ==========================================
     CATEGORY LIST — Two-column grid (icon + name)
     ========================================== */
  .advisor-category-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-1) var(--space-6);
    width: 100%;
    max-width: 630px;
    margin-top: var(--space-5);
    padding-left: var(--space-6);
  }

  .advisor-category-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-2);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: background var(--transition-base);
    user-select: none;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
  }

  .advisor-category-item:hover {
    background: var(--bg-sunken);
  }

  .advisor-category-item:active {
    background: var(--border);
  }

  .advisor-category-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
  }

  .advisor-category-icon svg {
    width: 100%;
    height: 100%;
  }

  .advisor-category-name {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
  }

  /* ==========================================
     RESULT CARD
     ========================================== */
  #advisor-result {
    width: 100%;
    max-width: 630px;
  }

  .advisor-result {
    animation: slide-up 0.3s ease;
  }

  .result-card {
    background: var(--color-bg-elevated);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-card);
    border: none;
    overflow: hidden;
  }

  /* Result Header - Best Card Tag */
  .result-header {
    padding: var(--space-4) var(--space-5);
    background: linear-gradient(135deg, var(--success-light) 0%, rgba(59, 130, 246, 0.05) 100%);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .result-best-tag {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--weight-bold);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--success);
  }

  .result-category-tag {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    background: var(--bg-sunken);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-full);
    margin-bottom: var(--space-4);
  }

  .result-category-tag svg {
    width: 12px;
    height: 12px;
  }

  /* Result Body */
  .result-body {
    padding: var(--space-6);
  }

  .result-card-display {
    display: flex;
    align-items: center;
    gap: var(--space-5);
    margin-bottom: var(--space-5);
  }

  .result-card-visual {
    width: 100px;
    height: 63px;
    border-radius: var(--radius-lg);
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), 0 2px 4px rgba(0, 0, 0, 0.1);
  }

  .result-card-info {
    flex: 1;
    min-width: 0;
  }

  .result-card-name {
    font-size: var(--text-xl);
    font-weight: var(--weight-bold);
    color: var(--text);
    margin-bottom: var(--space-1);
  }

  .result-card-issuer {
    font-size: var(--text-sm);
    color: var(--text-muted);
  }

  .result-rate {
    text-align: right;
    flex-shrink: 0;
  }

  .result-rate-value {
    font-family: var(--font-body);
    font-size: var(--text-5xl);
    font-weight: 800;
    color: var(--success);
    line-height: 1;
    letter-spacing: -0.02em;
  }

  .result-rate-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-top: var(--space-1);
  }

  /* Result Explanation */
  .result-explanation {
    padding: var(--space-4);
    background: var(--success-light);
    border-radius: var(--radius-lg);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
  }

  .result-explanation strong {
    color: var(--text);
  }

  .result-merchant-note {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-xs);
    color: var(--text-tertiary, #888);
    font-style: italic;
    line-height: var(--leading-relaxed);
  }

  /* AI Indicator */
  .result-ai-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    margin-top: var(--space-3);
    padding: var(--space-1) var(--space-2);
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.1) 0%, rgba(59, 130, 246, 0.1) 100%);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    color: var(--text-muted);
  }

  /* ==========================================
     RUNNER UP
     ========================================== */
  .result-runner-up {
    margin-top: var(--space-4);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
  }

  .runner-up-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--text-muted);
    margin-bottom: var(--space-3);
  }

  .runner-up-card {
    display: flex;
    align-items: center;
    gap: var(--space-3);
  }

  .runner-up-swatch {
    width: 40px;
    height: 25px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
  }

  .runner-up-name {
    flex: 1;
    font-size: var(--text-sm);
    color: var(--text-secondary);
  }

  .runner-up-rate {
    font-size: var(--text-base);
    font-weight: var(--weight-bold);
    color: var(--success);
  }

  /* ==========================================
     EMPTY STATE
     ========================================== */
  .advisor-empty {
    text-align: center;
    padding: var(--space-12) var(--space-5);
    background: var(--bg-elevated);
    border-radius: var(--radius-2xl);
    box-shadow: var(--shadow-sm);
  }

  .advisor-empty-icon {
    font-size: 4rem;
    margin-bottom: var(--space-4);
    opacity: 0.3;
  }

  .advisor-empty h3 {
    font-size: var(--text-lg);
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
  }

  .advisor-empty p {
    color: var(--text-muted);
  }

  /* ==========================================
     LOADING STATE
     ========================================== */
  .advisor-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: var(--space-10);
  }

  .advisor-loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: var(--space-4);
  }

  @keyframes spin {
    to { transform: rotate(360deg); }
  }

  .advisor-loading p {
    color: var(--text-muted);
    font-size: var(--text-sm);
  }

  /* ==========================================
     RESPONSIVE
     ========================================== */
  @media (min-width: 640px) {
    .advisor-ghost {
      font-size: var(--text-2xl);
    }

    .advisor-search-input {
      height: 72px;
      font-size: var(--text-2xl);
    }

    .advisor-conveyor-text span {
      font-size: var(--text-2xl);
    }

    .advisor-search-btn {
      width: 72px;
      height: 72px;
    }

    .advisor-search-btn svg {
      width: 28px;
      height: 28px;
    }

    .result-rate-value {
      font-size: 4rem;
    }

    .result-card-visual {
      width: 120px;
      height: 76px;
    }

    .result-card-name {
      font-size: var(--text-2xl);
    }
  }

  @media (min-width: 1024px) {
    .advisor-ghost {
      font-size: var(--text-3xl);
    }

    .advisor-search-input {
      height: 76px;
      font-size: var(--text-3xl);
    }

    .advisor-conveyor-text span {
      font-size: var(--text-3xl);
    }

    .advisor-search-btn {
      width: 76px;
      height: 76px;
    }

    .advisor-search-btn svg {
      width: 30px;
      height: 30px;
    }
  }

  /* ==========================================
     MOBILE — 480px
     ========================================== */
  @media (max-width: 480px) {
    .advisor-conveyor {
      min-height: calc(70dvh - var(--nav-height));
      padding: var(--space-4) 0;
    }
    .advisor-conveyor--active {
      min-height: auto;
      padding-top: var(--space-4);
    }
    .advisor-category-list {
      padding-left: var(--space-3);
      gap: 0 var(--space-3);
    }
    .advisor-category-name {
      font-size: var(--text-xs);
    }
    .advisor-search-input {
      font-size: 16px; /* iOS zoom prevention */
      height: 52px;
    }
    .advisor-search-btn {
      width: 52px;
      height: 52px;
    }
    .result-body {
      padding: var(--space-4);
    }
    .result-explanation {
      padding: var(--space-3);
      font-size: var(--text-xs);
    }
    .result-card-display {
      gap: var(--space-3);
      margin-bottom: var(--space-3);
    }
    .result-card-visual {
      width: 80px;
      height: 50px;
    }
  }

  /* ==========================================
     REDUCED MOTION
     ========================================== */
  @media (prefers-reduced-motion: reduce) {
    .advisor-search-input,
    .advisor-search-btn,
    .advisor-category-item {
      transition: none !important;
    }

    .advisor-video-bg {
      display: none !important;
    }
  }

  /* Gemini Badge */
  .gemini-badge {
    display: flex;
    align-items: center;
    opacity: 0.7;
    transition: opacity 0.2s;
  }

  .gemini-badge:hover {
    opacity: 1;
  }

  /* Clear button: keep compact on mobile, shift right */
  @media (max-width: 480px) {
    .advisor-search-clear {
      right: var(--space-3);
      width: 28px;
      height: 28px;
    }
    .advisor-search-input {
      padding-right: calc(var(--space-3) + 36px);
    }
  }

}
