/* Reset and Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Core Analitica palette */
    --color-primary: #65BDC6;
    --color-primary-hover: #4fa8b1;
    --color-primary-light: rgba(101, 189, 198, 0.1);
    --color-primary-shadow: rgba(101, 189, 198, 0.25);
    --color-navy: #1e3a5f;

    /* Neutrals */
    --color-bg: #F7FAFF;
    --color-surface: #ffffff;
    --color-sidebar: #202020;
    --color-sidebar-hover: #2a2a2a;
    --color-sidebar-active: #343434;

    /* Text */
    --color-text: #3b3b3b;
    --color-text-secondary: #848484;
    --color-text-light: rgba(255, 255, 255, 0.9);
    --color-text-muted: rgba(255, 255, 255, 0.6);

    /* Borders */
    --color-border: #e8ecf3;
    --color-border-light: rgba(255, 255, 255, 0.1);

    /* States */
    --color-error: #ef4444;
    --color-error-bg: #fef2f2;
    --color-success: #22c55e;

    /* Typography */
    --font-heading: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-body: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, monospace;

    /* Spacing */
    --radius: 12px;
    --radius-lg: 16px;
    --radius-full: 30px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 20px 50px 5px var(--color-primary-shadow);

    /* Layout */
    --sidebar-width: 280px;
    --header-height: 60px;
}

/* Import fonts */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@500;600;700&family=Roboto:wght@400;500&display=swap');

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    color: var(--color-text);
    background-color: var(--color-bg);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============================================
   Landing Page
   ============================================ */

.landing-layout {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.landing-header {
    padding: 1.5rem 3rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.landing-logo {
    text-decoration: none;
    display: flex;
    align-items: center;
}

.logo-img {
    height: 65px;
    width: auto;
}

.landing-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
}

.landing-hero {
    text-align: center;
    max-width: 600px;
}

.landing-hero h1 {
    font-family: var(--font-heading);
    font-size: 3rem;
    font-weight: 700;
    color: var(--color-text);
    margin-bottom: 1rem;
    line-height: 1.2;
}

.landing-hero h1 span {
    background: linear-gradient(135deg, var(--color-primary), var(--color-navy));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.landing-tagline {
    font-size: 1.25rem;
    color: var(--color-text-secondary);
    margin-bottom: 2.5rem;
    line-height: 1.7;
}

.landing-cta {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.error-banner {
    background: var(--color-error-bg);
    color: var(--color-error);
    padding: 0.875rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9375rem;
    width: 100%;
    max-width: 320px;
}

.landing-features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    margin-top: 4rem;
    text-align: left;
}

.landing-feature {
    background: var(--color-surface);
    padding: 2rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--color-border);
}

.landing-feature-icon {
    width: 48px;
    height: 48px;
    background: var(--color-primary-light);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.landing-feature-icon svg {
    width: 24px;
    height: 24px;
    color: var(--color-primary);
}

.landing-feature h3 {
    font-family: var(--font-heading);
    font-size: 1.125rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-text);
}

.landing-feature p {
    font-size: 0.9375rem;
    color: var(--color-text-secondary);
    line-height: 1.6;
}

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

    .landing-hero h1 {
        font-size: 2rem;
    }
}

/* ============================================
   Buttons
   ============================================ */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    padding: 0.875rem 1.75rem;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 500;
    border-radius: var(--radius-full);
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
    box-shadow: 0 4px 14px var(--color-primary-shadow);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px var(--color-primary-shadow);
}

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

.btn-secondary:hover:not(:disabled) {
    background: var(--color-bg);
    border-color: var(--color-primary);
}

.btn-dark {
    background: var(--color-sidebar);
    color: white;
}

.btn-dark:hover:not(:disabled) {
    background: var(--color-sidebar-hover);
}

.btn .icon {
    width: 20px;
    height: 20px;
}

.btn-icon {
    padding: 0.75rem;
    border-radius: var(--radius);
}

/* ============================================
   App Layout (OpenAI-style)
   ============================================ */

