:root {
    --bg:          #0d0d0d;
    --card-bg:     #1a1a1a;
    --card-border: #2a2a2a;
    --text:        #ffffff;
    --muted:       #888888;
    --muted2:      #555555;
    --red:         #e53935;
    --red-glow:    rgba(229,57,53,.18);
    --green:       #22c55e;
    --green-glow:  rgba(34,197,94,.15);
    --amber:       #f59e0b;
    --amber-glow:  rgba(245,158,11,.15);
    --gray-glow:   rgba(255,255,255,.06);
    --header-h:    56px;
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ─────────────────────────────────────────────── */

.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-h);
    background: rgba(13,13,13,.85);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(255,255,255,.07);
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    height: 100%;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
}

.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: var(--red);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 16px;
    color: #fff;
    line-height: 1;
    flex-shrink: 0;
}

.brand-excl {
    font-size: 12px;
    vertical-align: super;
    margin-left: 1px;
}

.brand-name {
    font-size: 19px;
    letter-spacing: -.3px;
}

.brand-name strong {
    font-weight: 800;
}

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

.header-updated {
    font-size: 12px;
    color: var(--muted);
}

.refresh-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    color: var(--muted);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: color .15s, border-color .15s;
}

.refresh-btn:hover { color: var(--text); border-color: #444; }
.refresh-btn:disabled { opacity: .4; cursor: wait; }
.refresh-btn.spinning svg { animation: spin .6s linear infinite; }

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

/* ── Hero ───────────────────────────────────────────────── */

.hero {
    position: relative;
    min-height: 340px;
    background: #000;
    overflow: hidden;
    display: flex;
    align-items: center;
}

#heroChart {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

.hero-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to bottom,
        rgba(0,0,0,.45) 0%,
        rgba(0,0,0,.15) 50%,
        rgba(0,0,0,.75) 100%
    );
    pointer-events: none;
}

.hero-inner {
    position: relative;
    z-index: 2;
    width: min(880px, 100%);
    margin: 0 auto;
    padding: 56px 24px 60px;
    text-align: center;
}

.hero-inner h1 {
    margin: 0 0 28px;
    font-size: clamp(26px, 4.5vw, 48px);
    font-weight: 800;
    letter-spacing: -.5px;
    line-height: 1.1;
    color: #fff;
    text-shadow: 0 2px 24px rgba(0,0,0,.8);
}

.hero-stats {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 32px;
    margin-bottom: 18px;
}

.hero-stat strong {
    display: block;
    font-size: 32px;
    font-weight: 800;
    color: #fff;
    line-height: 1;
}

.hero-stat span {
    font-size: 13px;
    color: rgba(255,255,255,.55);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.hero-stat-sep {
    width: 1px;
    height: 48px;
    background: rgba(255,255,255,.2);
}

.hero-sub {
    margin: 0 0 28px;
    font-size: 16px;
    color: rgba(255,255,255,.6);
}

/* ── Search ─────────────────────────────────────────────── */

.search-wrap {
    display: flex;
    justify-content: center;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    width: min(560px, 100%);
    background: rgba(255,255,255,.1);
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 999px;
    padding: 12px 20px;
    cursor: text;
    transition: background .15s, border-color .15s;
    backdrop-filter: blur(10px);
}

.search-box:focus-within {
    background: rgba(255,255,255,.14);
    border-color: rgba(255,255,255,.35);
}

.search-icon {
    color: rgba(255,255,255,.5);
    flex-shrink: 0;
}

.search-box input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-size: 15px;
    color: #fff;
    font-family: inherit;
    min-width: 0;
}

.search-box input::placeholder { color: rgba(255,255,255,.45); }

/* Remove browser search clear button */
.search-box input::-webkit-search-cancel-button { display: none; }

/* ── Content ─────────────────────────────────────────────── */

.content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px 64px;
}

/* ── Section header ───────────────────────────────────────── */

.section-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.overall-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--gray-glow);
    border: 1px solid var(--card-border);
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    transition: background .3s, border-color .3s, color .3s;
}

.overall-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--muted2);
    transition: background .3s;
}

.overall-operational .overall-badge,
body.overall-operational .overall-badge {
    background: var(--green-glow);
    border-color: rgba(34,197,94,.3);
    color: var(--green);
}

