/* ── APP.CSS ── */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg: #06060f;
    --bg2: #0c0c1e;
    --purple: #7c3aed;
    --purple2: #a78bfa;
    --cyan: #22d3ee;
    --border: rgba(124, 58, 237, 0.25);
    --surface: rgba(255, 255, 255, 0.04);
    --text: #f1f5f9;
    --muted: #94a3b8;
}

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── NAV ── */
.nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 4%;
    height: 64px;
    background: rgba(6, 6, 15, 0.85);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
}

.nav-brand {
    font-size: 1.25rem;
    font-weight: 800;
    text-decoration: none;
    color: var(--text);
}

.nav-brand .ai {
    color: var(--purple2);
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.user-chip {
    background: rgba(124, 58, 237, 0.15);
    border: 1px solid var(--border);
    color: var(--purple2);
    font-size: 0.82rem;
    font-weight: 600;
    padding: 5px 14px;
    border-radius: 40px;
}

.logout-btn {
    padding: 7px 16px;
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.3);
    color: #f87171;
    border-radius: 8px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: rgba(248, 113, 113, 0.25);
}

.nav-login {
    padding: 8px 20px;
    background: var(--purple);
    color: #fff;
    text-decoration: none;
    border-radius: 40px;
    font-size: 0.9rem;
    font-weight: 600;
    transition: background 0.2s;
}

.nav-login:hover {
    background: #6d28d9;
}

/* ── MAIN LAYOUT ── */
.app-main {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 28px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 92px 24px 40px;
    min-height: 100vh;
}

/* ── EXPLAINER PANEL ── */
.explainer-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.panel-header h1 {
    font-size: 2rem;
    font-weight: 900;
    margin-bottom: 6px;
}

.panel-header .grad {
    background: linear-gradient(135deg, var(--purple2), var(--cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.panel-header p {
    color: var(--muted);
    font-size: 0.95rem;
}

.search-box {
    display: flex;
    gap: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 8px;
    backdrop-filter: blur(8px);
    transition: border-color 0.3s;
}

.search-box:focus-within {
    border-color: var(--purple2);
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    padding: 10px 14px;
}

.search-box input::placeholder {
    color: var(--muted);
}

.search-box button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: linear-gradient(135deg, var(--purple), #6366f1);
    color: #fff;
    border: none;
    border-radius: 12px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    white-space: nowrap;
}

.search-box button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 24px rgba(124, 58, 237, 0.4);
}

.search-box button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Suggestions */
.suggestions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.sug-label {
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
}

.sug-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--muted);
    padding: 5px 14px;
    border-radius: 40px;
    font-family: 'Outfit', sans-serif;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s;
}

.sug-chip:hover {
    border-color: var(--purple2);
    color: var(--text);
}

/* Result Card */
.result-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 28px;
    min-height: 220px;
    backdrop-filter: blur(8px);
    transition: border-color 0.3s;
    flex: 1;
}

.result-card.active {
    border-color: var(--purple);
}

.result-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 180px;
    gap: 12px;
    color: var(--muted);
}

.ph-icon {
    font-size: 3rem;
}

.result-placeholder p {
    font-size: 0.95rem;
}

.section {
    background: rgba(12, 12, 30, 0.8);
    border-left: 3px solid var(--purple);
    border-radius: 12px;
    padding: 18px 20px;
    margin-bottom: 14px;
    animation: slideIn 0.4s ease both;
}

.section:last-child {
    margin-bottom: 0;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-12px);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.tag {
    display: block;
    font-size: 0.72rem;
    color: var(--purple2);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
}

.section p {
    font-size: 0.97rem;
    color: #d1d5db;
    line-height: 1.8;
    min-height: 1.2em;
}

.loading-state {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--purple2);
    padding: 20px 0;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(124, 58, 237, 0.3);
    border-top-color: var(--purple2);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.error-state {
    color: #f87171;
    padding: 16px 0;
}

/* ── HISTORY PANEL ── */
.history-panel {
    position: sticky;
    top: 80px;
    height: calc(100vh - 100px);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 20px;
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history-header {
    padding: 20px 20px 14px;
    border-bottom: 1px solid var(--border);
}

.history-header h3 {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.hist-sub {
    font-size: 0.78rem;
    color: var(--muted);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--purple) transparent;
}

.hist-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 10px;
    color: var(--muted);
    text-align: center;
    padding: 20px;
}

.hist-empty p {
    font-size: 0.88rem;
}

.hist-login-btn {
    display: inline-block;
    margin-top: 10px;
    padding: 9px 20px;
    background: var(--purple);
    color: #fff;
    text-decoration: none;
    border-radius: 40px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.2s;
}

.hist-login-btn:hover {
    background: #6d28d9;
}

.hist-item {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.2s, transform 0.2s;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.hist-item:hover {
    border-color: var(--purple2);
    transform: translateX(3px);
}

.hist-item-body {
    flex: 1;
    min-width: 0;
}

.hist-topic {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.hist-date {
    font-size: 0.72rem;
    color: var(--muted);
    margin-top: 3px;
}

.hist-del {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 4px;
    opacity: 0.5;
    transition: opacity 0.2s, color 0.2s;
    flex-shrink: 0;
}

.hist-del:hover {
    opacity: 1;
    color: #f87171;
}

@media (max-width: 900px) {
    .app-main {
        grid-template-columns: 1fr;
    }

    .history-panel {
        position: static;
        height: 350px;
    }
}