/**
 * Admin Dashboard Styles
 */

/* Reset and Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colors */
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --secondary: #64748b;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    /* Grays */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;

    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--gray-900);
    background: var(--gray-50);
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 var(--spacing-lg);
}

/* Header */
.header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 64px;
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--gray-900);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
}

/* Connection Status */
.connection-status {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--gray-100);
    border-radius: var(--radius-md);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray-400);
}

.status-indicator.connecting {
    background: var(--warning);
    animation: pulse 2s infinite;
}

.status-indicator.connected {
    background: var(--success);
}

.status-indicator.error {
    background: var(--danger);
}

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

/* Main Content */
.main-content {
    padding: var(--spacing-xl) 0;
}

/* Stats Overview */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: white;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: var(--spacing-xs);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--gray-600);
    font-weight: 500;
}

/* Filters Section */
.filters-section {
    background: white;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    margin-bottom: var(--spacing-lg);
}

.search-box {
    margin-bottom: var(--spacing-md);
}

.search-box input {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: all 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

.filter-buttons {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.filter-btn {
    padding: var(--spacing-xs) var(--spacing-md);
    border: 1px solid var(--gray-300);
    background: white;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    color: var(--gray-700);
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover {
    background: var(--gray-50);
}

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

/* Customers Table */
.customers-section {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    overflow: hidden;
}

.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
}

th {
    padding: var(--spacing-md);
    text-align: left;
    font-weight: 600;
    color: var(--gray-700);
    font-size: 0.875rem;
}

td {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.875rem;
}

tbody tr:hover {
    background: var(--gray-50);
}

.customer-id {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: var(--gray-600);
}

.loading-cell, .empty-cell, .error-cell {
    text-align: center;
    color: var(--gray-500);
    padding: var(--spacing-xl);
}

.error-cell {
    color: var(--danger);
}

/* Usage Bar */
.usage-bar {
    position: relative;
    width: 100px;
    height: 20px;
    background: var(--gray-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.usage-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    transition: width 0.3s ease;
}

.usage-fill.usage-low {
    background: var(--success);
}

.usage-fill.usage-medium {
    background: var(--warning);
}

.usage-fill.usage-high {
    background: var(--danger);
}

.usage-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-700);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    background: var(--gray-200);
    color: var(--gray-700);
}

.badge-success {
    background: var(--success);
    color: white;
}

.badge-warning {
    background: var(--warning);
    color: white;
}

.badge-danger {
    background: var(--danger);
    color: white;
}

.badge-info {
    background: var(--info);
    color: white;
}

.badge-secondary {
    background: var(--gray-400);
    color: white;
}

/* Buttons */
.btn {
    padding: var(--spacing-sm) var(--spacing-md);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
}

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

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

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    padding: var(--spacing-xs) var(--spacing-sm);
    font-size: 0.8rem;
}

.btn-xs {
    padding: 0.125rem var(--spacing-xs);
    font-size: 0.75rem;
}

.btn .icon {
    font-size: 1.1em;
}

/* Environment Toggle Button */
.env-toggle {
    background: var(--success);
    color: white;
    font-weight: 600;
    font-size: 0.75rem;
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-md);
    min-width: 60px;
    text-align: center;
    transition: all 0.2s ease;
}

.env-toggle:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.env-toggle.dev-mode {
    background: var(--warning);
    color: var(--gray-900);
}

.env-toggle.local-mode {
    background: var(--info);
    cursor: default;
}

.env-toggle:disabled {
    opacity: 0.8;
    cursor: not-allowed;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-small {
    max-width: 400px;
}

.modal-header {
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 1.5rem;
    color: var(--gray-400);
    cursor: pointer;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: var(--gray-100);
    color: var(--gray-600);
}

.modal-body {
    padding: var(--spacing-lg);
}

.modal-actions {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-lg);
    padding-top: var(--spacing-lg);
    border-top: 1px solid var(--gray-200);
}

/* Customer Info */
.customer-info {
    background: var(--gray-50);
    padding: var(--spacing-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--spacing-lg);
}

.info-row {
    display: flex;
    align-items: center;
    padding: var(--spacing-xs) 0;
}

.info-label {
    font-weight: 600;
    color: var(--gray-600);
    width: 140px;
    font-size: 0.875rem;
}

.info-value {
    color: var(--gray-900);
}

/* Usage Section */
.usage-section {
    margin-bottom: var(--spacing-lg);
}

.usage-section h3 {
    margin-bottom: var(--spacing-md);
    font-size: 1rem;
    font-weight: 600;
}

.usage-categories {
    display: grid;
    gap: var(--spacing-md);
}

.usage-category {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    background: var(--gray-50);
}

.category-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: var(--spacing-sm);
}

.category-name {
    font-weight: 600;
    color: var(--gray-700);
}

.category-usage {
    color: var(--gray-600);
    font-size: 0.875rem;
}

.category-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: var(--spacing-sm);
}

.reset-date {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* Limits Section */
.limits-section h3 {
    margin-bottom: var(--spacing-sm);
    font-size: 1rem;
    font-weight: 600;
}

.section-note {
    color: var(--gray-600);
    font-size: 0.875rem;
    margin-bottom: var(--spacing-md);
}

.custom-limits-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-md);
}

