/**
 * Bobbin Selector Styles
 * Modern, responsive design with enhanced UX
 * Includes Form Maker compatibility
 */

/* Container */
.bobbin-selector-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 20px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Form Maker Compatibility */
.wdform-page-and-images {
    width: 100%;
}

.wdform_page {
    background: #ffffff;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    padding: 30px;
    margin-bottom: 30px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.wdform_section {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

/* All form columns centered */
.wdform_column {
    width: 100%;
    max-width: 600px;
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Each form row centered */
.wdform_row {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Form groups centered with limited width */
.form-group {
    width: 100%;
    max-width: 400px;
    text-align: center;
}

/* Labels centered */
.form-label,
.wdform-label {
    text-align: center;
    width: 100%;
}

/* Form controls - 20% width on desktop */
select.form-control {
    width: 20%;
    min-width: 250px;
    max-width: 400px;
}

/* Dimension inputs - narrow and centered */
input.form-control[type="text"] {
    width: 20%;
    min-width: 200px;
    max-width: 250px;
}

/* Small text centered */
.form-text {
    text-align: center;
    width: 100%;
}

/* Mobile: full width */
@media (max-width: 768px) {
    select.form-control,
    input.form-control[type="text"] {
        width: 100%;
        max-width: 100%;
    }
    
    .wdform_column {
        max-width: 100%;
    }
    
    .form-group {
        max-width: 100%;
    }
}

/* Ensure dimension inputs don't stretch too wide - handled above in main layout */

.wdform_row {
    width: 100%;
}

.wdform-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: #24292e;
    margin-bottom: 8px;
}

.wdform-button {
    font-family: inherit;
}

.wdform_footer {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e1e4e8;
}

.wd-width-100 {
    width: 100%;
}

.wd-table {
    display: table;
    width: 100%;
}

.wd-table-group {
    display: table-row-group;
}

.wd-table-row {
    display: table-row;
}

.bobbin-selector-title {
    font-size: 28px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 30px;
    text-align: center;
}

/* Form Groups */
.form-group {
    margin-bottom: 0;
    animation: fadeIn 0.15s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: #24292e;
    margin-bottom: 8px;
    line-height: 1.4;
    word-wrap: break-word;
}

.form-label .required {
    color: #d73a49;
    margin-left: 2px;
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.5;
    color: #24292e;
    background-color: #ffffff;
    border: 1px solid #d1d5da;
    border-radius: 6px;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
    min-height: 42px;
}

/* Specific height for select dropdowns to prevent text cutoff */
select.form-control {
    height: auto;
    min-height: 42px;
    padding: 10px 12px;
}

/* Handle long option text */
select.form-control option {
    padding: 8px 12px;
    line-height: 1.6;
}

/* Dimension inputs - handled in main layout section above */

.form-control:focus {
    outline: none;
    border-color: #0366d6;
    box-shadow: 0 0 0 3px rgba(3, 102, 214, 0.1);
}

.form-control:disabled {
    background-color: #f6f8fa;
    cursor: not-allowed;
}

.form-text {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: #586069;
    line-height: 1.4;
}

.form-loading {
    display: inline-block;
    margin-left: 10px;
    color: #586069;
    font-size: 13px;
}

/* Spinner */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #0366d6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 5px;
}

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

/* Buttons */
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.btn {
    padding: 10px 24px;
    font-size: 14px;
    font-weight: 500;
    line-height: 20px;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 140px;
}

/* Buttons at smaller widths on desktop */
@media (min-width: 768px) {
    .btn {
        flex: 0 0 auto;
    }
}

.btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(3, 102, 214, 0.15);
}

.btn-primary {
    color: #ffffff;
    background-color: #0366d6;
    border-color: #0366d6;
}

.btn-primary:hover:not(:disabled) {
    background-color: #0256c5;
    border-color: #0256c5;
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    color: #24292e;
    background-color: #ffffff;
    border-color: #d1d5da;
}

.btn-secondary:hover {
    background-color: #f6f8fa;
    border-color: #d1d5da;
}

/* Alert Messages */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-top: 20px;
    font-size: 14px;
    line-height: 1.5;
}

.alert-error {
    color: #86181d;
    background-color: #ffdce0;
    border: 1px solid #f9c4c8;
}

/* Results Section */
.bobbin-results {
    background: #ffffff;
    border: 1px solid #e1e4e8;
    border-radius: 8px;
    padding: 30px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    animation: slideIn 0.4s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results-header {
    margin-bottom: 20px;
}

.results-title {
    font-size: 20px;
    font-weight: 600;
    color: #1a1a1a;
    margin-bottom: 8px;
}

.results-count {
    font-size: 14px;
    color: #586069;
}

/* Results Controls */
.results-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 15px;
    flex-wrap: wrap;
}

.results-search {
    flex: 1;
    min-width: 200px;
    max-width: 400px;
}

