/* =========================================================
   TestLink Design System: tokens & components
   Referensi: docs/DESIGN_SYSTEM.md (dial ENERGY 1 / RHYTHM 1 / MOTION 1)
   ========================================================= */

:root {
    --surface: #020617;
    --surface-card: #0f172a;
    --surface-raised: #1e293b;
    --border: #1e293b;
    --border-strong: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-faint: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-soft: rgba(99, 102, 241, 0.12);
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --shadow-overlay: 0 16px 48px rgba(0, 0, 0, 0.45);
    --dur: 160ms;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    color-scheme: dark;
}

body {
    background-color: var(--surface);
    color: var(--text);
    font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    margin: 0;
    padding-bottom: 6.5rem;
    min-height: 100vh;
}

/* Fokus terlihat di semua kontrol (R-32) */
:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* MOTION 1: hormati reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ---------- Layout ---------- */

.page-shell {
    background-color: var(--surface);
}

.app-container {
    max-width: 42rem;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Desktop: konten admin melebar agar tabel & grid tidak terjepit; di bawah 1024px tetap max-w-3xl dari markup */
@media (min-width: 1024px) {
    .admin-main {
        max-width: 72rem;
    }
}

/* Topbar: satu-satunya elemen dengan blur (batas R-10) */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 800;
    padding: 0.75rem 1rem;
    background: rgba(2, 6, 23, 0.88);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}

.app-topbar__inner {
    max-width: 42rem;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

/* ---------- Komponen inti ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    padding: 0.625rem 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 0.875rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--dur) ease, border-color var(--dur) ease, color var(--dur) ease;
}

.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); }

.btn--secondary {
    background: var(--surface-raised);
    border-color: var(--border-strong);
    color: var(--text);
}
.btn--secondary:hover { border-color: var(--text-faint); }

.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover { color: var(--text); background: var(--surface-raised); }

.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { filter: brightness(1.1); }

.btn--block { width: 100%; }

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

.card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
}

.input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.625rem 0.75rem;
    color: var(--text);
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color var(--dur) ease, box-shadow var(--dur) ease;
}

.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

textarea.input {
    resize: vertical;
}

select.input {
    appearance: auto;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    border: 1px solid transparent;
}

.badge--success { background: rgba(16, 185, 129, 0.12); color: #34d399; border-color: rgba(16, 185, 129, 0.25); }
.badge--danger { background: rgba(239, 68, 68, 0.12); color: #f87171; border-color: rgba(239, 68, 68, 0.25); }
.badge--warning { background: rgba(245, 158, 11, 0.12); color: #fbbf24; border-color: rgba(245, 158, 11, 0.25); }
.badge--neutral { background: var(--surface-raised); color: var(--text-muted); border-color: var(--border-strong); }

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

.table th {
    padding: 0.625rem 0.75rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-faint);
    border-bottom: 1px solid var(--border);
}

.table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: top;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 2.5rem 1rem;
    text-align: center;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.875rem;
}

.empty-state__title {
    font-weight: 600;
    color: var(--text);
}

.progress {
    height: 0.5rem;
    background: var(--surface-raised);
    border-radius: 999px;
    overflow: hidden;
}

.progress__bar {
    height: 100%;
    background: var(--primary);
    border-radius: 999px;
    transition: width 200ms ease;
}

.section-title {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    margin: 0 0 0.75rem;
}

/* Item navigasi sidebar admin; garis aksen kiri = motif identitas aktif */
.admin-nav-item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-align: left;
    cursor: pointer;
    transition: background var(--dur) ease, color var(--dur) ease, box-shadow var(--dur) ease;
}

.admin-nav-item:hover {
    color: var(--text);
    background: var(--surface-raised);
}

.admin-nav-item--active {
    color: var(--text);
    background: var(--primary-soft);
    box-shadow: inset 3px 0 0 var(--primary);
}

/* Tab bagian pengaturan */
.settings-tab {
    flex-shrink: 0;
    padding: 0.5rem 0.875rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: color var(--dur) ease, border-color var(--dur) ease;
}

.settings-tab:hover {
    color: var(--text);
}

