/**
 * AI Tools Explorer - Styles
 * Always dark-mode; no dependency on frontend.css variables.
 */

/* ============================================================
   CUSTOM PROPERTIES
   Defined on :root so they stay available when the modal is
   detached from .ai-te-container and appended to <body>.
   ============================================================ */
:root {
    --te-bg:           #161616;
    --te-input-bg:     #242424;
    --te-surface:      #1e1e1e;
    --te-card:         #242424;
    --te-card-hover:   #2c2c2c;
    --te-border:       #333333;
    --te-border-hover: #e63946;
    --te-text:         #f0f0f0;
    --te-text-muted:   #9ca3af;
    --te-text-dim:     #6b7280;
    --te-accent:       #e63946;
    --te-accent-hover: #c1121f;
    --te-accent-rgb:   230, 57, 70;
    --te-badge-free-bg:      rgba(34, 197, 94, 0.12);
    --te-badge-free-text:    #4ade80;
    --te-badge-paid-bg:      rgba(245, 158, 11, 0.12);
    --te-badge-paid-text:    #fbbf24;
    --te-badge-freemium-bg:  rgba(99, 102, 241, 0.12);
    --te-badge-freemium-text:#a5b4fc;
    --te-shadow-sm:    0 2px 8px rgba(0,0,0,0.4);
    --te-shadow-md:    0 8px 24px rgba(0,0,0,0.5);
    --te-radius-sm:    8px;
    --te-radius-md:    16px;
    --te-radius-pill:  999px;
    --te-footer-h:     72px;
}

/* ============================================================
   GLOBAL MODAL SCROLL LOCK
   ============================================================ */
body.ai-te-modal-open {
    overflow: hidden;
}

/* ============================================================
   SEARCH BAR
   ============================================================ */
.ai-te-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    display: block;
    width: 100%;
}

.ai-te-search {

    border-radius: 20px;

    width: 100%;
    box-sizing: border-box;
}

/* ============================================================
   MODE TOGGLE  (Tools / Ask)
   ============================================================ */
.ai-te-mode-toggle {
    display: inline-flex;
    align-items: center;
    background: var(--te-input-bg);
    border: 1.5px solid var(--te-border);
    border-radius: var(--te-radius-pill);
    padding: 3px;
    gap: 2px;
    margin-bottom: 10px;
}

.ai-te-mode-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 16px;
    border: none;
    border-radius: var(--te-radius-pill);
    background: transparent;
    color: var(--te-text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.18s, color 0.18s;
    line-height: 1;
    white-space: nowrap;
}

.ai-te-mode-btn:hover {
    color: var(--te-text);
}

.ai-te-mode-btn.ai-te-mode-active {
    background: var(--te-accent);
    color: #fff;
}

/* ============================================================
   Q&A SECTION  (Ask mode)
   ============================================================ */
.ai-te-qa-section {
    padding: 8px 0;
}

.ai-te-qa-content {
    color: var(--te-text);
    font-size: 15px;
    line-height: 1.75;
}

.ai-te-input-wrapper {
    display: flex;
    align-items: center;
    background: var(--te-input-bg);
    border: 1.5px solid var(--te-border);
    border-radius: var(--te-radius-pill);
    overflow: hidden;
    transition: border-color 0.2s;
    max-width: 700px;
}

.ai-te-input-wrapper:focus-within {
    border-color: var(--te-accent);
}

.ai-te-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--te-text);
    font-size: 15px;
    padding: 14px 18px;
    min-width: 0;
    box-shadow: none;
}

.ai-te-input::placeholder {
    color: var(--te-text-dim);
}

.ai-te-input:disabled {
    opacity: 0.5;
}

.ai-te-btn {
    flex-shrink: 0;
    background: var(--te-accent);
    border: none;
    border-radius: 0 var(--te-radius-pill) var(--te-radius-pill) 0;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 48px;
    padding: 0;
    transition: background 0.2s;
}

.ai-te-btn:hover:not(:disabled) {
    background: var(--te-accent-hover);
}

.ai-te-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-te-subtitle {
    margin: 10px 0 0;
    color: var(--te-text-dim);
    font-size: 13px;
    line-height: 1.5;
}

.ai-te-error {
    color: #f87171;
    font-size: 13px;
    margin-top: 8px;
    min-height: 18px;
}

/* ============================================================
   FULLSCREEN MODAL (results panel)
   ============================================================ */
.ai-te-results.ai-te-modal {
    position: fixed;
    top: var(--ai-te-modal-top, 0px);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(13, 13, 13, 0.97);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 999999;
    display: flex !important;
    flex-direction: column;
    overflow: hidden;
}

