/* ==========================================================================
   MySQL Database Studio - Modern Glassmorphism & High Aesthetic CSS
   ========================================================================== */

:root {
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', Consolas, monospace;

    /* Theme: Dark (Default) */
    --bg-main: #0b0f19;
    --bg-card: rgba(18, 24, 38, 0.85);
    --bg-sidebar: rgba(13, 17, 28, 0.95);
    --bg-surface: #151c2e;
    --bg-input: #1a2238;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-highlight: rgba(99, 102, 241, 0.4);
    
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent-blue: #3b82f6;
    --accent-indigo: #6366f1;
    --accent-emerald: #10b981;
    --accent-amber: #f59e0b;
    --accent-rose: #f43f5e;
    --accent-purple: #a855f7;

    --table-header-bg: #141b2d;
    --table-row-hover: rgba(99, 102, 241, 0.08);
    --table-row-alt: rgba(255, 255, 255, 0.015);
    --table-border: rgba(255, 255, 255, 0.06);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px 0 rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 12px 32px 0 rgba(0, 0, 0, 0.5);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

[data-theme="light"] {
    --bg-main: #f8fafc;
    --bg-card: rgba(255, 255, 255, 0.92);
    --bg-sidebar: rgba(248, 250, 252, 0.96);
    --bg-surface: #ffffff;
    --bg-input: #f1f5f9;
    --border-color: rgba(0, 0, 0, 0.08);
    --border-highlight: rgba(99, 102, 241, 0.5);
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;

    --table-header-bg: #e2e8f0;
    --table-row-hover: rgba(99, 102, 241, 0.06);
    --table-row-alt: rgba(0, 0, 0, 0.015);
    --table-border: rgba(0, 0, 0, 0.06);

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px 0 rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 32px 0 rgba(0, 0, 0, 0.12);
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Background Ambient Glows */
.bg-glow {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.glow-1 {
    position: absolute;
    top: -10%;
    left: 15%;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(99, 102, 241, 0.12) 0%, rgba(99, 102, 241, 0) 70%);
    filter: blur(60px);
}

.glow-2 {
    position: absolute;
    bottom: -10%;
    right: 10%;
    width: 700px;
    height: 700px;
    background: radial-gradient(circle, rgba(59, 130, 246, 0.1) 0%, rgba(59, 130, 246, 0) 70%);
    filter: blur(80px);
}

/* Layout App Container */
.app-container {
    position: relative;
    z-index: 1;
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden;
}

/* Sidebar Styles */
.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    backdrop-filter: blur(20px);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s ease;
    z-index: 20;
}

.sidebar-header {
    padding: 1.25rem 1.25rem 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
}

.brand-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent-indigo), var(--accent-blue));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.brand-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.45rem;
    border-radius: 9999px;
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-indigo);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-left: 0.25rem;
}

/* Sidebar Connection Status */
.connection-pill {
    margin: 0.75rem 1.25rem 0.25rem 1.25rem;
    padding: 0.65rem 0.85rem;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
}

.conn-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--accent-emerald);
    box-shadow: 0 0 8px var(--accent-emerald);
}

.conn-host {
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.conn-manage-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    transition: color 0.2s;
}

.conn-manage-btn:hover {
    color: var(--accent-blue);
}

/* Sidebar Search */
.sidebar-search {
    padding: 0.75rem 1.25rem;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-input-wrapper i {
    position: absolute;
    left: 0.75rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 0.5rem 0.75rem 0.5rem 2.2rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    outline: none;
    transition: all 0.2s;
}

.search-input:focus {
    border-color: var(--accent-indigo);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

/* Database Tree View */
.db-explorer {
    flex: 1;
    overflow-y: auto;
    padding: 0 0.75rem 1rem 0.75rem;
}

.db-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.db-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.system-db-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    font-size: 0.68rem;
    text-transform: none;
    color: var(--text-muted);
    user-select: none;
}

.system-db-toggle input {
    accent-color: var(--accent-indigo);
    cursor: pointer;
    width: 13px;
    height: 13px;
}

.system-db-toggle:hover {
    color: var(--text-primary);
}

.icon-btn-ghost {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.icon-btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-surface);
}

.db-item {
    margin-bottom: 0.25rem;
    border-radius: var(--radius-sm);
    transition: background-color 0.15s;
}

.db-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    user-select: none;
    transition: all 0.15s;
}

.db-header:hover {
    background: rgba(255, 255, 255, 0.05);
}

.db-header.active {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-indigo);
    font-weight: 600;
}

.db-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.db-title i {
    font-size: 1rem;
    color: var(--accent-amber);
}