.limit-input-group {
    display: flex;
    flex-direction: column;
}

.limit-input-group label {
    display: flex;
    flex-direction: column;
    margin-bottom: var(--spacing-xs);
}

.limit-label {
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.125rem;
}

.limit-description {
    font-size: 0.75rem;
    color: var(--gray-500);
}

.current-usage {
    font-size: 0.75rem;
    color: var(--gray-600);
    font-weight: 500;
}

.limit-input-group input {
    padding: var(--spacing-sm);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.limit-input-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

/* Export Modal */
.export-options {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-lg);
}

.export-options .btn {
    flex: 1;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: var(--spacing-lg);
    right: var(--spacing-lg);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.toast {
    padding: var(--spacing-md) var(--spacing-lg);
    border-radius: var(--radius-md);
    background: var(--gray-800);
    color: white;
    font-size: 0.875rem;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
}

.toast-success {
    background: var(--success);
}

.toast-error {
    background: var(--danger);
}

.toast-warning {
    background: var(--warning);
}

.toast-info {
    background: var(--info);
}

.toast.fade-out {
    animation: slideOut 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* No Data */
.no-data {
    text-align: center;
    color: var(--gray-500);
    padding: var(--spacing-lg);
}

/* ============================================
   Unified View Styles (Web + Desktop)
   ============================================ */

/* User Type Stats Section */
.user-type-stats {
    display: flex;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
    flex-wrap: wrap;
}

.stat-card-sm {
    flex: 1;
    min-width: 150px;
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
}

.stat-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

.stat-icon-web {
    background: rgba(33, 150, 243, 0.1);
    color: #2196F3;
}

.stat-icon-web::before {
    content: "🌐";
}

.stat-icon-desktop {
    background: rgba(76, 175, 80, 0.1);
    color: #4CAF50;
}

.stat-icon-desktop::before {
    content: "🖥️";
}

.stat-icon-both {
    background: rgba(156, 39, 176, 0.1);
    color: #9C27B0;
}

.stat-icon-both::before {
    content: "🔗";
}

.stat-card-sm .stat-value {
    font-size: 1.5rem;
    margin-bottom: 0;
}

.stat-card-sm .stat-label {
    font-size: 0.75rem;
}

/* Web Stats Section */
.web-stats-section {
    background: white;
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    margin-bottom: var(--spacing-lg);
}

.web-stats-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: var(--spacing-md);
}

.web-stats-container {
    min-height: 60px;
}

.web-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--spacing-md);
}

.web-stat-card {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md);
    background: var(--gray-50);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
}

.web-stat-card .stat-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

.web-stat-card .stat-content {
    flex: 1;
}

.web-stat-card .stat-value {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0;
}

.web-stat-card .stat-label {
    font-size: 0.7rem;
    color: var(--gray-500);
}

.loading-text {
    color: var(--gray-500);
    font-style: italic;
}

/* Filter Controls */
.filter-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--spacing-md);
}

.auth-filter {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.auth-filter label {
    font-size: 0.875rem;
    color: var(--gray-600);
    font-weight: 500;
}

.auth-filter select {
    padding: var(--spacing-xs) var(--spacing-sm);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    background: white;
    cursor: pointer;
}

.auth-filter select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.1);
}

/* Auth Method Badges */
.auth-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    color: white;
}

.auth-polar {
    background: #4CAF50;
}

.auth-supabase {
    background: #2196F3;
}

.auth-both {
    background: #9C27B0;
}

/* App Metrics in Table */
.app-metrics {
    display: flex;
    flex-direction: column;
    gap: 2px;
    font-size: 0.75rem;
    color: var(--gray-600);
}

.app-metrics span {
    white-space: nowrap;
}

.text-muted {
    color: var(--gray-400);
}

/* Web User Modal */
.web-user-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.web-user-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-md);
    margin-top: var(--spacing-md);
}

.metric-card {
    text-align: center;
    padding: var(--spacing-md);
    background: var(--gray-50);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
}

.metric-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.metric-label {
    font-size: 0.75rem;
    color: var(--gray-500);
    margin-top: var(--spacing-xs);
}

/* Application List Items */
.app-item {
    display: grid;
    grid-template-columns: 2fr 1fr 80px 80px;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    border-bottom: 1px solid var(--gray-100);
    align-items: center;
}

.app-item:last-child {
    border-bottom: none;
}

.app-title {
    font-weight: 500;
    color: var(--gray-800);
}

.app-company {
    font-size: 0.875rem;
    color: var(--gray-600);
}

.app-status .badge {
    font-size: 0.65rem;
}

.app-date {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-align: right;
}

/* Responsive */
@media (max-width: 768px) {
    .header .container {
        flex-direction: column;
        height: auto;
        padding: var(--spacing-md);
        gap: var(--spacing-md);
    }

    .header-actions {
        width: 100%;
        justify-content: space-between;
    }

    .stats-overview {
        grid-template-columns: repeat(2, 1fr);
    }

    .modal-content {
        width: 95%;
        margin: var(--spacing-md);
    }

    .custom-limits-form {
        grid-template-columns: 1fr;
    }

    .export-options {
        flex-direction: column;
    }

    table {
        font-size: 0.8rem;
    }

    th, td {
        padding: var(--spacing-sm);
    }
}