.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--color-sidebar);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--color-border-light);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.sidebar-logo-img {
    height: 50px;
    width: auto;
    filter: brightness(0) invert(1);
}

.sidebar-content {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
}

/* New Chat Button */
.new-chat-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--color-text-light);
    background: var(--color-sidebar-hover);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s ease;
}

.new-chat-btn:hover {
    background: var(--color-sidebar-active);
    border-color: var(--color-primary);
}

.new-chat-btn svg {
    width: 16px;
    height: 16px;
    opacity: 0.9;
}

/* Conversation Items */
.conversation-item {
    position: relative;
    padding-right: 2.5rem;
}

.conversation-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.delete-conv-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: var(--color-text-muted);
    cursor: pointer;
    opacity: 0;
    transition: all 0.15s ease;
}

.conversation-item:hover .delete-conv-btn {
    opacity: 1;
}

.delete-conv-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--color-error);
}

.no-conversations {
    padding: 0.75rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    text-align: center;
}

.sidebar-section {
    margin-bottom: 1.5rem;
}

.sidebar-section-title {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.5rem 0.75rem;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    color: var(--color-text-light);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    transition: background 0.15s ease;
}

.sidebar-nav-item:hover {
    background: var(--color-sidebar-hover);
}

.sidebar-nav-item.active {
    background: var(--color-sidebar-active);
}

.sidebar-nav-item svg {
    width: 20px;
    height: 20px;
    opacity: 0.8;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--color-border-light);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    transition: background 0.15s ease;
}

