/* ========================================
   Simpada Monitoring Dashboard
   Premium dark theme with glassmorphism
   ======================================== */

/* --- CSS Variables / Design Tokens --- */
:root {
    /* Base colors */
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2236;
    --bg-card: rgba(17, 24, 39, 0.7);
    --bg-card-hover: rgba(26, 34, 54, 0.9);

    /* Glass */
    --glass-bg: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);

    /* Text */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Status colors */
    --color-online: #10b981;
    --color-online-bg: rgba(16, 185, 129, 0.1);
    --color-online-glow: rgba(16, 185, 129, 0.3);

    --color-warning: #f59e0b;
    --color-warning-bg: rgba(245, 158, 11, 0.1);
    --color-warning-glow: rgba(245, 158, 11, 0.3);

    --color-critical: #f97316;
    --color-critical-bg: rgba(249, 115, 22, 0.1);
    --color-critical-glow: rgba(249, 115, 22, 0.3);

    --color-offline: #ef4444;
    --color-offline-bg: rgba(239, 68, 68, 0.1);
    --color-offline-glow: rgba(239, 68, 68, 0.3);

    /* Accent */
    --accent: #6366f1;
    --accent-light: #818cf8;

    /* Sizing */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Light Mode Variables --- */
body.theme-light {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: rgba(255, 255, 255, 0.85);
    --bg-card-hover: rgba(255, 255, 255, 1);

    --glass-bg: rgba(0, 0, 0, 0.03);
    --glass-border: rgba(0, 0, 0, 0.08);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.06);

    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
}

/* --- Reset & Base --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Animated Background --- */
.bg-gradient {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(ellipse 80% 60% at 20% 10%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 80% 90%, rgba(16, 185, 129, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse 50% 40% at 50% 50%, rgba(245, 158, 11, 0.04) 0%, transparent 40%);
    animation: gradientShift 20s ease-in-out infinite alternate;
}

@keyframes gradientShift {
    0% { opacity: 0.8; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.05); }
    100% { opacity: 0.8; transform: scale(1); }
}

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

/* --- Header --- */
.header {
    margin-bottom: 32px;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    border-radius: var(--radius-md);
    color: white;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 2px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.last-update {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}

.btn-refresh,
.btn-download,
.btn-theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    background: var(--glass-bg);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 500;
    transition: all var(--transition-fast);
    backdrop-filter: blur(10px);
}

.btn-theme-toggle {
    padding: 8px;
}

.btn-refresh:hover,
.btn-theme-toggle:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--accent);
    color: var(--accent-light);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.15);
}

.btn-download {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(16, 185, 129, 0.05));
    border-color: rgba(16, 185, 129, 0.3);
    color: var(--color-online);
}

.btn-download:hover {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.25), rgba(16, 185, 129, 0.1));
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.15);
}

.btn-refresh.spinning svg {
    animation: spin 0.8s linear infinite;
}

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

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card {
    position: relative;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 24px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    backdrop-filter: blur(20px);
    overflow: hidden;
    cursor: pointer;
    transition: all var(--transition-base);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transition: height var(--transition-base);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--glass-shadow);
}

.stat-card:hover::before {
    height: 4px;
}

.stat-card.active {
    border-color: transparent;
}

/* Status-specific card styles */
.stat-online::before { background: linear-gradient(90deg, var(--color-online), rgba(16, 185, 129, 0.5)); }
.stat-online:hover, .stat-online.active { border-color: rgba(16, 185, 129, 0.3); box-shadow: 0 8px 32px var(--color-online-glow); }

.stat-warning::before { background: linear-gradient(90deg, var(--color-warning), rgba(245, 158, 11, 0.5)); }
.stat-warning:hover, .stat-warning.active { border-color: rgba(245, 158, 11, 0.3); box-shadow: 0 8px 32px var(--color-warning-glow); }

.stat-critical::before { background: linear-gradient(90deg, var(--color-critical), rgba(249, 115, 22, 0.5)); }
.stat-critical:hover, .stat-critical.active { border-color: rgba(249, 115, 22, 0.3); box-shadow: 0 8px 32px var(--color-critical-glow); }

.stat-offline::before { background: linear-gradient(90deg, var(--color-offline), rgba(239, 68, 68, 0.5)); }
.stat-offline:hover, .stat-offline.active { border-color: rgba(239, 68, 68, 0.3); box-shadow: 0 8px 32px var(--color-offline-glow); }

.stat-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.stat-online .stat-icon { background: var(--color-online-bg); color: var(--color-online); }
.stat-warning .stat-icon { background: var(--color-warning-bg); color: var(--color-warning); }
.stat-critical .stat-icon { background: var(--color-critical-bg); color: var(--color-critical); }
.stat-offline .stat-icon { background: var(--color-offline-bg); color: var(--color-offline); }

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-number {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.03em;
}

.stat-online .stat-number { color: var(--color-online); }
.stat-warning .stat-number { color: var(--color-warning); }
.stat-critical .stat-number { color: var(--color-critical); }
.stat-offline .stat-number { color: var(--color-offline); }

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-top: 2px;
}

/* Decorative ring */
.stat-ring {
    position: absolute;
    right: -20px;
    top: -20px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    opacity: 0.04;
}

