/**
 * TCB Distance Calculator — Styles
 * Theme: white background, navy (#1B2A4A) card headers, teal/red/green brand
 * accents. Card-based layout matching the Cargo Intake Calculator, Freight Rate
 * Converter, Laytime Calculator, and Voyage Estimator.
 *
 * Scaffold only: this provides the card shell styling so the empty sections
 * render correctly. Input/route/results styling is extended in later tasks.
 */

/* ============================================
   HIDDEN-ATTRIBUTE GUARD (must stay first)
   ============================================
   The UA stylesheet's [hidden] { display: none } has low specificity, so a
   component rule like .tcb-dc-modal-overlay { display: flex } overrides it and
   re-shows elements that JS hid via the `hidden` attribute (modals/banner would
   stack on page load and Close would look dead). This scoped, !important guard
   makes the `hidden` attribute always win for every current and future element
   inside the calculator root. .tcb-dc is the plugin's root wrapper. */
.tcb-dc [hidden],
.tcb-dc[hidden] {
    display: none !important;
}

/* ============================================
   CSS CUSTOM PROPERTIES (brand palette)
   ============================================ */
:root {
    --tcb-dc-navy: #1B2A4A;
    --tcb-dc-teal: #2CA6A4;
    --tcb-dc-red: #D64045;
    --tcb-dc-green: #4CAF50;

    --tcb-dc-bg-page: #ffffff;
    --tcb-dc-bg-card: #ffffff;
    --tcb-dc-bg-muted: #f7f8fa;
    --tcb-dc-border: #d1d5db;
    --tcb-dc-border-focus: var(--tcb-dc-teal);
    --tcb-dc-text-primary: #1a1a2e;
    --tcb-dc-text-secondary: #4a5568;
    --tcb-dc-text-muted: #6b7280;
    --tcb-dc-text-on-dark: #ffffff;

    --tcb-dc-radius: 8px;
    --tcb-dc-radius-sm: 4px;
    --tcb-dc-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --tcb-dc-shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.12);
    --tcb-dc-transition: 0.2s ease;
    --tcb-dc-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
}

/* ============================================
   BASE WRAPPER
   ============================================ */
.tcb-dc {
    font-family: var(--tcb-dc-font);
    color: var(--tcb-dc-text-primary);
    background: var(--tcb-dc-bg-page);
    line-height: 1.5;
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
    box-sizing: border-box;
}

.tcb-dc *,
.tcb-dc *::before,
.tcb-dc *::after {
    box-sizing: border-box;
}

/* ============================================
   HEADER
   ============================================ */
.tcb-dc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    background: var(--tcb-dc-navy);
    color: var(--tcb-dc-text-on-dark);
    padding: 16px 24px;
    border-radius: var(--tcb-dc-radius) var(--tcb-dc-radius) 0 0;
}

.tcb-dc-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    /* Explicit so the navy header card title isn't hidden by a theme's
       inherited heading colour. */
    color: #fff;
}

.tcb-dc-subtitle {
    margin: 4px 0 0;
    font-size: 13px;
    opacity: 0.85;
}

.tcb-dc-header-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tcb-dc-header-btn {
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    color: var(--tcb-dc-text-on-dark);
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: var(--tcb-dc-radius-sm);
    cursor: pointer;
    transition: background var(--tcb-dc-transition);
}

.tcb-dc-header-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* User Guide link — anchor styled as a header button (Voyage Estimator parity):
   transparent with a teal outline, filling teal on hover. */
.tcb-dc-hdr-btn-guide {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    background: transparent;
    border: 1px solid #2CA6A4;
    color: #2CA6A4;
}

.tcb-dc-hdr-btn-guide:hover {
    background: #2CA6A4;
    color: #ffffff;
}

/* ============================================
   SHARED-LINK BANNER
   ============================================ */
.tcb-dc-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    font-size: 13px;
    color: var(--tcb-dc-text-primary);
    background: rgba(44, 166, 164, 0.12);
    border-left: 3px solid var(--tcb-dc-teal);
}

