/* =========================================================
   ThreatMeld Status Page — Dark Theme
   ========================================================= */

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

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: #1a2235;
    --bg-card-hover: #1f2942;
    --border: #2a3550;
    --border-light: #374160;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent-blue: #3b82f6;
    --accent-blue-dim: rgba(59, 130, 246, 0.15);
    --green: #10b981;
    --green-dim: rgba(16, 185, 129, 0.15);
    --yellow: #f59e0b;
    --yellow-dim: rgba(245, 158, 11, 0.15);
    --red: #ef4444;
    --red-dim: rgba(239, 68, 68, 0.15);
    --gray: #6b7280;
    --gray-dim: rgba(107, 114, 128, 0.15);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.4);
    --transition: 200ms ease;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--accent-blue);
    text-decoration: none;
    transition: color var(--transition);
}
a:hover { color: #60a5fa; }

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* ---------- Header ---------- */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
}

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

.logo-icon {
    width: 28px;
    height: 28px;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.logo-divider {
    color: var(--border-light);
    font-weight: 300;
    margin: 0 0.15rem;
}

.logo-subtitle {
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.header-meta {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.last-updated {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.auto-refresh-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--green);
    background: var(--green-dim);
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.pulse-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.85); }
}

/* ---------- Status Banner ---------- */
.status-banner {
    padding: 2rem 0;
    transition: background var(--transition);
}

.status-banner.operational { background: linear-gradient(135deg, rgba(16,185,129,0.08) 0%, transparent 100%); }
.status-banner.degraded    { background: linear-gradient(135deg, rgba(245,158,11,0.08) 0%, transparent 100%); }
.status-banner.major       { background: linear-gradient(135deg, rgba(239,68,68,0.08) 0%, transparent 100%); }

.banner-content {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.banner-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    flex-shrink: 0;
    transition: background var(--transition);
}

.banner-icon.bg-green  { background: var(--green-dim); }
.banner-icon.bg-yellow { background: var(--yellow-dim); }
.banner-icon.bg-red    { background: var(--red-dim); }
.banner-icon.bg-gray   { background: var(--gray-dim); }

.banner-text h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 0.15rem;
}

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

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ---------- Main Content ---------- */
.main-content {
    flex: 1;
    padding-top: 0.5rem;
    padding-bottom: 3rem;
}

.section {
    margin-top: 2rem;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-icon {
    font-size: 1.1rem;
}

/* ---------- Service Cards ---------- */
.service-grid {
    display: grid;
    gap: 0.75rem;
}

.service-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    transition: background var(--transition), border-color var(--transition);
}

.service-card:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-light);
}

.service-card.loading {
    opacity: 0.5;
}

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

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background var(--transition);
}

.status-indicator.status-operational { background: var(--green); box-shadow: 0 0 8px rgba(16,185,129,0.4); }
.status-indicator.status-degraded    { background: var(--yellow); box-shadow: 0 0 8px rgba(245,158,11,0.4); }
.status-indicator.status-down        { background: var(--red); box-shadow: 0 0 8px rgba(239,68,68,0.4); }
.status-indicator.status-checking    { background: var(--gray); animation: pulse 1.5s ease-in-out infinite; }
.status-indicator.status-unknown     { background: var(--gray); }

.service-name {
    font-weight: 600;
    font-size: 0.95rem;
    flex: 1;
}

.service-status-label {
    font-size: 0.8rem;
    font-weight: 500;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    white-space: nowrap;
}

.label-operational { color: var(--green); background: var(--green-dim); }
.label-degraded    { color: var(--yellow); background: var(--yellow-dim); }
.label-down        { color: var(--red); background: var(--red-dim); }
.label-unknown     { color: var(--gray); background: var(--gray-dim); }

.service-details {
    margin-top: 0.65rem;
    padding-top: 0.65rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.service-detail {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.service-detail .detail-label {
    color: var(--text-muted);
}

.service-detail .detail-value {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.78rem;
}

.service-description {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    margin-left: 1.6rem;
}

/* ---------- Fetcher Pipeline ---------- */
.fetcher-summary {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.fetcher-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.fetcher-stat {
    text-align: center;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.fetcher-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    font-family: var(--font-mono);
    line-height: 1.2;
}

.fetcher-stat-value.green  { color: var(--green); }
.fetcher-stat-value.yellow { color: var(--yellow); }
.fetcher-stat-value.red    { color: var(--red); }
.fetcher-stat-value.gray   { color: var(--gray); }

.fetcher-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.25rem;
}

.fetcher-bar {
    height: 8px;
    background: var(--bg-secondary);
    border-radius: 4px;
    margin-top: 1rem;
    overflow: hidden;
    display: flex;
}

.fetcher-bar-segment {
    height: 100%;
    transition: width 0.5s ease;
}

.fetcher-bar-segment.operational { background: var(--green); }
.fetcher-bar-segment.degraded    { background: var(--yellow); }
.fetcher-bar-segment.disabled    { background: var(--gray); }
.fetcher-bar-segment.error       { background: var(--red); }

/* ---------- Uptime History ---------- */
.uptime-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.uptime-row {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 0;
}

.uptime-row + .uptime-row {
    border-top: 1px solid var(--border);
}

.uptime-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    width: 80px;
    flex-shrink: 0;
}

.uptime-bar {
    flex: 1;
    display: flex;
    gap: 2px;
    height: 24px;
    align-items: stretch;
}

.uptime-block {
    flex: 1;
    border-radius: 3px;
    min-width: 3px;
    transition: opacity var(--transition);
    cursor: pointer;
    position: relative;
}

.uptime-block.up       { background: var(--green); }
.uptime-block.degraded { background: var(--yellow); }
.uptime-block.down     { background: var(--red); }
.uptime-block.no-data  { background: var(--border); }

.uptime-block:hover { opacity: 0.7; }

.uptime-block[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.7rem;
    white-space: nowrap;
    border: 1px solid var(--border);
    z-index: 10;
    margin-bottom: 4px;
    pointer-events: none;
}

.uptime-pct {
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--font-mono);
    width: 62px;
    text-align: right;
    flex-shrink: 0;
}

.uptime-pct.high { color: var(--green); }
.uptime-pct.mid  { color: var(--yellow); }
.uptime-pct.low  { color: var(--red); }

/* ---------- Footer ---------- */
.footer {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    margin-top: auto;
}

.footer-inner {
    text-align: center;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.footer-links {
    margin-top: 0.5rem;
}

.footer-sep {
    margin: 0 0.5rem;
    color: var(--border-light);
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .header-inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .banner-content {
        flex-direction: column;
        text-align: center;
        align-items: center;
    }

    .banner-text h1 { font-size: 1.25rem; }

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

    .uptime-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .uptime-bar { width: 100%; }
    .uptime-pct { text-align: left; }
}

/* ---------- Error message ---------- */
.error-message {
    background: var(--red-dim);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
    color: var(--red);
    margin-top: 0.5rem;
    margin-left: 1.6rem;
}

/* ---------- SSL Cert specific ---------- */
.cert-expiry {
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.cert-expiry.safe    { color: var(--green); }
.cert-expiry.warning { color: var(--yellow); }
.cert-expiry.danger  { color: var(--red); }

/* ---------- Cloudflare Component Grid ---------- */
.cf-components {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
    margin-top: 0.75rem;
    margin-left: 1.6rem;
}

.cf-component {
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
}

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

.cf-dot.operational    { background: var(--green); }
.cf-dot.degraded       { background: var(--yellow); }
.cf-dot.partial_outage { background: var(--yellow); }
.cf-dot.major_outage   { background: var(--red); }
