/* track BFIOT — Polished Design System v2 */

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

:root {
    /* Fonts */
    --font-sans: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-serif: 'Playfair Display', Georgia, serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Light Theme (Default) */
    --primary: #1800a8;
    --primary-rgb: 24, 0, 168;
    --primary-container: #2f24cd;
    --secondary: #4648d4;
    --secondary-rgb: 70, 72, 212;
    --background: #faf8ff;
    --surface: #ffffff;
    --surface-container-low: #f4f5fc;
    --surface-container: #eaedff;
    --surface-container-high: #e1e7ff;
    --surface-container-highest: #dae2fc;
    --on-background: #131b2e;
    --on-surface: #131b2e;
    --on-surface-variant: #464555;
    --on-primary: #ffffff;
    --outline: #c7c4d8;
    --outline-variant: rgba(199, 196, 216, 0.4);
    --error: #ba1a1a;
    --error-container: #ffdad6;
    --on-error: #ffffff;
    --success: #00875a;
    --success-rgb: 0, 135, 90;
    --success-container: #d4f2e6;

    /* Layout */
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    --shadow-sm: 0 2px 8px rgba(11, 0, 107, 0.04);
    --shadow-md: 0 8px 30px rgba(11, 0, 107, 0.06);
    --shadow-lg: 0 16px 40px rgba(11, 0, 107, 0.1);
    --logo-filter: none;
}

/* Dark Theme */
[data-theme="dark"] {
    --primary: #bac3ff;
    --primary-rgb: 186, 195, 255;
    --primary-container: #2f24cd;
    --secondary: #bec2ff;
    --secondary-rgb: 190, 194, 255;
    --background: #0b0e17;
    --surface: #121624;
    --surface-container-low: #171c2e;
    --surface-container: #1e243b;
    --surface-container-high: #242c48;
    --surface-container-highest: #2b3456;
    --on-background: #e2e2ec;
    --on-surface: #e2e2ec;
    --on-surface-variant: #c7c5d5;
    --on-primary: #0b006b;
    --outline: #454655;
    --outline-variant: rgba(69, 70, 85, 0.5);
    --error: #ffb4ab;
    --error-container: #93000a;
    --on-error: #690005;
    --success: #36b37e;
    --success-rgb: 54, 179, 126;
    --success-container: #1e4620;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.4);
    --logo-filter: invert(0.92) hue-rotate(180deg) brightness(1.1) contrast(1.2);
}

html,
body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

html {
    font-family: var(--font-sans);
    background-color: var(--background);
    color: var(--on-background);
    -webkit-font-smoothing: antialiased;
}

body {
    display: flex;
    flex-direction: column;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    color: var(--on-surface);
    font-weight: 700;
    line-height: 1.25;
}

p {
    line-height: 1.6;
    color: var(--on-surface-variant);
}

/* Grid Background */
.grid-pattern {
    background-image:
        linear-gradient(to right, var(--surface-container) 1px, transparent 1px),
        linear-gradient(to bottom, var(--surface-container) 1px, transparent 1px);
    background-size: 40px 40px;
    mask-image: radial-gradient(circle at center, black 40%, transparent 90%);
    -webkit-mask-image: radial-gradient(circle at center, black 40%, transparent 90%);
}

/* ─── Header ─── */
header {
    position: fixed;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 720px;
    background-color: rgba(250, 248, 255, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--outline-variant);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-sm);
    height: 56px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    z-index: 100;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

[data-theme="dark"] header {
    background-color: rgba(18, 22, 36, 0.85);
}

.header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    max-width: 900px;
    margin: 0 auto;
    padding: 0 20px;
}

.logo {
    font-size: 20px;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.04em;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo span.tag {
    font-size: 11px;
    font-family: var(--font-mono);
    background-color: var(--primary-container);
    color: var(--on-primary);
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    letter-spacing: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.theme-toggle-btn {
    background: none;
    border: 1px solid var(--outline-variant);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--on-surface-variant);
    transition: all 0.2s ease;
}

.theme-toggle-btn:hover {
    color: var(--primary);
    border-color: var(--primary);
    background-color: var(--surface-container-low);
}

/* ─── Main ─── */
main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 88px 16px 36px 16px;
    box-sizing: border-box;
    overflow: hidden;
}

