/* CSS Custom Properties */
:root {
    --primary-color: #2c3e50;
    --secondary-color: #3498db;
    --success-color: #27ae60;
    --error-color: #e74c3c;
    --warning-color: #f39c12;
    --bg-color: #f8f9fa;
    --text-color: #333;
    --border-color: #ddd;
    --border-radius: 4px;
    --spacing-unit: 1rem;
    --transition-speed: 0.3s;
    --max-width: 1200px;
}

/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    padding: var(--spacing-unit);
    min-height: 100%;
}

.container {
    max-width: var(--max-width);
    margin: 0 auto;
    background: white;
    padding: calc(var(--spacing-unit) * 2);
    border-radius: var(--border-radius);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: visible;
}

/* Main two-column layout */
.main-layout {
    display: flex;
    gap: calc(var(--spacing-unit) * 2);
    align-items: flex-start;
    position: relative;
}

.form-column {
    flex: 1;
    min-width: 0;
}

.results-column {
    flex: 0 0 320px;
    align-self: flex-start;
}

/* Sticky container for both results boxes */
.sticky-results-container {
    position: -webkit-sticky; /* Safari support */
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 1.5);
    max-height: 100vh;
    overflow-y: auto;
    z-index: 10;
    align-self: flex-start;
}

/* Header Styles */
header {
    margin-bottom: var(--spacing-unit);
    padding-bottom: calc(var(--spacing-unit) * 0.5);
    border-bottom: 2px solid var(--border-color);
}

.header-content {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing-unit) * 1.5);
}

.wcma-logo {
    height: 80px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
}

.header-text {
    flex: 1;
}

header h1 {
    color: var(--primary-color);
    font-size: 2rem;
    margin-bottom: calc(var(--spacing-unit) * 0.25);
}

.version {
    color: #666;
    font-size: 0.85rem;
    font-weight: normal;
    margin: 0;
}

.note {
    color: #666;
    font-size: 0.9rem;
    font-style: italic;
}

/* Instructions Box */
.instructions-box {
    background: #f8f9fa;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 0.75);
    margin-bottom: var(--spacing-unit);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.instructions-box h2 {
    color: var(--primary-color);
    font-size: 0.95rem;
    margin: 0 0 calc(var(--spacing-unit) * 0.4) 0;
    font-weight: 600;
}

.instructions-box p {
    color: #666;
    font-size: 0.85rem;
    line-height: 1.5;
    margin: 0;
}

/* Form Section Styles */
.form-section {
    margin-bottom: var(--spacing-unit);
    padding: var(--spacing-unit);
    background: #fafafa;
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.form-section.compact-section {
    margin-bottom: var(--spacing-unit);
    padding: var(--spacing-unit);
}

.form-section h2 {
    color: var(--primary-color);
    font-size: 1.25rem;
    margin-bottom: calc(var(--spacing-unit) * 0.75);
    padding-bottom: calc(var(--spacing-unit) * 0.5);
    border-bottom: 1px solid var(--border-color);
}

.section-note,
.file-note {
    color: #666;
    font-size: 0.85rem;
    margin-bottom: calc(var(--spacing-unit) * 0.5);
    font-style: italic;
}

/* Form Grid Layout */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: calc(var(--spacing-unit) * 0.75);
}

.form-grid.compact-grid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: calc(var(--spacing-unit) * 0.5);
}

.form-group {
    display: flex;
    flex-direction: column;
    min-width: 0; /* Prevent grid item overflow */
    width: 100%; /* Ensure full width within grid cell */
    gap: calc(var(--spacing-unit) * 0.25); /* Tighter spacing within form groups */
}

.form-group.full-width {
    grid-column: 1 / -1;
}

/* Form Elements */
label {
    font-weight: 600;
    margin-bottom: calc(var(--spacing-unit) * 0.25);
    color: var(--text-color);
    font-size: 0.9rem;
}

.required {
    color: var(--error-color);
    font-weight: bold;
}

input[type="text"],
input[type="email"],
input[type="number"],
select,
textarea {
    padding: calc(var(--spacing-unit) * 0.5);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

/* Input with inline result */
.input-with-result {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 0.25);
}

.input-with-result input {
    width: 100%;
}

