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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background-color: #f8f9fa;
    color: #333;
}

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: #f8f9fa;
    padding: 20px;
}

.login-wrapper {
    width: 100%;
    max-width: 500px;
}

.login-card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    padding: 50px 40px;
}

.login-logo {
    text-align: center;
    margin-bottom: 40px;
}

.login-logo img {
    max-height: 80px;
    width: auto;
    display: block;
    margin: 0 auto;
}

.login-subtitle {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: #666;
    margin-bottom: 30px;
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header h1 {
    font-size: 24px;
    color: #1a1a1a;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.login-header h1 i {
    color: #5555ff;
    font-size: 20px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-weight: 500;
    color: #333;
    font-size: 14px;
    display: block;
}

.form-group input[type="text"],
.form-group input[type="password"] {
    padding: 12px 14px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 15px;
    transition: all 0.3s ease;
    background-color: #f9f9f9;
}

.form-group input[type="text"]:focus,
.form-group input[type="password"]:focus {
    outline: none;
    border-color: #5555ff;
    background-color: #fff;
    box-shadow: 0 0 0 3px rgba(85, 85, 255, 0.1);
}

.form-group input::placeholder {
    color: #999;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
}

.form-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: #5555ff;
}

.form-checkbox label {
    cursor: pointer;
    font-size: 14px;
    color: #666;
    margin: 0;
    display: block;
}

.error-message {
    padding: 12px 14px;
    background-color: #fee8e8;
    color: #d32f2f;
    border-radius: 8px;
    font-size: 13px;
    border-left: 4px solid #d32f2f;
}

.login-footer {
    text-align: center;
    margin-top: 20px;
}

.login-footer a {
    color: #5555ff;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.3s;
}

.login-footer a:hover {
    color: #4444dd;
    text-decoration: underline;
}

/* Buttons */
.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-block;
}

.btn-primary {
    background-color: #667eea;
    color: white;
}

.btn-primary:hover {
    background-color: #5568d3;
}

.btn-secondary {
    background-color: #ddd;
    color: #333;
}

.btn-secondary:hover {
    background-color: #ccc;
}

.btn-full {
    width: 100%;
    padding: 12px;
    font-size: 16px;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
    padding: 8px 12px;
    font-size: 13px;
}

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

.btn-warning {
    background-color: #f59e0b;
    color: white;
    padding: 8px 12px;
    font-size: 13px;
}

.btn-warning:hover {
    background-color: #d97706;
}

/* Dashboard */
.dashboard-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    background-color: #f5f5f5;
}

.header {
    background: white;
    border-bottom: 1px solid #ddd;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 24px;
    color: #333;
}

/* Navigation Tabs */
.nav-tabs {
    background: white;
    border-bottom: 2px solid #ddd;
    display: flex;
    gap: 0;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 0 20px;
}

.nav-tab {
    padding: 15px 20px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: #666;
    border-bottom: 3px solid transparent;
    transition: all 0.3s;
}

.nav-tab:hover {
    color: #333;
}

.nav-tab.active {
    color: #667eea;
    border-bottom-color: #667eea;
}

/* Tab Content */
.tab-content {
    display: none;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
    padding: 30px 20px;
}

.tab-content.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 20px;
    color: #333;
}

/* Databases List */
.databases-list {
    display: grid;
    gap: 15px;
}

.database-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.database-header {
    background-color: #f9f9f9;
    padding: 15px;
    border-bottom: 1px solid #eee;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.database-header:hover {
    background-color: #f0f0f0;
}

.expand-icon {
    font-size: 20px;
    transition: transform 0.3s;
}

.database-card.expanded .expand-icon {
    transform: rotate(180deg);
}

.database-content {
    display: none;
    padding: 15px;
}

.database-card.expanded .database-content {
    display: block;
}

.tables-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.table-item {
    padding: 10px;
    background-color: #f9f9f9;
    border-left: 3px solid #667eea;
    border-radius: 4px;
    cursor: pointer;
}

