/* Apple-Inspired Design System - Blue/Purple Theme */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Light Mode */
    --bg-app: #F5F5F7;
    --bg-surface: rgba(255, 255, 255, 0.85); /* Translucent */
    --bg-secondary: #FFFFFF;
    
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --text-tertiary: #C1C1C4;
    
    /* Brand Colors: Blue & Purple */
    --primary: #007AFF;
    --primary-gradient: linear-gradient(135deg, #007AFF 0%, #5856D6 100%);
    --primary-hover: #0062CC;
    --primary-light: rgba(0, 122, 255, 0.1);
    
    --accent: #5856D6; /* Purple */
    
    --danger: #FF3B30;
    --success: #34C759;
    --warning: #FF9500;
    
    --border: #D1D1D6;
    --divider: #E5E5EA;
    
    /* Apple Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.12);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 28px;
    
    --font-sans: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    
    --blur: 20px;
}

[data-theme='dark'] {
    --bg-app: #000000;
    --bg-surface: rgba(28, 28, 30, 0.85);
    --bg-secondary: #1C1C1E;
    
    --text-primary: #F5F5F7;
    --text-secondary: #86868B;
    --text-tertiary: #48484A;
    
    --primary: #0A84FF;
    --primary-gradient: linear-gradient(135deg, #0A84FF 0%, #5E5CE6 100%);
    --primary-hover: #409CFF;
    --primary-light: rgba(10, 132, 255, 0.15);
    
    --accent: #5E5CE6;
    
    --border: #38383A;
    --divider: #2C2C2E;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
}

/* Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    background-color: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative; /* For blob */
}

/* Background Blob */
.bg-blob {
    position: absolute;
    top: -200px;
    right: -200px;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(0, 122, 255, 0.15) 0%, rgba(88, 86, 214, 0.05) 50%, transparent 70%);
    filter: blur(80px);
    z-index: -1;
    border-radius: 50%;
    animation: blobFloat 20s infinite ease-in-out;
}

@keyframes blobFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(-30px, 50px) scale(1.1); }
    66% { transform: translate(-50px, -20px) scale(0.95); }
}

a { color: var(--primary); text-decoration: none; transition: opacity 0.2s; }
a:hover { opacity: 0.8; }

/* Glassmorphism Utilities */
.glass {
    background: var(--bg-surface);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Typography */
h1 { font-size: 2.5rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.75rem; font-weight: 600; letter-spacing: -0.015em; }
h3 { font-size: 1.25rem; font-weight: 600; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.8rem 1.8rem;
    border-radius: 999px; /* Pill */
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    border: none;
    transition: transform 0.1s ease, box-shadow 0.2s ease, opacity 0.2s;
    background: var(--primary);
    color: #fff;
    min-width: 100px;
}

.btn-gradient {
    background: var(--primary-gradient);
    box-shadow: 0 4px 12px rgba(88, 86, 214, 0.3);
}

.btn:active { transform: scale(0.97); }
.btn:hover { opacity: 0.9; box-shadow: var(--shadow-md); }

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid rgba(255, 59, 48, 0.2);
}
.btn-danger:hover { background: rgba(255, 59, 48, 0.05); }