.tcb-dc-banner-close {
    background: none;
    border: none;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    color: var(--tcb-dc-text-secondary);
}

/* ============================================
   MODALS
   ============================================ */
.tcb-dc-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 22, 40, 0.55);
}

.tcb-dc-modal {
    width: 100%;
    max-width: 460px;
    max-height: 85vh;
    overflow-y: auto;
    background: var(--tcb-dc-bg-card);
    border-radius: var(--tcb-dc-radius);
    box-shadow: var(--tcb-dc-shadow-lg);
    padding: 22px;
}

.tcb-dc-modal-title {
    margin: 0 0 8px;
    font-size: 17px;
    color: var(--tcb-dc-navy);
}

.tcb-dc-modal-body {
    margin: 0 0 16px;
    font-size: 13px;
    color: var(--tcb-dc-text-secondary);
}

.tcb-dc-modal-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.tcb-dc-btn-primary,
.tcb-dc-btn-secondary {
    display: inline-block;
    padding: 9px 18px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    border-radius: var(--tcb-dc-radius-sm);
    cursor: pointer;
    border: 1px solid transparent;
    text-decoration: none;
}

.tcb-dc-btn-primary {
    color: var(--tcb-dc-text-on-dark);
    background: var(--tcb-dc-teal);
}

.tcb-dc-btn-secondary {
    color: var(--tcb-dc-navy);
    background: transparent;
    border-color: var(--tcb-dc-border);
}

.tcb-dc-btn-text {
    padding: 9px 8px;
    font-size: 13px;
    font-family: inherit;
    color: var(--tcb-dc-text-secondary);
    background: none;
    border: none;
    cursor: pointer;
}

.tcb-dc-share-row {
    display: flex;
    gap: 8px;
}

.tcb-dc-share-row .tcb-dc-input {
    flex: 1 1 auto;
}

.tcb-dc-load-list {
    max-height: 50vh;
    overflow-y: auto;
}

.tcb-dc-load-item {
    display: flex;
    align-items: stretch;
    gap: 6px;
    margin-bottom: 8px;
}

.tcb-dc-load-open {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 10px 12px;
    text-align: left;
    background: var(--tcb-dc-bg-muted);
    border: 1px solid var(--tcb-dc-border);
    border-radius: var(--tcb-dc-radius-sm);
    cursor: pointer;
    font-family: inherit;
}

.tcb-dc-load-open:hover {
    border-color: var(--tcb-dc-teal);
}

.tcb-dc-load-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--tcb-dc-text-primary);
}

.tcb-dc-load-date {
    font-size: 12px;
    color: var(--tcb-dc-text-muted);
}

.tcb-dc-load-delete {
    flex: 0 0 auto;
    padding: 0 12px;
    background: none;
    border: 1px solid var(--tcb-dc-border);
    border-radius: var(--tcb-dc-radius-sm);
    cursor: pointer;
    color: var(--tcb-dc-red);
}

.tcb-dc-load-delete:hover {
    border-color: var(--tcb-dc-red);
}

/* Report Issue modal */
.tcb-dc-report-profile {
    margin: 0 0 12px;
    font-size: 14px;
    line-height: 1.6;
}

.tcb-dc-report-success {
    color: #1B7F5A;
    margin: 8px 0 0;
}

/* ============================================
   CARD GRID + CARDS
   ============================================ */
.tcb-dc-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    padding: 16px;
    background: var(--tcb-dc-bg-muted);
    border-radius: 0 0 var(--tcb-dc-radius) var(--tcb-dc-radius);
}

/* Results spans the full width. */
#tcb-dc-card-results {
    grid-column: 1 / -1;
}

.tcb-dc-card {
    background: var(--tcb-dc-bg-card);
    border: 1px solid var(--tcb-dc-border);
    border-radius: var(--tcb-dc-radius);
    box-shadow: var(--tcb-dc-shadow);
    overflow: hidden;
}

.tcb-dc-card-head {
    background: var(--tcb-dc-navy);
    padding: 10px 16px;
}

