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

:root {
    --bg-dark: #0d1117;
    --bg-card: #161b22;
    --bg-sidebar: #0d1117;
    --bg-input: #1c2333;
    --green-primary: #2ecc71;
    --green-dark: #27ae60;
    --green-glow: rgba(46, 204, 113, 0.15);
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --border: #30363d;
    --danger: #f85149;
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 260px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--green-primary); text-decoration: none; }
a:hover { color: var(--green-dark); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    gap: 6px;
}
.btn-primary {
    background: var(--green-primary);
    color: #fff;
}
.btn-primary:hover { background: var(--green-dark); color: #fff; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-primary);
}
.btn-outline:hover { border-color: var(--green-primary); color: var(--green-primary); }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; }
.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
    font-size: 1.1rem;
}

/* ===== Flash Messages ===== */
.flash-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 360px;
}
.flash {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    animation: flashIn 0.3s ease, flashOut 0.3s ease 3.7s forwards;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
.flash-success { background: rgba(46, 204, 113, 0.2); color: var(--green-primary); border: 1px solid var(--green-dark); }
.flash-error { background: rgba(248, 81, 73, 0.2); color: var(--danger); border: 1px solid var(--danger); }

@keyframes flashIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes flashOut { from { opacity: 1; } to { opacity: 0; transform: translateX(20px); } }

/* ===== Spinner ===== */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.spinner-dark {
    border-color: rgba(0,0,0,0.2);
    border-top-color: var(--text-primary);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Landing ===== */
.landing { min-height: 100vh; }
.landing-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 40px;
}
.nav-brand { font-size: 1.3rem; font-weight: 700; color: var(--green-primary); }
.nav-links { display: flex; gap: 12px; }

.hero {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 80px 40px;
    gap: 60px;
    max-width: 1100px;
    margin: 0 auto;
}
.hero-content { flex: 1; }
.hero h1 { font-size: 3.5rem; font-weight: 800; line-height: 1.1; margin-bottom: 20px; }
.highlight { color: var(--green-primary); }
.hero-sub { font-size: 1.2rem; color: var(--text-secondary); margin-bottom: 32px; max-width: 520px; }
.hero-graphic { flex-shrink: 0; position: relative; width: 280px; height: 280px; }

/* Animated eco orb */
.eco-orb {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 40% 40%, var(--green-primary), var(--green-dark), #1a5c2e);
    animation: orbPulse 4s ease-in-out infinite;
    box-shadow: 0 0 60px rgba(46, 204, 113, 0.3), 0 0 120px rgba(46, 204, 113, 0.1);
}
.eco-orb::before {
    content: '';
    position: absolute;
    top: 15%;
    left: 20%;
    width: 30%;
    height: 30%;
    border-radius: 50%;
    background: rgba(255,255,255,0.15);
    filter: blur(8px);
}
.eco-orb-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 5rem;
    z-index: 1;
    filter: drop-shadow(0 0 20px rgba(46, 204, 113, 0.5));
}

@keyframes orbPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 60px rgba(46, 204, 113, 0.3); }
    50% { transform: scale(1.05); box-shadow: 0 0 80px rgba(46, 204, 113, 0.4); }
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
    padding: 60px 40px;
    max-width: 1100px;
    margin: 0 auto;
}
.feature-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    transition: border-color 0.3s, transform 0.3s;
}
.feature-card:hover { border-color: var(--green-primary); transform: translateY(-2px); }
.feature-icon { font-size: 2.5rem; margin-bottom: 16px; }
.feature-card h3 { font-size: 1.2rem; margin-bottom: 8px; }
.feature-card p { color: var(--text-secondary); font-size: 0.95rem; }

.landing-footer {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    border-top: 1px solid var(--border);
    margin-top: 60px;
}

/* ===== Auth ===== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}
.auth-brand {
    display: block;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--green-primary);
    margin-bottom: 24px;
}
.auth-card h2 { text-align: center; margin-bottom: 24px; font-weight: 600; }
.auth-switch { text-align: center; margin-top: 20px; color: var(--text-secondary); font-size: 0.9rem; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}
.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.95rem;
}
.form-group input:focus { outline: none; border-color: var(--green-primary); }

/* Inline flashes in auth */
.auth-flash {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 0.9rem;
}
.auth-flash-success { background: rgba(46, 204, 113, 0.15); color: var(--green-primary); }
.auth-flash-error { background: rgba(248, 81, 73, 0.15); color: var(--danger); }

/* ===== App Layout ===== */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
}
.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-brand {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--green-primary);
}
.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
}
.sidebar-actions { padding: 12px 16px; }

.sidebar-threads {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.thread-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.85rem;
    transition: all 0.2s;
    margin-bottom: 2px;
}
.thread-item:hover { background: var(--bg-card); color: var(--text-primary); }
.thread-item.active { background: var(--green-glow); color: var(--green-primary); }
.thread-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.thread-date { font-size: 0.75rem; margin-left: 8px; flex-shrink: 0; }
.sidebar-empty { color: var(--text-muted); font-size: 0.85rem; text-align: center; padding: 20px; }

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.user-name { font-size: 0.85rem; color: var(--text-secondary); }

