/**
 * Frontend styles for RPC Rate Calculator
 * Modern responsive design using CSS Grid, Flexbox, and intrinsic sizing
 * No media queries - fully responsive using minmax, clamp, min, max
 */

/* FontAwesome Font Definition */
@font-face {
    font-family: 'Font Awesome 5 Free';
    font-style: normal;
    font-weight: 900;
    font-display: swap;
    src: url('../fonts/fontawesome/fa-solid-900.woff2') format('woff2');
}

.rpc-calc-container .fas,
.rpc-calc-container .fa-solid {
    font-family: 'Font Awesome 5 Free' !important;
    font-weight: 900 !important;
    font-style: normal !important;
}

/* FontAwesome Icon Definitions */
.fa-map-marked-alt:before { content: '\f5a0' !important; }
.fa-map-marker-alt:before { content: '\f3c5' !important; }
.fa-user-md:before { content: '\f0f0' !important; }
.fa-redo:before { content: '\f01e' !important; }
.fa-clock:before { content: '\f017' !important; }
.fa-calculator:before { content: '\f1ec' !important; }
.fa-home:before { content: '\f015' !important; }
.fa-users:before { content: '\f0c0' !important; }
.fa-exclamation-triangle:before { content: '\f071' !important; }

/* Global box-sizing for calculator */
.rpc-calc-container *,
.rpc-calc-container *::before,
.rpc-calc-container *::after {
    box-sizing: border-box;
}

/* Container Setup - Sets container context */
.rpc-calc-container {
    container-type: inline-size;
    container-name: calculator;
    width: 100%;
    /* Remove max-width to use full available width */
    margin: 0;
    box-sizing: border-box;
}