.ai-te-results.ai-te-modal.ai-te-enter {
    animation: aiTeModalEnter 0.25s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
.ai-te-results.ai-te-modal.ai-te-leave {
    animation: aiTeModalLeave 0.2s ease-in forwards;
}

@keyframes aiTeModalEnter {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes aiTeModalLeave {
    from { opacity: 1; transform: translateY(0); }
    to   { opacity: 0; transform: translateY(12px); }
}

/* ============================================================
   CLOSE BUTTON
   ============================================================ */
.ai-te-close {
    position: absolute;
    top: 16px;
    right: var(--ai-te-close-right, 20px);
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--te-border);
    border-radius: 50%;
    color: var(--te-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    transition: background 0.15s, color 0.15s;
    z-index: 10;
    flex-shrink: 0;
}

.ai-te-close:hover {
    background: rgba(255,255,255,0.12);
    color: var(--te-text);
}

/* ============================================================
   SCROLLABLE BODY
   ============================================================ */
.ai-te-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 56px 24px calc(var(--te-footer-h) + 20px);
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Narrow the content for readability */
.ai-te-body > * {
    max-width: 960px;
    margin-left: auto;
    margin-right: auto;
}

/* ============================================================
   LOADER / ORB
   ============================================================ */
.ai-te-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 20px;
}

.ai-te-orb {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 35%,
        rgba(var(--te-accent-rgb), 0.9),
        rgba(var(--te-accent-rgb), 0.4) 50%,
        rgba(30, 30, 30, 0.8) 100%
    );
    box-shadow: 0 0 24px rgba(var(--te-accent-rgb), 0.4);
    animation: aiTeOrbSpin 2s linear infinite;
    flex-shrink: 0;
}

@keyframes aiTeOrbSpin {
    0%   { transform: rotate(0deg) scale(1);    box-shadow: 0 0 24px rgba(var(--te-accent-rgb), 0.5); }
    50%  { transform: rotate(180deg) scale(1.1); box-shadow: 0 0 32px rgba(var(--te-accent-rgb), 0.7); }
    100% { transform: rotate(360deg) scale(1);   box-shadow: 0 0 24px rgba(var(--te-accent-rgb), 0.5); }
}

.ai-te-loader-text {
    color: var(--te-text-muted);
    font-size: 14px;
    text-align: center;
}

/* ============================================================
   SECTION TITLES
   ============================================================ */
.ai-te-query-heading {
    color: var(--te-text);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 20px;
    padding: 0 0 16px;
    border-bottom: 1px solid var(--te-border);
    line-height: 1.3;
}

.ai-te-section-title {
    color: var(--te-text);
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin: 0 0 16px;
    padding: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-te-section-title::before {
    content: '';
    display: inline-block;
    width: 3px;
    height: 18px;
    background: var(--te-accent);
    border-radius: 2px;
    flex-shrink: 0;
}

/* ============================================================
   TOOL CARDS SECTION
   ============================================================ */
.ai-te-cards-section {
    margin-bottom: 40px;
}

.ai-te-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}

/* Individual Card — also used as <a> when URL present */
.ai-te-card {
    background: var(--te-card);
    border: 1.5px solid var(--te-border);
    border-radius: var(--te-radius-md);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
}

.ai-te-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--te-accent), transparent);
    opacity: 0;
    transition: opacity 0.2s;
}

.ai-te-card:hover {
    transform: translateY(-3px);
    border-color: rgba(var(--te-accent-rgb), 0.5);
    background: var(--te-card-hover);
    box-shadow: var(--te-shadow-md);
}

.ai-te-card:hover::before {
    opacity: 1;
}

/* Card top row: name + category */
.ai-te-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.ai-te-card-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--te-text);
    line-height: 1.3;
    flex: 1;
}


/* Description */
.ai-te-card-desc {
    font-size: 13px;
    color: var(--te-text-muted);
    line-height: 1.6;
    flex: 1;
}

/* Footer: pricing badge + link */
.ai-te-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
}

/* Pricing badges */
.ai-te-badge {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 3px 10px;
    border-radius: var(--te-radius-pill);
}

.ai-te-badge--free {
    background: var(--te-badge-free-bg);
    color: var(--te-badge-free-text);
}

.ai-te-badge--paid {
    background: var(--te-badge-paid-bg);
    color: var(--te-badge-paid-text);
}

.ai-te-badge--freemium {
    background: var(--te-badge-freemium-bg);
    color: var(--te-badge-freemium-text);
}

/* Visit indicator (now a <span> inside a fully-clickable card) */
.ai-te-card-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--te-accent);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none; /* card <a> handles the click */
}

.ai-te-card:hover .ai-te-card-link {
    color: var(--te-accent-hover);
}

.ai-te-card-link svg {
    flex-shrink: 0;
}

/* ============================================================
   ELABORATION SECTION (markdown article)
   ============================================================ */
.ai-te-elaboration {
    border-top: 1px solid var(--te-border);
    padding-top: 32px;
}

.ai-te-article {
    color: var(--te-text-muted);
    font-size: 15px;
    line-height: 1.75;
}

.ai-te-article p {
    margin: 0 0 16px;
}

.ai-te-article h1,
.ai-te-article h2,
.ai-te-article h3,
.ai-te-article h4 {
    color: var(--te-text);
    font-weight: 700;
    margin: 24px 0 10px;
    line-height: 1.35;
}

.ai-te-article h1 { font-size: 22px; }
.ai-te-article h2 { font-size: 19px; }
.ai-te-article h3 { font-size: 17px; }
.ai-te-article h4 { font-size: 15px; }

