:root {
    --primary-color: #4a69ff;
    --primary-hover: #3b54cc;
    --background-color: #f8f9fa;
    --container-bg: #ffffff;
    --border-color: #dee2e6;
    --text-color: #212529;
    --text-secondary: #6c757d;
    --status-saving: #ffc107;
    --status-saved: #28a745;
    --status-error: #dc3545;
    --status-new: #17a2b8;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body, #root {
    height: 100%;
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
}

.loading-overlay, .settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.spinner {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 4px solid var(--primary-color);
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

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

/* --- Toast Notification --- */
.toast-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 1rem 1.5rem;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    z-index: 2000;
    font-size: 0.95rem;
    font-weight: 500;
    animation: fadeInOut 3s ease-in-out forwards;
}

.toast-notification.toast-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}
.toast-notification.toast-error {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

@keyframes fadeInOut {
    0% {
        opacity: 0;
        top: 0px;
    }
    15% {
        opacity: 1;
        top: 20px;
    }
    85% {
        opacity: 1;
        top: 20px;
    }
    100% {
        opacity: 0;
        top: 0px;
    }
}


.welcome-page {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    background-color: var(--background-color);
}

.welcome-box {
    text-align: center;
    background: var(--container-bg);
    padding: 3rem 4rem;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    max-width: 600px;
}

.welcome-box h1 {
    color: var(--text-color);
    font-size: 2rem;
    margin-bottom: 1rem;
}

.welcome-box p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.welcome-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 2rem;
}

