/* ========== Light Theme (default) ========== */
:root {
    --bg-page: #f0f2f5;
    --bg-card: #fff;
    --bg-header: #1a365d;
    --bg-stats: #fff;
    --text-primary: #333;
    --text-secondary: #888;
    --text-heading: #2c3e50;
    --accent: #3498db;
    --online: #2ecc71;
    --offline: #e74c3c;
    --warning: #f39c12;
    --badge-bg: #e8edf3;
    --badge-color: #1a365d;
    --border-light: #e5e7eb;
    --card-shadow: 0 2px 8px rgba(0,0,0,0.06);
    --card-shadow-hover: 0 4px 16px rgba(0,0,0,0.1);
    --card-radius: 12px;
    --btn-hover-bg: rgba(52,152,219,0.04);
    --modal-overlay: rgba(0,0,0,0.5);
    --modal-shadow: 0 20px 60px rgba(0,0,0,0.15);
    --iframe-bg: #f8f9fa;
    --mobile-close-bg: rgba(0,0,0,0.08);
    --type-edgeflex-bg: rgba(52,152,219,0.12);
    --type-edgeflex-color: #2980b9;
    --type-xpresscan-bg: rgba(243,156,18,0.12);
    --type-xpresscan-color: #d68910;
    --type-magnetic-bg: rgba(156,39,176,0.12);
    --type-magnetic-color: #8e44ad;
}

/* ========== Dark Theme ========== */
[data-theme="dark"] {
    --bg-page: #111827;
    --bg-card: #1f2937;
    --bg-header: #0f172a;
    --bg-stats: #1f2937;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-heading: #f3f4f6;
    --accent: #60a5fa;
    --online: #34d399;
    --offline: #f87171;
    --warning: #fbbf24;
    --badge-bg: rgba(96,165,250,0.15);
    --badge-color: #93bbfc;
    --border-light: #374151;
    --card-shadow: 0 2px 8px rgba(0,0,0,0.3);
    --card-shadow-hover: 0 4px 16px rgba(0,0,0,0.4);
    --btn-hover-bg: rgba(96,165,250,0.08);
    --modal-overlay: rgba(0,0,0,0.7);
    --modal-shadow: 0 20px 60px rgba(0,0,0,0.5);
    --iframe-bg: #111827;
    --mobile-close-bg: rgba(255,255,255,0.1);
    --type-edgeflex-bg: rgba(96,165,250,0.15);
    --type-edgeflex-color: #93c5fd;
    --type-xpresscan-bg: rgba(251,191,36,0.15);
    --type-xpresscan-color: #fcd34d;
    --type-magnetic-bg: rgba(192,132,252,0.15);
    --type-magnetic-color: #c4b5fd;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background 0.3s, color 0.3s;
}

/* Header */
header {
    background: var(--bg-header);
    color: #fff;
    padding: 0 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    transition: background 0.3s;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header-right { display: flex; align-items: center; gap: 8px; }

.header-logo { height: 36px; }

h1 { font-size: 16px; font-weight: 600; color: #fff; white-space: nowrap; }

.badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-online { background: rgba(46,204,113,0.15); color: var(--online); }
.badge-offline { background: rgba(231,76,60,0.15); color: var(--offline); }

.btn-link {
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.9);
    border: none;
    border-radius: 8px;
    padding: 0 14px;
    height: 34px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.btn-link:hover { background: rgba(255,255,255,0.2); color: #fff; }

/* Theme Toggle */
.theme-toggle {
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 8px;
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    -webkit-tap-highlight-color: transparent;
    color: rgba(255,255,255,0.9);
    font-size: 16px;
    line-height: 1;
}

.theme-toggle:hover { background: rgba(255,255,255,0.2); }

.theme-toggle .icon-sun,
.theme-toggle .icon-moon { display: none; }

/* Light mode: show moon (click to go dark) */
:root .theme-toggle .icon-moon { display: inline; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }

.server-time {
    font-size: 13px;
    color: rgba(255,255,255,0.7);
    font-family: 'JetBrains Mono', Consolas, monospace;
}

/* Stats */
.stats-bar {
    background: var(--bg-stats);
    padding: 12px 24px;
    display: flex;
    gap: 32px;
    box-shadow: var(--card-shadow);
    border-bottom: 1px solid var(--border-light);
    transition: background 0.3s, border-color 0.3s;
}

.stat { display: flex; align-items: center; gap: 8px; }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text-heading); }
.stat-online { color: var(--online); }
.stat-offline { color: var(--offline); }
.stat-avail { color: var(--accent); }
.stat-label { font-size: 11px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; }

/* Grid */
.fleet-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 16px;
    padding: 24px;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-secondary);
    padding: 80px 20px;
    font-size: 15px;
}