.sidebar-user:hover {
    background: var(--color-sidebar-hover);
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    background: var(--color-primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.875rem;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-email {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    margin-top: 0.75rem;
    padding: 0.625rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    background: transparent;
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.sidebar-logout:hover {
    color: var(--color-text-light);
    background: var(--color-sidebar-hover);
    border-color: transparent;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-bg);
}

.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
}

.main-header-title {
    font-family: var(--font-heading);
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text);
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.model-selector label {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.model-selector select {
    padding: 0.5rem 2rem 0.5rem 0.875rem;
    font-size: 0.875rem;
    font-family: var(--font-body);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23848484' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    transition: border-color 0.15s ease;
}

.model-selector select:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* Chat Area */
.chat-area {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

.chat-container {
    max-width: 800px;
    margin: 0 auto;
}

.chat-welcome {
    text-align: center;
    padding: 4rem 2rem;
}

.chat-welcome-icon {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--color-primary), var(--color-navy));
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
}

.chat-welcome-icon svg {
    width: 32px;
    height: 32px;
    color: white;
}

.chat-welcome h2 {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.chat-welcome p {
    color: var(--color-text-secondary);
    font-size: 1rem;
}

/* Messages */
.chat-messages {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.chat-message {
    display: flex;
    gap: 1rem;
    animation: messageIn 0.3s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 0.875rem;
}

.chat-message-avatar.user {
    background: var(--color-primary);
    color: white;
}

.chat-message-avatar.assistant {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.chat-message-content {
    flex: 1;
    min-width: 0;
}

.chat-message-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.chat-message-role {
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--color-text);
}

.chat-message-meta {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.chat-message-body {
    background: var(--color-surface);
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    font-size: 0.9375rem;
    line-height: 1.7;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.chat-message-body.user {
    background: var(--color-primary-light);
    border-color: transparent;
}

.chat-message-body code {
    font-family: var(--font-mono);
    background: rgba(0, 0, 0, 0.05);
    padding: 0.125rem 0.375rem;
    border-radius: 4px;
    font-size: 0.875em;
}

.chat-message-body pre {
    background: var(--color-sidebar);
    color: var(--color-text-light);
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.75rem 0;
}

.chat-message-body pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.chat-message-usage {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.chat-message-usage span {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Input Area */
.chat-input-area {
    padding: 1rem 2rem 2rem;
    background: var(--color-bg);
}

.chat-input-container {
    max-width: 800px;
    margin: 0 auto;
}

.chat-input-wrapper {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-lg);
}

.chat-system-input {
    border-bottom: 1px solid var(--color-border);
}

.chat-system-input textarea {
    width: 100%;
    padding: 0.875rem 1rem;
    font-family: var(--font-body);
    font-size: 0.875rem;
    border: none;
    resize: none;
    background: transparent;
    color: var(--color-text);
    min-height: 44px;
}

.chat-system-input textarea::placeholder {
    color: var(--color-text-secondary);
}

.chat-system-input textarea:focus {
    outline: none;
}

.chat-main-input {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
}

.chat-main-input textarea {
    flex: 1;
    padding: 0.625rem 0;
    font-family: var(--font-body);
    font-size: 0.9375rem;
    border: none;
    resize: none;
    background: transparent;
    color: var(--color-text);
    min-height: 24px;
    max-height: 200px;
    line-height: 1.5;
}

.chat-main-input textarea::placeholder {
    color: var(--color-text-secondary);
}

.chat-main-input textarea:focus {
    outline: none;
}

.chat-submit-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: var(--color-primary);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.chat-submit-btn:hover:not(:disabled) {
    background: var(--color-primary-hover);
}

.chat-submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-submit-btn svg {
    width: 20px;
    height: 20px;
}

.chat-input-hint {
    text-align: center;
    margin-top: 0.75rem;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

/* Spinner */
.spinner {
    width: 18px;
    height: 18px;
    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); }
}

/* Error State */
.chat-error {
    background: var(--color-error-bg);
    border: 1px solid var(--color-error);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    color: var(--color-error);
}

.chat-error-title {
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.chat-error-message {
    font-size: 0.875rem;
}

/* Error Page */
.error-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.error-content {
    text-align: center;
}

.error-content h1 {
    font-family: var(--font-heading);
    font-size: 6rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-primary), var(--color-navy));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.5rem;
}

.error-content p {
    font-size: 1.25rem;
    color: var(--color-text-secondary);
    margin-bottom: 2rem;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        z-index: 100;
        transition: left 0.3s ease;
    }

    .sidebar.open {
        left: 0;
    }

    .main-content {
        width: 100%;
    }

    .chat-area {
        padding: 1rem;
    }

    .chat-input-area {
        padding: 1rem;
    }
}

/* Footer (for landing) */
.landing-footer {
    padding: 2rem;
    text-align: center;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    border-top: 1px solid var(--color-border);
}

/* ============================================
   Usage Stats Page
   ============================================ */

.usage-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    background: var(--color-bg);
}

.usage-container {
    max-width: 1000px;
    margin: 0 auto;
}

.usage-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.usage-card {
    background: var(--color-surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    text-align: center;
}

.usage-card-highlight {
    background: linear-gradient(135deg, var(--color-primary), var(--color-navy));
    border: none;
    color: white;
}

.usage-card-label {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
}

.usage-card-highlight .usage-card-label {
    color: rgba(255, 255, 255, 0.8);
}

.usage-card-value {
    font-family: var(--font-heading);
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--color-text);
}

.usage-card-highlight .usage-card-value {
    color: white;
}

.usage-section {
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.usage-section-title {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    padding: 1rem 1.5rem;
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    color: var(--color-text);
}

.usage-table-wrapper {
    overflow-x: auto;
}

.usage-table {
    width: 100%;
    border-collapse: collapse;
}

.usage-table th,
.usage-table td {
    padding: 0.875rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.usage-table th {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-secondary);
    background: var(--color-bg);
}

.usage-table td {
    font-size: 0.9375rem;
    color: var(--color-text);
}

.usage-table tbody tr:last-child td {
    border-bottom: none;
}

.usage-table tbody tr:hover {
    background: var(--color-bg);
}

.usage-table code {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    background: var(--color-bg);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.provider-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 20px;
}

.provider-anthropic {
    background: rgba(217, 119, 6, 0.1);
    color: #d97706;
}

.provider-openai {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.usage-empty {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--color-text-secondary);
}

.usage-empty svg {
    color: var(--color-primary);
    margin-bottom: 1rem;
}

.usage-empty p {
    font-size: 1rem;
}