.dashboard-container {
    width: 100%;
    max-width: 720px;
    margin: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    z-index: 10;
    min-height: 0;
    height: auto;
    max-height: 100%;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.dashboard-container.results-loaded {
    margin: 0 auto;
    height: 100%;
}

/* ─── Hero ─── */
.hero {
    text-align: center;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    flex-shrink: 0;
}

.dashboard-container.results-loaded .hero {
    display: none;
}

.live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background-color: rgba(24, 0, 168, 0.06);
    border: 1px solid rgba(24, 0, 168, 0.12);
    padding: 4px 12px;
    border-radius: var(--radius-full);
    margin-bottom: 12px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--primary);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

[data-theme="dark"] .live-badge {
    background-color: rgba(186, 195, 255, 0.08);
    border-color: rgba(186, 195, 255, 0.15);
}

.live-badge .dot {
    width: 6px;
    height: 6px;
    background-color: var(--primary);
    border-radius: 50%;
    animation: pulse-soft 2s infinite;
}

.hero-title {
    font-family: var(--font-serif);
    font-size: 30px;
    line-height: 1.2;
    margin-bottom: 8px;
}

@media (min-width: 640px) {
    .hero-title {
        font-size: 44px;
    }
}

.hero-title span.italic {
    font-family: var(--font-serif);
    font-style: italic;
    color: var(--secondary);
}

/* ─── Buttons ─── */
.btn {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 700;
    padding: 10px 20px;
    border-radius: var(--radius-full);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    white-space: nowrap;
}

.btn-primary {
    background-color: var(--primary);
    color: var(--on-primary);
}

.btn-primary:hover {
    opacity: 0.9;
    box-shadow: 0 4px 12px rgba(24, 0, 168, 0.15);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: scale(0.98) translateY(0);
}

/* ─── Search ─── */
.search-wrapper {
    position: relative;
    width: 100%;
    flex-shrink: 0;
}

.search-bg-glow {
    position: absolute;
    inset: -3px;
    background: linear-gradient(90deg, rgba(var(--primary-rgb), 0.12), rgba(var(--secondary-rgb), 0.12));
    border-radius: 20px;
    filter: blur(8px);
    opacity: 0.5;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.search-wrapper:focus-within .search-bg-glow {
    opacity: 0.8;
}

.search-bar {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-color: var(--surface);
    border: 1px solid var(--outline-variant);
    padding: 10px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

@media (min-width: 580px) {
    .search-bar {
        flex-direction: row;
        align-items: center;
        padding: 5px;
        border-radius: var(--radius-full);
    }
}

.search-icon-label {
    display: flex;
    align-items: center;
    padding-left: 8px;
    color: var(--on-surface-variant);
}

.search-input {
    flex-grow: 1;
    border: none;
    background: transparent;
    font-family: var(--font-sans);
    font-size: 15px;
    color: var(--on-surface);
    padding: 8px 6px;
    outline: none;
    width: 100%;
}

.search-input::placeholder {
    color: rgba(70, 69, 85, 0.45);
}

[data-theme="dark"] .search-input::placeholder {
    color: rgba(199, 197, 213, 0.35);
}

.search-button {
    width: 100%;
    justify-content: center;
}

@media (min-width: 580px) {
    .search-button {
        width: auto;
    }
}

/* ─── Results Panel ─── */
.results-section {
    display: none;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    flex-grow: 1;
    min-height: 0;
}

.results-section.show {
    display: flex;
    flex-direction: column;
    opacity: 1;
    transform: translateY(0);
}

.results-card {
    background-color: var(--surface);
    border: 1px solid var(--outline-variant);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.results-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--outline-variant);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.consignment-info h2 {
    font-size: 18px;
    margin-top: 2px;
    font-family: var(--font-mono);
    letter-spacing: -0.02em;
}

.sync-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    color: var(--primary);
    font-size: 13px;
}

.sync-status .material-symbols-outlined {
    font-size: 18px;
    animation: spin 1.5s linear infinite;
}

/* ─── Metadata Grid (4 items) ─── */
.metadata-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    background-color: var(--surface-container-low);
    border-bottom: 1px solid var(--outline-variant);
    flex-shrink: 0;
}

