/**
 * SUPAC IR - Formula Change Calculator Styles
 */

.supac-calculator-wrapper {
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    width: 90%;
    max-width: 1000px;
    background-color: #ffffff;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    margin: 15px auto;
}

.supac-title {
    font-size: 2.8em;
    font-weight: bold;
    text-align: center;
    margin-bottom: 20px;
    color: #FF971D;
}

/* Input Area Wrapper */
.supac-input-area-wrapper {
    background-color: #f8f8f8; 
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 10px 15px; 
    margin-bottom: 15px;
}

/* Header and Component Rows */
.supac-header-row, 
.supac-component-row {
    display: flex;
    gap: 15px;
    align-items: center;
    padding: 5px 0; 
}

.supac-component-row .supac-col {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.supac-component-row {
    align-items: flex-start;
    border-bottom: 1px solid #e9e9e9;
}

.supac-col input,
.supac-col select {
    margin-bottom: 2px;
}

#supac-component-rows-container .supac-component-row:last-child {
    border-bottom: none;
}

.supac-component-row:hover {
    background-color: #f1f1f1;
}

.supac-header-row {
    font-weight: bold;
    font-size: 1.6em;
    text-align: center;
    padding-bottom: 10px;
    line-height: 1;
    border-bottom: 2px solid #ddd;
    margin-bottom: 5px;
}

/* Column Sizing */
.supac-col { 
    flex: 1; 
}
.supac-col.col-name { 
    flex-basis: 25%;
}
.supac-col.col-function { 
    flex-basis: 25%;
}
.supac-col.col-quantity { 
    flex-basis: 20%;
}
.supac-col.col-action { 
    flex-basis: 5%;
    text-align: right;
}

/* Input Styling */
.supac-calculator-wrapper input[type="text"],
.supac-calculator-wrapper input[type="number"],
.supac-calculator-wrapper select {
    width: 95%;
    padding: 8px;
    margin: 5px 0;
    border: 1px solid #ddd;
    border-radius: 5px;
    box-sizing: border-box;
    text-align: center;
}

.supac-calculator-wrapper select {
    text-align: left; 
    text-align-last: center;
}

.supac-calculator-wrapper input:focus,
.supac-calculator-wrapper select:focus {
    border-color: #FF971D;
    outline: none;
}

/* Buttons */
.supac-button {
    background-color: #f1f1f1;
    color: black;
    border: 0.3px solid #666666;
    padding: 10px 20px;
    margin: 5px;
    cursor: pointer;
    border-radius: 5px;
    font-size: 1em;
    font-weight: bold;
    transition: background-color 0.3s ease;
}

.supac-button:hover {
    background-color: #BBBBBB;
}

.supac-button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Controls Container */
.supac-main-controls-container {
    display: flex;
    justify-content: space-between; 
    align-items: center;
    font-size: 1.4em;
    margin-top: 10px;
    margin-bottom: 10px;
    padding-top: 10px;
    border-top: 1px solid #eee;
}

.supac-right-controls {
    display: flex;
    gap: 10px; 
}

/* Remove Row Button */
.supac-remove-row-btn {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    font-weight: bold;
    width: 30px;
    height: 30px;
    line-height: 28px;
    padding: 0;
    text-align: center;
}

.supac-remove-row-btn:hover {
    background-color: #f1b0b7;
}

/* Validation Errors */
.supac-input-error {
    border-color: #d9534f !important;
    border-width: 2px !important;
    background-color: #fff2f2;
}

.supac-error-message {
    color: #d9534f;
    font-size: 14px;
    line-height: 1.3;
    margin-top: 5px;
    display: block;
}

.supac-calculator-wrapper .loader {
    text-align: center;
    margin: 20px 0;
    padding: 20px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.supac-calculator-wrapper .loader p {
    margin: 15px 0 0 0;
    font-size: 1.1em;
    color: #495057;
    font-weight: 500;
}

/* Classic Spinner */
.supac-calculator-wrapper .loader::before {
    content: "";
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #FF971D;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
/* Results Container */
#supac-calculator-result {
    margin-top: 10px;
    margin-bottom: 10px;
    background-color: #f9f9f9;
    padding: 20px;
    border: 1px solid #ddd;
    border-radius: 5px;
}

#supac-calculator-result h3 {
    text-align: center;
    font-size: 2.3em;
    margin-top: 0;
    margin-bottom: 20px;
}

