:root {
    --bg: #f5f7fa;
    --card: #fff;
    --primary: #3b82f6;
    --secondary: #f97316;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --radius: 0.75rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* App Container */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: 280px;
    height: 100vh;
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
    color: #fff;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 50;
    display: flex;
    flex-direction: column;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    display: none;
}

.sidebar-overlay.show {
    display: block;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    text-align: center;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem;
}

.sidebar-nav ul {
    list-style: none;
}

.nav-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    text-align: left;
    color: #fff;
    border-radius: var(--radius);
    background: transparent;
    border: none;
    cursor: pointer;
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
    transition: background 0.2s ease;
}

.nav-btn:hover,
.nav-btn.active {
    background: rgba(255, 255, 255, 0.2);
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    text-align: center;
    font-size: 0.875rem;
    opacity: 0.8;
}

.sidebar-footer .small {
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

/* Main Wrapper */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Header */
.header {
    position: sticky;
    top: 0;
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
    color: #fff;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.2);
    z-index: 30;
}

.menu-btn {
    position: absolute;
    left: 1rem;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    line-height: 1;
    transition: background 0.2s ease;
}

.menu-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.app-title {
    font-size: 1.25rem;
    font-weight: 800;
}

.header-actions {
    position: absolute;
    right: 1rem;
}

.auth-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    border-radius: 9999px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    font-size: 0.875rem;
    background: transparent;
    cursor: pointer;
    transition: background 0.2s ease;
}

.auth-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.avatar-placeholder {
    width: 1.25rem;
    height: 1.25rem;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1rem;
}

.content-wrapper {
    max-width: 56rem;
    margin: 0 auto;
}

/* Pages */
.page {
    display: none;
}

.page.active {
    display: block;
}

/* Subject Tabs */
.subject-tabs {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.75rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    -webkit-overflow-scrolling: touch;
}

.subject-btn {
    flex-shrink: 0;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.875rem;
    white-space: nowrap;
    transition: background 0.2s ease, color 0.2s ease;
}

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

.subject-btn.active {
    background: var(--secondary);
    color: #fff;
}

/* Input Card */
.input-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
}

.input-card textarea {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    resize: none;
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.2s ease;
}

.input-card textarea:focus {
    outline: none;
    border-color: var(--primary);
}

.submit-btn {
    width: 100%;
    padding: 0.875rem;
    background: linear-gradient(135deg, #f97316, #fb923c);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 600;
    margin-top: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.submit-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

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

/* Loading Card */
.loading-card {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.05), rgba(59, 130, 246, 0.1));
    border: 2px solid rgba(59, 130, 246, 0.2);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
    text-align: center;
}

.loading-bar {
    height: 0.375rem;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 9999px;
    overflow: hidden;
    margin-top: 0.75rem;
}

.loading-bar-fill {
    height: 100%;
    width: 30%;
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
    animation: loading 1.5s ease-in-out infinite;
}

@keyframes loading {
    0% {
        transform: translateX(-100%);
    }
    50% {
        transform: translateX(200%);
    }
    100% {
        transform: translateX(-100%);
    }
}

/* Result Card */
.result-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1rem;
    overflow: hidden;
}

.result-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
}

.result-icon {
    width: 2.5rem;
    height: 2.5rem;
    background: linear-gradient(135deg, #f97316, #fb923c);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.result-header h3 {
    flex: 1;
    font-size: 1.125rem;
    font-weight: 600;
}

.action-btn {
    padding: 0.375rem 0.75rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

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

.result-content {
    padding: 1rem;
    font-size: 0.9375rem;
    line-height: 1.7;
}

.result-content h1,
.result-content h2,
.result-content h3 {
    color: var(--primary);
    margin: 1rem 0 0.5rem;
    font-weight: 600;
}

.result-content h1:first-child,
.result-content h2:first-child,
.result-content h3:first-child {
    margin-top: 0;
}

.result-content p {
    margin-bottom: 0.75rem;
}

.result-content code {
    background: var(--bg);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
    font-size: 0.875em;
}

.result-content pre {
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 1rem 0;
}

.result-content pre code {
    background: transparent;
    padding: 0;
}

.result-content strong {
    color: var(--primary);
    font-weight: 600;
}

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

.result-content li {
    margin-bottom: 0.375rem;
}

/* Error Card */
.error-card {
    background: var(--card);
    border-left: 4px solid #ef4444;
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.error-card h3 {
    color: #ef4444;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.error-card p {
    color: var(--muted);
    font-size: 0.875rem;
}

/* Feature Cards */
.feature-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.feature-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease;
}

.feature-card:hover {
    transform: scale(1.02);
}

.feature-icon {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.75rem;
    font-size: 1.5rem;
    color: #fff;
}

.feature-icon.blue {
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
}

.feature-icon.green {
    background: linear-gradient(135deg, #22c55e, #4ade80);
}

.feature-icon.purple {
    background: linear-gradient(135deg, #a855f7, #c084fc);
}

.feature-icon.orange {
    background: linear-gradient(135deg, #f97316, #fb923c);
}

.feature-card h3 {
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.feature-card p {
    font-size: 0.75rem;
    color: var(--muted);
}

/* Back Button */
.back-btn {
    padding: 0.5rem 1rem;
    color: var(--muted);
    background: transparent;
    border: none;
    cursor: pointer;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    transition: color 0.2s ease;
}

.back-btn:hover {
    color: var(--text);
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--card);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 24rem;
    width: 100%;
    text-align: center;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--muted);
    line-height: 1;
    transition: color 0.2s ease;
}

.modal-close:hover {
    color: var(--text);
}

.modal-content h2 {
    margin-bottom: 1rem;
    font-weight: 600;
}

.google-btn {
    width: 100%;
    padding: 0.875rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: var(--card);
    cursor: pointer;
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.google-btn:hover {
    border-color: var(--primary);
}

/* Toast */
.toast {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    background: var(--text);
    color: var(--bg);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    z-index: 200;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Utility */
.hidden {
    display: none !important;
}

/* Responsive */
@media (max-width: 639px) {
    .sign-in-text {
        display: none;
    }
}

@media (min-width: 1024px) {
    .sidebar {
        position: static;
        transform: none;
    }

    .menu-btn {
        display: none;
    }

    .header {
        justify-content: space-between;
    }

    .header-actions {
        position: static;
    }

    .feature-cards {
        grid-template-columns: repeat(4, 1fr);
    }
}