/* Database Studio Professional Theme Engine */

/* Hide dotnet watch hot-reload error overlay — errors shown in browser devtools instead */
#dotnet-compile-error {
    display: none !important;
}

:root,
:root[data-theme="dark"] {
    --bg-workspace: #1e1e1e;
    --bg-panel: #252526;
    --bg-header: #333333;
    --bg-input: #2d2d2d;
    --bg-modal: #252526;
    --bg-tab-active: #1e1e1e;
    --bg-tab-inactive: #2d2d2d;
    --bg-hover: #37373d;
    --border-color: #3e3e42;
    --border-accent: #007acc;
    --text-primary: #cccccc;
    --text-heading: #ffffff;
    --text-muted: #999999;
    --table-header-bg: #2d2d2d;
    --table-hover-bg: #2a2d2e;
    --status-bar-bg: #007acc;
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --font-code: 'Fira Code', Consolas, Monaco, monospace;
}

:root[data-theme="light"] {
    --bg-workspace: #ffffff;
    --bg-panel: #f3f4f6;
    --bg-header: #e2e8f0;
    --bg-input: #ffffff;
    --bg-modal: #ffffff;
    --bg-tab-active: #ffffff;
    --bg-tab-inactive: #e2e8f0;
    --bg-hover: #cbd5e1;
    --border-color: #cbd5e1;
    --border-accent: #0284c7;
    --text-primary: #1e293b;
    --text-heading: #0f172a;
    --text-muted: #64748b;
    --table-header-bg: #e2e8f0;
    --table-hover-bg: #f1f5f9;
    --status-bar-bg: #0284c7;
}

body.studio-body {
    font-family: var(--font-ui);
    font-size: 13px;
    background-color: var(--bg-workspace);
    color: var(--text-primary);
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    display: flex;
    flex-direction: column;
}

/* Form Controls & Inputs Theme Override */
.studio-body .form-control,
.studio-body .form-select {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.studio-body .form-control:focus,
.studio-body .form-select:focus {
    background-color: var(--bg-input);
    color: var(--text-heading);
    border-color: var(--border-accent);
    box-shadow: 0 0 0 0.2rem rgba(2, 132, 199, 0.25);
}

.studio-body .modal-content {
    background-color: var(--bg-modal);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.studio-body .card {
    background-color: var(--bg-panel);
    color: var(--text-primary);
    border-color: var(--border-color);
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-panel);
}

::-webkit-scrollbar-thumb {
    background: #888888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555555;
}

/* Header Toolbar */
.studio-header {
    background-color: var(--bg-header);
    border-bottom: 1px solid var(--border-color);
    padding: 0 10px;
    position: relative;
    z-index: 100;
}

.studio-header-inner {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
    min-height: 48px;
    gap: 12px;
}

.studio-header-brand-group {
    flex-shrink: 0;
}

.studio-header-selectors {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 1 auto;
}

.studio-header-toolbar {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

#groupSelectConn {
    width: 240px;
    min-width: 160px;
}

#groupSelectDb {
    width: 180px;
    min-width: 130px;
}