.overall-operational .overall-dot,
body.overall-operational .overall-dot { background: var(--green); }

.overall-degraded .overall-badge,
body.overall-degraded .overall-badge {
    background: var(--amber-glow);
    border-color: rgba(245,158,11,.3);
    color: var(--amber);
}

.overall-degraded .overall-dot,
body.overall-degraded .overall-dot { background: var(--amber); }

.overall-outage .overall-badge,
body.overall-outage .overall-badge,
.overall-down .overall-badge,
body.overall-down .overall-badge {
    background: var(--red-glow);
    border-color: rgba(229,57,53,.3);
    color: var(--red);
}

.overall-outage .overall-dot,
body.overall-outage .overall-dot,
.overall-down .overall-dot,
body.overall-down .overall-dot { background: var(--red); }

.filter-count {
    font-size: 13px;
    color: var(--muted);
}

/* ── Services Grid ───────────────────────────────────────── */

.services {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
}

/* ── Service Card ─────────────────────────────────────────── */

.service-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 28px 20px 0;
    cursor: default;
    transition: transform .15s, border-color .15s, box-shadow .15s;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.service-card::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    opacity: 0;
    transition: opacity .2s;
}

.service-card:hover {
    transform: translateY(-2px);
    border-color: #3a3a3a;
    box-shadow: 0 8px 32px rgba(0,0,0,.4);
}

.service-card:hover::before { opacity: 1; }

/* Status colour themes */
.service-operational::before { background: radial-gradient(ellipse at 50% 0%, var(--green-glow), transparent 70%); }
.service-degraded::before    { background: radial-gradient(ellipse at 50% 0%, var(--amber-glow), transparent 70%); }
.service-outage::before,
.service-down::before        { background: radial-gradient(ellipse at 50% 0%, var(--red-glow), transparent 70%); }

/* Status top stripe */
.service-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 3px;
    border-radius: 12px 12px 0 0;
    background: var(--muted2);
    transition: background .3s;
}

.service-operational::after { background: var(--green); }
.service-degraded::after    { background: var(--amber); }
.service-outage::after,
.service-down::after        { background: var(--red); }

/* Logo */
.service-logo {
    width: 84px;
    height: 84px;
    border-radius: 22px;
    background: #fff;
    display: grid;
    place-items: center;
    margin-bottom: 16px;
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: 0 2px 16px rgba(0,0,0,.35);
}

.service-logo img {
    width: 58px;
    height: 58px;
    object-fit: contain;
    display: block;
}

.service-logo .logo-letter {
    display: none;
    font-size: 32px;
    font-weight: 800;
    color: #1a1a1a;
    line-height: 1;
}

.service-logo.logo-fallback { background: #232323; }
.service-logo.logo-fallback .logo-letter {
    display: block;
    color: var(--muted);
}

/* Card body */
.service-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 10px;
    overflow-wrap: anywhere;
    line-height: 1.3;
}

.service-status-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin-bottom: 16px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--muted2);
}

.service-operational .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.service-degraded .status-dot    { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.service-outage .status-dot,
.service-down .status-dot        { background: var(--red); box-shadow: 0 0 6px var(--red); }

.status-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.service-operational .status-label { color: var(--green); }
.service-degraded .status-label    { color: var(--amber); }
.service-outage .status-label,
.service-down .status-label        { color: var(--red); }

/* ── Sparkline ─────────────────────────────────────────────── */

.service-sparkline {
    display: block;
    width: 100%;
    height: 52px;
    margin-top: auto;
    border-radius: 0 0 14px 14px;
    /* canvas has no padding — flush to card edges */
}

/* ── Skeleton ─────────────────────────────────────────────── */

.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 20px;
}

.skeleton-card {
    height: 220px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    animation: pulse 1.5s ease-in-out infinite;
}

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

/* ── Error ─────────────────────────────────────────────────── */

.error-banner {
    margin-bottom: 20px;
    padding: 12px 16px;
    border-radius: 8px;
    background: var(--red-glow);
    border: 1px solid rgba(229,57,53,.35);
    color: #ff6b6b;
    font-size: 14px;
}

/* ── Empty / no-results ──────────────────────────────────── */

.no-results {
    grid-column: 1 / -1;
    padding: 40px 0;
    text-align: center;
    color: var(--muted);
    font-size: 15px;
}

