/* ========================================
   Zone Map Explorer — Tool Styles
   ======================================== */

/* ---- Zone Colors ---- */
:root {
    --zone-0: #d4dbe3;
    --zone-1: #c4a0e0;
    --zone-2: #8daae8;
    --zone-3: #6cc8dc;
    --zone-4: #5cc89a;
    --zone-5: #8ed46e;
    --zone-6: #cce060;
    --zone-7: #edd854;
    --zone-8: #eca85c;
    --zone-9: #e87868;
    --zone-highlight: rgba(255, 255, 255, 0.35);
    --map-stroke: rgba(0, 0, 0, 0.22);
    --continent-na: #6cb4a0;
    --continent-sa: #8ec87a;
    --continent-eu: #7baad4;
    --continent-af: #e8b060;
    --continent-as: #d48a8a;
    --continent-oc: #b898d0;
    --map-bg: var(--bg-card);
    --table-bg: var(--bg-card);
    --table-border: var(--border-subtle);
    --table-hover: var(--bg-card-hover);
    --cell-focus: var(--form-focus);
    --drag-handle: var(--accent);
}

[data-theme="dark"] {
    --zone-0: #2a3040;
    --zone-1: #8a68b0;
    --zone-2: #5c78c0;
    --zone-3: #4898b0;
    --zone-4: #3a9e78;
    --zone-5: #5aaa4a;
    --zone-6: #98b440;
    --zone-7: #c4a838;
    --zone-8: #c08040;
    --zone-9: #b85848;
    --continent-na: #4a8a78;
    --continent-sa: #6aa858;
    --continent-eu: #5a82b0;
    --continent-af: #c89040;
    --continent-as: #b06868;
    --continent-oc: #9070b0;
    --zone-highlight: rgba(255, 255, 255, 0.2);
    --map-stroke: rgba(255, 255, 255, 0.15);
}

/* ---- Top Bar ---- */
.top-bar-section {
    padding: 80px 0 8px;
}

.top-bar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    position: relative;
}


.top-bar-left {
    flex-shrink: 0;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 0.78rem;
    color: var(--text-muted);
    text-decoration: none;
    margin-bottom: 6px;
    transition: color var(--transition);
}

.back-link:hover {
    color: var(--text-primary);
}

.back-link svg {
    width: 14px;
    height: 14px;
}

.top-bar-left h1 {
    font-family: 'Spectral', serif;
    font-size: 1.6rem;
    font-weight: 500;
    line-height: 1.15;
}

.top-bar-right {
    text-align: right;
}

.tool-description {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    line-height: 1.4;
}

.top-bar-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
}

/* ---- Carrier Toggle ---- */
.carrier-toggle {
    display: inline-flex;
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 3px;
    gap: 0;
}

.carrier-btn {
    position: relative;
    z-index: 1;
    padding: 5px 16px;
    border: none;
    background: none;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: color 0.2s ease;
    user-select: none;
}

.carrier-btn.active {
    color: var(--btn-primary-text);
}

.carrier-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: calc(50% - 3px);
    height: calc(100% - 6px);
    background: var(--btn-primary-bg);
    border-radius: 6px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.carrier-toggle[data-active="ups"] .carrier-slider {
    transform: translateX(100%);
}

/* ---- Scope Toggle (Domestic/International) — primary toggle ---- */
.scope-toggle {
    display: inline-flex;
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    padding: 3px;
}

.scope-btn {
    position: relative;
    z-index: 1;
    padding: 5px 16px;
    border: none;
    background: none;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    transition: color 0.2s ease;
    user-select: none;
    white-space: nowrap;
}

.scope-btn.active {
    color: var(--btn-primary-text);
}