/* ===== Mobile Header (hidden on desktop) ===== */
.mobile-header {
    display: none;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-sidebar);
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.mobile-menu-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
}
.mobile-title {
    font-size: 1rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}
.sidebar-overlay.active { display: block; }

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== Dashboard ===== */
.dashboard-main { padding: 40px; overflow-y: auto; }
.dashboard-welcome h2 { margin-bottom: 24px; }

.thread-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.thread-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    transition: border-color 0.2s, transform 0.2s;
}
.thread-card:hover { border-color: var(--green-primary); transform: translateY(-1px); }
.thread-card a { color: inherit; }
.thread-card h3 { font-size: 1rem; margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 30px; }
.thread-card-meta {
    display: flex;
    gap: 12px;
    color: var(--text-muted);
    font-size: 0.8rem;
}
.thread-card-snippet {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.btn-delete {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    opacity: 0.4;
    transition: opacity 0.2s;
}
.btn-delete:hover { opacity: 1; }

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}
.empty-state p { font-size: 1.2rem; margin-bottom: 24px; }

/* ===== Chat ===== */
.chat-main { display: flex; flex-direction: column; }
.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
}
.chat-header h2 { font-size: 1.1rem; font-weight: 600; }
.chat-model { font-size: 0.8rem; color: var(--text-muted); }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    gap: 12px;
    max-width: 80%;
}
.message-user { align-self: flex-end; flex-direction: row-reverse; }
.message-assistant { align-self: flex-start; }

.message-avatar {
    font-size: 1.2rem;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--bg-card);
}
.message-user .message-avatar { background: var(--green-glow); }

.message-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px 16px;
    border: 1px solid var(--border);
    max-width: 100%;
    overflow-wrap: break-word;
}
.message-user .message-content {
    background: var(--green-glow);
    border-color: var(--green-dark);
}
.message-text {
    font-size: 0.95rem;
    line-height: 1.7;
}

/* Markdown rendering inside messages */
.message-text p { margin-bottom: 0.6em; }
.message-text p:last-child { margin-bottom: 0; }
.message-text ul, .message-text ol { margin: 0.5em 0; padding-left: 1.5em; }
.message-text li { margin-bottom: 0.3em; }
.message-text strong { color: var(--green-primary); }
.message-text em { color: var(--text-secondary); }
.message-text code {
    background: rgba(255,255,255,0.08);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.88em;
    font-family: 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}
.message-text pre {
    background: #0d1117;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    overflow-x: auto;
    margin: 0.8em 0;
}
.message-text pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
    line-height: 1.5;
}
.message-text blockquote {
    border-left: 3px solid var(--green-primary);
    padding-left: 12px;
    margin: 0.5em 0;
    color: var(--text-secondary);
}
.message-text h1, .message-text h2, .message-text h3 {
    margin: 0.8em 0 0.4em;
    font-size: 1.1em;
}
.message-text a { color: var(--green-primary); text-decoration: underline; }
.message-text table { border-collapse: collapse; margin: 0.5em 0; }
.message-text th, .message-text td { border: 1px solid var(--border); padding: 6px 10px; font-size: 0.9em; }
.message-text th { background: var(--bg-input); }

/* Thinking indicator */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 8px 0;
}
.thinking-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green-primary);
    animation: thinkBounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinkBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

.chat-input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    background: var(--bg-dark);
}
#chat-form {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    max-width: 800px;
    margin: 0 auto;
}
#chat-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 24px;
    color: var(--text-primary);
    padding: 12px 20px;
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    max-height: 200px;
    min-height: 48px;
    line-height: 1.5;
}
#chat-input:focus { outline: none; border-color: var(--green-primary); }

#send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    padding: 0;
    font-size: 1.2rem;
    flex-shrink: 0;
    background: var(--green-primary);
    border: none;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}
#send-btn:hover { background: var(--green-dark); transform: scale(1.05); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
#send-btn svg { width: 20px; height: 20px; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .hero { flex-direction: column; padding: 40px 20px; text-align: center; }
    .hero h1 { font-size: 2.2rem; }
    .hero-sub { margin: 0 auto 24px; }
    .hero-graphic { width: 180px; height: 180px; }
    .eco-orb-icon { font-size: 3.5rem; }
    .features { padding: 40px 20px; }
    .landing-nav { padding: 16px 20px; }
    .message { max-width: 95%; }

    .mobile-header { display: flex; }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }

    .dashboard-main { padding: 20px; }
    .chat-header { padding: 12px 16px; }
    .chat-messages { padding: 16px; }
    .chat-input-area { padding: 12px 16px; }
    .thread-grid { grid-template-columns: 1fr; }
}