.db-meta-badge {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* Tables Sub-list inside DB */
.table-sublist {
    padding-left: 1.25rem;
    margin-top: 0.15rem;
    display: none;
    border-left: 1px dashed var(--border-color);
    margin-left: 0.85rem;
}

.table-sublist.open {
    display: block;
}

.table-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.35rem 0.5rem;
    margin-bottom: 0.15rem;
    border-radius: var(--radius-sm);
    font-size: 0.825rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.table-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.table-item.active {
    background: linear-gradient(90deg, rgba(99, 102, 241, 0.25), rgba(59, 130, 246, 0.1));
    color: #fff;
    font-weight: 600;
    border-left: 2px solid var(--accent-indigo);
}

.table-item-name {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-item-name i {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.table-rows-count {
    font-size: 0.68rem;
    font-family: var(--font-mono);
    color: var(--text-muted);
}

/* Main Content Area */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: var(--bg-main);
}

/* Top App Navigation Bar */
.top-navbar {
    height: 60px;
    min-height: 60px;
    padding: 0 1.5rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(16px);
    z-index: 10;
}

.breadcrumb-area {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.bc-item {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.bc-item.highlight {
    color: var(--text-primary);
    font-weight: 700;
}

.bc-separator {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Navigation Tabs */
.tabs-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tab-btn {
    padding: 0.75rem 1rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

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

.tab-btn.active {
    color: var(--accent-indigo);
    border-bottom-color: var(--accent-indigo);
}

/* Action Toolbar */
.toolbar-section {
    padding: 0.75rem 1.5rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.85rem;
    font-size: 0.825rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    font-family: var(--font-sans);
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-indigo), var(--accent-blue));
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.35);
}

.btn-primary:hover {
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.5);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-surface);
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.2);
}

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.75rem;
}

.select-dropdown {
    padding: 0.45rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.825rem;
    outline: none;
    cursor: pointer;
}

/* Tab View Container */
.view-panel {
    flex: 1;
    overflow: hidden;
    position: relative;
    display: none;
}

.view-panel.active {
    display: flex;
    flex-direction: column;
}

/* Data Table Container */
.table-responsive-wrapper {
    flex: 1;
    overflow: auto;
    position: relative;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.825rem;
    text-align: left;
    white-space: nowrap;
}

.data-table th {
    position: sticky;
    top: 0;
    background: var(--table-header-bg);
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    border-right: 1px solid var(--table-border);
    cursor: pointer;
    user-select: none;
    z-index: 2;
    transition: background 0.15s;
}

.data-table th:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.th-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.th-sort-icon {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.th-sort-icon.active {
    color: var(--accent-indigo);
}

.data-table td {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--table-border);
    border-right: 1px solid var(--table-border);
    color: var(--text-primary);
    max-width: 350px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.data-table tr:nth-child(even) {
    background-color: var(--table-row-alt);
}

.data-table tr:hover {
    background-color: var(--table-row-hover);
}

.cell-null {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.75rem;
}

.cell-badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    font-family: var(--font-mono);
}

.badge-pk {
    background: rgba(244, 63, 94, 0.15);
    color: var(--accent-rose);
    border: 1px solid rgba(244, 63, 94, 0.3);
}

.badge-mul {
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-uni {
    background: rgba(16, 185, 129, 0.15);
    color: var(--accent-emerald);
    border: 1px solid rgba(16, 185, 129, 0.3);
}

/* Pagination Footer */
.table-footer {
    padding: 0.75rem 1.5rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.825rem;
    color: var(--text-secondary);
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.page-btn {
    min-width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.15s;
}

.page-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--border-highlight);
}

.page-btn.active {
    background: var(--accent-indigo);
    color: #fff;
    border-color: var(--accent-indigo);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* SQL Console Tab */
.sql-console-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    gap: 1rem;
    overflow-y: auto;
}

.sql-editor-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.sql-editor-header {
    padding: 0.65rem 1rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.8rem;
    font-weight: 600;
}

.sql-snippets {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.snippet-tag {
    padding: 0.25rem 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 0.72rem;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-mono);
}

.snippet-tag:hover {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-indigo);
    border-color: var(--accent-indigo);
}

.sql-textarea {
    width: 100%;
    min-height: 140px;
    padding: 1rem;
    background: #0d111c;
    border: none;
    color: #e2e8f0;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.6;
    outline: none;
    resize: vertical;
}

.sql-editor-footer {
    padding: 0.65rem 1rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sql-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.sql-result-card {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    min-height: 250px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

/* Empty & Loading States */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    color: var(--accent-indigo);
    opacity: 0.6;
}

.empty-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(99, 102, 241, 0.2);
    border-top-color: var(--accent-indigo);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Modal Dialog */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.modal-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    transform: scale(0.95);
    transition: transform 0.2s ease;
}

.modal-overlay.open .modal-card {
    transform: scale(1);
}

.modal-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 0.6rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-control:focus {
    border-color: var(--accent-indigo);
}

/* Toast Notification */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    z-index: 200;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toast-success {
    border-left: 4px solid var(--accent-emerald);
}

.toast-error {
    border-left: 4px solid var(--accent-rose);
}

.toast-info {
    border-left: 4px solid var(--accent-blue);
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -320px;
    }
    .sidebar.open {
        transform: translateX(320px);
    }
}
