/**
 * Trinity - Sistema de Busca v5.0 REFINADO
 * ✅ Botões sem envoltório
 * ✅ Botões menores e mais elegantes
 * ✅ Ícones seguem cor do texto (dark/light)
 * ✅ Título Trinity próximo dos botões
 * ✅ Input com gradiente no focus
 */

/* ==================== LAYOUT E HERO ==================== */

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 16px 40px;
}

.hero {
    position: relative;
    min-height: 62svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding-top: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

body.search-active .hero,
body.has-results .hero {
    min-height: 0;
    place-items: start;
    text-align: left;
    padding-top: 24px;
}

.hero-title {
    margin-bottom: 12px; /* ✅ MODO NORMAL: mais espaçamento */
    font-size: 2.2rem;
    font-weight: 900;
    letter-spacing: 0.2px;
    font-family: "Segoe UI Variable", system-ui;
    background: var(--gradient-2);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    filter: drop-shadow(0 0 30px var(--shadow-color));
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: margin-bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ✅ MODO ATIVO: título muito próximo dos botões */
body.search-active .hero-title,
body.has-results .hero-title {
    margin-bottom: 2px;
}

.beta-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.5rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 12px;
    background: var(--gradient-2);
    color: var(--bg);
    text-transform: uppercase;
    letter-spacing: 1px;
    vertical-align: super;
    box-shadow: 0 2px 8px var(--shadow-color), var(--glow);
    animation: betaPulse 3s ease-in-out infinite;
}

@keyframes betaPulse {
    0%, 100% {
        transform: translateY(0);
        opacity: 1;
    }
    50% {
        transform: translateY(-2px);
        opacity: 0.9;
    }
}

/* ==================== SEARCH WRAPPER ==================== */

.search-wrapper {
    width: clamp(240px, 36vw, 580px);
    margin: 0 auto;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

body.search-active .search-wrapper {
    width: 100%;
}

/* ==================== MODE SELECTOR (BOTÕES SEM ENVOLTÓRIO) ==================== */

.mode-selector {
    /* ✅ SEM ENVOLTÓRIO: Apenas container flex limpo */
    display: none;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    margin: 0 0 5px 0; /* ✅ 5px de espaço até o input */
    margin-left: auto;
    width: fit-content;
    max-width: 100%;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.search-active .mode-selector {
    display: flex;
    opacity: 1;
    transform: translateY(0);
}

/* ✅ BOTÕES MENORES E MAIS ELEGANTES */
.mode-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 5px 10px; /* ✅ REDUZIDO */
    border-radius: 16px; /* ✅ REDUZIDO */
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 0.75rem; /* ✅ REDUZIDO */
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    white-space: nowrap;
    min-height: 28px; /* ✅ REDUZIDO */
    will-change: transform, background-color;
}

.mode-btn svg {
    width: 14px; /* ✅ REDUZIDO */
    height: 14px; /* ✅ REDUZIDO */
    transition: all 0.25s ease;
    flex-shrink: 0;
}

.mode-btn:not(.active):hover {
    background: color-mix(in srgb, var(--accent) 8%, transparent);
    color: var(--fg);
}

.mode-btn:not(.active):hover svg {
    transform: scale(1.1);
}

/* ✅ BOTÃO ATIVO - DARK THEME: Ícone segue cor do texto */
[data-theme="dark"] .mode-btn.active {
    background: color-mix(in srgb, var(--fg) 95%, var(--bg));
    color: var(--bg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .mode-btn.active svg {
    /* ✅ ÍCONE SEGUE A COR DO TEXTO (dark) */
    stroke: var(--bg);
    opacity: 1;
    filter: none;
}

/* ✅ BOTÃO ATIVO - LIGHT THEME: Ícone segue cor do texto */
[data-theme="light"] .mode-btn.active {
    background: color-mix(in srgb, var(--fg) 85%, var(--bg));
    color: var(--bg);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .mode-btn.active svg {
    /* ✅ ÍCONE SEGUE A COR DO TEXTO (light) */
    stroke: var(--bg);
    opacity: 1;
    filter: none;
}

/* Botões não ativos - Dark theme */
[data-theme="dark"] .mode-btn:not(.active) {
    color: color-mix(in srgb, var(--fg) 60%, transparent);
}

[data-theme="dark"] .mode-btn:not(.active) svg {
    stroke: currentColor;
    opacity: 0.6;
    filter: none;
}

/* Botões não ativos - Light theme */
[data-theme="light"] .mode-btn:not(.active) {
    color: color-mix(in srgb, var(--fg) 70%, transparent);
}

[data-theme="light"] .mode-btn:not(.active) svg {
    stroke: currentColor;
    opacity: 0.7;
    filter: none;
}

.mode-btn:active {
    transform: scale(0.96);
}

/* ==================== SEARCH INPUT ==================== */

.hero-input {
    width: 100%;
    margin: 0 auto 10px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: visible;
}

input[type="search"] {
    position: relative;
    appearance: none;
    width: 100%;
    padding: 12px 58px 12px 20px;
    border-radius: 21px;
    border: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
    background: var(--card);
    color: var(--fg);
    font-size: .98rem;
    font-family: inherit;
    font-weight: 400;
    box-shadow: var(--shadow-md),
                inset 0 1px 0 rgba(255, 255, 255, 0.03);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    will-change: transform, box-shadow;
}

input[type="search"]::-webkit-search-cancel-button {
    display: none;
}

input[type="search"]::placeholder {
    color: var(--muted);
}

input[type="search"]:hover {
    border-color: color-mix(in srgb, var(--accent) 35%, transparent);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg),
                inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

/* ✅ INPUT FOCUS COM GRADIENTE ANIMADO - LIMPO */
input[type="search"]:focus {
    outline: none;
    border: 2px solid transparent;
    background:
        linear-gradient(var(--card), var(--card)) padding-box,
        linear-gradient(135deg,
            #a2a4a5 0%,
            #929fa3 25%,
            #89a4a8 50%,
            #929fa3 75%,
            #a2a4a5 100%
        ) border-box;
    background-size: 200% 200%;
    animation: gradientFlow 3s ease infinite;
    transform: scale(1.002);
}

@keyframes gradientFlow {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

input[type="search"].has-icons {
    padding-right: 144px;
}

/* ==================== ÍCONES DO INPUT ==================== */

.input-icon {
    display: none;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: #9ca3af;
    cursor: pointer;
    padding: 0;
    margin: 0;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.6;
    line-height: 1;
    overflow: visible;
    z-index: 10;
}

.input-icon svg {
    width: 22px;
    height: 22px;
    display: block;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#clear-btn {
    right: 10px;
}

#search-btn {
    right: 54px;
}

#share-btn {
    right: 98px;
}

.input-icon:hover,
.input-icon:focus {
    color: var(--accent);
    opacity: 1;
    outline: none;
}

.input-icon:hover svg,
.input-icon:focus svg {
    transform: scale(1.2);
}

#clear-btn:hover svg,
#clear-btn:focus svg {
    transform: scale(1.2) rotate(90deg);
}

#share-btn:hover svg,
#share-btn:focus svg {
    transform: scale(1.2) translateY(-1px);
}

#search-btn:hover svg,
#search-btn:focus svg {
    transform: scale(1.2) rotate(-8deg);
}

#search-btn.searching svg {
    animation: searchPulse 1s ease-in-out infinite;
}

