/* ===== CSS Variables ===== */
:root {
    --primary-color: #1a56db;
    --primary-hover: #1e429f;
    --success-color: #059669;
    --success-bg: #d1fae5;
    --warning-color: #d97706;
    --warning-bg: #fef3c7;
    --error-color: #dc2626;
    --error-bg: #fee2e2;
    --info-color: #2563eb;
    --info-bg: #dbeafe;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

/* ===== Base Styles ===== */
*, *::before, *::after {
    box-sizing: border-box;
}

body, html {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: var(--gray-800);
    background-color: var(--gray-50);
    -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.header {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    padding: 16px 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo {
    height: 60px;
    width: auto;
}

/* ===== Search Section ===== */
.search-section {
    background: linear-gradient(135deg, #1e3a5f 0%, #2d5a87 100%);
    padding: 60px 24px;
    text-align: center;
}

.search-container {
    max-width: 600px;
    margin: 0 auto;
}

.search-title {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--white);
    margin: 0 0 12px 0;
}

.search-subtitle {
    font-size: 1.125rem;
    color: rgba(255, 255, 255, 0.8);
    margin: 0 0 32px 0;
}

.search-form {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.search-input-wrapper {
    position: relative;
    flex: 1;
    min-width: 280px;
    max-width: 400px;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-400);
}

.search-input-wrapper input {
    width: 100%;
    padding: 16px 16px 16px 48px;
    font-size: 1rem;
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    outline: none;
    transition: all 0.2s ease;
    background: var(--white);
}

.search-input-wrapper input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(26, 86, 219, 0.1);
}

.search-input-wrapper input::placeholder {
    color: var(--gray-400);
}

.search-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 16px 28px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--white);
    background: var(--primary-color);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
}

.search-button:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.search-button:active {
    transform: translateY(0);
}

.input-hint {
    margin: 4px 0 12px 0;
    font-size: 0.8125rem;
    color: rgba(255, 255, 255, 0.6);
    text-align: left;
    width: 100%;
    max-width: 400px;
}

.help-text {
    margin-top: 20px;
    font-size: 0.9375rem;
    color: rgba(255, 255, 255, 0.8);
}

.help-text a {
    color: var(--white);
    font-weight: 500;
    text-decoration: underline;
}

.help-text a:hover {
    text-decoration: none;
}

/* ===== Main Content ===== */
.main-content {
    margin: 0 auto;
    padding: 32px 24px;
}

.content-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 1024px) {
    .content-grid {
        grid-template-columns: 1fr;
    }

    .order-column {
        order: 2;
    }

    .shipment-column {
        order: 1;
    }
}

/* ===== Cards ===== */
.card {
    background: var(--white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 20px;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
}

.card-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title svg {
    color: var(--gray-500);
}

.card-body {
    padding: 20px;
}

/* ===== Order Summary Card ===== */
.order-summary-card {
    background: linear-gradient(135deg, var(--white) 0%, var(--gray-50) 100%);
}

.order-summary-card .card-body {
    padding: 24px;
}

.order-number {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin-bottom: 4px;
}

.order-number-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 16px;
}

.order-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.order-meta-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.order-meta-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
}

.order-meta-value {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
}

/* ===== Status Badges ===== */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 100px;
}

.status-badge svg {
    width: 14px;
    height: 14px;
}

.status-delivered {
    background: var(--success-bg);
    color: var(--success-color);
}

.status-out-for-delivery,
.status-available-for-pickup {
    background: #d1fae5;
    color: #047857;
}

.status-in-transit,
.status-shipped {
    background: var(--info-bg);
    color: var(--info-color);
}

.status-label-created,
.status-processing,
.status-awaiting-shipment {
    background: var(--warning-bg);
    color: var(--warning-color);
}

.status-exception,
.status-error,
.status-delivery-attempt-failed {
    background: var(--error-bg);
    color: var(--error-color);
}

/* ===== Products List ===== */
.product-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px 0;
    border-bottom: 1px solid var(--gray-100);
}

.product-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.product-item:first-child {
    padding-top: 0;
}

.product-name {
    font-weight: 500;
    color: var(--gray-800);
    flex: 1;
    padding-right: 16px;
}

.product-meta {
    text-align: right;
    white-space: nowrap;
}