.tcb-dc-card-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--tcb-dc-text-on-dark);
}

.tcb-dc-optional {
    font-weight: 400;
    font-size: 12px;
    opacity: 0.8;
}

.tcb-dc-card-body {
    padding: 16px;
    min-height: 48px;
}

/* Results panel gets a teal accent rule along the top of its head. */
.tcb-dc-results .tcb-dc-card-head {
    border-top: 3px solid var(--tcb-dc-teal);
}

.tcb-dc-placeholder {
    margin: 0;
    font-size: 13px;
    color: var(--tcb-dc-text-muted);
}

/* ============================================
   FIELDS / INPUTS
   ============================================ */
.tcb-dc-field {
    margin-bottom: 14px;
}

.tcb-dc-field:last-child {
    margin-bottom: 0;
}

.tcb-dc-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--tcb-dc-text-secondary);
    margin-bottom: 5px;
}

.tcb-dc-unit {
    font-weight: 400;
    color: var(--tcb-dc-text-muted);
    font-size: 12px;
}

.tcb-dc-input {
    width: 100%;
    padding: 9px 11px;
    font-size: 14px;
    font-family: inherit;
    color: var(--tcb-dc-text-primary);
    background: var(--tcb-dc-bg-card);
    border: 1px solid var(--tcb-dc-border);
    border-radius: var(--tcb-dc-radius-sm);
    transition: border-color var(--tcb-dc-transition), box-shadow var(--tcb-dc-transition);
}

.tcb-dc-input:focus {
    outline: none;
    border-color: var(--tcb-dc-border-focus);
    box-shadow: 0 0 0 3px rgba(44, 166, 164, 0.15);
}

.tcb-dc-num {
    text-align: right;
}

.tcb-dc-input-error {
    border-color: var(--tcb-dc-red);
}

.tcb-dc-input-error:focus {
    box-shadow: 0 0 0 3px rgba(214, 64, 69, 0.15);
}

/* ============================================
   PORT AUTOCOMPLETE
   ============================================
   .tcb-dc-port-dropdown is appended to <body> by the ports module and
   absolutely positioned under the input, so it is intentionally NOT scoped
   under .tcb-dc. */
.tcb-dc-port-dropdown {
    background: var(--tcb-dc-bg-card);
    border: 1px solid var(--tcb-dc-border);
    border-radius: var(--tcb-dc-radius-sm);
    box-shadow: var(--tcb-dc-shadow-lg);
    max-height: 280px;
    overflow-y: auto;
    font-family: var(--tcb-dc-font);
}

.tcb-dc-port-option {
    padding: 9px 12px;
    font-size: 14px;
    color: var(--tcb-dc-text-primary);
    cursor: pointer;
    border-bottom: 1px solid var(--tcb-dc-bg-muted);
}

.tcb-dc-port-option:last-child {
    border-bottom: none;
}

.tcb-dc-port-option-active,
.tcb-dc-port-option:hover {
    background: rgba(44, 166, 164, 0.12);
}

/* Swap button sits between From and To. */
.tcb-dc-swap-row {
    display: flex;
    justify-content: center;
    margin: -4px 0 10px;
}

.tcb-dc-swap-btn {
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    color: var(--tcb-dc-teal);
    background: transparent;
    border: 1px solid var(--tcb-dc-teal);
    border-radius: 999px;
    cursor: pointer;
    transition: background var(--tcb-dc-transition), color var(--tcb-dc-transition);
}

.tcb-dc-swap-btn:hover {
    background: var(--tcb-dc-teal);
    color: #fff;
}

/* ============================================
   INLINE VALIDATION ERROR
   ============================================ */
.tcb-dc-error {
    display: block;
    min-height: 14px;
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.2;
    color: var(--tcb-dc-red);
}

/* ============================================
   RESULTS PANEL
   ============================================ */
.tcb-dc-result-placeholder {
    margin: 0;
    padding: 24px 8px;
    text-align: center;
    color: var(--tcb-dc-text-muted);
    font-size: 14px;
}