.scope-slider {
    position: absolute;
    top: 3px;
    left: 3px;
    width: calc(50% - 3px);
    height: calc(100% - 6px);
    background: var(--btn-primary-bg);
    border-radius: 6px;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.scope-toggle[data-active="international"] .scope-slider {
    transform: translateX(100%);
}

/* ---- Service Selector (Custom Dropdown) ---- */
.service-selector {
    position: relative;
}

.custom-dropdown {
    position: relative;
}

.dropdown-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    width: 210px;
    padding: 4px 10px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-card);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.2s;
}

.dropdown-trigger:hover {
    border-color: var(--text-muted);
}

.dropdown-arrow {
    width: 12px;
    height: 12px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.custom-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-options {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 8px;
    padding: 4px;
    list-style: none;
    z-index: 20;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .dropdown-trigger {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .dropdown-trigger:hover {
    border-color: rgba(255, 255, 255, 0.25);
}

[data-theme="dark"] .dropdown-options {
    background: rgba(30, 40, 64, 0.8);
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .dropdown-option:hover {
    background: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .dropdown-option.selected {
    color: #90b8d8;
}

.custom-dropdown.open .dropdown-options {
    display: block;
}

.dropdown-option {
    padding: 6px 10px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    border-radius: 5px;
    cursor: pointer;
    white-space: nowrap;
    text-align: left;
    transition: background 0.15s, color 0.15s;
}

.dropdown-option:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}

.dropdown-option.selected {
    color: var(--accent);
    font-weight: 600;
}

/* ---- Country Tooltip ---- */
.country-tooltip {
    position: absolute;
    padding: 10px 14px;
    background: var(--nav-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: 8px;
    pointer-events: none;
    z-index: 10;
    min-width: 240px;
    opacity: 0;
    transition: opacity 0.15s;
}

.country-tooltip.visible {
    opacity: 1;
}

.country-tooltip .tooltip-name {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 6px;
}

.country-tooltip .tooltip-code {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.country-tooltip .tooltip-zones {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding-left: 10px;
}

.country-tooltip .tooltip-zone-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.country-tooltip .tooltip-zone-value {
    font-weight: 600;
    color: var(--text-primary);
}

.country-tooltip .tooltip-carrier-header {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-primary);
    margin-top: 6px;
    margin-bottom: 2px;
}

.tooltip-region {
    font-weight: 400;
    font-size: 0.65rem;
    color: var(--text-muted);
}

/* ---- World Map ---- */
.zone-map .country-region {
    stroke: var(--map-stroke);
    stroke-width: 0.5;
    transition: none;
    cursor: pointer;
}

.zone-map .country-region.hovered {
    stroke: #000;
    stroke-width: 1.5;
    filter: brightness(0.9);
}

.zone-map .country-region.is-us {
    cursor: default;
}

.zone-map .ca-province {
    stroke: rgba(255, 255, 255, 0.2);
    stroke-width: 0.5;
}

/* ---- Legend Inline ---- */
.legend-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    transition: opacity 0.2s;
}

.legend-item.dim {
    opacity: 0.3;
}

.legend-swatch {
    width: 13px;
    height: 13px;
    border-radius: 3px;
    flex-shrink: 0;
}

.zone-1 { background: var(--zone-1); }
.zone-2 { background: var(--zone-2); }
.zone-3 { background: var(--zone-3); }
.zone-4 { background: var(--zone-4); }
.zone-5 { background: var(--zone-5); }
.zone-6 { background: var(--zone-6); }
.zone-7 { background: var(--zone-7); }
.zone-8 { background: var(--zone-8); }
.zone-9 { background: var(--zone-9); }

.usps-only {
    transition: opacity 0.2s, max-height 0.2s;
}

/* Hide zone 9 in international (UPS doesn't have zone 9) */
.scope-international .usps-only {
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    padding: 0;
    margin: 0;
}

/* Hide domestic legend when international is active */
.scope-international .map-legend-inside {
    display: none;
}

/* Hide domestic legend when international is active */
.scope-international .map-legend-inside {
    display: none;
}

/* ---- Map Section ---- */
.map-section {
    padding: 6px 0 8px;
}

.map-container {
    position: relative;
    background: var(--map-bg);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    overflow: visible;
    padding: 0 6px;
}

.map-container > svg {
    overflow: hidden;
}

.map-carrier-label {
    position: absolute;
    right: 100px;
    top: 50%;
    transform: translateY(-50%) translateY(-120px);
    font-size: 0.7rem;
    text-align: center;
    white-space: nowrap;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    pointer-events: none;
    z-index: 3;
}

.scope-international .map-carrier-label {
    display: none;
}

/* Hide legend and label until map is ready */
.map-carrier-label,
.map-legend-inside {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.map-container.map-ready .map-carrier-label,
.map-container.map-ready .map-legend-inside {
    opacity: 1;
}

/* ---- Map Legend (inside map, right side) ---- */
.map-legend-inside {
    position: absolute;
    right: 100px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 4px;
    pointer-events: none;
}

.map-legend-inside .legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.map-legend-inside .legend-swatch {
    width: 15px;
    height: 15px;
    border-radius: 3px;
    flex-shrink: 0;
}

.map-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-muted);
    z-index: 2;
    background: var(--map-bg);
}

.map-loading .spinner {
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.zone-map {
    width: 100%;
    height: auto;
    display: block;
    cursor: crosshair;
}

#worldMap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

#worldMap {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.zone-map .state-line {
    fill: none;
    stroke: rgba(0, 0, 0, 0.25);
    stroke-width: 1;
    pointer-events: none;
}

[data-theme="dark"] .zone-map .state-line {
    stroke: rgba(255, 255, 255, 0.15);
}

.zone-map .zip3-region {
    stroke: var(--map-stroke);
    stroke-width: 0.3;
    transition: none;
    fill: var(--zone-0);
}

.zone-map .zip3-region.z1 { fill: var(--zone-1); }
.zone-map .zip3-region.z2 { fill: var(--zone-2); }
.zone-map .zip3-region.z3 { fill: var(--zone-3); }
.zone-map .zip3-region.z4 { fill: var(--zone-4); }
.zone-map .zip3-region.z5 { fill: var(--zone-5); }
.zone-map .zip3-region.z6 { fill: var(--zone-6); }
.zone-map .zip3-region.z7 { fill: var(--zone-7); }
.zone-map .zip3-region.z8 { fill: var(--zone-8); }
.zone-map .zip3-region.z9 { fill: var(--zone-9); }

.zone-map .zip3-region.hovered-origin {
    stroke: #000;
    stroke-width: 1;
}

.zone-map .zip3-region.hovered-dest {
    stroke: var(--text-primary);
    stroke-width: 2;
    filter: brightness(1.15);
}

.zone-map .arc-path {
    fill: none;
    stroke: #000;
    stroke-width: 2.5;
    stroke-linecap: round;
    pointer-events: none;
}

.zone-map .arc-arrow {
    fill: #000;
    pointer-events: none;
}

/* International arrows need to be light in dark mode (dark ocean background) */
[data-theme="dark"] .scope-international .arc-path {
    stroke: #fff;
}

[data-theme="dark"] .scope-international .arc-arrow {
    fill: #fff;
}

/* ---- Table Section ---- */
.table-section {
    padding: 0 0 32px;
}

.lookup-table-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    overflow: hidden;
}

.lookup-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.lookup-table th {
    padding: 7px 12px;
    text-align: left;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-subtle);
    user-select: none;
}

.lookup-table .row-num-col {
    width: 32px;
    text-align: center;
}

.lookup-table td {
    padding: 0;
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
}

.lookup-table tr:last-child td {
    border-bottom: none;
}

.row-num {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
    padding: 8px 4px;
    user-select: none;
}

.lookup-table tr:hover .row-num {
    color: var(--text-primary);
}

.lookup-table tr.row-highlight {
    background: var(--table-hover);
}

/* ---- Cell Input ---- */
.cell-input {
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    color: var(--text-primary);
    outline: none;
}

.cell-input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

.cell-input:focus {
    background: var(--input-bg);
    box-shadow: inset 0 0 0 2px var(--cell-focus);
}

/* ---- Zone Badge ---- */
.zone-cell {
    padding: 8px 12px !important;
}

.zone-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    padding: 3px 10px;
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: 600;
    transition: background 0.2s, color 0.2s;
}