.inline-result {
    font-weight: 600;
    color: var(--secondary-color);
    font-size: 0.85rem;
    padding: calc(var(--spacing-unit) * 0.2) calc(var(--spacing-unit) * 0.4);
    background: #f0f7ff;
    border-radius: calc(var(--border-radius) * 0.75);
    text-align: left;
}

/* Calculation Results Box */
.calculation-results-box {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 2);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    width: 100%;
}

.calculation-results-box h2 {
    margin: 0 0 calc(var(--spacing-unit) * 1.5) 0;
    font-size: 1.5rem;
    color: white;
    text-align: center;
    padding-bottom: calc(var(--spacing-unit) * 0.75);
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

/* Class Ranges Box */
.class-ranges-box {
    background: rgba(255, 255, 255, 0.95);
    border-radius: var(--border-radius);
    padding: calc(var(--spacing-unit) * 1.5);
    margin-top: calc(var(--spacing-unit) * 1.5);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.class-ranges-box h3 {
    margin: 0 0 calc(var(--spacing-unit) * 1) 0;
    font-size: 1.1rem;
    color: var(--primary-color);
    text-align: center;
    padding-bottom: calc(var(--spacing-unit) * 0.5);
    border-bottom: 1px solid var(--border-color);
}

.class-ranges-list {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 0.5);
}

.class-range-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(var(--spacing-unit) * 0.5);
    background: #f8f9fa;
    border-radius: calc(var(--border-radius) * 0.5);
    transition: background-color 0.2s;
}

.class-range-item:hover {
    background: #e9ecef;
}

.class-range-item.active-class {
    background: #d4edda;
    border: 2px solid #28a745;
    font-weight: 600;
}

.class-name {
    font-weight: 700;
    color: var(--primary-color);
    font-size: 0.95rem;
    min-width: 40px;
}

.class-range {
    font-size: 0.9rem;
    color: #666;
    font-family: 'Courier New', monospace;
    text-align: right;
}


/* Inline calculation summary */
.inline-calculation-summary {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 1.5);
}

.summary-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: calc(var(--spacing-unit) * 0.5);
    padding: calc(var(--spacing-unit) * 0.75);
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    backdrop-filter: blur(10px);
}

.summary-item.highlight {
    font-weight: bold;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.4);
}

.summary-label {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.9);
}

.summary-item.highlight .summary-label {
    color: white;
}

.summary-value {
    font-size: 1.2rem;
    font-weight: 600;
    color: white;
    min-width: 70px;
    text-align: right;
}

.summary-item.highlight .summary-value {
    font-size: 1.5rem;
    color: white;
}

/* Select with modifier value */
.select-with-modifier {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 0.25);
}

.select-with-modifier select {
    width: 100%;
}

.modifier-value {
    font-weight: 600;
    color: var(--secondary-color);
    font-size: 0.85rem;
    padding: calc(var(--spacing-unit) * 0.2) calc(var(--spacing-unit) * 0.4);
    background: #f0f7ff;
    border-radius: calc(var(--border-radius) * 0.75);
    text-align: left;
}

/* Checkbox group for brake/suspension mods */
.checkbox-group {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 0.5);
}

.checkbox-options {
    display: flex;
    flex-direction: column;
    gap: calc(var(--spacing-unit) * 0.5);
}

.checkbox-item {
    display: flex;
    align-items: flex-start;
    gap: calc(var(--spacing-unit) * 0.5);
    padding: calc(var(--spacing-unit) * 0.5);
    background: #f8f9fa;
    border-radius: calc(var(--border-radius) * 0.5);
    transition: background-color 0.2s;
}

.checkbox-item:hover {
    background: #e9ecef;
}

.checkbox-item input[type="checkbox"] {
    margin-top: 0.2rem;
    cursor: pointer;
}

.checkbox-item label {
    cursor: pointer;
    font-weight: normal;
    margin-bottom: 0;
    font-size: 0.9rem;
    flex: 1;
}

.modifier-value-container {
    margin-top: calc(var(--spacing-unit) * 0.5);
    padding-top: calc(var(--spacing-unit) * 0.5);
    border-top: 1px solid var(--border-color);
}

input:disabled,
select:disabled {
    background-color: #e9ecef;
    cursor: not-allowed;
    opacity: 0.6;
}