@keyframes searchPulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }
}

.input-icon:active {
    transform: translateY(-50%) scale(0.95);
}

/* ==================== RESULTS GRID ==================== */

.results-section {
    display: none;
    background: var(--card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 12px;
    border: 1px solid var(--border);
    margin-top: 20px;
    overflow: visible !important;
    position: relative;
    z-index: 40;
}

body.has-results .results-section {
    display: block;
}

.grid-container {
    position: relative;
    overflow: visible !important;
}

.grid-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: color-mix(in srgb, var(--card) 96%, var(--bg));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 2px solid var(--border);
    margin-bottom: 4px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.grid-row {
    display: grid;
    grid-template-columns: 1.2fr 1fr 1.5fr 80px;
    gap: 12px;
    align-items: center; /* ✅ Centraliza verticalmente */
}

.grid-row--header {
    padding: 8px 12px; /* ✅ REDUZIDO: header mais slim */
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.grid-body {
    position: relative;
}

.grid-row--item {
    padding: 7px 12px; /* ✅ REDUZIDO: linhas mais slim */
    border-radius: var(--radius-sm);
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    margin-bottom: 3px; /* ✅ REDUZIDO: menos espaço entre linhas */
    background: color-mix(in srgb, var(--card) 40%, transparent);
    position: relative;
    z-index: 1;
    overflow: visible;
}

.grid-row--item:hover {
    transform: translateY(-2px) scale(1.005);
    background: color-mix(in srgb, var(--card) 80%, var(--accent));
    box-shadow: var(--shadow-lg),
                0 0 0 2px color-mix(in srgb, var(--accent) 15%, transparent),
                var(--glow);
    border-color: color-mix(in srgb, var(--accent) 40%, transparent);
    z-index: 200 !important;
}

.grid-row--item:active {
    transform: translateY(0) scale(0.995);
}

.grid-row--empty {
    text-align: center;
    color: var(--muted);
    padding: 40px 20px;
    font-size: 0.95rem;
}

.grid-cell {
    font-size: 0.85rem;
    color: var(--fg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.4;
}

/* ==================== BOTÕES DE AÇÃO ==================== */

.grid-cell-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 8px;
    /* ✅ Altura mínima para acomodar os botões de 34px */
    min-height: 34px;
}

/* ✅ Forçar alinhamento consistente para ambos os tipos de botão */
.grid-cell-actions > * {
    margin: 0;
    padding: 0;
    flex-shrink: 0;
}

.feedback-btn {
    position: relative;
    width: 34px; /* ✅ Aumentado para 34px */
    height: 34px;
    min-width: 34px;
    min-height: 34px;
    box-sizing: border-box;
    border-radius: var(--radius-full);
    border: 1.5px solid color-mix(in srgb, var(--border) 60%, transparent);
    background: var(--card);
    color: var(--muted);
    cursor: pointer;
    /* ✅ CORREÇÃO: inline-block + vertical-align para alinhar com xai-radial-menu */
    display: inline-block;
    vertical-align: middle;
    line-height: 34px; /* Centralizar verticalmente */
    text-align: center; /* Centralizar horizontalmente */
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    padding: 0;
    margin: 0;
    box-shadow: var(--shadow-sm),
                inset 0 1px 0 rgba(255, 255, 255, 0.03);
    overflow: visible;
    will-change: transform, box-shadow, filter;
}

.feedback-btn:hover {
    transform: scale(1.1) translateY(-2px);
    border-color: color-mix(in srgb, var(--accent) 40%, transparent);
    box-shadow: var(--shadow-lg),
                0 0 0 4px color-mix(in srgb, var(--accent) 8%, transparent),
                var(--glow);
}

.feedback-btn:active {
    transform: scale(1.05);
}

.feedback-btn svg {
    width: 60%;
    height: 60%;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    pointer-events: none;
    position: relative;
    z-index: 1;
    transition: all 0.3s ease, transform 0.3s ease;
    /* ✅ CORREÇÃO: Ajustar alinhamento vertical do SVG */
    vertical-align: middle;
    display: inline-block;
}

[data-theme="dark"] .feedback-btn svg {
    filter: brightness(0) saturate(100%) invert(85%) sepia(0%) saturate(0%) hue-rotate(0deg) brightness(100%) contrast(92%);
}

[data-theme="light"] .feedback-btn svg {
    filter: brightness(0) saturate(100%) invert(60%) sepia(0%) saturate(0%) hue-rotate(0deg) brightness(95%) contrast(90%);
}

[data-theme="dark"] .feedback-btn:hover svg {
    filter: brightness(0) saturate(100%) invert(100%) sepia(0%) saturate(0%) hue-rotate(0deg) brightness(105%) contrast(105%);
    transform: scale(1.1);
}

[data-theme="light"] .feedback-btn:hover svg {
    filter: brightness(0) saturate(100%) invert(0%) sepia(0%) saturate(0%) hue-rotate(0deg) brightness(10%) contrast(100%);
    transform: scale(1.1);
}

xai-radial-menu {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    display: inline-block;
    vertical-align: middle;
}

/* ==================== MOBILE CARDS ==================== */

.card-item {
    display: none;
    background: color-mix(in srgb, var(--card) 98%, var(--accent));
    border-radius: var(--radius-md);
    margin-bottom: 12px;
    padding: 16px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card-item:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    gap: 10px;
}

.card-title {
    flex: 1;
    font-weight: 700;
    font-size: 0.95rem;
    background: var(--gradient-2);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    line-height: 1.4;
}

.card-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    align-items: center;
}

.card-body {
    display: grid;
    gap: 10px;
}

.card-field {
    display: flex;
    gap: 10px;
    font-size: 0.85rem;
    line-height: 1.5;
}

.card-field-label {
    font-weight: 600;
    color: var(--muted);
    min-width: 90px;
}

.card-field-value {
    color: var(--fg);
    flex: 1;
    word-break: break-word;
}

/* ==================== LOADING STATES ==================== */

.loading-indicator {
    display: none;
    text-align: center;
    padding: 20px;
    color: var(--muted);
    font-size: 0.95rem;
}

.loading-indicator.show {
    display: block;
}

.state {
    display: none;
    padding: 12px 10px;
    color: var(--muted);
    font-size: 0.875rem;
    font-weight: 500;
}

body.has-results .state {
    display: block;
}

/* ==================== SKELETON LOADER ==================== */

.skeleton {
    display: none;
    padding: 8px 6px;
}

.skeleton.show {
    display: block;
}

.skeleton .sk-row {
    height: 60px;
    margin: 8px 0;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg,
        color-mix(in srgb, var(--border) 80%, transparent),
        color-mix(in srgb, var(--border) 60%, transparent),
        color-mix(in srgb, var(--border) 80%, transparent));
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
}

