/* ===== CSS Custom Properties (Apple-inspired theme) ===== */
:root {
    --primary: #0071E3;
    --primary-hover: #0077ED;
    --primary-light: rgba(0, 113, 227, 0.08);
    --text-primary: #1D1D1F;
    --text-secondary: #86868B;
    --bg-primary: #FFFFFF;
    --bg-secondary: #F5F5F7;
    --bg-tertiary: #FAFAFA;
    --border: #D2D2D7;
    --border-light: #E8E8ED;
    --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-pill: 24px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --transition: 0.2s ease;
}

/* ===== Global Reset ===== */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font-family);
    -webkit-font-smoothing: antialiased;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: grid;
    grid-template-columns: 300px 1fr;
    height: 100vh;
    overflow: hidden;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

/* ===== Sidebar ===== */
#sidebar {
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Sidebar brand */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.brand-video {
    width: 100%;
    border-radius: var(--radius-md);
    display: block;
}

.brand-icon {
    font-size: 1.5rem;
}

.brand-text {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

#sidebar h4 {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 0 0.75rem;
}

/* ===== News Ticker ===== */
.news-section {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#news-ticker {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.news-item {
    display: block;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    text-decoration: none;
    color: var(--text-primary);
    transition: background var(--transition);
    border-bottom: 1px solid var(--border-light);
}

.news-item:hover {
    background: rgba(0, 0, 0, 0.04);
}

.news-item:last-child {
    border-bottom: none;
}

.news-title {
    font-size: 0.8rem;
    line-height: 1.4;
    font-weight: 500;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.news-meta {
    font-size: 0.65rem;
    color: var(--text-secondary);
    margin-top: 3px;
}

.news-loading {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 12px 10px;
}

/* ===== Conversations Section ===== */
.conversations-section {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    max-height: 40%;
    overflow-y: auto;
    flex-shrink: 0;
}

.btn-primary {
    width: 100%;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    padding: 10px;
    font-weight: 500;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font-family);
    margin-bottom: 0.75rem;
    transition: background var(--transition);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

/* Conversation list items */
.conv-item {
    padding: 4px 0;
    margin-bottom: 2px;
}

.conv-item.active .conv-title {
    color: var(--primary);
    font-weight: 500;
}

.conv-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.conv-title {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
    text-align: left;
    flex: 1;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-family: var(--font-family);
    transition: background var(--transition);
}

.conv-title:hover {
    background: rgba(0, 0, 0, 0.04);
}

.conv-delete {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    line-height: 1;
    transition: all var(--transition);
}

.conv-delete:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #FF3B30;
}

.conv-meta {
    font-size: 0.65rem;
    color: var(--text-secondary);
    padding-left: 10px;
    line-height: 1.2;
}

/* ===== Main Area ===== */
#main-area {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ===== Tab Navigation ===== */
.tab-nav {
    display: flex;
    gap: 4px;
    padding: 12px 1.5rem;
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-primary);
    flex-shrink: 0;
}

.tab-btn {
    padding: 8px 20px;
    border: none;
    background: transparent;
    font-family: var(--font-family);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-pill);
    transition: all var(--transition);
}

.tab-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--text-primary);
    color: white;
}

/* ===== Views ===== */
.view {
    display: none;
    flex: 1;
    overflow: hidden;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* ===== Dashboard View ===== */
.dashboard-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem 2.5rem 3rem;
    max-width: 960px;
    margin: 0 auto;
    width: 100%;
}

.dashboard-header {
    margin-bottom: 2rem;
}

.dashboard-header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    margin: 0 0 0.25rem;
}

.dashboard-header p {
    color: var(--text-secondary);
    font-size: 1rem;
    margin: 0;
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 2.5rem;
}

.stat-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    line-height: 1;
    margin-bottom: 6px;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Refresh Banner */
.refresh-banner {
    background: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: var(--radius-md);
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--primary);
}

.banner-dismiss {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 0.25rem;
}

/* Refresh Bar */
.refresh-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.btn-refresh {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: var(--radius-pill);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--font-family);
    transition: background var(--transition);
}

.btn-refresh:hover { background: var(--primary-hover); }
.btn-refresh:disabled { opacity: 0.5; cursor: not-allowed; }

.refresh-status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Quick Actions */
.quick-actions h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.25rem;
}

