/* General body styling */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f0f2f5;
    color: #333;
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    min-height: 100vh;
    box-sizing: border-box;
}

/* Main container for the application */
.container {
    background-color: #ffffff;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 900px;
    text-align: left;
}

h1 {
    color: #1d2129;
    margin-top: 0;
    margin-bottom: 25px;
    text-align: center;
}

/* Introductory content styling */
.intro-content {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 15px 25px;
    margin-bottom: 30px;
    font-size: 0.95em;
    line-height: 1.6;
}
.intro-content h3 {
    margin-top: 15px;
    margin-bottom: 10px;
    color: #333;
}
.intro-content ul {
    padding-left: 20px;
    margin-bottom: 0;
}


h2 {
    color: #1d2129;
    margin-top: 30px;
    margin-bottom: 15px;
    border-bottom: 1px solid #eee;
    padding-bottom: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

/* Builder area styles */

/* SELECT Statement Styling */
.select-statement {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    margin-bottom: 20px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
}

.select-statement span {
    font-weight: bold;
    color: #007bff; /* Using the primary button color for keywords */
}

.select-statement input[type="text"] {
    padding: 10px;
    border: 1px solid #ced4da;
    border-radius: 5px;
    font-size: 1em;
    font-family: inherit;
    min-width: 150px;
    flex-grow: 1;
}
.builder-area {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    background-color: #fdfdfd;
    margin-bottom: 20px;
}

.conditions-container {
    margin-bottom: 20px;
    padding: 10px;
    border: 1px dashed #ccc;
    min-height: 100px;
    background-color: #fff;
    border-radius: 5px;
}

/* Placeholder text for empty containers */
.placeholder-text {
    text-align: center;
    color: #999;
    padding: 20px;
    font-style: italic;
    pointer-events: none; /* Make it unclickable */
}

/* Hide the placeholder if there are any condition wrappers present */
.conditions-container:has(.condition-wrapper) .placeholder-text,
.conditions-container:has(.orderby-wrapper) .placeholder-text,
.conditions-container:has(.select-wrapper) .placeholder-text {
    display: none;
}

/* Container for simple, single-line inputs like FROM, GROUP BY, etc. */
.single-line-container {
    padding: 10px;
}

.single-line-container .column-input {
    width: 100%;
    box-sizing: border-box;
}


/* Import Area */
.import-area {
    margin-top: 20px;
}
.import-area textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px;
    border: 1px solid #ced4da;
    border-radius: 5px;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
    box-sizing: border-box;
    margin-bottom: 10px;
    resize: vertical;
}

.sql-group .conditions-container-nested,
.and-group .conditions-container-nested {
    padding: 15px;
    margin: 10px;
    border: 1px dashed #ced4da;
    border-radius: 5px;
    background-color: #ffffff;
}

/* Wrapper for each condition to hold the operator */
.condition-wrapper {
    position: relative;
}

/* Hide the operator for the very first condition in any list */
.conditions-container > .condition-wrapper:first-child > .operator-selector,
.conditions-container-nested > .condition-wrapper:first-child > .operator-selector {
    display: none;
}

.operator-selector {
    text-align: center;
    margin: 5px 0;
}

.operator-dropdown {
    font-weight: bold;
    padding: 4px 8px;
    border-radius: 5px;
    border: 1px solid #007bff;
    background-color: #e7f3ff;
    color: #0056b3;
}

/* Individual condition/line styling */
.sql-line, .sql-group {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 5px;
    padding: 10px;
    position: relative;
}
.sql-line { display: flex; gap: 10px; align-items: center; }

.sql-group {
    background-color: #fff3e6;
    border: 1px solid #ffe0b3;
    margin-left: 20px;
    padding-bottom: 15px; /* Add padding to the bottom for controls */
    position: relative;
}

.and-group {
    background-color: #e7f3ff;
    border: 1px solid #b3d7ff;
    margin-left: 20px;
    padding-bottom: 15px; /* Add padding to the bottom for controls */
    display: block; /* Ensure vertical stacking */
    padding: 10px;
    position: relative;
}

.sql-group::before {
    content: "Group";
    position: absolute;
    top: -10px;
    left: 10px;
    background-color: #ffe0b3;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
    color: #5d4037;
    z-index: 1; /* Ensure label is on top of the group content */
}

.and-group::before {
    content: "Group";
    position: absolute;
    top: -10px;
    left: 10px;
    background-color: #b3d7ff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: bold;
    color: #004085;
    z-index: 1; /* Ensure label is on top of the group content */
}

