:root {
    --bg: #000000;
    --surface: #111111;
    --surface-light: #1c1c1e;
    --border: rgba(255, 255, 255, 0.1);
    --text: #ffffff;
    --text-muted: rgba(255, 255, 255, 0.6);
    --primary: #ec4899;
    --secondary: #8b5cf6;
    --gradient: linear-gradient(135deg, #ec4899 0%, #8b5cf6 100%);
    --font: 'Space Grotesk', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    height: 100%;
    height: 100dvh;
    overflow: hidden;
}

.ai-app {
    position: relative;
    max-width: 500px;
    margin: 0 auto;
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding: env(safe-area-inset-top, 2rem) 1.5rem env(safe-area-inset-bottom, 0) 1.5rem;
    overflow: hidden;
}

/* 3D Neural Network Background */
#nexus-ai-bg {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: -1;
    pointer-events: none;
}

/* Big Ambient Glow (Top Left) */
.ambient-glow {
    position: absolute;
    top: -100px;
    left: -50px;
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, rgba(236,72,153,0.5) 0%, rgba(139,92,246,0.25) 50%, transparent 70%);
    filter: blur(60px);
    z-index: 0;
    pointer-events: none;
}

/* Header */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
    position: relative;
    margin-bottom: 2rem;
}

.menu-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    color: white;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.premium-btn {
    background: #000000;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: white;
    padding: 0.6rem 1.2rem;
    border-radius: 100px;
    font-weight: 600;
    font-family: var(--font);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    cursor: pointer;
}

/* Home Screen Title */
.hero-title {
    font-size: 2.25rem;
    font-weight: 700;
    line-height: 1.2;
    margin-bottom: 1.5rem;
    z-index: 10;
    position: relative;
    letter-spacing: -0.5px;
}

/* Search Bar */
.search-box {
    position: relative;
    z-index: 10;
    margin-bottom: 2rem;
}

.search-box i {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-box input {
    width: 100%;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 100px;
    padding: 1rem 1rem 1rem 3rem;
    color: white;
    font-family: var(--font);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

.search-box input:focus {
    border-color: var(--text);
}

/* Horizontal Tools Scroll */
.tools-scroll {
    display: flex;
    overflow-x: auto;
    gap: 1rem;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    -ms-overflow-style: none;
    scrollbar-width: none;
    z-index: 10;
    position: relative;
}

.tools-scroll::-webkit-scrollbar { display: none; }

.tool-card {
    min-width: 140px;
    height: 140px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(255,255,255,0.02);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    cursor: pointer;
    transition: background 0.3s;
}

.tool-card:hover {
    background: rgba(255,255,255,0.05);
}

.tool-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.2;
}

.tool-card i.arrow {
    align-self: flex-end;
    color: var(--text-muted);
}

/* History Section */
.history-section {
    z-index: 10;
    position: relative;
    display: flex;
    flex-direction: column;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.history-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.history-header span {
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    cursor: pointer;
}

.hi-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    font-size: 1.2rem;
}

.hi-icon i {
    z-index: 2;
}

.hi-icon::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    background: var(--gradient);
    filter: blur(10px);
    z-index: 1;
}

.hi-content {
    flex: 1;
}

.hi-title {
    font-weight: 600;
    font-size: 1rem;
}

.hi-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.hi-arrow {
    color: var(--text-muted);
}

/* Bottom Input Area */
.chat-input-wrapper {
    position: fixed;
    bottom: max(24px, env(safe-area-inset-bottom, 24px));
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 500px;
    padding: 0 1.5rem;
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    z-index: 1000;
}

.chat-input-box {
    flex: 1;
    background: #1a1a1a;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 20px;
    padding: 0.6rem 0.5rem 0.6rem 1rem;
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    transition: border-color 0.3s;
}
.chat-input-box:focus-within {
    border-color: rgba(255,255,255,0.3);
}

