:root {
    /* Color Palette */
    --bg-dark: #0f1115;
    --bg-card: rgba(25, 28, 36, 0.6);
    --border-color: rgba(255, 255, 255, 0.08);
    
    --accent-primary: #3b82f6; /* Blue */
    --accent-secondary: #8b5cf6; /* Purple */
    --accent-success: #10b981; /* Green */
    
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    
    --glow-primary: rgba(59, 130, 246, 0.4);
    
    /* Typography */
    --font-main: 'Inter', sans-serif;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-main);
    min-height: 100vh;
    /* Subtle background gradient */
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.05), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(139, 92, 246, 0.05), transparent 25%);
}

/* --- Layout --- */
.dashboard-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 3rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 3rem; /* Spacing between header and main content */
}

.main-content {
    display: flex;
    flex-direction: column;
    gap: 3rem; /* Real spacing between blocks */
}

/* --- Glassmorphism Utils --- */
.glass-panel {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

/* --- Header --- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 2rem; /* Increased padding */
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo i {
    font-size: 2rem;
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px var(--glow-primary));
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.logo h1 span {
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 0.25rem;
}

/* Status Badge */
.status-badge {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(16, 185, 129, 0.1);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.pulse-dot {
    width: 8px;
    height: 8px;
    background-color: var(--accent-success);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem; /* Increased gap */
}

.stat-card {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.4);
    border-color: rgba(255, 255, 255, 0.15);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(139, 92, 246, 0.2));
    color: var(--accent-primary);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.stat-info h3 {
    font-size: 0.875rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
}

/* --- Charts Section --- */
.charts-section {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem; /* Increased gap */
}

@media (max-width: 800px) {
    .charts-section {
        grid-template-columns: 1fr;
    }
}

/* --- Responsive Adjustments --- */
@media (max-width: 600px) {
    .dashboard-container {
        padding: 1.5rem 1rem;
        gap: 2rem;
    }

    .main-content {
        gap: 2rem;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        padding-bottom: 1.5rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .stat-card {
        padding: 1.25rem;
    }

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

    .canvas-wrapper {
        height: 250px;
    }

    .chart-container, .table-section {
        padding: 1.25rem;
    }

    .section-header h2, .chart-header h2 {
        font-size: 1rem;
    }

    /* --- Mobile Table Card Layout (Polished) --- */
    table, thead, tbody, th, td, tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .table-row {
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        padding: 1.5rem 0;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .table-row:last-child {
        border-bottom: none;
    }

    .td-manga {
        grid-column: span 2;
        font-size: 1.05rem !important;
        font-weight: 700 !important;
        color: var(--text-main);
        line-height: 1.4;
        margin-bottom: 0.5rem;
        background: transparent !important;
        padding: 0 !important;
    }

    .td-volume, .td-lang, .td-size, .td-date {
        font-size: 0.8rem !important;
        padding: 0 !important;
        background: transparent !important;
        display: flex;
        flex-direction: column;
        gap: 2px;
        border: none !important;
    }

    /* Add pseudo-labels for context */
    .td-volume::before { content: "VOLUMEN"; font-size: 0.6rem; color: var(--text-muted); font-weight: 600; }
    .td-lang::before { content: "IDIOMA"; font-size: 0.6rem; color: var(--text-muted); font-weight: 600; }
    .td-size::before { content: "TAMAÑO"; font-size: 0.6rem; color: var(--text-muted); font-weight: 600; }
    .td-date::before { content: "FECHA"; font-size: 0.6rem; color: var(--text-muted); font-weight: 600; }

    .td-method {
        grid-column: span 2;
        padding: 0.5rem 0 0 0 !important;
        background: transparent !important;
        border: none !important;
    }

    .td-date {
        text-align: right;
        align-items: flex-end;
    }
}

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

.chart-header {
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
}

.canvas-wrapper {
    position: relative;
    height: 300px;
    width: 100%;
}

.donut-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
}

.donut-wrapper canvas {
    max-width: 250px !important; /* Force a reasonable size */
    max-height: 250px !important;
    margin: 0 auto;
}

/* --- Table Section --- */
.table-section {
    padding: 1.5rem;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.btn-refresh {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    transition: all 0.2s ease;
}

.btn-refresh:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.2);
}

.table-responsive {
    overflow-x: hidden; /* We'll use card layout instead of horizontal scroll */
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    padding: 1rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 1rem;
    font-size: 0.875rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

/* Method Badges */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge.telegram {
    background: rgba(56, 189, 248, 0.1);
    color: #38bdf8;
    border: 1px solid rgba(56, 189, 248, 0.2);
}

.badge.r2 {
    background: rgba(249, 115, 22, 0.1);
    color: #f97316;
    border: 1px solid rgba(249, 115, 22, 0.2);
}

.badge.usb {
    background: rgba(168, 85, 247, 0.1);
    color: #a855f7;
    border: 1px solid rgba(168, 85, 247, 0.2);
}

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

/* --- Footer --- */
footer {
    text-align: center;
    padding-top: 1rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Loading States */
.loading {
    opacity: 0.5;
    animation: pulse-opacity 1.5s infinite;
}

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