.table-search-input {
    width: 100%;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid #d1d5da;
    border-radius: 6px;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.table-search-input:focus {
    outline: none;
    border-color: #0366d6;
    box-shadow: 0 0 0 3px rgba(3, 102, 214, 0.1);
}

.results-actions {
    display: flex;
    gap: 10px;
}

.btn-export {
    padding: 8px 16px;
    font-size: 13px;
    color: #24292e;
    background-color: #ffffff;
    border: 1px solid #d1d5da;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
}

.btn-export:hover {
    background-color: #f6f8fa;
}

.results-table-wrapper {
    overflow-x: auto;
    margin-top: 20px;
}

/* Table Styles */
.bobbin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.bobbin-table thead {
    background-color: #f6f8fa;
}

.bobbin-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    color: #24292e;
    border-bottom: 2px solid #e1e4e8;
    position: relative;
    user-select: none;
}

.bobbin-table th.sortable {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.bobbin-table th.sortable:hover {
    background-color: #eaecef;
}

.bobbin-table th.sorted {
    background-color: #e8f1f8;
}

.sort-icon {
    margin-left: 6px;
    font-size: 12px;
    color: #959da5;
    display: inline-block;
}

.bobbin-table th.sorted .sort-icon {
    color: #0366d6;
}

.bobbin-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #e1e4e8;
    color: #24292e;
}

.bobbin-table tbody tr {
    transition: background-color 0.15s ease;
}

.bobbin-table tbody tr:hover {
    background-color: #f6f8fa;
}

.bobbin-table tbody tr:last-child td {
    border-bottom: none;
}

/* Part Number Link */
.part-link {
    color: #0366d6;
    text-decoration: none;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.part-link:hover {
    text-decoration: underline;
}

.external-link-icon {
    font-size: 12px;
    opacity: 0.7;
}

/* No Results */
.no-results {
    text-align: center;
    padding: 40px 20px;
    color: #586069;
}

.no-results p {
    margin: 0;
    font-size: 14px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .bobbin-selector-container {
        padding: 15px;
    }
    
    .bobbin-selector-form,
    .bobbin-results {
        padding: 20px;
    }
    
    .wdform_page {
        padding: 25px 20px;
    }
    
    /* All controls full width on mobile */
    select.form-control,
    input.form-control[type="text"] {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0;
    }
    
    .wdform_column,
    .form-group {
        max-width: 100%;
    }
    
    .form-actions {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
    }
    
    .results-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .results-search {
        max-width: 100%;
    }
    
    .results-actions {
        justify-content: stretch;
    }
    
    .btn-export {
        flex: 1;
    }
    
    .bobbin-table {
        font-size: 13px;
    }
    
    .bobbin-table th,
    .bobbin-table td {
        padding: 10px 12px;
    }
    
    .sort-icon {
        font-size: 10px;
    }
}

@media (max-width: 480px) {
    .bobbin-selector-title {
        font-size: 22px;
    }
    
    .results-title {
        font-size: 18px;
    }
    
    .wdform_page {
        padding: 20px 15px;
    }
    
    /* Stack table on very small screens */
    .bobbin-table thead {
        display: none;
    }
    
    .bobbin-table tbody tr {
        display: block;
        margin-bottom: 15px;
        border: 1px solid #e1e4e8;
        border-radius: 6px;
    }
    
    .bobbin-table td {
        display: block;
        text-align: right;
        padding: 10px;
        border-bottom: 1px solid #f6f8fa;
        position: relative;
        padding-left: 50%;
    }
    
    .bobbin-table td:last-child {
        border-bottom: none;
    }
    
    .bobbin-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 10px;
        font-weight: 600;
        color: #586069;
        text-align: left;
    }
    
    .bobbin-table td .part-link {
        display: block;
        text-align: right;
    }
}

/* Tablet landscape and desktop - optimize for horizontal space */
@media (min-width: 769px) and (max-width: 1024px) {
    .wdform_section {
        grid-template-columns: 1fr 1fr;
    }
    
    /* Keep dimension fields in same row but compact */
    .wdform_column:has([wdid="5"]), 
    .wdform_column:has([wdid="6"]) {
        grid-column: auto;
    }
}

/* Large screens - more compact layout */
@media (min-width: 1025px) {
    .wdform_section {
        grid-template-columns: repeat(4, 1fr);
    }
    
    /* Core Shape - first position */
    .wdform_column:has([wdid="2"]) {
        grid-column: 1;
    }
    
    /* Industry Designation - second position */
    .wdform_column:has([wdid="3"]) {
        grid-column: 2;
    }
    
    /* Dimension 1 - third position */
    .wdform_column:has([wdid="5"]) {
        grid-column: 3;
    }
    
    /* Dimension 2 - fourth position */
    .wdform_column:has([wdid="6"]) {
        grid-column: 4;
    }
    
    /* Buttons span full width below */
    .wdform_column:has([wdid="1"]) {
        grid-column: 1 / -1;
        margin-top: 10px;
    }
}

/* Accessibility */
.form-control:focus,
.btn:focus {
    outline: 2px solid transparent;
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .bobbin-selector-form,
    .form-actions {
        display: none;
    }
    
    .bobbin-results {
        border: none;
        box-shadow: none;
    }
    
    .part-link {
        color: #000;
        text-decoration: none;
    }
    
    .external-link-icon {
        display: none;
    }
}

/* Hidden by default utility */
.fm-hide {
    display: none !important;
}