/* Cards */
.crawler-card {
    background: var(--bg-card);
    border-radius: var(--card-radius);
    padding: 20px;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s, box-shadow 0.2s, background 0.3s;
}

.crawler-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--card-shadow-hover);
}

.crawler-card.is-offline { opacity: 0.65; }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.card-hostname { display: flex; align-items: center; gap: 10px; }

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

.status-dot.online {
    background: var(--online);
    box-shadow: 0 0 8px var(--online);
    animation: pulse 2s ease-in-out infinite;
}

.status-dot.offline { background: var(--offline); }

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

.card-hostname h3 { font-size: 16px; font-weight: 600; color: var(--text-heading); }

.type-badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: var(--badge-bg);
    color: var(--badge-color);
}

.type-edgeflex { background: var(--type-edgeflex-bg); color: var(--type-edgeflex-color); }
.type-xpresscan { background: var(--type-xpresscan-bg); color: var(--type-xpresscan-color); }
.type-magnetic { background: var(--type-magnetic-bg); color: var(--type-magnetic-color); }
.type-unknown { background: var(--badge-bg); color: var(--text-secondary); }

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    margin-bottom: 16px;
}

.info-item { display: flex; flex-direction: column; gap: 1px; }

.info-label {
    font-size: 10px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    font-size: 13px;
    font-family: 'JetBrains Mono', Consolas, monospace;
    color: var(--text-heading);
    word-break: break-all;
}

.val-green { color: var(--online); }
.val-red { color: var(--offline); }

/* Buttons */
.card-actions { display: flex; gap: 8px; }

.btn {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    text-align: center;
}

.btn:hover { border-color: var(--accent); color: var(--accent); background: var(--btn-hover-bg); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }
.btn-sm { flex: none; padding: 4px 12px; font-size: 11px; }

.btn-ping.success { border-color: var(--online); color: var(--online); }
.btn-ping.fail { border-color: var(--offline); color: var(--offline); }

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: var(--modal-overlay);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-terminal {
    width: 85vw; height: 80vh;
}

.modal-webui {
    width: 90vw; height: 85vh;
}

.modal-box {
    background: var(--bg-card);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    box-shadow: var(--modal-shadow);
    transition: background 0.3s;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.modal-header h2 { font-size: 15px; color: var(--text-heading); font-weight: 600; }

.modal-actions { display: flex; align-items: center; gap: 12px; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover { color: var(--text-primary); }

.modal-iframe { flex: 1; border: none; background: var(--iframe-bg); border-radius: 0 0 14px 14px; }

/* Responsive */
@media (max-width: 768px) {
    .fleet-grid { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
    header { flex-direction: column; gap: 10px; padding: 12px 16px; height: auto; }
    .stats-bar { flex-wrap: wrap; justify-content: center; gap: 16px; padding: 10px 16px; }
    .modal-overlay {
        align-items: flex-start;
    }
    .modal-terminal, .modal-webui {
        width: 100vw;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
    }
    .modal-box { border-radius: 0; }
    .modal-iframe { border-radius: 0; }
    .modal-header {
        padding: 10px 16px;
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
        background: var(--bg-card);
        z-index: 10;
        position: relative;
    }
    .modal-close {
        font-size: 28px;
        padding: 6px 12px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--mobile-close-bg);
        border-radius: 8px;
        color: var(--text-primary);
    }
}