.settings-tab.active {
    color: var(--text);
    border-bottom-color: var(--primary);
}

.page-title {
    font-size: 1.375rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
    margin: 0;
}

/* ---------- Komponen halaman existing (nama class dipertahankan) ---------- */

.fab-tools {
    position: fixed;
    right: 1.25rem;
    bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    z-index: 850;
    width: 3.25rem;
    height: 3.25rem;
    border-radius: var(--radius);
    border: none;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background var(--dur) ease, transform var(--dur) ease;
}

.fab-tools:hover {
    background: var(--primary-hover);
}

.fab-tools:active {
    transform: scale(0.97);
}

.tools-sheet-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--surface-card);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
    transition: background var(--dur), border-color var(--dur);
}

.tools-sheet-btn:hover {
    background: var(--surface-raised);
    border-color: var(--border-strong);
}

.toast-host {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
    max-width: min(22rem, calc(100vw - 2rem));
}

.toast-item {
    pointer-events: auto;
    background: var(--surface-card);
    border: 1px solid var(--border-strong);
    color: var(--text);
    font-size: 0.8125rem;
    font-weight: 500;
    padding: 0.625rem 1rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-overlay);
    animation: fadeIn 200ms ease-out forwards;
}

.site-card {
    background: var(--surface-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color var(--dur) ease, background var(--dur) ease;
}

.site-card:hover {
    background: var(--surface-raised);
    border-color: var(--border-strong);
}

.site-card.finished {
    opacity: 0.7;
}

/* ---------- Footer ---------- */

.site-footer {
    max-width: 42rem;
    margin: 0 auto;
    padding: 1.75rem 1rem calc(5.5rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
}

.site-footer__inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.65rem;
    text-align: center;
}

.site-footer__brand {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: center;
}

.site-footer__label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-faint);
}

.site-footer__dot {
    width: 3px;
    height: 3px;
    border-radius: 999px;
    background: var(--primary);
    opacity: 0.6;
}

.site-footer__cr {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.site-footer__credit {
    margin: 0;
    font-size: 0.8125rem;
}

.site-footer__meta {
    margin: 0;
    font-size: 0.75rem;
}

.site-footer__link {
    color: var(--primary-hover);
    text-decoration: none;
    transition: color var(--dur) ease;
}

.site-footer__link:hover {
    color: #a5b4fc;
}

.site-footer__link--muted {
    color: var(--text-faint);
}

.site-footer__link--muted:hover {
    color: var(--primary-hover);
}

/* ---------- Animasi (MOTION 1: transisi state saja) ---------- */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUpTools {
    from { opacity: 0; transform: translateY(100%); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.98); }
    to { opacity: 1; transform: scale(1); }
}

.animate-fade-in {
    animation: fadeIn 200ms ease-out forwards;
}

.animate-scale-in {
    animation: scaleIn 160ms ease-out forwards;
}