/* Inputs */
input, textarea, select {
    width: 100%;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background-color: var(--bg-secondary); /* Usually solid for inputs */
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s;
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Layout */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem;
    width: 100%;
    flex: 1; /* Grow to fill available space */
    overflow-y: auto; /* Scroll internally if content is tall */
    -webkit-overflow-scrolling: touch;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.card {
    background: var(--bg-surface);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border-radius: var(--radius-xl);
    padding: 2.5rem;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
}

/* Header */
header {
    background: rgba(255, 255, 255, 0.7); /* Light mode specific translucent */
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border-bottom: 1px solid var(--border);
    padding: 0 2rem;
    height: 64px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 100;
}

[data-theme='dark'] header {
    background: rgba(28, 28, 30, 0.7);
}

header .logo-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

header .logo-icon {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

header .logo-text {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

header .logo-title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

header .status-indicator {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    color: var(--success);
    font-weight: 500;
}

header .status-dot {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
}

header .actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Chat Layout - Nexus Style */
#chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    scroll-behavior: smooth;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

/* Session Divider */
.session-divider {
    text-align: center;
    margin: 1rem 0;
    display: flex;
    justify-content: center;
}

.session-label {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    padding: 0.3rem 0.8rem;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Messages with Avatars */
.msg-row {
    display: flex;
    gap: 1rem;
    max-width: 90%;
    animation: fadeInUp 0.3s ease-out forwards;
}

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

.msg-row.bot-row {
    align-self: flex-start;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.25rem;
}

.bot-avatar {
    background: var(--primary);
    color: white;
}

.user-avatar {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.message {
    padding: 1rem 1.25rem;
    font-size: 1rem;
    line-height: 1.6;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.user-message {
    background: var(--primary);
    background: var(--primary-gradient);
    color: white;
    border-radius: 18px; /* Rounded pill */
}

/* Bot Message - White Card style */
.bot-message {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 0 18px 18px 18px; /* Square top-left */
    box-shadow: var(--shadow-sm);
}

[data-theme='dark'] .bot-message {
    background: #262628;
    border: 1px solid #38383A;
}

.bot-message strong { color: var(--accent); }

/* Input Area - Redesigned */
.input-area {
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    padding: 1rem 2rem 2rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    position: sticky;
    bottom: 0;
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
}

/* Quick Actions */
.quick-actions {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 0.8rem;
}

.action-pill {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    backdrop-filter: blur(10px);
    border-radius: 99px;
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}

.action-icon {
    font-size: 1.1rem;
    color: var(--primary);
}

.action-pill:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.15);
}

/* Input Wrapper Nexus Style */
.input-wrapper {
    background: var(--bg-app); 
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.8rem;
    display: flex;
    align-items: center; 
    gap: 0.8rem;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
    width: 100%;
    max-width: 800px;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.input-wrapper:focus-within {
    background: var(--bg-secondary);
    border-color: var(--primary); /* Keep border but make it consistent */
    box-shadow: 0 0 0 4px var(--primary-light); /* Soft glow instead of hard shadow */
}

.input-actions-left {
    display: flex;
    gap: 0.2rem;
    padding-left: 0.2rem;
    /* Removed border-right */
    padding-right: 0.5rem;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.3rem;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { 
    background: rgba(0,0,0,0.05); 
    color: var(--primary); 
}

.input-wrapper textarea {
    background: transparent;
    border: none;
    box-shadow: none !important;
    padding: 0.6rem 0; /* Slightly more vertical padding */
    min-height: 24px;
    max-height: 200px;
    resize: none; 
    font-size: 1rem;
    line-height: 1.5;
    flex: 1; 
    margin: 0;
    color: var(--text-primary);
}

.input-wrapper .send-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px; /* Rounded Square */
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    border: none;
    flex-shrink: 0;
    font-size: 1.1rem;
    transition: background 0.2s, transform 0.1s;
}
.input-wrapper .send-btn:hover { background: var(--primary-hover); transform: none; }

/* Login Page Only */
.login-bg {
    background: radial-gradient(circle at 50% 0%, rgba(88, 86, 214, 0.15), transparent 70%),
                radial-gradient(circle at 0% 100%, rgba(0, 122, 255, 0.1), transparent 50%);
}

.login-card {
    width: 100%;
    max-width: 420px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.7);
}

[data-theme='dark'] .login-card {
    background: rgba(28, 28, 30, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-icon {
    width: 64px;
    height: 64px;
    background: var(--primary-gradient);
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: white;
    margin-bottom: 1.5rem;
    box-shadow: 0 10px 30px rgba(0, 122, 255, 0.3);
}

/* Animations */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeInUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards; }

.loader {
    width: 1.2rem; height: 1.2rem;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Admin File List */
.file-list-container {
    background: var(--bg-secondary); 
    border-radius: var(--radius-md); 
    border: 1px solid var(--border);
}

.file-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.file-item:last-child { border-bottom: none; }

/* Theme Toggle */
.theme-toggle {
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem; /* Bottom Left */
    z-index: 200;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-surface);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    font-size: 1.2rem;
    color: var(--text-primary);
    transition: all 0.2s ease;
}
.theme-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
}
[data-theme='dark'] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* Chat Input Refinement */
.input-area {
    padding: 1.5rem 2rem 2rem;
    background: linear-gradient(to top, var(--bg-app) 20%, transparent 100%);
    position: sticky;
    bottom: 0;
    z-index: 50;
    display: flex;
    justify-content: center;
}

.input-wrapper {
    background: var(--bg-surface);
    backdrop-filter: blur(var(--blur));
    -webkit-backdrop-filter: blur(var(--blur));
    border: 1px solid var(--border);
    border-radius: 26px; /* Pill */
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    display: flex;
    align-items: flex-end;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 750px;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.input-wrapper textarea {
    background: transparent;
    border: none;
    box-shadow: none !important;
    padding: 0.8rem 0;
    min-height: 24px;
    max-height: 150px;
    resize: none; 
    font-size: 1rem;
    line-height: 1.5;
    flex: 1; /* Take remaining space */
    margin-right: 0.5rem;
}

/* Message Bubbles - Apple iMessage Style */
.message {
    max-width: 80%;
    padding: 0.8rem 1.2rem;
    font-size: 1rem;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05); /* very subtle */
    margin-bottom: 0.2rem; /* tight spacing */
    animation: fadeInUp 0.3s ease-out forwards;
}

.user-message {
    align-self: flex-end;
    background: var(--primary); /* Solid Blue usually, gradient is nice too */
    background: var(--primary-gradient);
    color: white;
    border-radius: 18px 18px 4px 18px;
    margin-left: auto; /* push right */
}

/* Small tail for user */
.user-message::after {
    content: "";
    position: absolute;
    bottom: 0;
    right: -6px;
    width: 12px;
    height: 12px;
    background: inherit;
    border-bottom-left-radius: 10px;
    z-index: -1;
    /* Create curve */
    /* This is tricky without intricate CSS/SVG. 
       Simple border-radius based tail is safer. 
       Let's stick to the bubble shape which implies a tail with the sharp corner. */
    display: none; 
}

.bot-message {
    align-self: flex-start;
    background: var(--bg-secondary); /* E5E5EA in light mode for Apple */
    color: var(--text-primary);
    border: 1px solid transparent; /* No border usually on iMessage received */
    border-radius: 18px 18px 18px 4px;
    margin-right: auto;
}

/* Dark mode adjustment for bot message to look like received iMessage */
[data-theme='dark'] .bot-message {
    background: #262628; /* Dark gray */
    border: 1px solid #38383A;
}

/* Admin Styles */
.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: rgba(0,0,0,0.02);
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.upload-area:hover, .upload-area.dragover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.log-container {
    overflow-x: auto;
    max-height: 400px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-secondary);
}

.log-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    font-family: monospace;
}

.log-table th, .log-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.log-table th {
    background: var(--bg-app);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
    color: var(--text-secondary);
    font-family: var(--font-sans);
}

.log-table tr:last-child td { border-bottom: none; }
.log-table tr:hover { background: rgba(0,0,0,0.02); }

[data-theme='dark'] .log-table tr:hover { background: rgba(255,255,255,0.03); }

.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.badge-info { background: rgba(0, 122, 255, 0.1); color: var(--primary); }
.badge-error { background: rgba(255, 59, 48, 0.1); color: var(--danger); }
.badge-warning { background: rgba(255, 149, 0, 0.1); color: var(--warning); }
.badge-success { background: rgba(52, 199, 89, 0.1); color: var(--success); }