textarea {
    resize: vertical;
    min-height: 100px;
}

/* File Input Styles */
input[type="file"] {
    padding: calc(var(--spacing-unit) * 0.5);
    border: 2px dashed var(--border-color);
    border-radius: var(--border-radius);
    background: white;
    cursor: pointer;
    transition: border-color var(--transition-speed);
}

input[type="file"]:hover {
    border-color: var(--secondary-color);
}

input[type="file"]:focus {
    outline: none;
    border-color: var(--secondary-color);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.1);
}

.file-info {
    font-size: 0.85rem;
    color: #666;
    margin-top: calc(var(--spacing-unit) * 0.25);
    font-style: italic;
}

.field-note {
    font-size: 0.75rem;
    color: #666;
    margin-top: calc(var(--spacing-unit) * 0.25);
    font-style: italic;
    line-height: 1.3;
}

/* Error Messages */
.error-message {
    color: var(--error-color);
    font-size: 0.85rem;
    margin-top: calc(var(--spacing-unit) * 0.25);
    display: none;
}

.error-message.show {
    display: block;
}

input.error,
select.error,
textarea.error {
    border-color: var(--error-color);
}

/* Results Section */
.results-section {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
}

.results-section h2 {
    color: white;
    border-bottom-color: rgba(255, 255, 255, 0.3);
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--spacing-unit);
}

.result-item {
    background: rgba(255, 255, 255, 0.1);
    padding: var(--spacing-unit);
    border-radius: var(--border-radius);
    backdrop-filter: blur(10px);
}

.result-item.full-width {
    grid-column: 1 / -1;
}

.result-item label {
    color: white;
    font-size: 0.9rem;
    margin-bottom: calc(var(--spacing-unit) * 0.5);
    display: block;
}

.result-subtitle {
    font-weight: normal;
    font-size: 0.85em;
    opacity: 0.9;
}

.result-value {
    font-size: 1.5rem;
    font-weight: bold;
    color: white;
    min-height: 2rem;
    display: flex;
    align-items: center;
}

.class-selector {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-unit);
}

.class-selector select {
    background: white;
    color: var(--text-color);
}

.calculated-class {
    display: flex;
    align-items: center;
    gap: calc(var(--spacing-unit) * 0.5);
    padding: calc(var(--spacing-unit) * 0.75);
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--border-radius);
}

.class-label {
    font-weight: 600;
}

.class-value {
    font-size: 1.25rem;
    font-weight: bold;
    padding: calc(var(--spacing-unit) * 0.25) calc(var(--spacing-unit) * 0.75);
    background: rgba(255, 255, 255, 0.3);
    border-radius: var(--border-radius);
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: var(--spacing-unit);
    justify-content: flex-end;
    margin-top: var(--spacing-unit);
    padding-top: var(--spacing-unit);
    border-top: 1px solid var(--border-color);
}

.submit-note {
    text-align: center;
    color: #666;
    font-size: 0.85rem;
    margin-top: calc(var(--spacing-unit) * 0.5);
    font-style: italic;
}

/* Buttons */
.btn {
    padding: calc(var(--spacing-unit) * 0.75) calc(var(--spacing-unit) * 2);
    border: none;
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-speed);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.btn-primary {
    background-color: var(--secondary-color);
    color: white;
}

.btn-primary:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    background-color: #95a5a6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-secondary:active {
    transform: translateY(0);
}

/* Form Messages */
.form-messages {
    margin-top: calc(var(--spacing-unit) * 2);
    padding: var(--spacing-unit);
    border-radius: var(--border-radius);
    display: none;
}

.form-messages.show,
.form-messages.success,
.form-messages.error,
.form-messages.info {
    display: block !important;
}

.form-messages.success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.form-messages.error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.form-messages.info {
    background-color: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Small buttons for modal */
.btn-small {
    padding: calc(var(--spacing-unit) * 0.5) calc(var(--spacing-unit) * 1);
    font-size: 0.875rem;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

/* Modal Styles */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 9999;
    padding: var(--spacing-unit);
    margin: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: 600px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: auto;
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-unit);
    border-bottom: 1px solid var(--border-color);
    background-color: var(--secondary-color);
    color: white;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.25rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: white;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color var(--transition-speed);
}