.import-btn {
    padding: 0.8rem 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.import-btn:hover {
    background-color: #f1f3f5;
    border-color: #ced4da;
    color: var(--text-color);
}


.settings-form {
    background: var(--container-bg);
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 750px;
    display: flex;
    flex-direction: column;
    position: relative;
    max-height: 90vh;
    overflow: hidden;
}

.settings-form-header {
    padding: 2.5rem 2.5rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    position: relative;
    flex-shrink: 0;
}

.settings-form-body {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.settings-form-footer {
    padding: 1.5rem 2.5rem;
    border-top: 1px solid var(--border-color);
    background-color: var(--container-bg);
    flex-shrink: 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.footer-left-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.settings-form h2 {
    text-align: center;
    color: var(--text-color);
    margin-bottom: 0;
    font-size: 1.5rem;
}

.settings-form h3 {
    text-align: center;
    color: var(--text-secondary);
    font-size: 1.1rem;
    font-weight: 500;
    margin-top: -0.5rem;
    margin-bottom: 0.5rem;
}

.settings-form hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 0;
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0;
}

.close-btn:hover {
    color: var(--text-color);
}

.form-error-message {
    background-color: #fff5f5;
    color: #a52834;
    border: 1px solid #f1b0b7;
    padding: 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap; /* To respect newlines in the error message */
    text-align: left;
}

.form-error-message.field-error {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
    padding: 0.75rem;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.input-group label {
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.input-group input,
.input-group select,
.input-group textarea {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: var(--font-family);
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: var(--container-bg);
    color: var(--text-color);
}

.input-group select[multiple] {
    min-height: 120px;
}


.input-group select:not([multiple]) {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 16px 12px;
}

.input-group input:focus,
.input-group select:focus,
.input-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 105, 255, 0.2);
}

.input-group select:disabled {
    background-color: #e9ecef;
    cursor: not-allowed;
}

.connect-btn {
    padding: 0.8rem 1.5rem;
    border: 1px solid var(--primary-color);
    border-radius: 6px;
    background-color: var(--primary-color);
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

.connect-btn:hover:not(:disabled) {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}
.connect-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.settings-form-footer .connect-btn {
    flex-grow: 1;
    margin-top: 0;
}

.export-btn, .disconnect-btn-form {
    padding: 0.8rem 1.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: transparent;
    color: var(--text-secondary);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.export-btn:hover:not(:disabled) {
    background-color: #f1f3f5;
    border-color: #ced4da;
    color: var(--text-color);
}
.export-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.disconnect-btn-form {
    color: var(--status-error);
    border-color: #f1b0b7;
}

.disconnect-btn-form:hover {
    background-color: #fff5f5;
    color: #a52834;
}


/* --- Settings Editor Config --- */
.config-container {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 1.5rem;
    min-height: 250px;
}
.settings-table-list {
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem;
    overflow-y: auto;
    background-color: #f8f9fa;
}
.settings-table-list p {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 0.5rem 0.5rem;
}
.settings-table-list ul {
    list-style: none;
}
.settings-table-list-item {
    padding: 0.6rem 0.8rem;
    font-size: 0.9rem;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.settings-table-list-item.hidden {
    text-decoration: line-through;
    color: var(--text-secondary);
}
.settings-table-list-item.hidden .table-name {
    opacity: 0.7;
}

.settings-table-list-item:hover {
    background-color: #e9ecef;
}
.settings-table-list-item.active {
    background-color: rgba(74, 105, 255, 0.1);
    color: var(--primary-color);
    font-weight: 600;
}
.editor-table-badge-sm {
    font-size: 0.8rem;
    color: var(--primary-color);
}
.settings-table-list-item.configured {
    font-weight: 600;
}
.table-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.visibility-toggle-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 2px;
    line-height: 0;
    color: var(--text-secondary);
    opacity: 0.6;
}
.visibility-toggle-btn:hover {
    opacity: 1;
    color: var(--text-color);
}
.settings-table-list-item.hidden .visibility-toggle-btn {
    opacity: 1;
}

.config-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.config-section h4 {
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
}
.config-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
}
.clear-config-btn {
    align-self: flex-start;
    background: transparent;
    border: 1px solid #f1b0b7;
    color: var(--status-error);
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    margin-top: auto;
}
.clear-config-btn:hover {
    background: #fff5f5;
}


.error-message {
    background-color: #fff5f5;
    color: #a52834;
    border: 1px solid #f1b0b7;
    padding: 1rem 1.5rem;
    border-radius: 6px;
    margin: 0 0 1.5rem;
    text-align: left;
    white-space: pre-wrap; /* To respect newlines */
    position: relative; 
    z-index: 10;
}


.app-container {
    display: flex;
    height: 100%;
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--container-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 0 0;
    position: relative;
}

.sidebar-header {
    padding: 0 1.5rem;
    margin-bottom: 1.5rem;
}

.sidebar-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.sidebar-tables-title {
    padding: 0 1.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.75rem;
}

.table-list {
    list-style: none;
    overflow-y: auto;
    flex-grow: 1;
}

.table-list li {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s, color 0.2s;
    border-left: 3px solid transparent;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.table-list li:hover {
    background-color: #f1f3f5;
}

.table-list li.active {
    background-color: rgba(74, 105, 255, 0.1);
    color: var(--primary-color);
    border-left-color: var(--primary-color);
}

.editor-table-badge {
    font-size: 0.9rem;
    color: var(--primary-color);
    font-weight: bold;
}


.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-btn {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-btn:hover {
    background-color: #f1f3f5;
    border-color: #ced4da;
    color: var(--text-color);
}

.main-content {
    flex-grow: 1;
    padding: 2rem;
    overflow-y: auto;
    position: relative;
    display: flex;
    flex-direction: column;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: var(--text-secondary);
}

.welcome-message h2 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

/* --- VIEW HEADERS & TOGGLES --- */
.view-header, .view-toggle-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-shrink: 0;
}

.view-toggle-header h2, .view-header h2 {
    font-size: 1.75rem;
    font-weight: 700;
}

.view-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.view-toggle {
    display: flex;
    background-color: #e9ecef;
    border-radius: 6px;
    padding: 4px;
}

.view-toggle-btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    background-color: transparent;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.view-toggle-btn.active {
    background-color: var(--container-bg);
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* --- DIKTIERGERÄT EDITOR VIEW --- */
.configured-view-wrapper {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.editor-view {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.searchable-dropdown {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
}
.searchable-dropdown > label {
    margin-bottom: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-color);
}
.searchable-dropdown > div {
    position: relative;
}

.search-input-container {
    position: relative;
}

.searchable-dropdown input {
    width: 100%;
    padding: 0.8rem 2.5rem 0.8rem 1rem; /* Add padding for clear button */
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: var(--font-family);
    transition: border-color 0.2s, box-shadow 0.2s;
    background-color: var(--container-bg);
    color: var(--text-color);
}

.searchable-dropdown input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 105, 255, 0.2);
}

.clear-selection-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1;
    padding: 0 5px;
}

.clear-selection-btn:hover {
    color: var(--text-color);
}

.dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--container-bg);
    border: 1px solid var(--border-color);
    border-top: none;
    border-radius: 0 0 6px 6px;
    list-style: none;
    margin-top: -1px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.dropdown-list li {
    padding: 0.75rem 1rem;
    cursor: pointer;
}

.dropdown-list li:hover {
    background-color: #f1f3f5;
}

.dropdown-header {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    background-color: #f8f9fa;
    border-bottom: 1px solid var(--border-color);
    cursor: default;
}


.dropdown-list li.no-results {
    color: var(--text-secondary);
    cursor: default;
    background-color: transparent;
}
.dropdown-list li.no-results:hover {
    background-color: transparent;
}


.dropdown-list li.error {
    color: var(--status-error);
    white-space: normal;
    font-size: 0.9rem;
}

.field-editor {
    display: flex;
    flex-direction: column;
}

.editable-field-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 1.5rem;
}
.editable-field-group:last-child {
    margin-bottom: 0;
}

.editable-field-group label {
    margin-bottom: 0.75rem;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.editable-field-group textarea,
.editable-field-group input {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: var(--font-family);
    transition: border-color 0.2s, box-shadow 0.2s;
    resize: vertical;
    min-height: 44px; /* Align with input height */
    background-color: var(--container-bg);
    color: var(--text-color);
}
.editable-field-group textarea {
    min-height: 120px;
}


.editable-field-group textarea:focus,
.editable-field-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 105, 255, 0.2);
}