@media (min-width: 580px) {
    .metadata-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.metadata-item {
    padding: 12px 10px;
    text-align: center;
    border-right: 1px solid var(--outline-variant);
    border-bottom: 1px solid var(--outline-variant);
}

.metadata-item:nth-child(2n) {
    border-right: none;
}

@media (min-width: 580px) {
    .metadata-item {
        border-bottom: none;
    }

    .metadata-item:nth-child(2n) {
        border-right: 1px solid var(--outline-variant);
    }

    .metadata-item:last-child {
        border-right: none;
    }
}

.meta-label {
    font-family: var(--font-mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--on-surface-variant);
    margin-bottom: 4px;
    display: block;
}

.meta-val {
    font-size: 13px;
    font-weight: 700;
    color: var(--on-surface);
}

/* ─── Gamified Horizontal Track ─── */
.gamified-track-wrapper {
    padding: 0 20px;
    flex-shrink: 0;
    border-bottom: 1px solid var(--outline-variant);
    background: linear-gradient(180deg, var(--surface-container-low) 0%, var(--surface) 100%);
}

.gamified-track-container {
    position: relative;
    padding: 52px 0 56px 0;
    z-index: 10;
}

/* Base dashed rail */
.base-circuit-path {
    position: absolute;
    left: 12px;
    right: 12px;
    top: 44px;
    height: 6px;
    background-color: var(--surface-container);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.dashed-pattern {
    width: 100%;
    height: 100%;
    background-image: repeating-linear-gradient(
        90deg,
        var(--outline-variant) 0px,
        var(--outline-variant) 8px,
        transparent 8px,
        transparent 16px
    );
}

/* Glowing active fill */
.progress-fill {
    position: absolute;
    left: 12px;
    top: 44px;
    height: 6px;
    background: linear-gradient(90deg, var(--secondary), var(--primary));
    border-radius: var(--radius-full);
    transition: width 1.8s cubic-bezier(0.22, 1, 0.36, 1);
    width: 0;
    box-shadow: 0 0 12px rgba(var(--primary-rgb), 0.4);
    z-index: 10;
}

/* Node containers */
.nodes-container {
    position: absolute;
    left: 12px;
    right: 12px;
    top: 44px;
    transform: translateY(-50%);
    display: flex;
    justify-content: space-between;
    z-index: 20;
}

.node-point-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.node-point {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background-color: var(--surface-container-highest);
    border: 3px solid var(--surface);
    box-shadow: var(--shadow-sm), 0 0 0 2px var(--outline-variant);
    transition: all 0.5s cubic-bezier(0.22, 1, 0.36, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.node-point .material-symbols-outlined {
    font-size: 14px;
    color: white;
    opacity: 0;
    transition: opacity 0.3s ease;
}

/* Labels below nodes */
.node-label {
    position: absolute;
    top: 34px;
    text-align: center;
    width: 72px;
    left: 50%;
    margin-left: -36px;
}

.node-label .node-level {
    font-family: var(--font-mono);
    font-size: 9px;
    color: var(--outline);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 1px;
}

.node-label .node-name {
    font-size: 11px;
    font-weight: 700;
    color: var(--on-surface);
    line-height: 1.2;
}

/* Active node animation */
.node-point.node-active {
    background-color: var(--primary);
    box-shadow: var(--shadow-sm), 0 0 0 3px rgba(var(--primary-rgb), 0.2), 0 0 16px rgba(var(--primary-rgb), 0.3);
    border-color: var(--surface);
    transform: scale(1.15);
}

.node-point.node-active .material-symbols-outlined {
    opacity: 1;
}

/* Current pulsing node */
.node-point.node-current {
    background-color: var(--primary);
    box-shadow: var(--shadow-sm), 0 0 0 3px rgba(var(--primary-rgb), 0.2);
    border-color: var(--surface);
    transform: scale(1.15);
    animation: node-pulse 2s infinite ease-in-out;
}

.node-point.node-current .material-symbols-outlined {
    opacity: 1;
}

/* Delivered state */
.node-point.node-delivered {
    background-color: var(--success);
    box-shadow: var(--shadow-sm), 0 0 0 3px rgba(var(--success-rgb), 0.2), 0 0 16px rgba(var(--success-rgb), 0.3);
    border-color: var(--surface);
    transform: scale(1.15);
    animation: reward-burst 0.8s forwards;
}

.node-point.node-delivered .material-symbols-outlined {
    opacity: 1;
}

/* Delivery payload (truck) */
.delivery-payload {
    position: absolute;
    top: 44px;
    transform: translateY(-50%);
    z-index: 30;
    transition: left 1.8s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.4s ease;
    left: 12px;
    opacity: 0;
}

.payload-icon-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.payload-glow {
    position: absolute;
    inset: -6px;
    background-color: rgba(var(--primary-rgb), 0.25);
    border-radius: 50%;
    filter: blur(6px);
    animation: glow-pulse 2s infinite ease-in-out;
}

.payload-box {
    background-color: var(--surface);
    padding: 6px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    border: 2px solid var(--primary);
    color: var(--primary);
    position: relative;
    z-index: 10;
    transition: border-color 0.5s ease, color 0.5s ease;
}

.payload-box .material-symbols-outlined {
    font-size: 20px;
    display: block;
}

.payload-box.delivered {
    border-color: var(--success);
    color: var(--success);
}

/* ─── Timeline (vertical event list) ─── */
.results-body {
    padding: 20px;
    overflow-y: auto;
    flex-grow: 1;
    min-height: 0;
}

.results-body::-webkit-scrollbar {
    width: 5px;
}

.results-body::-webkit-scrollbar-track {
    background: transparent;
}

.results-body::-webkit-scrollbar-thumb {
    background-color: var(--outline);
    border-radius: 4px;
}

.results-body::-webkit-scrollbar-thumb:hover {
    background-color: var(--on-surface-variant);
}

.timeline {
    position: relative;
}

.timeline-item {
    position: relative;
    padding-left: 28px;
    padding-bottom: 22px;
    animation: fadeSlideIn 0.4s ease both;
}

.timeline-item:last-child {
    padding-bottom: 0;
}

.timeline-line {
    position: absolute;
    left: 5px;
    top: 14px;
    bottom: 0;
    width: 2px;
    background-color: var(--outline-variant);
}

.timeline-item:last-child .timeline-line {
    display: none;
}

.timeline-dot {
    position: absolute;
    left: 0;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--outline);
    border: 2px solid var(--surface);
    z-index: 2;
    transition: all 0.3s ease;
}

.timeline-item.active .timeline-dot {
    background-color: var(--primary);
    box-shadow: 0 0 0 5px rgba(var(--primary-rgb), 0.12);
}

.timeline-item.active .timeline-dot::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 1.5px solid var(--primary);
    animation: ripple 2s infinite ease-in-out;
}

.timeline-item.completed .timeline-dot {
    background-color: var(--success);
}

.timeline-item.completed .timeline-line {
    background-color: var(--success);
}

.event-time {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--on-surface-variant);
    font-weight: 600;
    letter-spacing: 0.05em;
    margin-bottom: 2px;
    display: block;
}

.timeline-item.active .event-time {
    color: var(--primary);
}

.event-title {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 2px;
}

.event-details {
    font-size: 12px;
    color: var(--on-surface-variant);
}

/* ─── Loading & Error States ─── */
.loading-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 0;
    text-align: center;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--surface-container-high);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