/* Main Calculator Container */
.rpc-rate-calculator {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #ffffff;
    border-radius: clamp(8px, 2vw, 12px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    /* Allow hover popovers and shadows to render outside the container (was overflow: hidden) */
    overflow: visible;
    margin: clamp(10px, 2vw, 20px) 0;
}

/* Main Layout - Responsive Grid */
.rpc-calc-main-layout {
    display: grid;
    grid-template-columns: minmax(300px, 1fr);
    min-height: 500px;
}

/* Auto-switch to two columns when container is wide enough */
@container calculator (min-width: 768px) {
    .rpc-calc-main-layout {
        grid-template-columns: minmax(350px, 1fr) minmax(350px, 1fr);
    }
}

/* Left Column - Map and Location */
.rpc-calc-left-column {
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    border-bottom: 1px solid #e9ecef;
}

@container calculator (min-width: 768px) {
    .rpc-calc-left-column {
        border-right: 1px solid #e9ecef;
        border-bottom: none;
    }
}

/* Right Column - Form and Results */
.rpc-calc-right-column {
    display: flex;
    flex-direction: column;
    background: #ffffff;
}

/* Map Section - Intrinsic sizing */
.rpc-calc-map-section {
    flex: 1;
    position: relative;
    min-height: clamp(250px, 40vh, 500px);
}

.rpc-calc-map-container {
    height: 100%;
    position: relative;
}

.rpc-calc-map {
    width: 100%;
    height: 100%;
}

/* Map Legend */
.rpc-calc-map-legend {
    position: absolute;
    bottom: clamp(5px, 1vw, 15px);
    left: clamp(5px, 1vw, 15px);
    background: white;
    padding: clamp(6px, 1vw, 10px) clamp(8px, 1.5vw, 15px);
    border-radius: 4px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    font-size: clamp(11px, 1.5vw, 13px);
    display: flex;
    gap: clamp(8px, 1.5vw, 12px);
}

.rpc-calc-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.rpc-calc-legend-marker {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.rpc-calc-marker-selected { background: #dc2626; } /* Red for selected location */
.rpc-calc-marker-highlighted { background: #08186f; } /* RPC blue for MSAs in selected state */
.rpc-calc-marker-available { background: #9ca3af; } /* Gray for other locations */
.rpc-calc-legend-state-outline {
    width: 12px;
    height: 12px;
    border: 2px solid #08186f;
    background: transparent;
}

/* Location Section */
.rpc-calc-location-section {
    padding: clamp(15px, 3vw, 25px);
    background: #ffffff;
    border-top: 1px solid #e9ecef;
}

/* Form Section */
.rpc-calc-form-section {
    padding: clamp(15px, 3vw, 25px);
}

/* Form Controls with Intrinsic Sizing */
.rpc-calc-field {
    margin-bottom: clamp(12px, 2vw, 20px);
}

.rpc-calc-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    margin-bottom: clamp(6px, 1vw, 10px);
    color: #2c3e50;
    font-size: clamp(13px, 1.5vw, 15px);
}

.rpc-calc-label i {
    color: #08186f;
    font-size: clamp(14px, 1.8vw, 16px);
}

.rpc-calc-select,
.rpc-calc-autocomplete-input {
    width: 100%;
    padding: clamp(10px, 1.5vw, 14px);
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: clamp(14px, 1.8vw, 16px);
    transition: all 0.3s ease;
    background-color: #ffffff;
    box-sizing: border-box;
    max-width: 100%;
}

.rpc-calc-select:focus,
.rpc-calc-autocomplete-input:focus {
    outline: none;
    border-color: #08186f;
    box-shadow: 0 0 0 3px rgba(8, 24, 111, 0.1);
}

/* Form Grid - Responsive without media queries */
.rpc-calc-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: clamp(10px, 2vw, 15px);
    margin-top: clamp(15px, 2vw, 20px);
}

/* Buttons - Intrinsic sizing */
.rpc-calc-button {
    padding: clamp(12px, 2vw, 16px) clamp(20px, 3vw, 32px);
    font-size: clamp(14px, 1.8vw, 16px);
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    width: 100%;
}

.rpc-calc-button-primary {
    background: linear-gradient(135deg, #08186f 0%, #3b4251 100%);
    color: white;
}

.rpc-calc-button-primary:hover {
    background: linear-gradient(135deg, #08186f 0%, #212934 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(8, 24, 111, 0.3);
}

.rpc-calc-button-secondary {
    background: #f3f4f6;
    color: #4b5563;
}

.rpc-calc-button-secondary:hover {
    background: #e5e7eb;
}

/* Results Section */
.rpc-calc-results-section {
    padding: clamp(20px, 3vw, 30px);
    background: #ffffff;
    flex: 1;
}

.rpc-calc-results-header {
    text-align: center;
    margin-bottom: clamp(20px, 3vw, 30px);
}

.rpc-calc-results-title {
    font-size: clamp(20px, 3vw, 28px);
    font-weight: 700;
    color: #08186f;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}


/* Results Grid - Responsive with minmax */
.rpc-calc-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
    gap: clamp(15px, 2vw, 20px);
    margin-bottom: clamp(20px, 3vw, 30px);
}

/* Rate Grid - 2x4 layout for 8 values (HHA, LPN/LVN, NA, RN - each with Part-Time and Full-Time) */
.rpc-calc-rate-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: clamp(12px, 1.5vw, 16px);
    max-width: 600px;
    margin: 0 auto;
}

/* On very small screens, stack cards vertically */
@container calculator (max-width: 400px) {
    .rpc-calc-rate-grid {
        grid-template-columns: 1fr;
        max-width: 300px;
    }
}

/* Rate Cards */
.rpc-calc-rate-card {
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-radius: 12px;
    padding: clamp(12px, 2vw, 18px);
    border: 1px solid #e9ecef;
    transition: all 0.3s ease;
    position: relative;
    cursor: pointer;
}

/* Info icon indicator */
.rpc-calc-rate-card::after {
    content: 'ⓘ';
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 12px;
    color: #9ca3af;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.rpc-calc-rate-card:hover::after {
    opacity: 1;
    color: #08186f;
}

.rpc-calc-rate-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1);
    border-color: #08186f;
    z-index: 10;
}

.rpc-calc-rate-header {
    margin-bottom: clamp(8px, 1.5vw, 12px);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.rpc-calc-rate-provider {
    font-size: clamp(11px, 1.4vw, 13px);
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
}

.rpc-calc-rate-level {
    font-size: clamp(14px, 1.8vw, 16px);
    font-weight: 600;
    color: #08186f;
    margin-top: 2px;
    display: block;
}

.rpc-calc-rate-amount {
    text-align: center;
    margin: clamp(10px, 1.5vw, 15px) 0;
}

.rpc-calc-rate-value {
    font-size: clamp(24px, 4vw, 32px);
    font-weight: 700;
    color: #08186f;
    display: block;
}

.rpc-calc-rate-unit {
    font-size: clamp(11px, 1.4vw, 13px);
    color: #6b7280;
    margin-top: 2px;
    display: block;
}

/* Rate Details - Hidden by default, shown on hover */
.rpc-calc-rate-details {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e9ecef;
    border-top: none;
    border-radius: 0 0 12px 12px;
    padding: clamp(10px, 1.5vw, 15px);
    margin-top: -1px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.rpc-calc-rate-card:hover .rpc-calc-rate-details {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.rpc-calc-rate-detail {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: clamp(11px, 1.4vw, 13px);
}

.rpc-calc-rate-detail:last-child {
    margin-bottom: 0;
}

.rpc-calc-detail-label {
    color: #6b7280;
}

.rpc-calc-detail-value {
    font-weight: 600;
    color: #3b4251;
}

/* Comparison Section */
.rpc-calc-comparison {
    background: #f8f9fa;
    border-radius: 8px;
    padding: clamp(15px, 2vw, 20px);
    margin-top: clamp(20px, 3vw, 30px);
}

.rpc-calc-comparison-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: clamp(10px, 2vw, 15px);
    text-align: center;
}

/* Empty State */
.rpc-calc-empty-state {
    text-align: center;
    padding: clamp(40px, 5vw, 60px) 20px;
    color: #6b7280;
}

.rpc-calc-empty-icon {
    font-size: clamp(48px, 8vw, 64px);
    color: #d1d5db;
    margin-bottom: 20px;
}

.rpc-calc-empty-text {
    font-size: clamp(16px, 2vw, 18px);
    margin-bottom: 8px;
}

.rpc-calc-empty-description {
    font-size: clamp(14px, 1.8vw, 16px);
    color: #9ca3af;
}

/* Loading State */
.rpc-calc-loading {
    display: none;
    text-align: center;
    padding: clamp(20px, 3vw, 40px);
}

.rpc-calc-loading.active {
    display: block;
}

.rpc-calc-loading-spinner {
    display: inline-block;
    width: clamp(40px, 5vw, 50px);
    height: clamp(40px, 5vw, 50px);
    border: 4px solid #e9ecef;
    border-radius: 50%;
    border-top-color: #08186f;
    animation: spin 1s linear infinite;
}

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

/* Error State */
.rpc-calc-error {
    background-color: #fee;
    border: 1px solid #fcc;
    color: #c33;
    padding: clamp(10px, 2vw, 15px);
    border-radius: 8px;
    margin: 10px 0;
    font-size: clamp(13px, 1.8vw, 15px);
}

.rpc-calc-error-content {
    display: flex;
    align-items: center;
    gap: 10px;
}

.rpc-calc-error-icon {
    font-size: clamp(18px, 2.5vw, 24px);
    flex-shrink: 0;
}

/* Autocomplete Dropdown */
.rpc-calc-autocomplete-container {
    position: relative;
}

.rpc-calc-autocomplete-dropdown,
.rpc-calc-autocomplete-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid #e9ecef;
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: min(300px, 50vh);
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.rpc-calc-autocomplete-item {
    padding: clamp(10px, 1.5vw, 12px) clamp(12px, 2vw, 15px);
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    font-size: clamp(13px, 1.8vw, 15px);
}

.rpc-calc-autocomplete-item:hover,
.rpc-calc-autocomplete-item.active {
    background: #f0f9ff;
}

.rpc-calc-autocomplete-item strong {
    color: #08186f;
}

/* Accessibility */
.rpc-calc-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus States */
.rpc-calc-select:focus,
.rpc-calc-autocomplete-input:focus,
.rpc-calc-button:focus {
    outline: 2px solid #08186f;
    outline-offset: 2px;
}

/* Leaflet Map Markers */
.rpc-leaflet-marker {
    background: transparent;
    border: none;
    pointer-events: none;
}

.rpc-leaflet-marker > div {
    pointer-events: auto;
}

.rpc-marker-blue {
    background: #9ca3af;  /* Gray for other/unselected locations (legend: Other) */
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.rpc-marker-red {
    background: #dc2626;  /* Red for selected location (legend: Selected) */
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    z-index: 1000;
}

.rpc-marker-lightblue {
    background: #08186f;  /* RPC blue for MSAs in selected state (legend: State MSAs) */
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.rpc-marker-small {
    width: 12px;
    height: 12px;
}

.rpc-marker-large {
    width: 20px;
    height: 20px;
}

/* Print Styles */

/* Mobile accordion behavior for rate cards */
@media (max-width: 768px) {
  /* Neutralize hover popover and use in-flow accordion instead */
  .rpc-calc-rate-card:hover .rpc-calc-rate-details {
    opacity: 1;
    visibility: visible;
    transform: none;
  }
  .rpc-calc-rate-details {
    position: static;
    top: auto;
    left: auto;
    right: auto;
    display: none; /* hidden until card is open */
    opacity: 1;
    visibility: visible;
    transform: none;
    box-shadow: none;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-top: 8px;
    padding: 10px 12px;
  }
  .rpc-calc-rate-card.is-open .rpc-calc-rate-details {
    display: block;
  }
  /* Optional: indicate expandable state with chevron */
  .rpc-calc-rate-card::after {
    content: '▾';
    font-size: 14px;
    color: #6b7280;
  }
  .rpc-calc-rate-card.is-open::after {
    content: '▴';
  }
}

@media print {
    .rpc-calc-map-section {
        display: none;
    }

    .rpc-calc-main-layout {
        display: block;
    }

    .rpc-calc-rate-card {
        break-inside: avoid;
        margin-bottom: 15px;
    }
}