.quick-actions-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0 0 1.25rem;
}

.actions-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.action-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    text-align: left;
    cursor: pointer;
    font-family: var(--font-family);
    transition: all var(--transition);
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.action-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(0, 113, 227, 0.12);
    transform: translateY(-1px);
}

.action-icon {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.action-card strong {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.action-card span {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ===== Chat View ===== */
#chat-view {
    display: none;
    flex-direction: column;
}

#chat-view.active {
    display: flex;
}

.chat-header {
    padding: 1.5rem 1.5rem 1rem;
    max-width: 820px;
    margin: 0 auto;
    width: 100%;
    flex-shrink: 0;
}

.chat-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin: 0 0 0.25rem;
}

.chat-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0;
}

#messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 0 1.25rem;
    max-width: 820px;
    margin: 0 auto;
    width: 100%;
}

/* ===== Messages ===== */
.message {
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg);
    margin-bottom: 1rem;
}

.message-user {
    background: var(--bg-secondary);
}

.message-assistant {
    background: var(--bg-primary);
}

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

.message-role {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.copy-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    opacity: 0;
    transition: all var(--transition);
    display: flex;
    align-items: center;
}

.message:hover .copy-btn {
    opacity: 1;
}

.copy-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-primary);
}

.copy-btn.copied {
    opacity: 1;
    color: #34C759;
}

.message-content {
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-primary);
}

.message-content p {
    margin: 0 0 0.75rem;
}

.message-content p:last-child {
    margin: 0;
}

.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 1rem 0 0.5rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.message-content h1 { font-size: 1.4rem; }
.message-content h2 { font-size: 1.2rem; }
.message-content h3 { font-size: 1.05rem; }

.message-content ul,
.message-content ol {
    margin: 0 0 0.75rem;
    padding-left: 1.5rem;
}

.message-content li {
    margin-bottom: 0.25rem;
}

.message-content strong {
    font-weight: 600;
}

.message-content code {
    background: #F0F0F0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

.message-content pre {
    background: #F5F5F7;
    padding: 1rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 0 0 0.75rem;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content blockquote {
    border-left: 3px solid var(--border);
    margin: 0 0 0.75rem;
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
}

/* ===== Sources Card ===== */
.sources-card {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin-top: 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.sources-title {
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.source-item {
    padding: 2px 0;
}

/* ===== Chat Input ===== */
.chat-input-container {
    padding: 1rem 1.25rem;
    max-width: 820px;
    margin: 0 auto;
    width: 100%;
    flex-shrink: 0;
}

.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 4px 4px 4px 16px;
    transition: all var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

#chat-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 0.95rem;
    font-family: var(--font-family);
    resize: none;
    max-height: 200px;
    line-height: 1.5;
    padding: 8px 0;
}

#send-btn {
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--transition);
}

#send-btn:hover {
    background: var(--primary-hover);
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#send-btn svg {
    color: white;
    width: 18px;
    height: 18px;
}

/* ===== Loading Indicator ===== */
.loading-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 1rem 1.25rem;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* ===== Empty State (Chat) ===== */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-secondary);
}

.empty-state h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.empty-state-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.empty-state p {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.prompt-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    max-width: 600px;
    margin: 0 auto;
}

.prompt-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 16px;
    text-align: left;
    cursor: pointer;
    font-family: var(--font-family);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.prompt-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 113, 227, 0.1);
}

.prompt-card strong {
    display: block;
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.prompt-card span {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

/* ===== Hamburger Button (hidden on desktop) ===== */
.hamburger-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: background var(--transition);
    align-items: center;
    justify-content: center;
}

.hamburger-btn:hover {
    background: var(--bg-secondary);
}

/* ===== Sidebar Overlay (mobile) ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 90;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .actions-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    body {
        grid-template-columns: 1fr;
    }

    .hamburger-btn {
        display: flex;
    }

    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 280px;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: none;
    }

    #sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .dashboard-content {
        padding: 1.5rem 1rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .actions-grid {
        grid-template-columns: 1fr;
    }

    .prompt-grid {
        grid-template-columns: 1fr;
    }

    .chat-header h1 {
        font-size: 1.2rem;
    }

    .dashboard-header h1 {
        font-size: 1.5rem;
    }
}

@media (max-width: 600px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-number {
        font-size: 1.5rem;
    }
}
