/* ==========================================
   TELEGRAM ANALYTICS DASHBOARD - CSS
   ========================================== */

:root {
    /* Colors */
    --primary: #0088cc;
    --primary-dark: #006699;
    --primary-light: #33a3d9;
    --secondary: #6c757d;
    --success: #28a745;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #17a2b8;

    /* Dark theme */
    --bg-dark: #1a1a2e;
    --bg-card: #16213e;
    --bg-sidebar: #0f0f23;
    --text-primary: #ffffff;
    --text-secondary: #a0aec0;
    --text-muted: #718096;
    --border-color: #2d3748;

    /* Spacing */
    --sidebar-width: 250px;
    --header-height: 70px;
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
}

/* ==========================================
   SIDEBAR
   ========================================== */

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    z-index: 100;
    transition: width 0.3s ease;
}

.mobile-menu-btn {
    display: none;
}

.logo {
    padding: var(--spacing-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.logo-icon {
    font-size: 2rem;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.nav-menu {
    list-style: none;
    padding: var(--spacing-md);
    flex: 1;
}

.nav-item {
    margin-bottom: var(--spacing-xs);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.nav-link:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.nav-item.active .nav-link {
    background: var(--primary);
    color: white;
}

.nav-link .icon {
    font-size: 1.25rem;
}

.sidebar-footer {
    padding: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

.export-buttons {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

/* ==========================================
   MAIN CONTENT
   ========================================== */

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: var(--spacing-lg);
    max-width: calc(100vw - var(--sidebar-width));
}

/* ==========================================
   HEADER
   ========================================== */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-xl);
    padding-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.header h1 {
    font-size: 1.75rem;
    font-weight: 600;
}

.header-controls {
    display: flex;
    gap: var(--spacing-md);
    align-items: center;
}

/* ==========================================
   BUTTONS & INPUTS
   ========================================== */

.btn {
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn:hover {
    background: var(--border-color);
}

.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-sm {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.75rem;
}

.select, .select-sm {
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.875rem;
    cursor: pointer;
}

.select-sm {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.75rem;
}

.select:focus, .select-sm:focus {
    outline: none;
    border-color: var(--primary);
}

input[type="text"], input[type="search"] {
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.875rem;
    width: 100%;
}

input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ==========================================
   STATS CARDS
   ========================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    border: 1px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.stat-icon {
    font-size: 2.5rem;
    opacity: 0.9;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: var(--spacing-xs);
}

/* ==========================================
   CHARTS
   ========================================== */

.charts-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.chart-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    border: 1px solid var(--border-color);
}

.chart-card.large {
    grid-column: span 1;
}

.chart-card.full-width {
    grid-column: span 2;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-md);
}

.chart-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.chart-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.chart-container {
    position: relative;
    height: 250px;
}

/* ==========================================
   HEATMAP
   ========================================== */

.heatmap-container {
    overflow-x: auto;
}

.heatmap-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
}

.heatmap-table th,
.heatmap-table td {
    padding: var(--spacing-xs);
    text-align: center;
    min-width: 35px;
}

.heatmap-table th {
    color: var(--text-muted);
    font-weight: 500;
}

.heatmap-cell {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    display: inline-block;
    transition: transform 0.2s ease;
}

.heatmap-cell:hover {
    transform: scale(1.2);
}

.day-label {
    text-align: right;
    padding-right: var(--spacing-sm) !important;
    color: var(--text-secondary);
}

/* ==========================================
   LISTS
   ========================================== */

.lists-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.list-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.list-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.link {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.875rem;
}

.link:hover {
    text-decoration: underline;
}

.list-content {
    max-height: 350px;
    overflow-y: auto;
}

.list-item {
    display: flex;
    align-items: center;
    padding: var(--spacing-sm) var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
    gap: var(--spacing-md);
}

.list-item:last-child {
    border-bottom: none;
}

.list-item:hover {
    background: rgba(255, 255, 255, 0.02);
}

.list-rank {
    font-weight: 700;
    color: var(--text-muted);
    min-width: 30px;
}

.list-rank.gold { color: #ffd700; }
.list-rank.silver { color: #c0c0c0; }
.list-rank.bronze { color: #cd7f32; }

.list-info {
    flex: 1;
    min-width: 0;
}

.list-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.list-value {
    font-weight: 600;
    color: var(--primary);
}

/* ==========================================
   USERS PAGE
   ========================================== */

.users-table {
    width: 100%;
    border-collapse: collapse;
}

.users-table th,
.users-table td {
    padding: var(--spacing-md);
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.users-table th {
    background: var(--bg-sidebar);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
    position: sticky;
    top: 0;
}

.users-table tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
}

.user-cell {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

.progress-bar {
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
    margin-top: var(--spacing-xs);
}

.progress-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
}

/* ==========================================
   SEARCH PAGE
   ========================================== */

.search-box {
    display: flex;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.search-input {
    flex: 1;
}

.search-results {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.search-result-item {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.search-result-author {
    font-weight: 600;
    color: var(--primary);
}

.search-result-date {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.search-result-text {
    color: var(--text-secondary);
    line-height: 1.5;
}

.search-highlight {
    background: rgba(0, 136, 204, 0.3);
    padding: 0 2px;
    border-radius: 2px;
}

/* ==========================================
   PAGINATION
   ========================================== */

.pagination {
    display: flex;
    justify-content: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-xl);
}

.page-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.page-btn:hover {
    background: var(--border-color);
}

.page-btn.active {
    background: var(--primary);
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ==========================================
   USER MODAL
   ========================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    transform: translateY(-20px);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    font-size: 1.25rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.modal-body {
    padding: var(--spacing-lg);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.user-profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: 700;
}

.user-profile-info h3 {
    font-size: 1.5rem;
    margin-bottom: var(--spacing-xs);
}

.user-profile-info p {
    color: var(--text-muted);
}

.user-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-xl);
}

.user-stat {
    text-align: center;
    padding: var(--spacing-md);
    background: var(--bg-sidebar);
    border-radius: var(--radius-md);
}

.user-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.user-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: var(--spacing-xs);
}

/* ==========================================
   LOADING & EMPTY STATES
   ========================================== */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    color: var(--text-muted);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.empty-state {
    text-align: center;
    padding: var(--spacing-xl);
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
}

/* ==========================================
   RESPONSIVE
   ========================================== */

@media (max-width: 1200px) {
    .lists-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 992px) {
    .sidebar {
        width: 70px;
    }

    .logo-text, .nav-link span:not(.icon) {
        display: none;
    }

    .main-content {
        margin-left: 70px;
        max-width: calc(100vw - 70px);
    }

    .charts-row {
        grid-template-columns: 1fr;
    }

    .chart-card.full-width,
    .chart-card.large {
        grid-column: span 1;
    }

    .lists-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 0;
        overflow: hidden;
        transition: width 0.3s ease;
    }

    .sidebar.open {
        width: 250px;
        overflow-y: auto;
    }

    /* Reset the 992px display:none - sidebar is hidden by width:0 anyway */
    .logo-text, .nav-link span:not(.icon) {
        display: inline !important;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 99;
    }

    .sidebar-overlay.active {
        display: block;
    }

    .mobile-menu-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        background: var(--bg-card);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-md);
        color: var(--text-primary);
        font-size: 1.5rem;
        cursor: pointer;
        position: fixed;
        top: var(--spacing-md);
        left: var(--spacing-md);
        z-index: 98;
    }

    .main-content {
        margin-left: 0;
        max-width: 100vw;
        padding: var(--spacing-md);
        padding-top: 60px;
    }

    .header {
        flex-direction: column;
        gap: var(--spacing-md);
        align-items: flex-start;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    .header-controls {
        width: 100%;
        flex-wrap: wrap;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stats-grid .stat-card {
        padding: var(--spacing-md);
    }

    .charts-row {
        grid-template-columns: 1fr;
    }

    .chart-card.full-width,
    .chart-card.large {
        grid-column: span 1;
    }

    .lists-row {
        grid-template-columns: 1fr;
    }

    .user-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .heatmap-table th,
    .heatmap-table td {
        min-width: 25px;
        font-size: 0.65rem;
        padding: 2px;
    }

    .heatmap-cell {
        width: 22px;
        height: 22px;
    }

    /* Chat messages */
    .message {
        max-width: 95% !important;
    }

    /* Search */
    .search-box {
        flex-direction: column;
    }

    .search-box input {
        width: 100%;
    }

    /* Tables */
    .data-table {
        font-size: 0.8rem;
    }

    .data-table th,
    .data-table td {
        padding: var(--spacing-sm);
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .user-stats-grid {
        grid-template-columns: 1fr;
    }

    .header h1 {
        font-size: 1.1rem;
    }

    .chart-container {
        height: 200px;
    }
}

/* ==========================================
   SCROLLBAR
   ========================================== */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-sidebar);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}