.loading-text {
    font-family: var(--font-mono);
    font-size: 11px;
    letter-spacing: 0.08em;
    color: var(--primary);
    font-weight: 700;
    text-transform: uppercase;
}

.error-message {
    padding: 16px;
    border-left: 4px solid var(--error);
    background-color: var(--error-container);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--on-background);
    margin-top: 10px;
    font-size: 14px;
}

/* ─── Footer ─── */
.footer-credits {
    position: absolute;
    bottom: 12px;
    left: 0;
    width: 100%;
    text-align: center;
    font-size: 11px;
    color: var(--on-surface-variant);
    opacity: 0.5;
    pointer-events: none;
    z-index: 5;
}

/* ─── Keyframe Animations ─── */
@keyframes pulse-soft {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.6; }
}

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

@keyframes ripple {
    0% { transform: scale(0.9); opacity: 1; }
    100% { transform: scale(2); opacity: 0; }
}

@keyframes glow-pulse {
    0%, 100% { opacity: 0.3; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

@keyframes node-pulse {
    0%, 100% { box-shadow: var(--shadow-sm), 0 0 0 3px rgba(var(--primary-rgb), 0.2); }
    50% { box-shadow: var(--shadow-sm), 0 0 0 8px rgba(var(--primary-rgb), 0.1), 0 0 20px rgba(var(--primary-rgb), 0.2); }
}

@keyframes reward-burst {
    0% { transform: scale(0.8); box-shadow: 0 0 0 0 rgba(var(--success-rgb), 0.6); }
    60% { transform: scale(1.25); box-shadow: 0 0 0 20px rgba(var(--success-rgb), 0); }
    100% { transform: scale(1.15); box-shadow: var(--shadow-sm), 0 0 0 3px rgba(var(--success-rgb), 0.2), 0 0 16px rgba(var(--success-rgb), 0.3); }
}

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