.animate-slide-up-tools {
    animation: slideUpTools 240ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.btn-click-feedback {
    transform: scale(0.98);
}

/* ---------- Floating variant switcher (pojok kiri bawah) ---------- */
/* Dipakai bersama index.html (v1) dan index2.html (v2). Default offset di sini;
   v2.css override --float-variant-bottom supaya di atas bottom-nav v2. */

.float-variant {
    --float-variant-bottom: 1.25rem;
    position: fixed;
    left: max(1rem, env(safe-area-inset-left, 0px));
    bottom: calc(var(--float-variant-bottom) + env(safe-area-inset-bottom, 0px));
    z-index: 800;            /* di bawah .fab-tools (850) dan toast */
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 44px;        /* target sentuh min */
    padding: 0.625rem 1rem;
    border-radius: 9999px;
    background: var(--surface-card);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    box-shadow:
        0 6px 18px -8px rgba(0, 0, 0, 0.35),
        0 2px 4px rgba(0, 0, 0, 0.1),
        0 0 0 0 rgba(99, 102, 241, 0);
    transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease, border-color 160ms ease;
    animation: float-variant-pulse 2.4s ease-in-out infinite;
    will-change: box-shadow, transform;
}

.float-variant:hover,
.float-variant:focus-visible {
    background: var(--surface-raised);
    border-color: var(--border-strong);
    color: var(--text);
    transform: translateY(-1px);
    box-shadow:
        0 10px 22px -10px rgba(0, 0, 0, 0.45),
        0 2px 4px rgba(0, 0, 0, 0.12),
        0 0 0 0 rgba(99, 102, 241, 0);
}

.float-variant:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.float-variant:active {
    transform: scale(0.98);
}

.float-variant__icon {
    width: 1.125rem;
    height: 1.125rem;
    flex-shrink: 0;
    stroke-width: 2;
}

@keyframes float-variant-pulse {
    0%, 100% {
        box-shadow:
            0 6px 18px -8px rgba(0, 0, 0, 0.35),
            0 2px 4px rgba(0, 0, 0, 0.1),
            0 0 0 0 rgba(99, 102, 241, 0);
    }
    50% {
        box-shadow:
            0 8px 20px -8px rgba(0, 0, 0, 0.4),
            0 2px 4px rgba(0, 0, 0, 0.1),
            0 0 0 8px rgba(99, 102, 241, 0.18);
    }
}

@media (prefers-reduced-motion: reduce) {
    .float-variant {
        animation: none;
    }
    .float-variant:hover,
    .float-variant:focus-visible,
    .float-variant:active {
        transform: none;
    }
}

/* ---------- PWA install banner (atas) ---------- */
/* Di-inject oleh js/install-banner.js saat beforeinstallprompt fire. */

.pwa-install {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1999;     /* di atas topbar (800) & fab-tools (850), di bawah modal/toast */
    background: linear-gradient(135deg, var(--primary) 0%, #818cf8 100%);
    color: #fff;
    box-shadow: 0 4px 16px -6px rgba(0, 0, 0, 0.4);
    transform: translateY(-100%);
    transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);
    padding-top: env(safe-area-inset-top, 0px);
}

.pwa-install--visible {
    transform: translateY(0);
}

.pwa-install__inner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 64rem;
    margin: 0 auto;
    padding: 0.75rem 1rem;
}

.pwa-install__icon {
    width: 2.25rem;
    height: 2.25rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 0.5rem;
}

.pwa-install__icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

.pwa-install__text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.pwa-install__title {
    font-size: 0.9375rem;
    font-weight: 600;
    color: #fff;
}

.pwa-install__sub {
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.85);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pwa-install__actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.pwa-install__btn {
    min-height: 36px;
    padding: 0.5rem 0.875rem;
    border-radius: 9999px;
    border: none;
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background 160ms ease, transform 120ms ease, opacity 160ms ease;
}

.pwa-install__btn--primary {
    background: #fff;
    color: var(--primary);
}

.pwa-install__btn--primary:hover {
    background: rgba(255, 255, 255, 0.92);
}

.pwa-install__btn--primary:active {
    transform: scale(0.97);
}

.pwa-install__btn--ghost {
    width: 36px;
    min-height: 36px;
    padding: 0;
    background: transparent;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
}

.pwa-install__btn--ghost:hover {
    background: rgba(255, 255, 255, 0.18);
    opacity: 1;
}

.pwa-install__btn--ghost svg {
    width: 1.125rem;
    height: 1.125rem;
}

.pwa-install__btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

@media (max-width: 480px) {
    .pwa-install__sub {
        display: none;
    }
    .pwa-install__icon {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .pwa-install {
        transition: none;
    }
}

/* ---------- Utilitas ---------- */

.safe-pb {
    padding-bottom: max(2rem, env(safe-area-inset-bottom, 0px));
}

.no-scrollbar::-webkit-scrollbar {
    display: none;
}
.no-scrollbar {
    -ms-overflow-style: none;
    scrollbar-width: none;
}

::-webkit-scrollbar {
    width: 6px;
}
::-webkit-scrollbar-thumb {
    background: var(--surface-raised);
    border-radius: 10px;
}

input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

#speedChart {
    width: 100% !important;
    height: 100% !important;
}

#speedValue {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: normal;
}