.editor-placeholder {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
    background-color: #f8f9fa;
    border-radius: 6px;
    border: 1px dashed var(--border-color);
}

.status-indicator-inline {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}
.status-indicator-inline.saving { background-color: var(--status-saving); }
.status-indicator-inline.saved { background-color: var(--status-saved); }
.status-indicator-inline.error { background-color: var(--status-error); }

.editor-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

.editor-actions button {
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

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

.save-btn:hover {
    background-color: var(--primary-hover);
}

.cancel-btn {
    background-color: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}

.cancel-btn:hover {
    background-color: #f1f3f5;
    color: var(--text-color);
}


/* --- GENERAL DATA TABLE VIEW --- */
.table-view-container {
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Allow table to fill space */
    min-height: 0; /* Important for flexbox scrolling */
}

.add-record-btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 6px;
    background-color: var(--primary-color);
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

.add-record-btn:hover {
    background-color: var(--primary-hover);
}

.add-record-btn.header-btn {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.table-wrapper {
    overflow: auto; /* Changed to auto for better scrollbar handling */
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: var(--container-bg);
    flex-grow: 1; /* Allow wrapper to grow */
    min-height: 0;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th, .data-table td {
    padding: 0.8rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.data-table thead th {
    font-weight: 600;
    background-color: #f8f9fa;
    color: var(--text-secondary);
    font-size: 0.9rem;
    position: sticky;
    top: 0;
    z-index: 10;
}

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

.data-table tbody tr:not(.editing-row):hover {
    background-color: #f1f3f5;
}

.data-table .new-record-row {
    background-color: #eef2ff;
}
.data-table .new-record-row:hover {
    background-color: #e6ecff;
}

.data-table .new-record-row input,
.data-table .inline-input {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid #c7d2fe;
    border-radius: 4px;
    background-color: #fff;
    color: var(--text-color);
}
.data-table .new-record-row input:focus,
.data-table .inline-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 105, 255, 0.2);
}

.data-table .inline-textarea {
    width: 30ch;
    max-width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid #c7d2fe;
    border-radius: 4px;
    background-color: #fff;
    resize: vertical;
    font-family: var(--font-family);
    font-size: inherit;
    color: var(--text-color);
}
.data-table .inline-textarea:focus {
     outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(74, 105, 255, 0.2);
}


.actions-cell {
    white-space: nowrap;
}

.actions-cell button {
    padding: 0.3rem 0.8rem;
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.actions-cell .save-new-btn {
    background-color: var(--status-saved);
    color: white;
    margin-right: 0.5rem;
}
.actions-cell .save-new-btn:hover {
    opacity: 0.85;
}
.actions-cell .cancel-new-btn {
    background-color: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.actions-cell .cancel-new-btn:hover {
    background-color: #e9ecef;
}

.edit-btn {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.edit-btn:hover {
    background-color: #f1f3f5;
    color: var(--text-color);
}

.actions-header {
    width: 150px;
}