/* ==========================================================================
   speedtest.isprin.me - Main Application Stylesheet
   Modern Dark Cyber-Minimalist Aesthetic (#0f172a Slate, Neon Cyan & Emerald)
   ========================================================================== */

:root {
    --color-bg-base: #0f172a;
    --color-bg-surface: #1e293b;
    --color-bg-surface-elevated: #243247;
    --color-border: #334155;
    --color-border-subtle: #1e293b;

    --color-text-bright: #ffffff;
    --color-text-main: #f8fafc;
    --color-text-muted: #94a3b8;
    --color-text-dim: #64748b;

    --color-cyan: #06b6d4;
    --color-cyan-glow: rgba(6, 182, 212, 0.4);
    --color-emerald: #10b981;
    --color-emerald-glow: rgba(16, 185, 129, 0.4);
    --color-violet: #8b5cf6;
    --color-amber: #f59e0b;
    --color-rose: #f43f5e;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    --shadow-card: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
    --shadow-glow-cyan: 0 0 25px rgba(6, 182, 212, 0.35);
    --shadow-glow-emerald: 0 0 25px rgba(16, 185, 129, 0.35);

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    background-color: var(--color-bg-base);
    color: var(--color-text-main);
    font-family: var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--color-bg-base);
    background-image: 
        /* Cyber dot matrix pattern */
        radial-gradient(rgba(56, 189, 248, 0.07) 1px, transparent 1px),
        /* Ambient top-left cyan glow orb */
        radial-gradient(circle at 18% 12%, rgba(6, 182, 212, 0.18) 0%, transparent 45%),
        /* Ambient top-right emerald glow orb */
        radial-gradient(circle at 82% 18%, rgba(16, 185, 129, 0.15) 0%, transparent 45%),
        /* Ambient center-deep violet glow */
        radial-gradient(circle at 50% 55%, rgba(139, 92, 246, 0.12) 0%, transparent 55%),
        /* Deep slate background gradient */
        radial-gradient(ellipse at 50% -10%, #1e293b 0%, #0a0f1d 80%);
    background-size: 28px 28px, 100% 100%, 100% 100%, 100% 100%, 100% 100%;
    background-attachment: fixed;
    overflow-x: hidden;
    position: relative;
}

/* Subtle animated ambient flare */
body::before {
    content: '';
    position: fixed;
    top: -20%;
    left: 25%;
    width: 50vw;
    height: 50vw;
    max-width: 600px;
    max-height: 600px;
    background: radial-gradient(circle, rgba(6, 182, 212, 0.12) 0%, transparent 70%);
    filter: blur(60px);
    pointer-events: none;
    z-index: 0;
    animation: ambientFloat 14s ease-in-out infinite alternate;
}

body::after {
    content: '';
    position: fixed;
    bottom: 5%;
    right: 15%;
    width: 40vw;
    height: 40vw;
    max-width: 500px;
    max-height: 500px;
    background: radial-gradient(circle, rgba(16, 185, 129, 0.1) 0%, transparent 70%);
    filter: blur(50px);
    pointer-events: none;
    z-index: 0;
    animation: ambientFloat 18s ease-in-out infinite alternate-reverse;
}

@keyframes ambientFloat {
    0% { transform: translateY(0) scale(1); }
    50% { transform: translateY(30px) scale(1.1); }
    100% { transform: translateY(-20px) scale(0.95); }
}

/* Base Containers */
.app-wrapper {
    width: 100%;
    max-width: 1060px;
    margin: 0 auto;
    padding: 1.25rem 1.5rem 3rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    position: relative;
    z-index: 1;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
}

.brand-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--color-text-main);
}

.brand-logo {
    width: 38px;
    height: 38px;
    filter: drop-shadow(0 0 10px var(--color-cyan-glow));
    transition: transform 0.25s ease;
}

.brand-group:hover .brand-logo {
    transform: rotate(-10deg) scale(1.05);
}

.brand-title {
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #ffffff 30%, #94a3b8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-tag {
    font-size: 0.75rem;
    font-weight: 600;
    background: rgba(6, 182, 212, 0.15);
    color: var(--color-cyan);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    border: 1px solid rgba(6, 182, 212, 0.3);
}

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

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
}

.status-indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-emerald);
    box-shadow: 0 0 8px var(--color-emerald);
}