/* Result Summary Boxes */
.supac-result-summary {
    display: flex;
    justify-content: space-around;
    gap: 15px;
    margin-bottom: 25px;
    text-align: center;
}

.supac-summary-box {
    flex: 1;
    background-color: #fff;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #ddd;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.supac-summary-box h4 {
    margin: 0 0 10px 0;
    font-size: 1.6em;
    color: #555;
}

.supac-summary-box span {
    font-size: 2.3em;
    font-weight: bold;
    color: #333;
}

.supac-summary-box span1 {
    font-size: 1.9em;
    color: #333;
}

.supac-summary-box-highlight span {
    color: #d9534f;
}

/* Result Table */
#supac-calculator-result .supac-result-table {
    width: 100%;
    line-height: 1.2;
    border-collapse: collapse;
}

#supac-calculator-result .supac-result-table th:nth-child(1),
#supac-calculator-result .supac-result-table td:nth-child(1) {
    min-width: 220px;
    white-space: normal;
    text-align: left;
    padding-left: 15px;
}

#supac-calculator-result .supac-result-table th,
#supac-calculator-result .supac-result-table td {
    font-size: 1.6em;
    padding: 0.9em; 
    vertical-align: middle;
    border: 1px solid #ddd;
    text-align: center;
}

.supac-result-table th {
    background-color: #f4f4f4;
}

.supac-result-table tr:nth-child(even) {
    background-color: #f9f9f9;
}

.supac-result-table tr:hover {
    background-color: #f1f1f1;
}

/* Classification Box */
.supac-classification-box {
    margin-top: 25px;
    padding: 1.2em;
    border-radius: 8px;
    font-size: 1.6em;
    line-height: 1.2;
    font-weight: bold;
    text-align: center;
    border: 1px solid;
}

.supac-level-1 { 
    background-color: #FFF4E5; 
    color: #FF971D; 
    border-color: #FFDAB9; 
}

.supac-level-2 { 
    background-color: #fff3cd; 
    color: #856404; 
    border-color: #ffeeba; 
}

.supac-level-3 { 
    background-color: #f8d7da; 
    color: #721c24; 
    border-color: #f5c6cb; 
}

.supac-calculator-wrapper .notes-container {
    padding: 15px;
    background-color: #f2f2f2;
    border: 1px solid #000000;
    border-radius: 5px;
}

.supac-calculator-wrapper .notes-container h3 {
    margin-bottom: 10px;
    font-size: 18px;
    color: #000000;
    text-align: center;
}

.supac-calculator-wrapper .notes-container p {
    font-size: 14px;
    color: #000000;
    line-height: 1.5;
    font-weight: 500;
}

.supac-calculator-wrapper .notes-container ul {
    padding-left: 20px;
    list-style-type: disc;
    font-size: 14px;
    color: #000000;
    line-height: 1.5;
    font-weight: 500;
}

.supac-calculator-wrapper .notes-container li {
    margin-bottom: 8px;
}

.supac-calculator-wrapper .supac-input-area-wrapper {
    padding-left: 35px;
    position: relative;
}

.supac-calculator-wrapper #supac-component-rows-container {
    position: relative;
}

.supac-calculator-wrapper .supac-component-row {
    position: relative;
}

.supac-calculator-wrapper .supac-component-row::before {
    content: attr(data-row-number) ".";
    position: absolute;
    left: -25px;
    top: 50%;
    transform: translateY(-50%);
    color: #333333;
    font-size: 15px;
    font-weight: 600;
    font-family: 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    display: inline-block;
    line-height: 1;
    width: 20px;
    text-align: center;
}

.supac-calculator-wrapper .supac-header-row::before {
    display: none;
}