@keyframes skeletonShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==================== PAGINATION ==================== */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-top: 16px;
    padding: 12px;
    border-top: 1px solid var(--border);
}

.pagination button {
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--border);
    background: var(--card);
    color: var(--fg);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 600;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    box-shadow: var(--shadow-sm);
}

.pagination button:hover:not(:disabled) {
    background: var(--hover-bg);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.pagination button:active:not(:disabled) {
    transform: translateY(0);
}

.pagination button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-info {
    color: var(--fg);
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0 8px;
}

/* ==================== RESPONSIVE ==================== */

@media (max-width: 768px) {
    .grid-header {
        display: none;
    }

    .grid-row--item {
        display: none;
    }

    .card-item {
        display: block;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 0 12px 32px;
    }

    .hero {
        min-height: 40svh;
    }

    body.search-active .hero,
    body.has-results .hero {
        padding-top: 16px; /* ✅ Menos padding no mobile ativo */
    }

    .hero-title {
        font-size: 1.75rem;
        margin-bottom: 20px; /* ✅ MOBILE NORMAL: Bastante espaço */
    }

    /* ✅ Mobile ativo: título próximo */
    body.search-active .hero-title,
    body.has-results .hero-title {
        margin-bottom: 4px;
    }

    .search-wrapper {
        width: 100% !important;
    }

    input[type="search"] {
        padding: 10px 48px 10px 16px;
        font-size: 0.85rem;
        font-weight: 350;
        border-radius: 20px;
    }

    .input-icon {
        width: 32px;
        height: 32px;
    }

    .input-icon svg {
        width: 20px;
        height: 20px;
    }

    #clear-btn {
        right: 8px;
    }

    #search-btn {
        right: 46px;
    }

    #share-btn {
        right: 84px;
    }

    input[type="search"].has-icons {
        padding-right: 122px;
    }

    .results-section {
        padding: 10px;
        border-radius: var(--radius-sm);
    }

    /* Mobile: apenas ícones nos botões de modalidade */
    .mode-selector {
        gap: 4px;
        margin-bottom: 6px; /* ✅ 6px para melhor espaçamento no mobile */
    }

    .mode-btn {
        padding: 5px 7px;
        min-width: 32px;
        min-height: 26px;
    }

    .mode-btn span {
        display: none;
    }

    .mode-btn svg {
        width: 16px;
        height: 16px;
    }
}