/* Lemon Data — palette dal logo: giallo limone + arancio sparkle */

:root {
    --lemon: #fbbf24;
    --lemon-light: #fef3c7;
    --lemon-pale: #fffbeb;
    --orange: #f59e0b;
    --orange-dark: #d97706;
    --text: #1c1917;
    --text-muted: #78716c;
    --text-light: #a8a29e;
    --bg: #fafaf9;
    --bg-white: #ffffff;
    --border: #e7e5e4;
    --border-light: #f5f5f4;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

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

body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    height: 100dvh;
    overflow: hidden;
}

/* layout */

.layout {
    display: flex;
    height: 100dvh;
}

/* sidebar */

.sidebar {
    width: 240px;
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-light);
}

.logo {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    object-fit: cover;
}

.brand {
    font-size: 17px;
    font-weight: 600;
    color: var(--text);
}

.sidebar-nav {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-btn {
    background: none;
    border: none;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text-muted);
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
}

.nav-btn:hover {
    background: var(--lemon-pale);
    color: var(--text);
}

.nav-btn.active {
    background: var(--lemon-light);
    color: var(--orange-dark);
    font-weight: 500;
}

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

.source-count {
    font-size: 12px;
    color: var(--text-light);
}

/* main */

.main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* views */

.view {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.view.active {
    display: flex;
}

.view-header {
    padding: 24px 32px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-shrink: 0;
}

.view-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.search-input {
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    width: 240px;
    outline: none;
    transition: border-color 0.15s;
}

.search-input:focus {
    border-color: var(--lemon);
}

/* chat */

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

.welcome {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    text-align: center;
}

.welcome-logo {
    width: 64px;
    height: 64px;
    border-radius: 16px;
}

.welcome h1 {
    font-size: 24px;
    font-weight: 600;
}

.welcome p {
    color: var(--text-muted);
    font-size: 15px;
}

.suggestions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.suggestion {
    background: var(--bg-white);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    font-family: var(--font);
    transition: all 0.15s;
}

.suggestion:hover {
    border-color: var(--lemon);
    color: var(--orange-dark);
    background: var(--lemon-pale);
}

/* message bubbles */

.msg {
    max-width: 720px;
    width: 100%;
    margin: 0 auto;
}

.msg-user {
    background: var(--lemon-light);
    padding: 14px 18px;
    border-radius: var(--radius) var(--radius) 4px var(--radius);
    font-size: 15px;
    line-height: 1.5;
    margin-left: auto;
    max-width: 480px;
    width: fit-content;
}

.msg-assistant {
    font-size: 15px;
    line-height: 1.6;
}

.msg-assistant .answer {
    white-space: pre-wrap;
}

.msg-sources {
    margin-top: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.msg-source-tag {
    display: inline-block;
    background: var(--lemon-pale);
    border: 1px solid var(--lemon);
    color: var(--orange-dark);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.msg-timing {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-light);
}

.msg-error {
    color: #dc2626;
    background: #fef2f2;
    padding: 14px 18px;
    border-radius: var(--radius);
    font-size: 14px;
}

/* loading dots */

.msg-loading {
    display: flex;
    gap: 6px;
    padding: 16px 0;
}

.msg-loading span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--lemon);
    animation: pulse 1.2s ease-in-out infinite;
}

.msg-loading span:nth-child(2) { animation-delay: 0.2s; }
.msg-loading span:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
}

/* chat input */

.chat-input-wrap {
    padding: 16px 32px 24px;
    flex-shrink: 0;
}

.chat-form {
    max-width: 720px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    box-shadow: var(--shadow);
    transition: border-color 0.15s;
}

.chat-form:focus-within {
    border-color: var(--lemon);
    box-shadow: var(--shadow-md), 0 0 0 3px var(--lemon-pale);
}

#chat-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 15px;
    font-family: var(--font);
    resize: none;
    line-height: 1.5;
    max-height: 150px;
    color: var(--text);
    background: transparent;
}

#chat-input::placeholder {
    color: var(--text-light);
}

.send-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--lemon);
    color: var(--bg-white);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

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

.send-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
}

/* sources grid */