@media (max-width: 768px) {
    .supac-calculator-wrapper {
        padding: 20px 15px;
    }

    .supac-title {
        font-size: 2.2em;
    }
    
    /* HORIZONTAL SCROLL FOR INPUT AREA */
    .supac-input-area-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
        padding: 10px;
    }
    .supac-input-area-wrapper {
        position: relative;
        margin-bottom: 35px; /* Space for scroll hint */
    }
    
    .supac-input-area-wrapper::after {
        display: block;
    }


    /* Prevent rows from wrapping - maintain table structure */
    .supac-header-row,
    .supac-component-row {
        min-width: 700px; /* Force minimum width to enable scroll */
    }

    /* Add scroll hint shadow */
    .supac-input-area-wrapper {
        background: 
            linear-gradient(90deg, #f8f8f8 0%, rgba(248,248,248,0) 20px),
            linear-gradient(90deg, rgba(248,248,248,0) calc(100% - 20px), #f8f8f8 100%),
            linear-gradient(90deg, rgba(0,0,0,.1) 0%, rgba(0,0,0,0) 10px),
            linear-gradient(270deg, rgba(0,0,0,.1) 0%, rgba(0,0,0,0) 10px);
        background-repeat: no-repeat;
        background-size: 20px 100%, 20px 100%, 10px 100%, 10px 100%;
        background-position: 0 0, 100% 0, 0 0, 100% 0;
        background-attachment: local, local, scroll, scroll;
    }

    /* Adjust button layout for mobile */
    .supac-main-controls-container {
        display: grid;
        grid-template-columns: 1fr 1fr; /* Two equal columns */
        gap: 10px;
        margin-top: 15px;
    }

    /* This is the key: 'unwrap' the left/right containers so grid can control buttons directly */
    .supac-left-controls,
    .supac-right-controls {
        display: contents;
    }

    /* Button 1: Add Component (Top Left) */
    #supac-add-component-btn {
        grid-column: 1;
        width: 100%;
        margin: 0;
    }

    /* Button 2: Clear All (Top Right) */
    #supac-clear-btn {
        grid-column: 2;
        width: 100%;
        margin: 0;
    }

    /* Button 3: Calculate (Bottom Full Width) */
    .supac-calculate-btn {
        grid-column: 1 / span 2; /* Span across both columns */
        width: 100%;
        margin: 0;
        margin-top: 5px; /* Small spacing from top row */
    }
    
    #supac-calculator-result h3 {
        font-size: 2.2em;
    }

    /* Results - Stack summary boxes vertically */
    .supac-result-summary {
        flex-direction: column;
    }
    
    .supac-summary-box span {
        font-size: 2.1em;
    }
    
    .supac-summary-box span1 {
        font-size: 1.7em;
    }
    
    .supac-result-scroll-wrapper {
        display: block;
        width: 100%;
        overflow-x: auto; /* Enables scrolling on the wrapper */
        -webkit-overflow-scrolling: touch;
    }
    .supac-result-scroll-wrapper {
        background: 
                linear-gradient(90deg, #f8f8f8 0%, rgba(248,248,248,0) 20px),
                linear-gradient(90deg, rgba(248,248,248,0) calc(100% - 20px), #f8f8f8 100%),
                linear-gradient(90deg, rgba(0,0,0,.1) 0%, rgba(0,0,0,0) 10px),
                linear-gradient(270deg, rgba(0,0,0,.1) 0%, rgba(0,0,0,0) 10px);
        background-repeat: no-repeat;
        background-size: 20px 100%, 20px 100%, 10px 100%, 10px 100%;
        background-position: 0 0, 100% 0, 0 0, 100% 0;
        background-attachment: local, local, scroll, scroll;
    }

    /* Results Table - Also scrollable */
    .supac-result-table {
        width: 100%;
        min-width: 700px;
    }

    .supac-result-table thead,
    .supac-result-table tbody,
    .supac-result-table tr {
        display: table;
        width: 100%;
        table-layout: fixed;
    }

    #supac-calculator-result .supac-result-table th,
    #supac-calculator-result .supac-result-table td {
        font-size: 1.4em;
        padding: 8px 5px;
        white-space: nowrap;
    }
    
    .supac-result-table th:nth-child(1),
    .supac-result-table td:nth-child(1) {
        min-width: 220px;
        white-space: normal;
        text-align: left;
        padding-left: 15px;
    }
    
    .supac-calculator-wrapper .supac-input-area-wrapper {
        padding-left: 30px;
    }
    .supac-calculator-wrapper .supac-component-row::before {
        left: -22px;
        font-size: 14px;
    }
    .supac-classification-box {
        font-size: 1.4em;     
        line-height: 1.2;
        padding: 1.0em;
        word-wrap: break-word;
        height: auto;
    }
}

@media (max-width: 480px) {
    .supac-calculator-wrapper {
        padding: 15px 10px;
    }

    .supac-title {
        font-size: 2.0em;
    }

    .supac-header-row,
    .supac-component-row {
        min-width: 650px; /* Slightly smaller for tiny screens */
    }

    .supac-button {
        font-size: 0.9em;
        padding: 10px 15px;
    }
}

/* Scroll Hint Animation (Optional) */
@keyframes scroll-hint {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}