/* =========================================================================
   BASE & RESET
   ========================================================================= */
:root {
    /* Color Palette - Premium Dark Mode */
    --clr-bg-base: #0a0b10;
    --clr-bg-elevated: rgba(22, 24, 34, 0.4);
    --clr-bg-elevated-hover: rgba(30, 33, 46, 0.5);
    
    --clr-primary: #6366f1;
    --clr-primary-glow: rgba(99, 102, 241, 0.5);
    --clr-secondary: #ec4899;
    --clr-secondary-glow: rgba(236, 72, 153, 0.4);
    
    --clr-text-main: #f8fafc;
    --clr-text-dim: #94a3b8;
    --clr-text-muted: #64748b;
    
    --clr-danger: #ef4444;
    --clr-success: #10b981;
    --clr-twitch: #9146FF;

    /* Glassmorphism settings */
    --glass-border: 1px solid rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --glass-blur: blur(12px);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    /* Animation */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--clr-bg-base);
    color: var(--clr-text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
}

a {
    color: var(--clr-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

button, input, select, textarea {
    font-family: inherit;
    color: inherit;
    background: none;
    border: none;
}

/* =========================================================================
   BACKGROUND & EFFECTS
   ========================================================================= */
.bg-gradient {
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: radial-gradient(circle at top right, rgba(30,27,75,0.4) 0%, transparent 60%),
                radial-gradient(circle at bottom left, rgba(17,24,39,0.8) 0%, var(--clr-bg-base) 100%);
    z-index: -2;
}

.bg-glow {
    position: fixed;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.15;
    z-index: -1;
    animation: pulse 10s infinite alternate cubic-bezier(0.4, 0, 0.2, 1);
}

.bg-glow-primary {
    top: -100px; right: -100px; 
    background: var(--clr-primary);
}

.bg-glow-secondary {
    bottom: -150px; left: -100px;
    background: var(--clr-secondary);
    animation-delay: -5s;
}

@keyframes pulse {
    0% { transform: scale(1) translate(0, 0); opacity: 0.1; }
    100% { transform: scale(1.1) translate(-20px, 20px); opacity: 0.2; }
}

/* =========================================================================
   COMPONENTS - GLASSMORPHISM
   ========================================================================= */
.glass-panel {
    background: var(--clr-bg-elevated);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: var(--glass-border);
    border-radius: 16px;
    box-shadow: var(--glass-shadow);
}

.glass-input, .glass-select {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--clr-text-main);
    width: 100%;
    transition: all var(--transition-fast);
}

.glass-input:focus, .glass-select:focus {
    outline: none;
    border-color: var(--clr-primary);
    box-shadow: 0 0 0 2px var(--clr-primary-glow);
}

/* =========================================================================
   TYPOGRAPHY
   ========================================================================= */
h1, h2, h3, h4, h5 {
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

h1 { font-size: 2.5rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.25rem; }

.subtitle {
    color: var(--clr-text-dim);
    font-size: 1.125rem;
    font-weight: 400;
}

.text-dim { color: var(--clr-text-dim); }
.text-sm { font-size: 0.875rem; }
.text-glow-primary {
    text-shadow: 0 0 20px var(--clr-primary-glow);
    color: #fff;
}

/* =========================================================================
   BUTTONS
   ========================================================================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    gap: 0.5rem;
    white-space: nowrap;
}

.btn-lg { padding: 0.875rem 1.5rem; font-size: 1.125rem; }
.btn-sm { padding: 0.4rem 0.875rem; font-size: 0.875rem; }
.btn-icon { padding: 0.5rem; }
.w-full { width: 100%; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }

.btn-primary {
    background: var(--clr-primary);
    color: white;
    box-shadow: 0 4px 14px 0 var(--clr-primary-glow);
}
.btn-primary:hover {
    background: #4f46e5;
    transform: translateY(-1px);
    box-shadow: 0 6px 20px 0 var(--clr-primary-glow);
}

.btn-secondary {
    background: rgba(255,255,255,0.1);
    color: white;
    border: 1px solid rgba(255,255,255,0.1);
}
.btn-secondary:hover {
    background: rgba(255,255,255,0.15);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--clr-danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

.btn-ghost {
    color: var(--clr-text-dim);
}
.btn-ghost:hover {
    color: var(--clr-text-main);
    background: rgba(255,255,255,0.05);
}

.btn-twitch {
    background: var(--clr-twitch);
    box-shadow: 0 4px 14px 0 rgba(145, 70, 255, 0.4);
}
.btn-twitch:hover {
    background: #772ce8;
}

/* =========================================================================
   LAYOUT VIEWS
   ========================================================================= */
.app-container {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

.view {
    display: none;
    width: 100%;
    height: 100%;
}
.view.view-active {
    display: flex; /* Or flex depending on view, overriden below */
}

/* --- LOGIN VIEW --- */
#view-login {
    align-items: center;
    justify-content: center;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.login-header {
    text-align: center;
}

.logo-container {
    width: 64px; height: 64px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--clr-primary), var(--clr-secondary));
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1.5rem;
    font-size: 2rem;
    box-shadow: 0 8px 16px var(--clr-primary-glow);
}

/* --- DASHBOARD VIEW --- */
#view-dashboard.view-active {
    display: flex;
    padding: 1rem;
    gap: 1rem;
}

.sidebar {
    width: 280px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
    padding: 0 0.5rem;
}

.logo-icon.sm {
    font-size: 1.5rem;
    width: 36px; height: 36px;
    border-radius: 8px;
    background: linear-gradient(135deg, var(--clr-primary), var(--clr-secondary));
    display: flex; align-items: center; justify-content: center;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: rgba(0,0,0,0.2);
    border-radius: 12px;
    margin-bottom: 2rem;
}

.avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255,255,255,0.1);
}

.default-avatar { background: var(--clr-text-muted); }

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-name {
    font-weight: 600;
    white-space: nowrap; text-overflow: ellipsis; overflow: hidden;
}

.badge {
    font-size: 0.65rem;
    font-weight: 800;
    letter-spacing: 0.05em;
    padding: 0.1em 0.5em; /* Adjusted padding for top/bottom */
    border-radius: 4px;
    background: var(--clr-primary-glow);
    color: var(--clr-primary);
    width: fit-content;
    border: 1px solid var(--clr-primary);
    display: inline-flex;  /* Ensure items flow neatly inside */
    align-items: center; /* Center vertically inside */
    line-height: 1; /* Match the line height strictly to text */
}

/* Remove extra margins on unordered list */
.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.nav-btn {
    width: 100%;
    text-align: left;
    padding: 0.875rem 1rem;
    border-radius: 8px;
    color: var(--clr-text-dim);
    font-weight: 500;
    transition: all var(--transition-fast);
}

.nav-btn:hover {
    background: rgba(255,255,255,0.05);
    color: var(--clr-text-main);
}

.nav-btn.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--clr-primary);
    border-right: 3px solid var(--clr-primary);
}

.sidebar-footer {
    padding-top: 1rem;
    border-top: 1px solid rgba(255,255,255,0.05);
}

/* Dashboard Content */
.dashboard-content {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 2rem;
}

.dashboard-content::-webkit-scrollbar { width: 8px; }
.dashboard-content::-webkit-scrollbar-track { background: transparent; }
.dashboard-content::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.tab-pane {
    display: none;
}
.tab-pane.active {
    display: block;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

/* Stats Grids */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: transform 0.2s ease;
}

.stat-card:hover { transform: translateY(-3px); }

.stat-card.highlight {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.1), rgba(236, 72, 153, 0.1));
    border-color: rgba(99, 102, 241, 0.3);
}

.stat-label {
    color: var(--clr-text-dim);
    font-size: 0.875rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1;
}

/* Charts */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
}

@media (min-width: 1200px) {
    .charts-grid { grid-template-columns: 2fr 1fr; }
}

.chart-card {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
}

.chart-card h3 {
    margin-bottom: 1rem;
    color: var(--clr-text-dim);
    font-size: 1rem;
}

.chart-container {
    position: relative;
    width: 100%;
    /* Flex grow effectively makes it span to max possible height, preventing jumping */
    flex-grow: 1; 
    min-height: 250px;
}

/* Settings */
.settings-container {
    max-width: 600px;
}

.settings-card {
    padding: 2rem;
}

.api-key-container {
    display: flex;
    gap: 0.5rem;
}
.locked {
    font-family: monospace;
    letter-spacing: 0.1em;
}

/* Utilities / Animations */
.fade-in {
    animation: fadeIn var(--transition-normal);
}

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

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

/* =========================================================================
   NEW DASHBOARD EXPANSION STYLES
   ========================================================================= */
.mt-6 { margin-top: 1.5rem; }

.stats-mini {
    padding: 1rem 1.25rem;
}

.stat-value.sm {
    font-size: 1.5rem;
}

/* Heatmap Section */
.heatmap-section {
    padding: 1.5rem;
}

.heatmap-container {
    display: grid;
    grid-template-columns: repeat(52, 1fr);
    grid-template-rows: repeat(7, 1fr);
    gap: 3px;
    margin-top: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.heatmap-cell {
    aspect-ratio: 1/1;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 2px;
    min-width: 10px;
    transition: transform 0.1s ease;
}

.heatmap-cell:hover {
    transform: scale(1.2);
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.1);
    z-index: 10;
}

.lvl-0 { background: rgba(255, 255, 255, 0.03); }
.lvl-1 { background: rgba(99, 102, 241, 0.2); }
.lvl-2 { background: rgba(99, 102, 241, 0.4); }
.lvl-3 { background: rgba(99, 102, 241, 0.7); }
.lvl-4 { background: #6366f1; box-shadow: 0 0 10px var(--clr-primary-glow); }

.heatmap-legend {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 0.75rem;
    font-size: 0.75rem;
    color: var(--clr-text-dim);
}

.legend-cells {
    display: flex;
    gap: 3px;
}

.legend-cells .cell {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

@media (max-width: 900px) {
    .heatmap-container {
        grid-template-columns: repeat(26, 1fr); /* scrollable or halved */
    }
}

/* History Tab Styles */
.history-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 1.5rem;
    height: calc(100vh - 250px);
    min-height: 500px;
}

.history-list-container {
    overflow-y: auto;
    padding: 1rem;
}

.history-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.history-item {
    padding: 1rem;
    border-radius: 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.05);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.history-item:hover {
    background: rgba(255,255,255,0.05);
    transform: translateX(4px);
    border-color: var(--clr-primary-glow);
}

.history-item.active {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--clr-primary);
}

.history-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.25rem;
}

.history-item-token {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--clr-text-main);
}

.history-item-date {
    font-size: 0.75rem;
    color: var(--clr-text-muted);
}

.history-item-meta {
    font-size: 0.8rem;
    color: var(--clr-text-dim);
    display: flex;
    gap: 0.75rem;
}

.history-detail {
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.history-empty-state {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--clr-text-muted);
    gap: 1rem;
}

.history-empty-state .icon {
    font-size: 3rem;
    opacity: 0.3;
}

.history-detail-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.detail-header {
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.raw-code-block {
    flex-grow: 1;
    margin: 0;
    padding: 1.5rem;
    background: rgba(0,0,0,0.3);
    color: #a5d6ff;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.9rem;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

@media (max-width: 1000px) {
    .history-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
    .history-detail {
        min-height: 400px;
    }
}