.btn-install {
    display: none; /* revealed via JS when eligible */
    align-items: center;
    gap: 0.5rem;
    background: rgba(6, 182, 212, 0.12);
    border: 1px solid rgba(6, 182, 212, 0.4);
    color: var(--color-cyan);
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-install:hover {
    background: rgba(6, 182, 212, 0.25);
    box-shadow: var(--shadow-glow-cyan);
}

/* Speed Test Control & Gauge Area */
.test-hero-card {
    background: rgba(26, 36, 56, 0.65);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(56, 189, 248, 0.22);
    border-radius: var(--radius-lg);
    padding: 2.25rem 1.5rem;
    box-shadow: 
        0 14px 35px -5px rgba(0, 0, 0, 0.6),
        0 0 45px rgba(6, 182, 212, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.test-hero-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 10%;
    right: 10%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #06b6d4 25%, #10b981 50%, #8b5cf6 75%, transparent);
    filter: drop-shadow(0 0 6px rgba(6, 182, 212, 0.8));
}

/* Subtle corner ambient glow within the card */
.test-hero-card::after {
    content: '';
    position: absolute;
    top: -50px;
    right: -50px;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(16, 185, 129, 0.15) 0%, transparent 70%);
    pointer-events: none;
}

.control-cta-container {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
}

.btn-start-test {
    position: relative;
    background: linear-gradient(135deg, #06b6d4, #0284c7);
    color: #ffffff;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.9rem 2.8rem;
    border-radius: var(--radius-full);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(6, 182, 212, 0.4);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
}

.btn-start-test:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(6, 182, 212, 0.6);
    filter: brightness(1.1);
}

.btn-start-test:active:not(:disabled) {
    transform: translateY(0);
}

.btn-start-test:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    box-shadow: none;
}

.btn-abort-test {
    background: none;
    border: none;
    color: var(--color-rose);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    opacity: 0.8;
    transition: opacity 0.2s ease;
    display: none;
}

.btn-abort-test:hover {
    opacity: 1;
}

.test-status-msg {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    font-weight: 500;
    min-height: 1.25rem;
    text-align: center;
}

/* Metrics Grid (Ping, Jitter, Download, Upload) */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    width: 100%;
    margin-top: 1.5rem;
}

.metric-card {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(51, 65, 85, 0.5);
    border-radius: var(--radius-md);
    padding: 1.1rem 1rem;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    transition: all 0.25s ease;
}

.metric-card.active-phase {
    border-color: var(--color-cyan);
    box-shadow: 0 0 16px rgba(6, 182, 212, 0.25);
    background: rgba(15, 23, 42, 0.85);
}

.metric-card.active-phase.phase-upload {
    border-color: var(--color-emerald);
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.25);
}

.metric-card.active-phase.phase-ping {
    border-color: var(--color-violet);
    box-shadow: 0 0 16px rgba(139, 92, 246, 0.25);
}

.metric-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.metric-title {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--color-text-muted);
    text-transform: uppercase;
}

.metric-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-border);
    transition: background 0.3s ease;
}

.metric-card.active-phase .metric-dot {
    background: var(--color-cyan);
    box-shadow: 0 0 8px var(--color-cyan);
    animation: pulseGlow 1.2s infinite alternate;
}

@keyframes pulseGlow {
    from { opacity: 0.5; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1.2); }
}

.metric-value-wrap {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
}

.metric-value {
    font-size: 1.8rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    color: var(--color-text-bright);
    line-height: 1.1;
}

.metric-unit {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

/* Action & Metadata Bar */
.action-metadata-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    width: 100%;
    padding-top: 1.25rem;
    border-top: 1px solid rgba(51, 65, 85, 0.4);
    margin-top: 1.5rem;
}

.metadata-left-group {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.85rem;
}

.device-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.82rem;
    font-weight: 700;
    color: #ffffff;
    background: rgba(15, 23, 42, 0.85);
    padding: 4px 12px;
    border-radius: var(--radius-full);
    border: 1px solid rgba(56, 189, 248, 0.4);
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.15);
}

.device-icon {
    font-size: 1rem;
    line-height: 1;
}

.route-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.route-info strong {
    color: var(--color-text-main);
}

.result-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.btn-secondary {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid var(--color-border);
    color: var(--color-text-main);
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: all 0.2s ease;
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-border);
    border-color: #475569;
}

.btn-secondary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Recent Tests Section */
.recent-tests-section {
    background: rgba(30, 41, 59, 0.4);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(51, 65, 85, 0.5);
    border-radius: var(--radius-lg);
    padding: 1.75rem 1.5rem;
    box-shadow: var(--shadow-card);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.section-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.section-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-text-bright);
}