.table-item:hover {
    background-color: #f0f0f0;
}

.table-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.fields-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.field-badge {
    background-color: #e8f0ff;
    color: #667eea;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

/* Backups */
.backup-actions {
    background: white;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.upload-progress {
    margin-top: 15px;
    padding: 15px;
    background-color: #f0f0f0;
    border-radius: 6px;
}

.progress-bar {
    width: 100%;
    height: 24px;
    background-color: #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    width: 0%;
    transition: width 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 12px;
}

.progress-text {
    font-size: 13px;
    color: #666;
    text-align: center;
}

.backups-list {
    display: grid;
    gap: 12px;
}

.backup-item {
    background: white;
    padding: 15px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.backup-info {
    flex: 1;
}

.backup-filename {
    font-weight: 600;
    color: #333;
    margin-bottom: 5px;
}

.backup-meta {
    font-size: 12px;
    color: #666;
    display: flex;
    gap: 15px;
}

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

.backup-actions-group .btn {
    padding: 8px 12px;
    font-size: 12px;
}

/* Loading and Toast */
.loading {
    text-align: center;
    padding: 30px;
    color: #666;
}

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 15px 20px;
    background-color: #333;
    color: white;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    max-width: 400px;
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
}

.toast.success {
    background-color: #28a745;
}

.toast.error {
    background-color: #dc3545;
}

.toast.info {
    background-color: #17a2b8;
}

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

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    gap: 5px;
    margin-top: 20px;
}

.pagination button {
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    border-radius: 4px;
}

.pagination button.active {
    background-color: #667eea;
    color: white;
    border-color: #667eea;
}

/* Records Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    max-width: 95vw;
    max-height: 90vh;
    width: 100%;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
    color: #333;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: #333;
}

.modal-body {
    flex: 1;
    overflow: auto;
    padding: 20px;
}

.records-stats {
    margin-bottom: 15px;
    padding: 12px;
    background-color: #f0f0f0;
    border-radius: 4px;
    font-size: 13px;
    color: #666;
}

.records-table-container {
    overflow-x: auto;
}

.records-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.records-table thead {
    background-color: #f9f9f9;
    border-bottom: 2px solid #ddd;
}

.records-table th {
    padding: 10px;
    text-align: left;
    font-weight: 600;
    color: #333;
    white-space: nowrap;
}

.records-table td {
    padding: 10px;
    border-bottom: 1px solid #eee;
    color: #333;
    word-break: break-word;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.records-table tbody tr:hover {
    background-color: #f9f9f9;
}

.records-table td.null-value {
    color: #999;
    font-style: italic;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.page-info {
    min-width: 120px;
    text-align: center;
    font-size: 13px;
    color: #666;
}

.records-per-page {
    display: flex;
    align-items: center;
    gap: 10px;
}

.records-per-page label {
    font-size: 13px;
    color: #666;
    margin: 0;
}

.records-per-page select {
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
}

/* Search Section */
.search-section {
    margin-bottom: 20px;
    background-color: #f9f9f9;
    border-radius: 4px;
    border: 1px solid #eee;
}

.search-header {
    padding: 12px;
    background-color: #f0f0f0;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.search-header h3 {
    margin: 0;
    font-size: 14px;
    color: #333;
    font-weight: 600;
}

.btn-sm {
    padding: 4px 8px;
    font-size: 12px;
}

.search-form {
    padding: 15px;
}

.search-filters {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.search-filter-row {
    display: grid;
    grid-template-columns: 1fr 1fr 2fr auto;
    gap: 10px;
    align-items: center;
}

.search-filter-row select,
.search-filter-row input {
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.search-filter-row input {
    min-width: 150px;
}

.search-buttons {
    display: flex;
    gap: 10px;
}

.search-buttons .btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 13px;
}

/* Responsive */
@media (max-width: 768px) {
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .databases-list {
        grid-template-columns: 1fr;
    }

    .fields-list {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }

    .backup-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .backup-actions-group {
        width: 100%;
    }

    .backup-actions-group .btn {
        flex: 1;
    }

    .modal-content {
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }

    .modal-footer {
        flex-direction: column;
        align-items: stretch;
    }

    .pagination-controls {
        flex-direction: column;
        width: 100%;
    }

    .page-info {
        width: 100%;
    }

    .pagination-controls .btn {
        width: 100%;
    }

    .records-table td {
        max-width: 150px;
        font-size: 12px;
    }

    .search-filter-row {
        grid-template-columns: 1fr;
        gap: 5px;
    }

    .search-filter-row select,
    .search-filter-row input,
    .search-filter-row button {
        width: 100%;
    }
/* Manual Query Tab */
.query-container {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
    margin-top: 10px;
}

.query-db-selector {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #fff;
    padding: 8px 15px;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.query-db-selector label {
    font-size: 14px;
    font-weight: 600;
    color: #444;
}

.query-db-selector select {
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background-color: #f9f9f9;
    cursor: pointer;
    min-width: 200px;
}

.query-editor-wrapper {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-bottom: 25px;
}

#sqlQueryInput {
    width: 100%;
    height: 180px;
    padding: 15px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.6;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    background-color: #fafbfc;
    resize: vertical;
    color: #2c3e50;
    transition: all 0.3s ease;
}

#sqlQueryInput:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
    background-color: #fff;
}

.query-actions {
    display: flex;
    gap: 12px;
}

.query-actions .btn {
    padding: 10px 24px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

#queryResultStatus {
    margin: 20px 0;
    padding: 15px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
    border-left: 5px solid;
}

.search-filter-row {
    display: grid;
    grid-template-columns: 1fr 140px 2fr 45px;
    gap: 12px;
    align-items: center;
    background: #fdfdfd;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #f0f0f0;
}

.search-filter-row select, 
.search-filter-row input {
    height: 38px;
}

.search-filter-row .btn-danger {
    height: 38px;
    width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-radius: 6px;
}

    .search-buttons {
        flex-direction: column;
    }
}

/* ── Access Control / Whitelist ─────────────────────────────────────────── */
.whitelist-form {
    margin-bottom: 20px;
}
.whitelist-form-inner {
    background: #f8f9fb;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 20px 24px;
}
.whitelist-form-inner h3 {
    margin: 0 0 16px;
    font-size: 15px;
    font-weight: 600;
    color: #1e293b;
}
.form-row {
    display: grid;
    grid-template-columns: 140px 1fr 1fr;
    gap: 16px;
    margin-bottom: 14px;
}
.form-actions {
    display: flex;
    gap: 10px;
}
.whitelist-legend {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    font-size: 13px;
    color: #64748b;
}
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .3px;
}
.badge-ip      { background: #dbeafe; color: #1d4ed8; }
.badge-domain  { background: #d1fae5; color: #065f46; }
.badge-enabled { background: #dcfce7; color: #166534; }
.badge-disabled{ background: #fee2e2; color: #991b1b; }

.whitelist-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.whitelist-entry {
    display: grid;
    grid-template-columns: 90px 1fr 1fr auto;
    align-items: center;
    gap: 16px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 12px 16px;
    transition: box-shadow .15s;
}
.whitelist-entry:hover {
    box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.whitelist-entry.disabled-entry {
    opacity: .55;
    background: #f8f8f8;
}
.wl-value {
    font-family: monospace;
    font-size: 14px;
    font-weight: 600;
    color: #1e293b;
}
.wl-desc {
    font-size: 13px;
    color: #64748b;
}
.wl-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}
.btn-toggle {
    padding: 4px 12px;
    font-size: 12px;
    border-radius: 6px;
    border: 1px solid;
    cursor: pointer;
    font-weight: 500;
}
.btn-toggle.enabled  { background:#dcfce7; color:#166534; border-color:#86efac; }
.btn-toggle.disabled { background:#fee2e2; color:#991b1b; border-color:#fca5a5; }
.btn-icon {
    background: none;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #64748b;
    transition: all .15s;
}
.btn-icon:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
