/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f7fa;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    font-weight: 700;
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Form sections */
.form-section {
    background: white;
    padding: 30px;
    margin-bottom: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
    border: 1px solid #e1e8ed;
}

.form-section h2 {
    color: #2c3e50;
    margin-bottom: 25px;
    font-size: 1.5rem;
    font-weight: 600;
    border-bottom: 2px solid #3498db;
    padding-bottom: 10px;
}

.form-section h3 {
    color: #34495e;
    margin-bottom: 15px;
    font-size: 1.2rem;
    font-weight: 500;
}

/* Alerts */
.alert {
    padding: 15px 20px;
    margin-bottom: 25px;
    border-radius: 8px;
    font-weight: 500;
    border-left: 4px solid;
}

.alert-error {
    background-color: #fdf2f2;
    color: #c53030;
    border-left-color: #e53e3e;
}

.alert-success {
    background-color: #f0fff4;
    color: #2f855a;
    border-left-color: #38a169;
}

/* File input */
.file-input-wrapper {
    position: relative;
    margin-bottom: 20px;
}

.file-input-wrapper input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.file-input-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border: 2px dashed #cbd5e0;
    border-radius: 8px;
    background-color: #f7fafc;
    cursor: pointer;
    transition: all 0.3s ease;
    min-height: 80px;
}

.file-input-label:hover {
    border-color: #4299e1;
    background-color: #ebf8ff;
}

.file-input-text {
    font-size: 1.1rem;
    color: #4a5568;
    margin-right: 10px;
}

.file-input-icon {
    font-size: 1.5rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
}

.btn-primary {
    background-color: #4299e1;
    color: white;
}

.btn-primary:hover {
    background-color: #3182ce;
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #e2e8f0;
    color: #4a5568;
}

.btn-secondary:hover {
    background-color: #cbd5e0;
}

.btn-success {
    background-color: #48bb78;
    color: white;
}

.btn-success:hover {
    background-color: #38a169;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9rem;
}

.btn-large {
    padding: 16px 32px;
    font-size: 1.1rem;
}

.btn-remove {
    background-color: #f56565;
    color: white;
}

.btn-remove:hover {
    background-color: #e53e3e;
}

/* Rule groups */
.rule-group {
    margin-bottom: 30px;
    padding: 20px;
    background-color: #f8fafc;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

/* Radio group */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.radio-label {
    display: flex;
    align-items: flex-start;
    cursor: pointer;
    padding: 12px;
    border-radius: 6px;
    transition: background-color 0.2s ease;
}

.radio-label:hover {
    background-color: #edf2f7;
}

.radio-label input[type="radio"] {
    margin-right: 12px;
    margin-top: 2px;
    transform: scale(1.2);
}

.radio-text {
    font-size: 1rem;
    color: #2d3748;
    line-height: 1.5;
}

/* Column options */
.column-options {
    display: flex;
    align-items: center;
    gap: 20px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.9rem;
    color: #4a5568;
}

.checkbox-label input[type="checkbox"] {
    margin-right: 8px;
    transform: scale(1.1);
}

.checkbox-text {
    cursor: pointer;
}

/* Column grid */
.column-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.column-checkbox {
    display: flex;
    align-items: center;
    padding: 10px;
    background-color: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.column-checkbox.draggable {
    cursor: grab;
}

.column-checkbox.dragging {
    opacity: 0.5;
    z-index: 1000;
}

.column-checkbox.drag-over {
    border-color: #4299e1;
    background-color: #ebf8ff;
    transform: scale(1.15);
}

.drag-handle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 14px;
    background: repeating-linear-gradient(
        0deg,
        #646c78,
        #646c78 2px,
        transparent 2px,
        transparent 4px
    );
    cursor: grab;
    opacity: 0.6;
    transition: all 0.2s ease;
    border-radius: 2px;
    border: 1px solid #a0aec0;
}

.column-checkbox:hover .drag-handle {
    opacity: 1;
    background: repeating-linear-gradient(
        0deg,
        #4a5568,
        #4a5568 2px,
        transparent 2px,
        transparent 4px
    );
    border-color: #4a5568;
    transform: translateY(-50%) scale(1.1);
}

.column-checkbox:hover {
    border-color: #4299e1;
    background-color: #ebf8ff;
}

.column-checkbox input[type="checkbox"] {
    margin-right: 8px;
    transform: scale(1.1);
}

.column-checkbox label {
    cursor: pointer;
    font-size: 0.9rem;
    color: #4a5568;
    flex: 1;
}

.sample-data {
    font-size: 0.8rem;
    font-style: italic;
    color: #666;
    margin-top: 2px;
    line-height: 1.2;
}

.column-name-input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    font-size: 0.9rem;
    margin-top: 4px;
}