.zone-badge:empty {
    display: none;
}

/* Carrier-branded zone badges for international */
.zone-badges {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.carrier-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: default;
    position: relative;
}

.carrier-badge.ups {
    background: #3E2723;
    color: #FFB300;
}

.carrier-badge.fedex {
    background: #4D148C;
    color: #FF6600;
}

.carrier-badge.dhl {
    background: #FFCC00;
    color: #D40511;
}

/* Badge tooltip on hover */
.carrier-badge .badge-tip {
    display: none;
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    padding: 4px 8px;
    background: var(--nav-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: 5px;
    font-size: 0.68rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    pointer-events: none;
    z-index: 10;
}

.carrier-badge:hover .badge-tip {
    display: block;
}

.zone-badge[data-zone="1"] { background: var(--zone-1); color: #fff; }
.zone-badge[data-zone="2"] { background: var(--zone-2); color: #fff; }
.zone-badge[data-zone="3"] { background: var(--zone-3); color: #fff; }
.zone-badge[data-zone="4"] { background: var(--zone-4); color: #fff; }
.zone-badge[data-zone="5"] { background: var(--zone-5); color: #fff; }
.zone-badge[data-zone="6"] { background: var(--zone-6); color: #1a1a1a; }
.zone-badge[data-zone="7"] { background: var(--zone-7); color: #1a1a1a; }
.zone-badge[data-zone="8"] { background: var(--zone-8); color: #fff; }
.zone-badge[data-zone="9"] { background: var(--zone-9); color: #fff; }

/* ---- Drag Handle ---- */
.cell.editable {
    position: relative;
}

.drag-handle {
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 10px;
    height: 10px;
    background: var(--drag-handle);
    border: 2px solid var(--bg-card);
    border-radius: 1px;
    cursor: crosshair;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}

.cell-input:focus ~ .drag-handle,
.drag-handle.visible {
    opacity: 1;
    pointer-events: auto;
}

.cell.drag-target {
    background: rgba(42, 63, 110, 0.08);
}

[data-theme="dark"] .cell.drag-target {
    background: rgba(144, 184, 216, 0.08);
}

/* ---- Clear Button (inline in header) ---- */
.lookup-table th:last-child {
    position: relative;
}

.btn-clear {
    float: right;
    padding: 2px 8px;
    border: none;
    background: none;
    font-family: 'Inter', sans-serif;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
    text-transform: none;
    letter-spacing: 0;
}

.btn-clear:hover {
    color: var(--text-primary);
    background: var(--bg-card-hover);
}

/* ---- Zone Info Section ---- */
.zone-info-section {
    padding: 48px 0;
}

.zone-info-section h2 {
    font-family: 'Spectral', serif;
    font-size: 1.5rem;
    font-weight: 500;
    margin-bottom: 20px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 24px;
}

.info-card h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.info-card p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ---- Tool CTA ---- */
.tool-cta {
    padding: 48px 0 64px;
    text-align: center;
}

.tool-cta h2 {
    font-family: 'Spectral', serif;
    font-size: 1.75rem;
    font-weight: 500;
    margin-bottom: 12px;
}

.tool-cta p {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .top-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .top-bar-right {
        text-align: left;
    }

    .top-bar-controls {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .map-legend-inside {
        right: 8px;
        gap: 2px;
    }

    .map-legend-inside .legend-item {
        font-size: 0.65rem;
    }

    .map-legend-inside .legend-swatch {
        width: 12px;
        height: 12px;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }
}
