/* Modern Dark Theme Design System */
:root {
    /* Background Colors */
    --bg-primary: #0a0a0a;
    --bg-secondary: #141414;
    --bg-card: #1a1a1a;
    --bg-elevated: #222222;

    /* Accent Colors */
    --accent-primary: #8b5cf6;
    --accent-secondary: #06b6d4;
    --accent-success: #10b981;
    --accent-danger: #ef4444;
    --accent-warning: #f59e0b;

    /* Text Colors */
    --text-primary: #f5f5f5;
    --text-secondary: #a3a3a3;
    --text-muted: #737373;

    /* Chart Colors */
    --chart-1: #8b5cf6;
    --chart-2: #06b6d4;
    --chart-3: #10b981;
    --chart-4: #f59e0b;
    --chart-5: #ef4444;
    --chart-6: #ec4899;

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
}

.hidden {
    display: none !important;
}

/* Container */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* Navigation */
.nav {
    background: var(--bg-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.nav-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-logo {
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.btn-logout {
    background: transparent;
    border: 1px solid var(--text-muted);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.2s;
}

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

.nav-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Time Filter */
.time-filter {
    display: flex;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 4px;
    gap: 4px;
}

.filter-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
}

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

.filter-btn.active {
    background: var(--accent-primary);
    color: white;
}

/* Period Indicator */
.period-indicator {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.period-indicator span:first-child {
    font-weight: 600;
    color: var(--text-primary);
}

.period-comparison {
    color: var(--text-muted);
}

/* Metric Cards Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.metric-card {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-lg);
    padding: 24px;
    position: relative;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.metric-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    opacity: 0;
    transition: opacity 0.2s;
}

.metric-card:hover::before {
    opacity: 1;
}

.metric-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.metric-value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
    margin-bottom: 8px;
}

.metric-subtext {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Trend Indicators */
.trend {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}

.trend-up {
    color: var(--accent-success);
    background: rgba(16, 185, 129, 0.1);
}

.trend-down {
    color: var(--accent-danger);
    background: rgba(239, 68, 68, 0.1);
}

.trend-neutral {
    color: var(--text-muted);
    background: rgba(115, 115, 115, 0.1);
}

/* Section Headers */
.section-header {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Charts Section */
.charts-section {
    margin-bottom: 32px;
}

.chart-card {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 24px;
}

.chart-card-full {
    width: 100%;
}

.chart-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.chart-card-header .chart-title {
    margin: 0;
}

.dream-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-secondary);
    padding: 4px 8px;
    border-radius: 12px;
}

.chart-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 20px 0;
}

.load-more-btn {
    width: 100%;
    margin-top: 16px;
    padding: 12px;
    background: var(--bg-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
}

.load-more-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--accent-primary);
}

.load-more-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chart-wrapper {
    position: relative;
    height: 250px;
}

.chart-wrapper-large {
    height: 300px;
}

/* Two Column Layout */
.two-column {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

@media (max-width: 900px) {
    .two-column {
        grid-template-columns: 1fr;
    }
}

/* Recent Dreams List */
.recent-dreams-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 400px;
    overflow-y: auto;
}

.dream-item {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    transition: background 0.2s;
}

.dream-item:hover {
    background: var(--bg-elevated);
}

.dream-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

.dream-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.dream-title {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

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

.dream-emotion {
    padding: 2px 8px;
    border-radius: 12px;
    background: rgba(139, 92, 246, 0.2);
    color: var(--accent-primary);
    font-weight: 500;
}

/* Login Screen */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
}

.login-card {
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-lg);
    padding: 48px;
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 16px;
}

.login-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.login-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 16px;
    transition: border-color 0.2s;
}

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

.login-input::placeholder {
    color: var(--text-muted);
}

.login-button {
    width: 100%;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--accent-primary), #7c3aed);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.login-button:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
}

.login-error {
    color: var(--accent-danger);
    font-size: 0.875rem;
    margin-top: 16px;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Loading State */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-muted);
}

.loading::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 12px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .container {
        padding: 16px;
    }

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

    .metric-value {
        font-size: 1.75rem;
    }

    .chart-wrapper {
        height: 200px;
    }

    .two-column {
        grid-template-columns: 1fr;
    }
}

/* ============================================================
   Excluded-accounts chip + drill-down modal (email visibility)
   ============================================================ */

.excluded-chip {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 999px;
    cursor: pointer;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
}

.excluded-chip:hover {
    color: var(--text-primary);
    border-color: var(--accent-primary);
    background: var(--bg-elevated);
}

#excluded-chip-count {
    font-weight: 700;
    color: var(--text-primary);
}

/* Clickable metric cards (first-time dreamers / returning users) */
.metric-card-clickable {
    cursor: pointer;
}

.metric-card-clickable:hover::before {
    opacity: 1;
}

.metric-subtext-link span {
    color: var(--accent-secondary);
    font-weight: 600;
    white-space: nowrap;
}

.metric-card-clickable:hover .metric-subtext-link span {
    text-decoration: underline;
}

/* Standalone "View emails" link line (cards whose subtext shows a trend) */
.metric-link {
    margin-top: 8px;
    font-size: 0.8125rem;
}

.metric-link span {
    color: var(--accent-secondary);
    font-weight: 600;
    white-space: nowrap;
}

.metric-card-clickable:hover .metric-link span {
    text-decoration: underline;
}

/* Modal overlay */
.detail-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    animation: detailFade 0.15s ease-out;
}

@keyframes detailFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.detail-modal {
    width: 100%;
    max-width: 460px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.detail-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 8px;
}

.detail-modal-title {
    font-size: 1.0625rem;
    font-weight: 700;
    color: var(--text-primary);
}

.detail-modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    transition: color 0.2s;
}

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

.detail-modal-subtitle {
    padding: 0 24px 12px;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.detail-modal-body {
    padding: 0 12px 16px;
    overflow-y: auto;
}

.email-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.email-row:hover {
    background: var(--bg-elevated);
}

.email-row + .email-row {
    border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.email-row .email-addr {
    color: var(--text-primary);
    word-break: break-all;
}

.email-row .email-meta {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.email-row .email-tag {
    flex-shrink: 0;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

.detail-empty {
    padding: 24px 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Moderation queue */
#moderation-section { border-left: 3px solid #e5484d; }
.moderation-row { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; padding: 14px 0; border-bottom: 1px solid rgba(255,255,255,0.06); }
.moderation-row:last-child { border-bottom: none; }
.moderation-body { min-width: 0; flex: 1; }
.moderation-body p { margin: 6px 0; }
.moderation-meta { font-size: 11px; letter-spacing: 0.04em; opacity: 0.65; text-transform: uppercase; }
.moderation-dream { margin-top: 8px; padding: 10px 12px; border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; }
.moderation-dream p { font-size: 13px; opacity: 0.85; }
.moderation-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }
.moderation-actions button { padding: 6px 12px; border-radius: 6px; border: 1px solid rgba(255,255,255,0.15); background: transparent; color: inherit; cursor: pointer; font-size: 12px; white-space: nowrap; }
.moderation-actions button:hover { border-color: rgba(255,255,255,0.4); }
.moderation-actions button[data-action="blocked"], .moderation-actions button[data-action="block-dream"] { border-color: rgba(229,72,77,0.5); color: #e5484d; }
.moderation-actions button:disabled { opacity: 0.4; cursor: default; }