.condition-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Utility classes for flexbox layouts previously in inline styles */
.flex-container {
    display: flex;
    gap: 5px;
}

.flex-grow {
    flex-grow: 1;
}

.flex-col-1 { flex: 1; }
.flex-col-2 { flex: 2; }

.margin-bottom-5 { margin-bottom: 5px; }

/* General styling for all input types within a builder area */
.builder-area input[type="text"],
.builder-area input[type="number"],
.builder-area textarea,
.builder-area select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 1em;
    box-sizing: border-box; /* Ensures padding doesn't affect width */
}

.condition-controls {
    margin-left: auto;
}

.sql-line textarea {
    resize: vertical;
    min-height: 40px;
}

/* Controls at the bottom of a group */
.group-footer-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 15px;
    padding: 0 10px; /* Align with content padding */
}

.group-add-controls {
    display: flex;
    gap: 10px;
}


/* Validation Styling */
.input-invalid {
    border-color: #dc3545 !important; /* Use important to override other border styles */
    animation: shake 0.5s;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.validation-message {
    color: #dc3545;
    font-size: 0.9em;
}

/* Buttons */
.btn {
    background-color: #007bff;
    color: white;
    border: none;
    padding: 10px 18px;
    font-size: 0.95em;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    margin-right: 10px;
}

.btn:hover {
    background-color: #0056b3;
}

.btn.btn-remove {
    background-color: #dc3545;
    margin: 0;
}

.btn.btn-remove:hover {
    background-color: #c82333;
}

.btn.btn-add-nested {
    background-color: #28a745;
}

.btn.btn-add-nested:hover {
    background-color: #218838;
}

.btn-header {
    padding: 5px 12px;
    font-size: 0.8em;
    font-weight: normal;
    margin-left: auto; /* Pushes button to the right */
    margin-right: 0;
    line-height: 1.5;
}

.controls {
    display: flex;
    gap: 10px;
    margin-top: 15px;
    justify-content: flex-end;
}

.storage-controls {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: center;
}

/* Notification Area */
.notification-area {
    text-align: center;
    margin-bottom: 15px;
    height: 22px; /* Reserve space to prevent layout shift */
    transition: opacity 0.5s ease-in-out;
}

.notification-message {
    padding: 8px 20px;
    border-radius: 6px;
    display: inline-block;
    font-size: 0.9em;
    font-weight: 500;
    opacity: 0;
    transition: opacity 0.4s ease;
}

.notification-message.show {
    opacity: 1;
}

.notification-message.success {
    background-color: #d4edda;
    color: #155724;
}

.notification-message.error {
    background-color: #f8d7da;
    color: #721c24;
}

/* WHERE Indicator */
.where-indicator {
    font-weight: bold;
    color: #495057;
    margin-bottom: 10px;
    font-size: 1.2em;
    padding: 8px 12px; /* Increased padding */
    border: 1px solid #a2d9ff; /* Added border */
    background-color: #e0f2ff; /* Light blue background */
    border-radius: 5px; /* Rounded corners */
    text-align: center; /* Center the text */
}

/* Order By Area */
.order-by-area {
    margin-top: 20px;
    padding: 15px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap;
}

.order-by-area label {
    font-weight: bold;
    color: #495057;
}

.order-by-area input[type="text"] {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ced4da;
    border-radius: 5px;
    font-size: 1em;
    min-width: 250px;
}

/* Output areas */
.output-area {
    margin-top: 30px;
}

.sql-output, .json-output {
    background-color: #f4f4f4;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 15px;
    min-height: 100px;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, Courier, monospace;
    font-size: 0.9em;
}

.json-output {
    background-color: #e6ffe6;
    border-color: #b3ffb3;
}

#local-storage-preview {
    background-color: #f0f0f0; /* Neutral gray for stored data */
    border-color: #e0e0e0;
    color: #555;
}

/* JSON Status Indicator */
#json-output-area.unsaved .json-output {
    border-color: #ffc107; /* Orange/Amber for unsaved */
    background-color: #fff9e6;
}

#json-output-area.saved .json-output {
    border-color: #28a745; /* Green for saved */
    background-color: #eafaf1;
}

#json-status-indicator {
    font-size: 0.8em;
    font-weight: normal;
    padding: 3px 8px;
    border-radius: 10px;
    margin-left: 10px;
    color: white;
}

#json-status-indicator.unsaved { background-color: #ffc107; color: #333; }
#json-status-indicator.saved { background-color: #28a745; }