/* Both routing endpoints down: recoverable notice with a Retry button.
   The Retry button reuses .tcb-dc-btn-primary (no new button colours). */
.tcb-dc-result-offline { text-align: center; padding: 2rem 1rem; }
.tcb-dc-result-offline-msg { color: var(--tcb-dc-navy, #1B2A4A); margin: 0 0 1rem; }

.tcb-dc-hero {
    text-align: center;
    padding: 8px 0 18px;
}

.tcb-dc-hero-figure {
    font-size: 44px;
    font-weight: 800;
    line-height: 1.1;
    color: var(--tcb-dc-teal);
}

.tcb-dc-hero-unit {
    font-size: 13px;
    color: var(--tcb-dc-text-muted);
    margin-top: 2px;
}

/* Route-alternative chips (e.g. Via Suez / Via Cape). */
.tcb-dc-route-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.tcb-dc-route-options:empty {
    display: none;
}

.tcb-dc-chip {
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    color: var(--tcb-dc-text-secondary);
    background: var(--tcb-dc-bg-muted);
    border: 1px solid var(--tcb-dc-border);
    border-radius: 999px;
    cursor: pointer;
    transition: background var(--tcb-dc-transition), color var(--tcb-dc-transition), border-color var(--tcb-dc-transition);
}

.tcb-dc-chip:hover {
    border-color: var(--tcb-dc-teal);
}

.tcb-dc-chip-active {
    color: var(--tcb-dc-text-on-dark);
    background: var(--tcb-dc-teal);
    border-color: var(--tcb-dc-teal);
}

.tcb-dc-route-desc {
    margin: 16px 0 0;
    font-size: 13px;
    line-height: 1.5;
    color: var(--tcb-dc-text-primary);
    text-align: center;
}

/* Derived voyage figures grid. */
.tcb-dc-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-top: 18px;
}

.tcb-dc-metric {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 14px;
    background: var(--tcb-dc-bg-muted);
    border-radius: var(--tcb-dc-radius-sm);
    border-left: 3px solid var(--tcb-dc-teal);
}

.tcb-dc-metric-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--tcb-dc-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.tcb-dc-metric-sub {
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    color: var(--tcb-dc-text-muted);
}

.tcb-dc-metric-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--tcb-dc-text-primary);
    font-variant-numeric: tabular-nums;
}

/* ============================================
   ROUTE MAP (Leaflet; bundled, tile-free)
   ============================================ */
.tcb-dc-map-panel {
    margin-top: 18px;
}

.tcb-dc-map-frame {
    position: relative;
    z-index: 0;                /* contain Leaflet's internal z-indexes so the
                                  map never bleeds over the theme's sticky header */
    border: 1px solid var(--tcb-dc-border);
    border-radius: var(--tcb-dc-radius-sm);
    overflow: hidden;
    background: #d3e0ec;       /* ocean */
}

#tcb-dc-map {
    width: 100%;
    aspect-ratio: 2 / 1;       /* gives the Leaflet container a real height */
    background: #d3e0ec;       /* ocean shows through where there is no land */
}

#tcb-dc-map.leaflet-container {
    font-family: var(--tcb-dc-font);
    background: #d3e0ec;
}

/* Route labels = Leaflet permanent tooltips, restyled flat + haloed (no bubble). */
.tcb-dc-map-label.leaflet-tooltip {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
    font-family: var(--tcb-dc-font);
    font-size: 13px;
    font-weight: 600;
    color: var(--tcb-dc-text-primary);
    white-space: nowrap;
    text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 2px #fff, 0 0 2px #fff;
}
.tcb-dc-map-label.leaflet-tooltip::before { display: none; }   /* no pointer nub */
.tcb-dc-map-label-node.leaflet-tooltip {
    font-weight: 400;
    color: var(--tcb-dc-text-secondary);
}

/* Country + ocean name labels (divIcon text, MarineTraffic-style), rendered in
   the 'tcb-labels' map pane below the route. The icon root is 0x0 at the anchor
   point; the inner <span> is centred on it via transform, so it never fights
   Leaflet's own positioning transform on the icon root. */
