/**
 * ERG Order Sync — Tracking page styles
 * Mobile-first. Each order is a self-contained block.
 * Timeline + iframe below each order.
 */

/* ── Wrap ───────────────────────────────────────────────────────────────────── */
.erg-tracking-wrap {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 0 40px;
    font-size: 14px;
    line-height: 1.6;
    color: #111827;
}

.erg-page-header { margin-bottom: 20px; }
.erg-page-header h2 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
.erg-page-sub { font-size: 13px; color: #9ca3af; margin: 0; }

/* ── Order block ────────────────────────────────────────────────────────────── */
.erg-order-block {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    margin-bottom: 24px;
    overflow: hidden;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.erg-order-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 16px 20px;
    border-bottom: 1px solid #f3f4f6;
}

.erg-order-ident {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.erg-order-num {
    font-weight: 600;
    font-size: 15px;
}

.erg-order-date {
    font-size: 12px;
    color: #9ca3af;
}

/* Status pills */
.erg-status-pill {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 999px;
    white-space: nowrap;
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #e5e7eb;
    flex-shrink: 0;
}
.erg-s-forwarded, .erg-s-warehouse-confirmed { background:#eff6ff; color:#1d4ed8; border-color:#bfdbfe; }
.erg-s-preparing                             { background:#fffbeb; color:#92400e; border-color:#fde68a; }
.erg-s-dispatched, .erg-s-in-transit        { background:#f0fdf4; color:#166534; border-color:#bbf7d0; }
.erg-s-shipment-update                      { background:#fff7ed; color:#9a3412; border-color:#fed7aa; }
.erg-s-completed                            { background:#f0fdf4; color:#166534; border-color:#bbf7d0; }
.erg-s-on-hold                              { background:#fef2f2; color:#991b1b; border-color:#fecaca; }

/* ── Products ───────────────────────────────────────────────────────────────── */
.erg-items {
    padding: 12px 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-bottom: 1px solid #f3f4f6;
}

.erg-item {
    display: flex;
    align-items: center;
    gap: 12px;
}

.erg-item-img {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid #e5e7eb;
    flex-shrink: 0;
}

.erg-item-img-placeholder {
    background: #f3f4f6;
}

.erg-item-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.erg-item-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.erg-item-qty {
    font-size: 12px;
    color: #9ca3af;
}

.erg-item-total {
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    flex-shrink: 0;
}

/* ── Shipping strip ─────────────────────────────────────────────────────────── */
.erg-ship-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    border-bottom: 1px solid #f3f4f6;
    background: #f9fafb;
}

.erg-ship-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 20px;
    border-right: 1px solid #f3f4f6;
    flex: 1;
    min-width: 120px;
}

.erg-ship-cell:last-child { border-right: none; }

.erg-ship-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #9ca3af;
    font-weight: 500;
}

.erg-ship-val {
    font-size: 13px;
    font-weight: 500;
    color: #111827;
}

.erg-mono {
    font-family: 'Courier New', monospace;
    font-size: 12px;
    letter-spacing: .04em;
}

/* ── Timeline ───────────────────────────────────────────────────────────────── */
.erg-timeline {
    padding: 20px 20px 16px;
    border-bottom: 1px solid #f3f4f6;
}

.erg-tl-track {
    position: relative;
    padding-left: 28px;
}

.erg-tl-track::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 8px;
    bottom: 8px;
    width: 2px;
    background: #e5e7eb;
}

.erg-tl-item {
    position: relative;
    margin-bottom: 16px;
    min-height: 22px;
}

.erg-tl-item:last-child { margin-bottom: 0; }

/* Dots */
.erg-tl-dot {
    position: absolute;
    left: -24px;
    top: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e5e7eb;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px #e5e7eb;
    z-index: 1;
}

.erg-dot-done    { background: #16a34a; box-shadow: 0 0 0 2px #16a34a; }
.erg-dot-active  { background: #2563eb; box-shadow: 0 0 0 3px #bfdbfe; animation: erg-pulse 1.8s ease-in-out infinite; }
.erg-dot-pending { background: #fff; box-shadow: 0 0 0 2px #d1d5db; }
.erg-dot-hold    { background: #dc2626; box-shadow: 0 0 0 2px #dc2626; }

@keyframes erg-pulse {
    0%, 100% { box-shadow: 0 0 0 3px #bfdbfe; }
    50%       { box-shadow: 0 0 0 6px #dbeafe; }
}

.erg-tl-body { line-height: 1.4; }

.erg-tl-label {
    font-size: 13px;
    font-weight: 500;
    color: #111827;
}

.erg-tl-pending .erg-tl-label {
    color: #9ca3af;
    font-weight: 400;
}

.erg-tl-date {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
}

.erg-tl-sub {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
}

/* ── Tracking section (toggle + iframe) ─────────────────────────────────────── */
.erg-tracking-section {
    padding: 16px 20px;
}

.erg-track-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
    transition: border-color .12s, background .12s;
    font-family: inherit;
    line-height: 1;
}

.erg-track-toggle:hover {
    border-color: #2563eb;
    color: #2563eb;
    background: #eff6ff;
}

.erg-track-toggle[aria-expanded="true"] {
    border-color: #2563eb;
    color: #2563eb;
    background: #eff6ff;
}

.erg-track-toggle-icon {
    font-size: 10px;
}

/* iframe wrap */
.erg-iframe-wrap {
    margin-top: 14px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    min-height: 60px;
}

.erg-iframe-loading {
    padding: 20px;
    text-align: center;
    font-size: 13px;
    color: #9ca3af;
}

.erg-track-frame {
    width: 100%;
    height: 480px;
    border: none;
    display: none;  /* shown by JS after load */
}

/* Fallback when iframe is blocked */
.erg-iframe-fallback {
    padding: 20px;
    text-align: center;
    background: #f9fafb;
}

.erg-iframe-fallback p {
    font-size: 13px;
    color: #6b7280;
    margin: 0 0 10px;
}

.erg-ext-link {
    display: inline-block;
    background: #111827;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    padding: 8px 18px;
    border-radius: 6px;
    text-decoration: none;
    transition: background .12s;
}

.erg-ext-link:hover { background: #1f2937; color: #fff; }

/* Pre-dispatch placeholder */
.erg-track-pending {
    font-size: 13px;
    color: #9ca3af;
    font-style: italic;
    margin: 0;
}

/* ── Lookup form ────────────────────────────────────────────────────────────── */
.erg-lookup-wrap {
    max-width: 440px;
    margin: 0 auto;
}

.erg-lookup-wrap h2 {
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 6px;
}

.erg-lookup-sub {
    color: #6b7280;
    font-size: 13px;
    margin: 0 0 20px;
}

.erg-lookup-form {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 14px;
}

.erg-field { margin-bottom: 14px; }
.erg-field:last-of-type { margin-bottom: 18px; }

.erg-field label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 5px;
}

.erg-field input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    color: #111827;
    background: #fff;
    box-sizing: border-box;
    transition: border-color .12s, box-shadow .12s;
    font-family: inherit;
}

.erg-field input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.erg-btn {
    width: 100%;
    background: #111827;
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    padding: 10px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background .12s;
    font-family: inherit;
}

.erg-btn:hover { background: #1f2937; }

.erg-lookup-note {
    font-size: 12px;
    color: #9ca3af;
    text-align: center;
    margin: 0;
}

.erg-lookup-note a, .erg-lookup-back a { color: #2563eb; }

.erg-lookup-back {
    font-size: 13px;
    margin-top: 16px;
}

/* ── Errors / empty ─────────────────────────────────────────────────────────── */
.erg-tracking-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    padding: 10px 14px;
    font-size: 13px;
    color: #991b1b;
    margin-bottom: 16px;
}

.erg-tracking-error a { color: #991b1b; }

.erg-tracking-empty {
    text-align: center;
    padding: 48px 20px;
    color: #6b7280;
}

.erg-tracking-empty p { margin: 0 0 8px; }
.erg-tracking-empty a { color: #2563eb; }

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .erg-order-head    { padding: 14px 16px; flex-wrap: wrap; }
    .erg-items         { padding: 12px 16px; }
    .erg-ship-strip    { flex-direction: column; }
    .erg-ship-cell     { border-right: none; border-bottom: 1px solid #f3f4f6; padding: 10px 16px; }
    .erg-ship-cell:last-child { border-bottom: none; }
    .erg-timeline      { padding: 16px; }
    .erg-tracking-section { padding: 14px 16px; }
    .erg-track-frame   { height: 380px; }
    .erg-lookup-form   { padding: 16px; }
}

/* ── Carrier scan events log ─────────────────────────────────────────────────── */
.erg-scan-log {
    border-top: 1px solid #f3f4f6;
}

.erg-scan-log-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #6b7280;
    background: #f9fafb;
    border-bottom: 1px solid #f3f4f6;
}

.erg-scan-count {
    font-weight: 400;
    color: #9ca3af;
}

.erg-scan-events {
    padding: 8px 20px 16px;
}

.erg-scan-event {
    display: flex;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid #f9fafb;
    position: relative;
}

.erg-scan-event:last-child { border-bottom: none; }

.erg-scan-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d1d5db;
    margin-top: 5px;
    flex-shrink: 0;
}

.erg-scan-event:first-child .erg-scan-dot {
    background: #22c55e;
}

.erg-scan-body {
    flex: 1;
    min-width: 0;
}

.erg-scan-desc {
    font-size: 13px;
    color: #111827;
    font-weight: 500;
    line-height: 1.4;
}

.erg-scan-event:first-child .erg-scan-desc {
    color: #16a34a;
}

.erg-scan-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    margin-top: 2px;
}

.erg-scan-meta .erg-scan-loc {
    font-size: 12px;
    color: #374151;
    font-weight: 500;
}

.erg-scan-meta .erg-scan-time {
    font-size: 12px;
    color: #9ca3af;
}

@media (max-width: 600px) {
    .erg-scan-events { padding: 8px 16px 12px; }
    .erg-scan-log-head { padding: 10px 16px; }
}
