/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --rex-blue: #2E86AB;
    --rex-blue-light: #4A9BC7;
    --rex-green: #A3D977;
    --rex-green-dark: #8BC34A;
    --rex-gray: #6B7280;
    --rex-gray-light: #F3F4F6;
    --rex-gray-dark: #374151;
    --rex-text: #1F2937;
    --rex-text-light: #6B7280;
    --rex-white: #FFFFFF;
    --rex-border: #E5E7EB;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 12px;
    --radius-large: 20px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--rex-gray-light);
    min-height: 100vh;
    line-height: 1.6;
    color: var(--rex-text);
}

/* Main container */
.calculator-container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--rex-white);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    border: 1px solid var(--rex-border);
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

/* Desktop layout */
@media (min-width: 1024px) {
    .calculator-container {
        grid-template-columns: 2fr 1fr;
        gap: 24px;
        align-items: start;
        padding: 32px;
    }
    
    .main-content {
        grid-column: 1;
    }
    
    .results-section {
        grid-column: 2;
        position: sticky;
        top: 20px;
        margin-bottom: 0;
    }
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 20px;
}

@media (min-width: 1024px) {
    .header {
        grid-column: 1 / -1;
        margin-bottom: 16px;
    }
}

.header h1 {
    color: var(--rex-blue);
    font-size: 2rem;
    margin-bottom: 8px;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.header p {
    color: var(--rex-text-light);
    font-size: 1rem;
    font-weight: 400;
}

/* Form sections */
.form-section {
    margin-bottom: 20px;
    padding: 18px;
    background: var(--rex-white);
    border-radius: var(--radius);
    border: 1px solid var(--rex-border);
    box-shadow: var(--shadow-sm);
}

.form-section h3 {
    color: var(--rex-text);
    margin-bottom: 14px;
    font-size: 1.125rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 8px;
    color: var(--rex-text);
    font-weight: 500;
    font-size: 0.875rem;
}

input[type="number"] {
    width: 100%;
    padding: 16px;
    border: 2px solid var(--rex-border);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s ease;
    background: var(--rex-white);
}

input[type="number"]:focus {
    outline: none;
    border-color: var(--rex-blue);
    box-shadow: 0 0 0 3px rgba(46, 134, 171, 0.1);
}

/* Products grid */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

@media (min-width: 768px) {
    .products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }
}

.product-card {
    background: var(--rex-white);
    border: 2px solid var(--rex-border);
    border-radius: var(--radius);
    padding: 14px;
    transition: all 0.2s ease;
    cursor: pointer;
    position: relative;
    box-shadow: var(--shadow-sm);
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.product-card:hover {
    border-color: var(--rex-blue-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.product-card.selected {
    border-color: var(--rex-blue);
    background: rgba(46, 134, 171, 0.05);
    box-shadow: var(--shadow-md);
}

.product-card.selected::before {
    content: "✓";
    position: absolute;
    top: 12px;
    right: 12px;
    background: var(--rex-blue);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
}

.product-card h4 {
    color: var(--rex-text);
    margin-bottom: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.2;
}

.product-card p {
    color: var(--rex-text-light);
    font-size: 0.75rem;
    margin-bottom: 8px;
    line-height: 1.3;
    flex-grow: 1;
}

.product-price {
    font-weight: 600;
    color: var(--rex-blue);
    font-size: 0.85rem;
    margin-top: auto;
}

.addons-badge {
    display: inline-block;
    background: var(--rex-green);
    color: var(--rex-white);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.65rem;
    font-weight: 600;
    margin-top: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}


/* Results section */
.results-section {
    background: var(--rex-white);
    color: var(--rex-text);
    padding: 30px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: var(--shadow-lg);
    border: 2px solid var(--rex-blue-light);
}

/* Sticky results for desktop */
@media (min-width: 1024px) {
    .results-section {
        min-height: 400px;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
    }
}

.results-section h3 {
    margin-bottom: 24px;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--rex-blue);
}

.price-display {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 15px;
}

.price-box {
    background: var(--rex-gray-light);
    padding: 24px;
    border-radius: var(--radius);
    transition: all 0.3s ease;
    border: 2px solid var(--rex-border);
}

.price-box:hover {
    transform: translateY(-1px);
    border-color: var(--rex-blue-light);
    box-shadow: var(--shadow-md);
}

.price-box.highlight {
    animation: priceUpdate 0.6s ease-out;
}

@keyframes priceUpdate {
    0% { 
        transform: scale(1);
        background: var(--rex-gray-light);
    }
    50% { 
        transform: scale(1.02);
        background: rgba(163, 217, 119, 0.2);
        border-color: var(--rex-green);
    }
    100% { 
        transform: scale(1);
        background: var(--rex-gray-light);
    }
}

/* Empty state styling */
.results-section.empty-state {
    opacity: 0.7;
}

.results-section.empty-state .price-display {
    animation: gentlePulse 2s ease-in-out infinite;
}

@keyframes gentlePulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.price-value {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 8px;
    word-break: break-word;
    color: var(--rex-blue);
    letter-spacing: -0.02em;
}

@media (min-width: 1024px) {
    .price-value {
        font-size: 3rem;
    }
}

.price-label {
    font-size: 0.875rem;
    color: var(--rex-text-light);
    font-weight: 500;
}

.breakdown {
    margin-top: 24px;
    text-align: left;
    background: var(--rex-gray-light);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--rex-border);
}

.breakdown-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--rex-border);
    color: var(--rex-text);
}