.column-name-input:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 2px rgba(66, 153, 225, 0.1);
}

/* New columns */
.new-column-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}

/* New column inputs - always visible */
.new-column-row .column-name-input {
    width: 150px;
    flex: none;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: .9rem;
}

.new-column-row .column-value-input,
.column-position-select {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: .9rem;
    transition: border-color 0.2s ease;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Textarea-specific styling for value input */
.column-value-input {
    resize: vertical;
    min-height: 36px;
    max-height: 300px;
    font-family: inherit;
    line-height: 1.4;
    overflow-y: auto;
}

/* Excel Formula Help styling */
.excel-formula-help {
    position: relative;
    margin-left: 10px;
    display: inline-block;
}

.excel-formula-help a {
    color: #4299e1;
    text-decoration: none;
    font-size: 0.8rem;
    cursor: pointer;
}

.excel-formula-help a:hover {
    text-decoration: underline;
}

.formula-help-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    z-index: 1000;
    max-height: 200px;
    overflow-y: auto;
    min-width: 400px;
    margin-top: 2px;
}

.formula-item {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    transition: background-color 0.2s ease;
}

.formula-item:hover {
    background-color: #f8f9fa;
}

.formula-item:last-child {
    border-bottom: none;
}

.formula-item > div:first-child {
    flex: 1;
    font-weight: 600;
    color: #2d3748;
}

.formula-item > div:last-child {
    flex: 2;
    margin-left: 10px;
}

.formula-item code {
    color: #666;
    font-size: 0.75rem;
    background: #f7fafc;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
}

.new-column-row .column-position-select {
    min-width: 1px;
    font-size: .85rem;
}

.new-column-row .column-type-select {
    min-width: 125px;
    padding: 6px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: .9rem;
    transition: border-color 0.2s ease;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Row filter section dropdowns and inputs */
#target_column,
#filter_column,
#filter_condition,
#filter_value {
    min-width: 180px;
    padding: 6px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: .85rem;
    transition: border-color 0.2s ease;
}

/* Sort options styling */
.sort-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.sort-level {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sort-level label {
    font-weight: 600;
    min-width: 120px;
    color: #374151;
}

.sort-level select {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.9rem;
    background-color: white;
    min-width: 200px;
}

.sort-level select:last-child {
    min-width: 150px;
}

.column-name-input:focus,
.column-value-input:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66, 153, 225, 0.1);
}

/* Placeholder styling for column inputs */
.column-name-input::placeholder,
.column-value-input::placeholder {
    font-size: 0.85rem;
    font-style: italic;
    color: #9ca3af;
}

/* Form actions */
.form-actions {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
}

/* Download section */
.download-section {
    text-align: center;
    padding: 30px;
    background-color: #f0fff4;
    border-radius: 8px;
    border: 1px solid #9ae6b4;
}

.download-section p {
    font-size: 1.1rem;
    color: #2f855a;
    margin-bottom: 20px;
}

/* Responsive design */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2rem;
    }
    
    .form-section {
        padding: 20px;
    }
    
    .column-grid {
        grid-template-columns: 1fr;
    }
    
    .new-column-row {
        flex-direction: column;
        align-items: stretch;
    }
    
    .btn {
        width: 100%;
        margin-bottom: 10px;
    }
}

/* Loading states */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #4299e1;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}
