/* =============================================================================
   Shipdon API Integration — Frontend Styles
   Version: 1.0.0
   Uses CSS custom properties so colours and typography blend with the active
   WordPress theme. Override --shipdon-accent in your theme's Additional CSS
   if the default blue doesn't match.
   ============================================================================= */

/* ── Theme-aware custom properties ────────────────────────────────────────── */

:root {
    /* Falls back to the theme's primary preset if defined, else Shipdon blue */
    --shipdon-accent:        var(--wp--preset--color--primary, #2563eb);
    --shipdon-accent-hover:  var(--wp--preset--color--primary, #1d4ed8);
    --shipdon-accent-light:  rgba(37, 99, 235, 0.12);
    --shipdon-success-bg:    #f0fdf4;
    --shipdon-success-border:#86efac;
    --shipdon-success-text:  #166534;
    --shipdon-error-bg:      #fef2f2;
    --shipdon-error-border:  #fca5a5;
    --shipdon-error-text:    #991b1b;
}

/* ── Widget container ──────────────────────────────────────────────────────── */

.shipdon-widget {
    /* Inherit the theme's body font and text color */
    font-family: inherit;
    font-size: 0.95rem;
    color: inherit;
    max-width: 740px;
    margin: 0 auto 2rem;
    line-height: 1.5;
}

.shipdon-widget-title {
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 1.25rem;
    color: inherit;
}

/* ── Form shell ────────────────────────────────────────────────────────────── */

.shipdon-form {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 1.5rem;
    box-sizing: border-box;
}

.shipdon-form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 0;
}

.shipdon-form-row > .shipdon-field-group {
    flex: 1 1 200px;
}

/* ── Field group ───────────────────────────────────────────────────────────── */

.shipdon-field-group {
    margin-bottom: 1rem;
}

.shipdon-field-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: #374151;
}

.shipdon-field-group .required {
    color: #ef4444;
    margin-left: 2px;
}

.shipdon-field-group input,
.shipdon-field-group select,
.shipdon-field-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    color: #111827;
    background: #fff;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

.shipdon-field-group select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7280' d='M6 8L0 0h12z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2rem;
}

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

.shipdon-field-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* ── Button ────────────────────────────────────────────────────────────────── */

.shipdon-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--shipdon-accent);
    color: #fff !important;
    border: none;
    padding: 0.6rem 1.6rem;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
    text-decoration: none;
    margin-top: 0.25rem;
}

.shipdon-btn:hover,
.shipdon-btn:focus {
    background: var(--shipdon-accent-hover);
    outline: none;
}

.shipdon-btn:active {
    transform: scale(0.98);
}

.shipdon-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.shipdon-btn-sm {
    padding: 0.45rem 1rem;
    font-size: 0.875rem;
}

/* ── Inline form (quote lookup row) ───────────────────────────────────────── */

.shipdon-inline-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    padding: 1rem;
    border-radius: 8px;
}

.shipdon-inline-form input {
    flex: 1 1 200px;
    padding: 0.5rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    font-family: inherit;
    color: #111827;
    box-sizing: border-box;
    transition: border-color 0.15s ease;
}

.shipdon-inline-form input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* ── Alerts ────────────────────────────────────────────────────────────────── */

.shipdon-result {
    margin-top: 1.25rem;
}

.shipdon-alert {
    padding: 0.9rem 1.1rem;
    border-radius: 8px;
    font-size: 0.925rem;
    line-height: 1.55;
}

.shipdon-alert p:last-child {
    margin-bottom: 0;
}

.shipdon-alert-success {
    background: var(--shipdon-success-bg);
    border: 1px solid var(--shipdon-success-border);
    color: var(--shipdon-success-text);
}

.shipdon-alert-error {
    background: var(--shipdon-error-bg);
    border: 1px solid var(--shipdon-error-border);
    color: var(--shipdon-error-text);
}

/* ── Spinner / loading ─────────────────────────────────────────────────────── */

.shipdon-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #d1d5db;
    border-top-color: var(--shipdon-accent);
    border-radius: 50%;
    animation: shipdon-spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 0.35rem;
}

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

.shipdon-routes-loading {
    font-size: 0.875rem;
    color: #6b7280;
    margin-bottom: 0.75rem;
}

/* ── Status badges ─────────────────────────────────────────────────────────── */

.shipdon-status {
    display: inline-block;
    padding: 0.2rem 0.65rem;
    border-radius: 9999px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: capitalize;
    background: #f3f4f6;
    color: #374151;
    white-space: nowrap;
    font-family: inherit;
}