.ai-te-article strong { color: var(--te-text); font-weight: 600; }
.ai-te-article em     { font-style: italic; color: var(--te-text-muted); }

.ai-te-article ul,
.ai-te-article ol {
    margin: 0 0 16px 20px;
    padding: 0;
}

.ai-te-article li {
    margin-bottom: 6px;
}

.ai-te-article code {
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--te-border);
    border-radius: 4px;
    font-family: "Fira Code", "Cascadia Code", "Consolas", monospace;
    font-size: 13px;
    padding: 1px 6px;
    color: #f9a8d4;
}

.ai-te-article pre {
    background: #111;
    border: 1px solid var(--te-border);
    border-radius: var(--te-radius-sm);
    padding: 16px;
    overflow-x: auto;
    margin: 0 0 16px;
}

.ai-te-article pre code {
    background: transparent;
    border: none;
    padding: 0;
    font-size: 13px;
    color: #e5e7eb;
}

.ai-te-article hr {
    border: none;
    border-top: 1px solid var(--te-border);
    margin: 24px 0;
}

/* Table */
.ai-te-article .ai-te-table-wrapper {
    overflow-x: auto;
    margin: 0 0 16px;
}

.ai-te-article table {
    border-collapse: collapse;
    width: 100%;
    font-size: 14px;
}

.ai-te-article th,
.ai-te-article td {
    border: 1px solid var(--te-border);
    padding: 8px 12px;
    text-align: left;
}

.ai-te-article th {
    background: rgba(255,255,255,0.04);
    color: var(--te-text);
    font-weight: 600;
}

/* Links inside article */
.ai-te-article a.ai-te-link {
    color: var(--te-accent);
    text-decoration: none;
    font-weight: 500;
}

.ai-te-article a.ai-te-link:hover {
    text-decoration: underline;
}

/* References styling */
.ai-te-article h4.ai-te-refs-title {
    color: var(--te-text-muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 32px 0 16px;
    border-top: 1px solid var(--te-border);
    padding-top: 24px;
}

.ai-te-article ul.ai-te-refs {
    list-style: none;
    margin: 0 0 24px;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
}

.ai-te-article ul.ai-te-refs li {
    margin: 0;
}

/* Reference Card */
.ai-te-ref-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--te-border);
    border-radius: 10px;
    padding: 10px 12px;
    text-decoration: none;
    transition: all 0.2s ease;
    height: 100%;
}

.ai-te-ref-card:hover {
    background: rgba(255,255,255,0.06);
    border-color: var(--te-text-muted);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.ai-te-ref-icon-wrap {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    background: rgba(255,255,255,0.1);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ai-te-ref-icon {
    width: 16px;
    height: 16px;
    object-fit: contain;
    border-radius: 2px;
}

.ai-te-ref-meta {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    gap: 2px;
}

.ai-te-ref-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--te-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.ai-te-ref-domain {
    font-size: 11px;
    color: var(--te-text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-te-ref-card:hover .ai-te-ref-title {
    color: var(--te-accent);
}

/* Streaming cursor */
.ai-te-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--te-accent);
    margin-left: 2px;
    border-radius: 1px;
    vertical-align: text-bottom;
    animation: aiTeCursorBlink 0.9s step-end infinite;
}

@keyframes aiTeCursorBlink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* ============================================================
   FOOTER BAR
   ============================================================ */
.ai-te-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(13, 13, 13, 0.96);
    border-top: 1px solid var(--te-border);
    padding: 12px 24px 14px;
    backdrop-filter: blur(8px);
    z-index: 5;
}

.ai-te-footer-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 960px;
    margin: 0 auto;
}

.ai-te-followup {
    flex: 1;
    background: var(--te-input-bg);
    border: 1.5px solid var(--te-border);
    border-radius: var(--te-radius-pill);
    color: var(--te-text);
    font-size: 14px;
    outline: none;
    padding: 10px 16px;
    min-width: 0;
    transition: border-color 0.2s;
    box-shadow: none;
}

.ai-te-followup::placeholder {
    color: var(--te-text-dim);
}

.ai-te-followup:focus {
    border-color: var(--te-accent);
}

.ai-te-followup:disabled {
    opacity: 0.5;
}

.ai-te-followup-btn {
    flex-shrink: 0;
    background: var(--te-accent);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    transition: background 0.15s;
}

.ai-te-followup-btn:hover:not(:disabled) {
    background: var(--te-accent-hover);
}

.ai-te-followup-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-te-stop {
    flex-shrink: 0;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--te-border);
    border-radius: 50%;
    color: var(--te-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    transition: background 0.15s, color 0.15s;
}

.ai-te-stop:hover:not(:disabled) {
    background: rgba(230, 57, 70, 0.15);
    border-color: var(--te-accent);
    color: var(--te-accent);
}

.ai-te-stop:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
    .ai-te-search {
        padding: 20px 16px;
        border-radius: 14px;
    }

    .ai-te-body {
        padding: 48px 16px calc(var(--te-footer-h) + 16px);
    }

    .ai-te-cards-grid {
        grid-template-columns: 1fr;
    }

    .ai-te-footer {
        padding: 10px 16px 12px;
    }
}
