:root {
    --bg: #0f172a;
    --bg2: #1e293b;
    --border: rgba(148, 163, 184, 0.15);
    --text: #f1f5f9;
    --muted: #94a3b8;
    --accent: #22d3ee;
    --accent2: #818cf8;
    --green: #22c55e;
    --amber: #f59e0b;
    --red: #ef4444;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    min-height: 100vh;
    color: var(--text);
}

.container {
    max-width: 820px;
    margin: 0 auto;
    padding: 2rem 1.25rem 3rem;
}

header { text-align: center; margin-bottom: 1.5rem; }
.logo { font-size: 3rem; margin-bottom: 0.4rem; }
h1 {
    font-size: 1.9rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.subtitle { color: var(--muted); margin-top: 0.4rem; font-size: 1rem; margin-bottom: 1.5rem; }

.tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.tab-btn {
    flex: 1;
    min-width: 200px;
    padding: 0.8rem 1rem;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    color: var(--muted);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}
.tab-btn:hover { border-color: rgba(34, 211, 238, 0.4); color: var(--text); }
.tab-btn.active {
    background: linear-gradient(135deg, rgba(34, 211, 238, 0.2), rgba(129, 140, 248, 0.2));
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 4px 14px rgba(34, 211, 238, 0.15);
}
.tab-panel[hidden] { display: none; }

.card {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    backdrop-filter: blur(10px);
}
.card-title {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    color: var(--text);
}

.controls { display: flex; flex-direction: column; gap: 1.2rem; }

.status-line {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.6rem;
}
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.6);
    animation: pulse 2s infinite;
}
.status-dot.busy { background: var(--amber); box-shadow: 0 0 8px rgba(245, 158, 11, 0.6); }
.status-dot.off { background: var(--red); box-shadow: 0 0 8px rgba(239, 68, 68, 0.6); animation: none; }
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

.hint { color: var(--muted); font-size: 0.88rem; line-height: 1.6; }

.primary {
    padding: 0.9rem;
    border: none;
    border-radius: 0.7rem;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #0f172a;
    font-size: 1.05rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
}
.primary:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }
.primary:disabled { opacity: 0.6; cursor: not-allowed; }
.primary.running { background: linear-gradient(135deg, var(--amber), var(--red)); color: #fff; }

.actions-row {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
}
.actions-row .primary { flex: 1; min-width: 220px; }
.ghost {
    padding: 0.9rem 1.2rem;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    background: rgba(15, 23, 42, 0.5);
    color: var(--muted);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
}
.ghost:hover { border-color: var(--accent); color: var(--text); }

.site-row {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}
.site-row label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.site-row input {
    padding: 0.7rem 0.9rem;
    border-radius: 0.6rem;
    border: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.6);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
}
.site-row input:focus { border-color: var(--accent); }

.alert-list { display: flex; flex-direction: column; gap: 0.5rem; }
.alert-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
    flex-wrap: wrap;
    padding: 0.7rem 0.9rem;
    border-radius: 0.6rem;
    border: 1px solid rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.08);
    font-size: 0.85rem;
}
.alert-item .date { color: var(--muted); }
.alert-item .val { color: var(--red); font-weight: 800; }

#dailyChart { max-height: 220px; }
.card-title small { color: var(--muted); font-weight: 400; }

.test-area { text-align: center; padding: 2.5rem 1.5rem; }

.spinner {
    width: 52px;
    height: 52px;
    margin: 0 auto 1.2rem;
    border: 5px solid rgba(34, 211, 238, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.phase {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 1.2rem;
}

.meta-row {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}
.meta-row > div { display: flex; flex-direction: column; gap: 0.2rem; }
.meta-row .label { font-size: 0.75rem; text-transform: uppercase; color: var(--muted); letter-spacing: 0.06em; }
.meta-row span:last-child { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }

.progress-track {
    height: 8px;
    background: rgba(15, 23, 42, 0.7);
    border-radius: 999px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent), var(--accent2));
    border-radius: 999px;
    transition: width 0.3s linear;
}

#speedChart { max-height: 260px; }

.result-date { color: var(--accent); font-weight: 700; margin-bottom: 1rem; font-size: 1rem; }
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.8rem;
}
.stat {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    padding: 0.9rem;
    text-align: center;
}
.stat.big { border-color: rgba(34, 211, 238, 0.35); }
.stat .stat-label { font-size: 0.72rem; text-transform: uppercase; color: var(--muted); letter-spacing: 0.06em; margin-bottom: 0.3rem; }
.stat .stat-value { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text); }
.stat.big .stat-value { font-size: 1.5rem; background: linear-gradient(135deg, var(--accent), var(--accent2)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }

.meta-extra {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}
.meta-extra > span {
    font-size: 0.8rem;
    color: var(--muted);
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 2rem;
    padding: 0.3rem 0.7rem;
}
.result-link { color: var(--accent); text-decoration: none; }
.result-link:hover { text-decoration: underline; }

.history-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.history-head .card-title { margin-bottom: 0; }
.count-badge {
    font-size: 0.75rem;
    color: var(--accent);
    background: rgba(34, 211, 238, 0.1);
    border: 1px solid rgba(34, 211, 238, 0.3);
    border-radius: 2rem;
    padding: 0.25rem 0.7rem;
    white-space: nowrap;
}

.table-wrap { overflow-x: auto; margin-top: 1.2rem; }
.history-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    text-align: left;
}
.history-table th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    padding: 0.55rem 0.6rem;
    border-bottom: 1px solid var(--border);
}
.history-table td {
    padding: 0.55rem 0.6rem;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
    font-variant-numeric: tabular-nums;
}
.history-table tbody tr:hover { background: rgba(34, 211, 238, 0.05); }
.history-table .accent { color: var(--accent); font-weight: 700; }
.history-table .accent2 { color: var(--accent2); font-weight: 700; }

footer {
    text-align: center;
    color: #475569;
    font-size: 0.8rem;
    margin-top: 2rem;
    line-height: 1.6;
}