.stat-online .stat-ring { background: var(--color-online); }
.stat-warning .stat-ring { background: var(--color-warning); }
.stat-critical .stat-ring { background: var(--color-critical); }
.stat-offline .stat-ring { background: var(--color-offline); }

/* --- Table Section --- */
.table-section {
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    backdrop-filter: blur(20px);
    overflow: hidden;
}

/* Filter bar */
.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--glass-border);
    gap: 16px;
    flex-wrap: wrap;
}

.filter-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.filter-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 500;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.filter-tab:hover {
    background: var(--glass-bg);
    color: var(--text-secondary);
}

.filter-tab.active {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--accent-light);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-online { background: var(--color-online); box-shadow: 0 0 6px var(--color-online-glow); }
.dot-warning { background: var(--color-warning); box-shadow: 0 0 6px var(--color-warning-glow); }
.dot-critical { background: var(--color-critical); box-shadow: 0 0 6px var(--color-critical-glow); }
.dot-offline { background: var(--color-offline); box-shadow: 0 0 6px var(--color-offline-glow); }

.badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
}

.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-critical { background: var(--color-critical-bg); color: var(--color-critical); }
.badge-offline { background: var(--color-offline-bg); color: var(--color-offline); }
.badge-online { background: var(--color-online-bg); color: var(--color-online); }

.filter-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.select-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.select-wrapper svg {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    pointer-events: none;
}

.filter-select {
    appearance: none;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: inherit;
    padding: 8px 36px 8px 36px;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
    min-width: 160px;
}

.filter-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.filter-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all var(--transition-fast);
    min-width: 240px;
}

.search-box:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.search-box input {
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 0.8rem;
    font-family: inherit;
    outline: none;
    width: 100%;
}

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

/* Table */
.table-wrapper {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.data-table thead th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid var(--glass-border);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 1;
}

.th-no { width: 50px; text-align: center; }
.th-status { width: 100px; }

.data-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.04);
}

.data-table tbody td {
    padding: 12px 16px;
    color: var(--text-secondary);
    vertical-align: middle;
}

.data-table tbody td:first-child {
    text-align: center;
    color: var(--text-muted);
    font-weight: 500;
}

/* Status badge in table */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-badge.status-Online {
    background: var(--color-online-bg);
    color: var(--color-online);
}
.status-badge.status-Online::before {
    background: var(--color-online);
    box-shadow: 0 0 6px var(--color-online);
}

.status-badge.status-Warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}
.status-badge.status-Warning::before {
    background: var(--color-warning);
    box-shadow: 0 0 6px var(--color-warning);
}

.status-badge.status-Critical {
    background: var(--color-critical-bg);
    color: var(--color-critical);
}
.status-badge.status-Critical::before {
    background: var(--color-critical);
    box-shadow: 0 0 6px var(--color-critical);
}

.status-badge.status-Offline {
    background: var(--color-offline-bg);
    color: var(--color-offline);
}
.status-badge.status-Offline::before {
    background: var(--color-offline);
    box-shadow: 0 0 6px var(--color-offline);
}

/* WP name styling */
.wp-name {
    font-weight: 500;
    color: var(--text-primary);
}

.device-code {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.04);
    padding: 2px 8px;
    border-radius: 4px;
}

/* Table footer */
.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-top: 1px solid var(--glass-border);
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* --- Loading states --- */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 14, 26, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity var(--transition-slow);
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xl);
    backdrop-filter: blur(20px);
}

.loading-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.loading-spinner {
    width: 24px;
    height: 24px;
    border: 2.5px solid var(--glass-border);
    border-top-color: var(--accent-light);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: inline-block;
}

.loading-spinner.large {
    width: 40px;
    height: 40px;
    border-width: 3px;
}

.loading-row td {
    text-align: center;
    padding: 60px 16px !important;
    color: var(--text-muted) !important;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

/* Empty state */
.empty-row td {
    text-align: center;
    padding: 60px 16px !important;
    color: var(--text-muted) !important;
}

/* --- Toast Notifications --- */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 2000;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    color: var(--text-primary);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    animation: slideInRight 0.3s ease-out;
    backdrop-filter: blur(20px);
}

.toast.success { border-left: 3px solid var(--color-online); }
.toast.error { border-left: 3px solid var(--color-offline); }
.toast.info { border-left: 3px solid var(--accent); }

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

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

/* --- Number animation --- */
.stat-number {
    transition: transform 0.3s ease;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .container {
        padding: 16px;
    }

    .header-content {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-right {
        width: 100%;
        flex-wrap: wrap;
    }

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

    .stat-card {
        padding: 16px;
    }

    .stat-number {
        font-size: 1.5rem;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-select {
        width: 100%;
    }

    .filter-tabs {
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .search-box {
        min-width: unset;
    }

    .data-table {
        font-size: 0.75rem;
    }

    .data-table thead th,
    .data-table tbody td {
        padding: 10px 12px;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .stat-card {
        padding: 12px;
        gap: 10px;
    }

    .stat-icon {
        width: 36px;
        height: 36px;
    }

    .stat-icon svg {
        width: 18px;
        height: 18px;
    }

    .stat-number {
        font-size: 1.3rem;
    }

    .header h1 {
        font-size: 1.2rem;
    }
}