.breakdown-item:last-child {
    border-bottom: none;
    font-weight: 600;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 2px solid var(--rex-blue);
    color: var(--rex-blue);
}

.breakdown-item span:first-child {
    flex: 1;
    margin-right: 15px;
}

.breakdown-item small {
    display: block;
    opacity: 0.8;
    font-size: 0.8rem;
    margin-top: 2px;
}

.uf-rate {
    text-align: center;
    margin-top: 20px;
    font-size: 0.875rem;
    color: var(--rex-text-light);
    font-style: italic;
}

/* Rex+ Style Button */
.rex-button {
    background: var(--rex-green);
    color: var(--rex-white);
    padding: 12px 24px;
    border: none;
    border-radius: 25px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.rex-button:hover {
    background: var(--rex-green-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.rex-button:active {
    transform: translateY(0);
}

/* Modal for Add-ons */
.modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 9999 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    pointer-events: none;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

.modal-content {
    background: var(--rex-white);
    border-radius: var(--radius-large);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
    border: 2px solid var(--rex-blue-light);
    position: relative;
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    padding: 24px 24px 0 24px;
    border-bottom: 1px solid var(--rex-border);
    margin-bottom: 20px;
}

.modal-header h3 {
    color: var(--rex-blue);
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-header p {
    color: var(--rex-text-light);
    font-size: 0.875rem;
    margin-bottom: 16px;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--rex-gray-light);
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--rex-text);
    font-size: 16px;
}

.modal-close:hover {
    background: var(--rex-border);
    transform: scale(1.1);
}

.modal-body {
    padding: 0 24px 24px 24px;
}

.modal-addon-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    background: var(--rex-gray-light);
    border-radius: 8px;
    margin-bottom: 12px;
    border: 1px solid var(--rex-border);
    transition: all 0.2s ease;
}

.modal-addon-item:hover {
    border-color: var(--rex-blue-light);
    background: var(--rex-white);
    box-shadow: var(--shadow-sm);
}

.modal-addon-item.selected {
    border-color: var(--rex-blue);
    background: rgba(46, 134, 171, 0.05);
}

.modal-addon-item input[type="checkbox"] {
    margin-right: 12px;
    transform: scale(1.2);
    cursor: pointer;
    accent-color: var(--rex-blue);
}

.modal-addon-details {
    flex: 1;
}

.modal-addon-details strong {
    color: var(--rex-text);
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
    font-size: 0.95rem;
}

.modal-addon-details small {
    color: var(--rex-text-light);
    line-height: 1.4;
    font-size: 0.8rem;
}

.modal-addon-price {
    font-weight: 600;
    color: var(--rex-blue);
    text-align: right;
    font-size: 0.875rem;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--rex-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--rex-gray-light);
    border-radius: 0 0 var(--radius-large) var(--radius-large);
}

.modal-summary {
    color: var(--rex-text);
    font-weight: 600;
}

.modal-total {
    color: var(--rex-blue);
    font-size: 1.125rem;
    font-weight: 700;
}

/* Loading and error states */
.loading-spinner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-spinner p {
    color: white;
    font-size: 1.1rem;
}

.error-message {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--secondary-color);
    color: white;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 1000;
}

/* Responsive design */
@media (max-width: 1023px) {
    .calculator-container {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .main-content {
        grid-column: 1;
    }
    
    .results-section {
        grid-column: 1;
        position: static;
        order: -1; /* Show results at top on mobile */
        margin-bottom: 20px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 15px;
    }
    
    .calculator-container {
        padding: 24px;
        margin: 0;
        gap: 24px;
    }
    
    .form-section,
    .addons-section {
        padding: 20px;
        margin-bottom: 20px;
    }
    
    .products-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .price-display {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .price-value {
        font-size: 2rem !important;
    }
    
    .header h1 {
        font-size: 1.875rem;
    }
    
    .addon-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        padding: 12px;
    }
    
    .addon-price {
        align-self: flex-end;
    }
}

@media (max-width: 480px) {
    body {
        padding: 10px;
    }
    
    .calculator-container {
        padding: 15px;
    }
    
    .price-value {
        font-size: 1.5rem;
    }
    
    .breakdown-item {
        flex-direction: column;
        gap: 5px;
        align-items: flex-start;
    }
}

/* Accessibility improvements */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border-color: #000;
        --light-gray: #333;
    }
    
    .product-card {
        border-width: 3px;
    }
    
    input[type="number"] {
        border-width: 3px;
    }
}