.chat-input-box textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-family: var(--font);
    font-size: 0.95rem;
    outline: none;
    resize: none;
    max-height: 120px;
    line-height: 1.4;
    padding: 0.2rem 0;
}

.chat-input-box textarea::placeholder {
    color: rgba(255,255,255,0.4);
}

.mic-btn, .send-chat-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: white;
    background: transparent;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
    flex-shrink: 0;
}

.mic-btn:hover {
    background: rgba(255,255,255,0.1);
}

.send-chat-btn {
    color: var(--bg);
    background: white;
}
.send-chat-btn:hover {
    background: #e5e7eb;
}

.mic-btn:active, .send-chat-btn:active {
    transform: scale(0.9);
}

.plus-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #1a1a1a;
    color: white;
    cursor: pointer;
    flex-shrink: 0;
    margin-bottom: 2px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}

/* ================== CHAT FEED SCREEN ================== */
.chat-feed-screen {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg);
    z-index: 50;
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-feed-screen.active {
    transform: translateX(0);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-direction: column;
    text-align: center;
}

.ch-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.ch-icon i { z-index: 2; }
.ch-icon::after {
    content: '';
    position: absolute;
    width: 15px;
    height: 15px;
    background: var(--gradient);
    filter: blur(8px);
    z-index: 1;
}

.ch-title h3 {
    font-size: 1.1rem;
    font-weight: 700;
}

.ch-title span {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding-bottom: 6rem;
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.messages-area::-webkit-scrollbar { display: none; }

.msg {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    gap: 0.5rem;
}

.msg.user {
    align-self: flex-end;
}

.msg.ai {
    align-self: flex-start;
}

.msg-bubble {
    padding: 1rem 1.25rem;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.msg.user .msg-bubble {
    background: var(--gradient);
    border-radius: 20px 20px 0px 20px;
    color: white;
}

.msg.ai .msg-bubble {
    background: var(--surface-light);
    border-radius: 20px 20px 20px 0px;
    color: rgba(255,255,255,0.9);
}

.msg.ai .ai-actions {
    display: flex;
    gap: 1rem;
    margin-top: 0.5rem;
    padding-left: 0.5rem;
}

.ai-actions i {
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
}

.msg-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    align-self: flex-end;
    margin-top: 0.5rem;
}

.typing-cluster {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.typing-cluster .hi-icon {
    width: 30px; height: 30px; border: none; font-size: 0.8rem; margin-right: 0.5rem;
}
.dots span {
    display: inline-block;
    width: 6px; height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    margin: 0 2px;
    animation: typing 1.4s infinite forwards;
}
.dots span:nth-child(1) { animation-delay: 0s; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0% { transform: translateY(0); opacity: 0.5; }
    50% { transform: translateY(-4px); opacity: 1; }
    100% { transform: translateY(0); opacity: 0.5; }
}

/* ========================================================= */
/* AI FUNCTION CALLING UI WIDGETS */
/* ========================================================= */

.ai-ui-carousel {
    display: flex;
    overflow-x: auto;
    gap: 1rem;
    padding: 0.5rem 0 1rem 0;
    margin-top: 1rem;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
}

.ai-ui-carousel::-webkit-scrollbar {
    display: none;
}

.ai-ui-card {
    flex: 0 0 85%;
    max-width: 280px;
    scroll-snap-align: center;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    overflow: hidden;
    backdrop-filter: blur(10px);
}

.ai-ui-img {
    width: 100%;
    height: 140px;
    object-fit: cover;
    display: block;
}

.ai-ui-details {
    padding: 1rem;
}

.ai-ui-details h4 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: white;
}

.ai-ui-meta {
    font-size: 0.85rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.ai-ui-meta i {
    font-size: 0.8rem;
    color: #ffd700;
}

.ai-ui-tags {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ai-ui-btn {
    width: 100%;
    padding: 0.75rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    transition: background 0.3s ease;
}

.ai-ui-btn:active {
    background: var(--gradient);
}