.sources-grid {
    flex: 1;
    overflow-y: auto;
    padding: 0 32px 24px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    align-content: start;
}

.source-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    transition: border-color 0.15s;
}

.source-card:hover {
    border-color: var(--lemon);
}

.source-card h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 6px;
}

.source-card .source-id {
    font-size: 12px;
    color: var(--text-light);
    font-family: var(--mono);
    margin-bottom: 8px;
}

.source-domains {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 8px;
}

.domain-tag {
    background: var(--lemon-pale);
    color: var(--orange-dark);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
}

.source-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
}

/* status */

.status-cards {
    flex: 1;
    overflow-y: auto;
    padding: 0 32px 24px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    align-content: start;
}

.status-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
}

.status-card .stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--orange-dark);
}

.status-card .stat-label {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.status-card.ok .stat-value { color: #16a34a; }
.status-card.warn .stat-value { color: var(--orange); }

/* auth sidebar */

.sidebar-auth {
    padding: 12px;
    border-bottom: 1px solid var(--border-light);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.auth-label {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}

.auth-input {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font);
    outline: none;
    width: 100%;
}

.auth-input:focus {
    border-color: var(--lemon);
}

.auth-btn {
    background: var(--lemon);
    color: var(--text);
    border: none;
    padding: 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: var(--font);
    transition: background 0.15s;
}

.auth-btn:hover {
    background: var(--orange);
    color: white;
}

.auth-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.auth-error {
    font-size: 12px;
    color: #dc2626;
    margin-top: 4px;
}

.auth-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.auth-email {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-plan {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.auth-plan.pro {
    color: var(--orange-dark);
}

.auth-quota {
    font-size: 11px;
    color: var(--text-light);
}

/* api key reveal */

.api-key-reveal {
    background: var(--lemon-pale);
    border: 1px solid var(--lemon);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 720px;
    margin: 0 auto;
    text-align: center;
}

.api-key-reveal h3 {
    font-size: 16px;
    margin-bottom: 6px;
}

.api-key-reveal p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.api-key-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
}

.api-key-box code {
    flex: 1;
    font-family: var(--mono);
    font-size: 12px;
    word-break: break-all;
    color: var(--text);
}

.copy-btn {
    background: var(--lemon);
    border: none;
    padding: 4px 12px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    font-family: var(--font);
    flex-shrink: 0;
}

.copy-btn:hover {
    background: var(--orange);
    color: white;
}

.welcome-hint {
    font-size: 13px;
    color: var(--text-light);
    font-style: italic;
}

/* account view */

.account-content {
    padding: 0 32px 24px;
    overflow-y: auto;
    flex: 1;
}

.account-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.account-card {
    background: var(--bg-white);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.account-card-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.account-card-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
}

.plan-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 14px;
}

.plan-badge.free {
    background: var(--border-light);
    color: var(--text-muted);
}

.plan-badge.pro {
    background: var(--lemon-light);
    color: var(--orange-dark);
}

.account-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 320px;
}

.upgrade-btn {
    background: var(--orange);
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    transition: background 0.15s;
}

.upgrade-btn:hover {
    background: var(--orange-dark);
}

.upgrade-btn:disabled {
    background: var(--border);
    cursor: not-allowed;
}

.upgrade-hint {
    font-size: 13px;
    color: var(--text-muted);
}

.manage-btn {
    background: var(--bg-white);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    cursor: pointer;
    font-family: var(--font);
    transition: border-color 0.15s;
}

.manage-btn:hover {
    border-color: var(--lemon);
}

.logout-btn {
    background: none;
    color: var(--text-muted);
    border: none;
    padding: 8px 0;
    font-size: 13px;
    cursor: pointer;
    font-family: var(--font);
    text-align: left;
}

.logout-btn:hover {
    color: #dc2626;
}

/* responsive */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -240px;
        top: 0;
        bottom: 0;
        z-index: 100;
        transition: left 0.2s;
    }

    .sidebar.open {
        left: 0;
        box-shadow: var(--shadow-md);
    }

    .chat-messages { padding: 16px; }
    .chat-input-wrap { padding: 12px 16px 16px; }
    .view-header { padding: 16px; }
    .sources-grid, .status-cards { padding: 0 16px 16px; }

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