/* ── Card as link ─────────────────────────────────────────── */

a.service-card {
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

/* ── Detail view ──────────────────────────────────────────── */

body.view-detail .hero,
body.view-detail #homeView { display: none; }

.detail-view { padding-top: 24px; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 22px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    text-decoration: none;
    transition: color .15s;
}

.back-link:hover { color: var(--text); }

.detail-head {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.detail-head .service-logo {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    margin-bottom: 0;
}

.detail-head .service-logo img { width: 44px; height: 44px; }
.detail-head .service-logo .logo-letter { font-size: 26px; }

.detail-title { flex: 1; min-width: 180px; }

.detail-title h2 {
    margin: 0 0 6px;
    font-size: 24px;
    font-weight: 800;
    letter-spacing: -.3px;
    overflow-wrap: anywhere;
}

.detail-status { justify-content: flex-start; margin-bottom: 0; }

.detail-status.s-operational .status-dot { background: var(--green); box-shadow: 0 0 6px var(--green); }
.detail-status.s-degraded    .status-dot { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.detail-status.s-outage      .status-dot { background: var(--red);   box-shadow: 0 0 6px var(--red); }
.detail-status.s-operational .status-label { color: var(--green); }
.detail-status.s-degraded    .status-label { color: var(--amber); }
.detail-status.s-outage      .status-label { color: var(--red); }

.range-picker {
    display: flex;
    gap: 4px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 10px;
    padding: 4px;
}

.range-picker button {
    border: none;
    background: none;
    color: var(--muted);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 7px;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.range-picker button:hover { color: var(--text); }

.range-picker button.active {
    background: #2a2a2a;
    color: var(--text);
}

/* Stat tiles */

.detail-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.tile {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 16px 18px;
}

.tile-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--muted);
    margin-bottom: 6px;
}

.tile strong {
    font-size: 24px;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

/* Chart / strip cards */

.detail-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 14px;
    padding: 20px 22px 22px;
    margin-bottom: 20px;
}

.detail-card h3 {
    margin: 0 0 16px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.detail-card-sub {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    margin-left: 6px;
}

.chart-wrap { position: relative; }

#historyChart {
    display: block;
    width: 100%;
    height: 280px;
    touch-action: pan-y;
}

.chart-tooltip {
    position: absolute;
    pointer-events: none;
    z-index: 10;
    background: rgba(13,13,13,.95);
    border: 1px solid #3a3a3a;
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 12px;
    line-height: 1.55;
    color: var(--text);
    white-space: nowrap;
    box-shadow: 0 6px 24px rgba(0,0,0,.5);
}

.chart-tooltip .tt-time {
    color: var(--muted);
    font-size: 11px;
    display: block;
    margin-bottom: 3px;
}

.chart-tooltip .tt-val { font-weight: 700; }

.chart-empty {
    padding: 60px 0;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}

/* Uptime strip */

.uptime-strip {
    display: flex;
    gap: 2px;
    height: 30px;
}

.uptime-strip i {
    flex: 1;
    border-radius: 2px;
    background: #2e2e2e;
    min-width: 2px;
}

.uptime-strip i.u-green { background: var(--green); }
.uptime-strip i.u-amber { background: var(--amber); }
.uptime-strip i.u-red   { background: var(--red); }

.uptime-legend {
    display: flex;
    gap: 18px;
    margin-top: 12px;
    font-size: 12px;
    color: var(--muted);
    flex-wrap: wrap;
}

.uptime-legend .lg {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 5px;
    vertical-align: -1px;
}

.lg-green { background: var(--green); }
.lg-amber { background: var(--amber); }
.lg-red   { background: var(--red); }
.lg-gray  { background: #2e2e2e; }

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 600px) {
    .hero-inner { padding: 40px 20px 48px; }
    .hero-inner h1 { font-size: 26px; }
    .hero-stats { gap: 20px; }
    .hero-stat strong { font-size: 24px; }

    .services,
    .skeleton-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 14px;
    }

    .header-updated { display: none; }

    .detail-head { gap: 14px; }
    .detail-title h2 { font-size: 19px; }
    .detail-tiles { grid-template-columns: repeat(2, 1fr); }
    .tile strong { font-size: 19px; }
    #historyChart { height: 220px; }
}