.section-badge {
    font-size: 0.75rem;
    background: rgba(51, 65, 85, 0.5);
    color: var(--color-text-muted);
    padding: 2px 8px;
    border-radius: var(--radius-full);
}

.table-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.search-input {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid var(--color-border);
    color: var(--color-text-main);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    outline: none;
    transition: border-color 0.2s ease;
}

.search-input:focus {
    border-color: var(--color-cyan);
}

.select-limit {
    background: rgba(15, 23, 42, 0.7);
    border: 1px solid var(--color-border);
    color: var(--color-text-main);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    outline: none;
    cursor: pointer;
}

/* Responsive Table */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid rgba(51, 65, 85, 0.4);
}

.recent-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 0.85rem;
}

.recent-table th {
    background: rgba(15, 23, 42, 0.8);
    padding: 10px 14px;
    font-weight: 700;
    color: var(--color-text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-size: 0.72rem;
    border-bottom: 1px solid var(--color-border);
}

.recent-table td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(51, 65, 85, 0.3);
    color: var(--color-text-main);
    white-space: nowrap;
}

.recent-table tbody tr {
    transition: background-color 0.15s ease;
}

.recent-table tbody tr:hover {
    background-color: rgba(51, 65, 85, 0.2);
}

.badge-platform {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    background: rgba(30, 41, 59, 0.7);
    border: 1px solid rgba(51, 65, 85, 0.5);
    color: var(--color-text-main);
}

.val-dl {
    color: var(--color-cyan);
    font-weight: 700;
}

.val-ul {
    color: var(--color-emerald);
    font-weight: 700;
}

.val-ping {
    color: var(--color-violet);
    font-weight: 600;
}

/* Pagination */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.25rem;
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

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

.btn-page {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--color-border);
    color: var(--color-text-main);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn-page:hover:not(:disabled) {
    background: var(--color-border);
}

.btn-page:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Privacy Notice Floating Banner */
.privacy-banner {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    z-index: 1000;
    width: calc(100% - 32px);
    max-width: 680px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(6, 182, 212, 0.4);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6), 0 0 20px rgba(6, 182, 212, 0.15);
    border-radius: var(--radius-md);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
}

.privacy-banner.hidden {
    transform: translateX(-50%) translateY(100px);
    opacity: 0;
    pointer-events: none;
}

.privacy-banner-text {
    font-size: 0.82rem;
    line-height: 1.45;
    color: var(--color-text-main);
}

.privacy-banner-actions {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-shrink: 0;
}

.btn-banner-gotit {
    background: var(--color-cyan);
    color: #0f172a;
    border: none;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease;
}

.btn-banner-gotit:hover {
    background: #38bdf8;
}

.btn-banner-learn {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.2s ease;
}

.btn-banner-learn:hover {
    color: #ffffff;
}

/* Full Privacy Disclosure Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-dialog {
    background: #1e293b;
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-card);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 650px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

.modal-overlay.open .modal-dialog {
    transform: scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--color-text-bright);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-modal-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: color 0.15s ease;
}

.btn-modal-close:hover {
    color: #ffffff;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    font-size: 0.88rem;
    line-height: 1.6;
    color: var(--color-text-main);
}

.modal-section {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid rgba(51, 65, 85, 0.5);
    border-radius: var(--radius-md);
    padding: 1rem 1.2rem;
}

.modal-section h4 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-cyan);
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.modal-section p {
    color: var(--color-text-muted);
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    justify-content: flex-end;
}

/* Footer */
.app-footer {
    border-top: 1px solid rgba(51, 65, 85, 0.4);
    padding: 1.5rem;
    text-align: center;
    font-size: 0.82rem;
    color: var(--color-text-dim);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.footer-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.footer-link {
    color: var(--color-text-muted);
    text-decoration: none;
    transition: color 0.2s ease;
    cursor: pointer;
}

.footer-link:hover {
    color: var(--color-cyan);
}

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

    .action-metadata-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .result-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .privacy-banner {
        flex-direction: column;
        align-items: flex-start;
    }

    .privacy-banner-actions {
        align-self: flex-end;
    }
}

@media (max-width: 480px) {
    .app-wrapper {
        padding: 1rem 0.75rem 2rem;
    }

    .metrics-grid {
        grid-template-columns: 1fr;
    }

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

    .table-controls {
        width: 100%;
    }

    .search-input {
        flex: 1;
    }
}