.tcb-dc-country-label,
.tcb-dc-ocean-label { width: 0; height: 0; background: none; border: none; }
.tcb-dc-country-label span,
.tcb-dc-ocean-label span {
    position: absolute;
    left: 0;
    top: 0;
    transform: translate(-50%, -50%);
    white-space: nowrap;
    font-family: var(--tcb-dc-font);
    text-shadow: 0 0 2px #fff, 0 0 2px #fff, 0 0 2px #fff, 0 0 2px #fff;
    pointer-events: none;
    user-select: none;
}
.tcb-dc-country-label span {
    font-size: 11px;
    font-weight: 600;
    color: #54607a;            /* muted navy-grey; reads over land and sea */
}
.tcb-dc-ocean-label span {
    font-size: 11px;
    font-style: italic;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: #8694ab;            /* lighter; recedes behind country names */
}

.tcb-dc-map-controls {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 500;              /* above Leaflet panes, inside the framed context */
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tcb-dc-map-btn {
    width: 30px;
    height: 30px;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    color: var(--tcb-dc-navy);
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--tcb-dc-border);
    border-radius: var(--tcb-dc-radius-sm);
    cursor: pointer;
    line-height: 1;
}

.tcb-dc-map-btn:hover { background: #ffffff; border-color: var(--tcb-dc-teal); }
.tcb-dc-map-fit { width: auto; padding: 0 8px; font-size: 12px; }

.tcb-dc-result-warnings {
    margin-top: 12px;
}

.tcb-dc-result-warning {
    margin: 0 0 6px;
    padding: 9px 12px;
    font-size: 13px;
    color: #7a2226;
    background: rgba(214, 64, 69, 0.08);
    border-left: 3px solid var(--tcb-dc-red);
    border-radius: var(--tcb-dc-radius-sm);
}

.tcb-dc-footnote {
    margin: 16px 0 0;
    font-size: 11px;
    line-height: 1.5;
    color: var(--tcb-dc-text-muted);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 720px) {
    .tcb-dc-grid {
        grid-template-columns: 1fr;
    }
    .tcb-dc-metrics {
        grid-template-columns: 1fr;
    }
    .tcb-dc-hero-figure {
        font-size: 36px;
    }
}

/* ============================================
   PRINT
   ============================================ */
@media print {
    /* Hide interactive chrome. */
    .tcb-dc-header-actions,
    .tcb-dc-banner,
    .tcb-dc-modal-overlay,
    .tcb-dc-result-placeholder,
    .tcb-dc-swap-btn {
        display: none !important;
    }

    /* Force a clean light background and full width. */
    .tcb-dc,
    .tcb-dc-grid {
        background: #fff !important;
        max-width: none !important;
        box-shadow: none !important;
    }

    .tcb-dc-card {
        box-shadow: none !important;
        border-color: #ccc !important;
    }

    /* Keep cards / metric tiles / chips from splitting across pages. */
    .tcb-dc-card,
    .tcb-dc-metric,
    .tcb-dc-route-options {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Render route-alternative chips as flat outlined pills (no button chrome);
       the active one keeps a solid fill so the printed page shows the selection. */
    .tcb-dc-chip {
        border: 1px solid #999 !important;
        color: #000 !important;
        background: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .tcb-dc-chip-active {
        border-color: var(--tcb-dc-navy) !important;
        background: var(--tcb-dc-bg-muted) !important;
        font-weight: 700;
    }

    /* Metric tiles: keep the teal accent rail visible on paper. */
    .tcb-dc-metric {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Route map: hide pan/zoom controls; print the fitted map at a sensible
       size with land/sea colours preserved. beforeprint calls fit(). */
    .tcb-dc-map-controls {
        display: none !important;
    }
    #tcb-dc-map {
        width: 100% !important;
        max-height: 9cm;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .leaflet-control-container { display: none !important; }
    .tcb-dc-map-frame {
        page-break-inside: avoid;
        break-inside: avoid;
    }
}