.shipdon-status-delivered        { background: #dcfce7; color: #166534; }
.shipdon-status-in-transit       { background: #dbeafe; color: #1d4ed8; }
.shipdon-status-pending          { background: #fef9c3; color: #854d0e; }
.shipdon-status-on-hold          { background: #fee2e2; color: #991b1b; }
.shipdon-status-picked-up        { background: #ede9fe; color: #5b21b6; }
.shipdon-status-arrived          { background: #d1fae5; color: #065f46; }
.shipdon-status-out-for-delivery { background: #bfdbfe; color: #1e40af; }
.shipdon-status-completed        { background: #dcfce7; color: #166534; }
.shipdon-status-cancelled        { background: #fee2e2; color: #991b1b; }

/* ── Tracking result ───────────────────────────────────────────────────────── */

.shipdon-tracking-result {
    font-family: inherit;
}

.shipdon-tracking-summary {
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.shipdon-tracking-summary p {
    margin: 0.25rem 0;
}

.shipdon-awb-card {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 1.25rem;
    margin-top: 0.75rem;
}

.shipdon-awb-card h4 {
    font-size: 0.95rem;
    font-weight: 700;
    margin: 0 0 0.75rem;
    color: inherit;
    border-bottom: 1px solid #e5e7eb;
    padding-bottom: 0.5rem;
}

.shipdon-awb-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1.5rem;
    font-size: 0.85rem;
    color: #6b7280;
    margin-bottom: 1rem;
}

/* ── Current status banner ─────────────────────────────────────────────────── */

.shipdon-current-status {
    background: var(--shipdon-accent-light);
    border: 1px solid var(--shipdon-accent);
    border-radius: 8px;
    padding: 0.9rem 1.1rem;
    margin-bottom: 1rem;
}

.shipdon-current-status-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--shipdon-accent);
    margin: 0 0 0.4rem;
}

.shipdon-current-status-body {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.shipdon-current-status-location {
    font-size: 0.875rem;
    color: #374151;
}

.shipdon-current-status-desc {
    width: 100%;
    font-size: 0.875rem;
    color: #374151;
    margin: 0.35rem 0 0;
}

.shipdon-current-status-time {
    width: 100%;
    font-size: 0.78rem;
    color: #9ca3af;
    display: block;
    margin-top: 0.2rem;
}

/* ── Timeline expand/collapse ──────────────────────────────────────────────── */

.shipdon-timeline-details {
    margin-top: 0.75rem;
}

.shipdon-timeline-details summary {
    font-size: 0.825rem;
    font-weight: 600;
    color: var(--shipdon-accent);
    cursor: pointer;
    user-select: none;
    margin-bottom: 0.75rem;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.shipdon-timeline-details summary::-webkit-details-marker { display: none; }

.shipdon-timeline-details summary::before {
    content: '\25BC'; /* ▼ */
    display: inline-block;
    font-size: 0.65rem;
    transition: transform 0.2s ease;
}

.shipdon-timeline-details:not([open]) summary::before {
    transform: rotate(-90deg);
}

/* ── Tracking timeline ─────────────────────────────────────────────────────── */

.shipdon-timeline {
    position: relative;
    padding-left: 1.4rem;
    border-left: 2px solid #e5e7eb;
    margin-top: 0.5rem;
}

.shipdon-timeline-item {
    position: relative;
    margin-bottom: 0.9rem;
    padding-left: 0.75rem;
}

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

.shipdon-timeline-dot {
    position: absolute;
    left: -1.55rem;
    top: 0.3rem;
    width: 10px;
    height: 10px;
    background: #d1d5db;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #d1d5db;
}

.shipdon-timeline-item.is-latest .shipdon-timeline-dot {
    background: var(--shipdon-accent);
    box-shadow: 0 0 0 3px var(--shipdon-accent-light);
    animation: shipdon-pulse 2s ease-in-out infinite;
}

@keyframes shipdon-pulse {
    0%, 100% { box-shadow: 0 0 0 3px var(--shipdon-accent-light); }
    50%       { box-shadow: 0 0 0 6px transparent; }
}

.shipdon-timeline-content {
    font-size: 0.875rem;
    color: #374151;
}

.shipdon-timeline-content strong {
    text-transform: capitalize;
    color: inherit;
}

.shipdon-timeline-loc {
    color: #6b7280;
    font-weight: 400;
}

.shipdon-timeline-desc {
    color: #6b7280;
    margin: 0.1rem 0 0.15rem;
    font-size: 0.85rem;
}

.shipdon-timeline-item time {
    font-size: 0.78rem;
    color: #9ca3af;
    display: block;
}

/* ── Quote result card ─────────────────────────────────────────────────────── */

.shipdon-quote-card p {
    margin: 0.3rem 0;
    font-size: 0.9rem;
}

.shipdon-quote-estimated-price {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--shipdon-accent);
    margin: 0.5rem 0 !important;
}

/* ── Quote lookup section ──────────────────────────────────────────────────── */

.shipdon-quote-lookup {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #e5e7eb;
}

.shipdon-quote-lookup h4 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 580px) {
    .shipdon-form-row {
        flex-direction: column;
    }

    .shipdon-btn {
        width: 100%;
        justify-content: center;
    }

    .shipdon-inline-form {
        flex-direction: column;
    }

    .shipdon-inline-form .shipdon-btn {
        width: auto;
    }
}