.studio-header-user {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Dropdown Menus Theme & Z-Index Fix */
.studio-body .dropdown-menu {
    background-color: var(--bg-modal);
    color: var(--text-primary);
    border-color: var(--border-color);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
    z-index: 2000 !important;
}

.studio-body .dropdown-item {
    color: var(--text-primary);
}

.studio-body .dropdown-item:hover,
.studio-body .dropdown-item:focus {
    background-color: var(--bg-hover);
    color: var(--text-heading);
}

.studio-select-compact {
    font-size: 11px !important;
    padding: 2px 20px 2px 6px !important;
    height: 26px !important;
    line-height: 1.2 !important;
}

/* Pill Group Toolbar Controls */
.studio-pill-group {
    background-color: var(--bg-input);
    border-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.studio-pill-group .input-group-text {
    background-color: var(--bg-panel);
    color: var(--text-muted);
    border-color: var(--border-color);
    font-size: 11px;
}

.studio-pill-group .form-select {
    background-color: var(--bg-input);
    color: var(--text-primary);
    border-color: var(--border-color);
    font-size: 11px;
    font-weight: 500;
}

.studio-pill-group .btn {
    border-color: var(--border-color);
    padding: 2px 7px;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Sidebar Tab Controls */
.studio-sidebar-tabs {
    background-color: var(--bg-tab-inactive);
    border-bottom: 1px solid var(--border-color) !important;
    height: 34px;
}

.studio-sidebar-tabs .nav-item {
    margin-bottom: 0;
}

.studio-sidebar-tabs .nav-link {
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 0 8px;
    border: none;
    border-right: 1px solid var(--border-color);
    border-radius: 0;
    background-color: var(--bg-tab-inactive);
    transition: background-color 0.15s, color 0.15s;
}

.studio-sidebar-tabs .nav-link:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.studio-sidebar-tabs .nav-link.active {
    background-color: var(--bg-panel);
    color: var(--text-heading);
    border-top: 2px solid var(--border-accent);
    font-weight: 600;
}

.cursor-pointer {
    cursor: pointer;
}

.studio-brand {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-heading);
    letter-spacing: 0.5px;
}

.studio-toolbar-btn {
    font-size: 13px;
    padding: 5px 9px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Layout Split Panels */
.studio-main-wrapper {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    display: flex;
    overflow: hidden;
    position: relative;
}

.studio-sidebar {
    width: 280px;
    min-width: 200px;
    max-width: 500px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.25s ease-in-out;
}

.studio-splitter-v {
    width: 5px;
    background-color: var(--border-color);
    cursor: col-resize;
    transition: background-color 0.2s;
    z-index: 10;
}

.studio-splitter-v:hover,
.studio-splitter-v.active {
    background-color: var(--border-accent);
}

.studio-content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.studio-editor-section {
    flex: 1;
    min-height: 120px;
    background-color: var(--bg-workspace);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.studio-splitter-h {
    height: 6px;
    background-color: var(--border-color);
    cursor: row-resize;
    transition: background-color 0.2s;
    z-index: 10;
}

.studio-splitter-h:hover,
.studio-splitter-h.active {
    background-color: var(--border-accent);
}

.studio-results-section {
    height: 280px;
    min-height: 90px;
    max-height: calc(100% - 100px);
    background-color: var(--bg-panel);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

/* Tabs */
.studio-tab-bar {
    background-color: var(--bg-tab-inactive);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    overflow-x: auto;
    white-space: nowrap;
}

.studio-tab {
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text-muted);
    background-color: var(--bg-tab-inactive);
    border-right: 1px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.studio-tab:hover {
    color: var(--text-primary);
    background-color: var(--bg-hover);
}

.studio-tab.active {
    color: var(--text-heading);
    background-color: var(--bg-tab-active);
    border-top: 2px solid var(--border-accent);
    font-weight: 600;
}

.studio-tab .close-tab {
    font-size: 10px;
    border-radius: 50%;
    padding: 2px 4px;
}

.studio-tab .close-tab:hover {
    background-color: rgba(128, 128, 128, 0.3);
}

/* Tree Explorer */
.tree-container {
    padding: 8px;
    overflow-y: auto;
    flex: 1;
}

.tree-node {
    padding: 4px 6px;
    border-radius: 3px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: pan-y;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    color: var(--text-primary);
}

.tree-node:hover {
    background-color: var(--bg-hover);
}

.tree-node.selected {
    background-color: #094771;
    color: #ffffff;
}

.tree-children {
    padding-left: 16px;
    display: none;
}

.tree-children.expanded {
    display: block;
}

/* Data Grid Table */
.grid-container {
    overflow: auto;
    flex: 1;
    font-family: var(--font-code);
    font-size: 12px;
    -webkit-overflow-scrolling: touch;
}

.table-studio {
    margin-bottom: 0;
    color: var(--text-primary);
    border-color: var(--border-color);
}

.table-studio th {
    background-color: var(--table-header-bg);
    color: var(--text-heading);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 5;
    border-bottom: 2px solid var(--border-color);
    user-select: none;
}

.table-studio td {
    border-color: var(--border-color);
    white-space: nowrap;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.table-studio tr:hover td {
    background-color: var(--table-hover-bg);
}

.table-studio tr.selected td {
    background-color: #094771 !important;
    color: #ffffff;
}

/* Status Bar */
.studio-status-bar {
    height: 24px;
    background-color: var(--status-bar-bg);
    color: #ffffff;
    font-size: 11px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 20;
    white-space: nowrap;
    overflow-x: auto;
}

.studio-status-bar.production {
    background-color: #c7254e;
}

/* Context Menu */
.context-menu {
    position: fixed;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    z-index: 2000;
    min-width: 180px;
    padding: 4px 0;
    border-radius: 6px;
}

.context-menu-item {
    padding: 8px 14px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-primary);
    user-select: none;
    -webkit-user-select: none;
}

.context-menu-item:hover {
    background: #094771;
    color: white;
}

.context-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* Code Editor Container */
.monaco-editor-target {
    width: 100%;
    height: 100%;
}

/* ----------------------------------------------------
   Mobile Responsive Layout Rules
---------------------------------------------------- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 24px;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
}

@media (max-width: 768px) {
    .studio-header {
        padding: 6px 8px;
    }

    .studio-header-inner {
        flex-wrap: wrap;
        gap: 6px;
        min-height: unset;
    }

    .studio-header-brand-group {
        order: 1;
    }

    .studio-header-toolbar {
        order: 2;
        margin-left: auto;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .studio-header-user {
        order: 3;
        display: flex;
        align-items: center;
        gap: 4px;
    }

    .studio-header-selectors {
        order: 4;
        width: 100%;
        max-width: 100%;
        display: flex;
        gap: 6px;
        margin-top: 2px;
    }

    #groupSelectConn {
        width: auto;
        flex: 1 1 58%;
        min-width: 0;
    }

    #groupSelectDb {
        width: auto;
        flex: 1 1 38%;
        min-width: 0;
    }

    .studio-select-compact {
        font-size: 11.5px !important;
        padding-left: 5px !important;
        padding-right: 18px !important;
        text-overflow: ellipsis;
        white-space: nowrap;
        height: 30px !important;
    }

    .studio-pill-group .btn {
        padding: 2px 6px !important;
    }

    .studio-splitter-v {
        display: none;
    }

    .studio-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 24px;
        width: 85% !important;
        max-width: 320px;
        z-index: 1050;
        transform: translateX(-100%);
        box-shadow: 4px 0 16px rgba(0, 0, 0, 0.4);
    }

    .studio-sidebar.mobile-open {
        transform: translateX(0);
    }

    .sidebar-backdrop.active {
        display: block;
    }

    .studio-splitter-h {
        height: 10px;
        background-color: var(--border-accent);
    }

    .studio-results-section {
        height: 40% !important;
        min-height: 90px !important;
        max-height: 55% !important;
    }

    .studio-status-bar {
        font-size: 10px;
        padding: 0 6px;
    }
}

/* Extra small button styling for row actions */
.btn-xs {
    padding: 0.15rem 0.35rem;
    font-size: 0.72rem;
    line-height: 1.2;
    border-radius: 0.2rem;
}

.table-studio th {
    font-size: 0.78rem;
    white-space: nowrap;
}

.table-studio td {
    font-size: 0.8rem;
    vertical-align: middle;
}