.modal-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.modal-body {
    padding: var(--spacing-unit);
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: var(--spacing-unit);
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

/* Saved Configuration Items */
.saved-config-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: calc(var(--spacing-unit) * 0.75);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: calc(var(--spacing-unit) * 0.75);
    transition: background-color var(--transition-speed);
}

.saved-config-item:hover {
    background-color: #f8f9fa;
}

.saved-config-info {
    flex: 1;
}

.saved-config-name {
    font-weight: 600;
    font-size: 1rem;
    color: var(--primary-color);
    margin-bottom: calc(var(--spacing-unit) * 0.25);
}

.saved-config-date {
    font-size: 0.875rem;
    color: #666;
}

.saved-config-actions {
    display: flex;
    gap: calc(var(--spacing-unit) * 0.5);
    margin-left: var(--spacing-unit);
}

/* Responsive form actions */
@media (max-width: 768px) {
    .form-actions {
        flex-wrap: wrap;
        justify-content: stretch;
    }
    
    .form-actions .btn {
        flex: 1 1 auto;
        min-width: 120px;
    }
}

/* Responsive Design */
/* Print Styles */
@media print {
    body {
        background: white;
        color: black;
    }
    
    .instructions-box,
    .form-actions,
    .no-print {
        display: none !important;
    }
    
    .container {
        max-width: 100%;
        padding: 0;
        box-shadow: none;
    }
    
    .main-layout {
        flex-direction: column;
    }
    
    .results-column {
        flex: 1 1 100%;
        width: 100%;
    }
    
    .sticky-results-container {
        position: static;
        max-height: none;
        overflow: visible;
    }
    
    .calculation-results-box,
    .class-ranges-box {
        page-break-inside: avoid;
        break-inside: avoid;
    }
    
    .form-section {
        page-break-inside: avoid;
        break-inside: avoid;
        border: 1px solid #ccc;
        margin-bottom: 15px;
    }
    
    input, select, textarea {
        border: 1px solid #ccc;
        background: white;
        color: black;
    }
    
    .form-group {
        margin-bottom: 8px;
    }
}

@media (max-width: 768px) {
    body {
        padding: calc(var(--spacing-unit) * 0.5);
    }

    .container {
        padding: var(--spacing-unit);
    }
    
    .header-content {
        flex-direction: column;
        text-align: center;
    }
    
    .wcma-logo {
        height: 60px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .class-selector {
        flex-direction: column;
    }

    .main-layout {
        flex-direction: column;
    }

    .results-column {
        flex: 1 1 100%;
        width: 100%;
    }

    .calculation-results-box {
        position: static;
    }

    .inline-calculation-summary {
        flex-direction: column;
        gap: var(--spacing-unit);
    }

    .summary-item {
        justify-content: space-between;
    }

    .input-with-result,
    .select-with-modifier {
        flex-direction: column;
        align-items: stretch;
    }

    .inline-result,
    .modifier-value {
        text-align: left;
        min-width: auto;
    }
}

@media (max-width: 480px) {
    header h1 {
        font-size: 1.25rem;
    }

    .form-section h2 {
        font-size: 1.25rem;
    }
}

/* Print Styles */
@media print {
    body {
        background: white;
        padding: 0;
    }

    .container {
        box-shadow: none;
        padding: 0;
    }

    .form-actions,
    .btn,
    #print-button,
    .submit-note {
        display: none;
    }

    .form-section {
        page-break-inside: avoid;
        border: 1px solid #000;
        margin-bottom: 1rem;
    }

    input,
    select,
    textarea {
        border: 1px solid #000;
        background: white;
    }

    .results-section {
        background: white;
        color: black;
        border: 2px solid #000;
    }

    .results-section h2 {
        color: black;
        border-bottom-color: #000;
    }

    .result-item {
        background: white;
        color: black;
        border: 1px solid #000;
    }

    .result-item label {
        color: black;
    }

    .result-value {
        color: black;
    }

    .calculated-class {
        background: white;
        color: black;
        border: 1px solid #000;
    }

    .class-value {
        background: #f0f0f0;
        color: black;
    }
}

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

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 3px solid var(--secondary-color);
    outline-offset: 2px;
}