.product-qty {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.product-price {
    font-weight: 600;
    color: var(--gray-800);
}

/* ===== Shipping Address ===== */
.address-name {
    font-weight: 600;
    color: var(--gray-800);
    margin-bottom: 4px;
}

.address-line {
    color: var(--gray-600);
    margin: 2px 0;
}

/* ===== Map Card ===== */
.map-card {
    padding: 0;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 300px;
}

/* ===== Shipment Cards ===== */
.shipment-card {
    border-left: 4px solid var(--gray-300);
}

.shipment-card.status-delivered {
    border-left-color: var(--success-color);
}

.shipment-card.status-in-transit,
.shipment-card.status-shipped {
    border-left-color: var(--info-color);
}

.shipment-card.status-out-for-delivery {
    border-left-color: #047857;
}

.shipment-card.status-label-created,
.shipment-card.status-processing {
    border-left-color: var(--warning-color);
}

.shipment-card.status-exception,
.shipment-card.status-error {
    border-left-color: var(--error-color);
}

.shipment-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
}

.shipment-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-800);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.shipment-body {
    padding: 20px;
}

.shipment-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.shipment-info-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.shipment-info-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
}

.shipment-info-value {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--gray-800);
}

.shipment-info-value a {
    color: var(--primary-color);
    text-decoration: none;
}

.shipment-info-value a:hover {
    text-decoration: underline;
}

/* ===== Tracking Timeline ===== */
.tracking-timeline {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-100);
}

.tracking-timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    cursor: pointer;
}

.tracking-timeline-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    gap: 8px;
}

.tracking-toggle {
    font-size: 0.75rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 4px;
}

.tracking-events {
    position: relative;
    padding-left: 24px;
}

.tracking-events::before {
    content: '';
    position: absolute;
    left: 7px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: var(--gray-200);
}

.tracking-event {
    position: relative;
    padding-bottom: 16px;
}

.tracking-event:last-child {
    padding-bottom: 0;
}

.tracking-event::before {
    content: '';
    position: absolute;
    left: -17px;
    top: 6px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--gray-300);
    border: 2px solid var(--white);
}

.tracking-event:first-child::before {
    background: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(26, 86, 219, 0.2);
}

.tracking-event-status {
    font-weight: 500;
    color: var(--gray-800);
    margin-bottom: 2px;
}

.tracking-event-location {
    font-size: 0.875rem;
    color: var(--gray-600);
}

.tracking-event-time {
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 2px;
}

.tracking-events-collapsed .tracking-event:nth-child(n+4) {
    display: none;
}

.show-more-events {
    margin-top: 12px;
    padding: 8px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--primary-color);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    cursor: pointer;
    width: 100%;
    transition: all 0.2s ease;
}

.show-more-events:hover {
    background: var(--gray-100);
}

/* ===== Warning Banner ===== */
.warning-banner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    background: var(--warning-bg);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.warning-banner svg {
    flex-shrink: 0;
    color: var(--warning-color);
}

.warning-banner-text {
    font-size: 0.875rem;
    color: var(--warning-color);
}

.warning-banner-text strong {
    display: block;
    margin-bottom: 2px;
}

/* ===== Refresh Button ===== */
.refresh-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 14px 24px;
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--gray-700);
    background: var(--white);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
}

.refresh-button:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

/* ===== Loading Overlay ===== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--gray-200);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    margin-top: 16px;
    font-size: 1rem;
    color: var(--gray-600);
}

/* ===== Error Container ===== */
.error-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 24px;
}

.error-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 40px;
    text-align: center;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

.error-card svg {
    color: var(--error-color);
    margin-bottom: 16px;
}

.error-card h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0 0 8px 0;
}

.error-card p {
    color: var(--gray-600);
    margin: 0 0 24px 0;
}

/* ===== 3JMS Info Box ===== */
.jms-info-box {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 12px;
}

.jms-info-box h5 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
    margin: 0 0 8px 0;
}

.jms-info-box p {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin: 0;
}

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .search-title {
        font-size: 1.75rem;
    }

    .search-subtitle {
        font-size: 1rem;
    }

    .search-form {
        flex-direction: column;
    }

    .search-input-wrapper {
        min-width: 100%;
        max-width: 100%;
    }

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

    .main-content {
        padding: 16px;
    }

    .shipment-info-grid {
        grid-template-columns: 1fr 1fr;
    }

    .order-meta {
        flex-direction: column;
        gap: 12px;
    }
}

/* ===== Mapbox Popup Override ===== */
.mapboxgl-popup-content {
    padding: 12px 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
}

.mapboxgl-popup-close-button {
    display: none;
}
