﻿/* =========================
   Global / Template Fixes
   ========================= */

html, body {
    margin: 0;
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

/* Box sizing prevents 1–2px overflow surprises */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Default: allow normal scrolling */
body {
    overflow: auto;
}

/* Query Tool Page: Detect presence of .tool-viewport using :has() selector */
/* When .tool-viewport exists, make parent chain fill viewport height */
body:has(.tool-viewport) {
    height: 100vh;
    overflow: hidden;
}

body:has(.tool-viewport) #app,
body:has(.tool-viewport) main,
body:has(.tool-viewport) .mud-main-content {
    height: 100%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Top bar can stay its natural height */
.top-row {
    flex: 0 0 auto;
}

/* The content/article area must be allowed to shrink (min-height:0),
   otherwise your grid children can't scroll and will overflow the page. */
.content,
main > .content,
article.content {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    padding-top: 0 !important; /* remove template padding that can cause overflow */
}

/* Keep your existing link/button styling */
a, .btn-link {
    color: #006bb7;
}

.btn-primary {
    color: #fff;
    background-color: #1b6ec2;
    border-color: #1861ac;
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus,
.form-control:focus, .form-check-input:focus {
    box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

/* Optional validation styles you already had */
.valid.modified:not([type=checkbox]) {
    outline: 1px solid #26b050;
}

.invalid {
    outline: 1px solid #e50000;
}

.validation-message {
    color: #e50000;
}

/* Error boundary (unchanged) */
.blazor-error-boundary {
    background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSI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LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
    padding: 1rem 1rem 1rem 3.7rem;
    color: white;
}

    .blazor-error-boundary::after {
        content: "An error has occurred.";
    }

/* =========================
   Query Tool Layout (SSMS-ish)
   ========================= */

/* Ensure MudLayout respects viewport width */
.mud-layout {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
}

/* Remove MudBlazor's default padding on MainContent for query tool */
.mud-main-content {
    padding: 0 !important;
    height: 100%;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Account for the MudAppBar which has fixed positioning */
    padding-top: 48px !important;
}

/* IMPORTANT: this must be 100%, NOT 100vh, because it's inside the layout */
.tool-viewport {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

/* Main 2-column shell */
.shell {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    height: 100%;
    min-height: 0;
    width: 100%;
    max-width: 100%;
    gap: 10px;
    padding: 10px;
    overflow: hidden;
    transition: grid-template-columns 0.3s ease;
}

/* Left explorer - Now using MudPaper, styles removed */

/* Right side: toolbar1 + toolbar2 + tabs-toolbar + editor + splitter + bottom */
.right.right-split {
    height: 100%;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    display: grid;
    gap: 10px;
    /* toolbar1 | toolbar2 | tabs-toolbar | editor | splitter | bottom */
    /* Account for 2 toolbars (~48px each) + tabs toolbar (~40px) + splitter (8px) + 4 gaps (40px) = ~184px fixed overhead */
    /* Use calc to subtract fixed overhead from percentage calculations */
    grid-template-rows: auto auto auto minmax(140px, calc((100% - 184px) * var(--editorPct, 65) / 100)) 8px minmax(140px, calc((100% - 184px) * (100 - var(--editorPct, 65)) / 100));
}

/* Right side (single toolbar): toolbar + tabs-toolbar + editor + splitter + bottom */
.right.right-split-single-toolbar {
    height: 100%;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    display: grid;
    gap: 10px;
    /* toolbar | tabs-toolbar | editor | splitter | bottom */
    /* Account for 1 toolbar (~48px) + tabs toolbar (~40px) + splitter (8px) + 3 gaps (30px) = ~126px fixed overhead */
    /* Use calc to subtract fixed overhead from percentage calculations */
    grid-template-rows: auto auto minmax(140px, calc((100% - 126px) * var(--editorPct, 65) / 100)) 8px minmax(140px, calc((100% - 126px) * (100 - var(--editorPct, 65)) / 100));
}


/* Toolbar - Now using MudToolBar component */
/* .editor-bar styles removed - MudToolBar provides its own styling */

/* Regions must allow internal scrolling */
.editor-region,
.bottom-region {
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

/* Monaco host */
.editor-host {
    height: 100%;
    width: 100%;
    min-height: 0;
    border: 1px solid var(--mud-palette-divider);
    background: var(--mud-palette-surface);
}

/* Splitter */
.splitter {
    height: 8px;
    cursor: row-resize;
    background: linear-gradient(to bottom, transparent 0, #cfcfcf 50%, transparent 100%);
    border-radius: 4px;
    user-select: none;
}

    .splitter:hover {
        background: linear-gradient(to bottom, transparent 0, #9aa7b2 50%, transparent 100%);
    }

/* Bottom pane (Results / Messages tabs) */
.bottom-pane {
    height: 100%;
    min-height: 0;
    min-width: 0;
    max-width: 100% !important;
    width: 100% !important;
    border: 1px solid var(--mud-palette-divider);
    background: var(--mud-palette-surface);
    display: grid;
    grid-template-rows: auto 1fr;
    overflow: hidden;
}


.tab-body {
    min-height: 0;
    min-width: 0;
    max-width: 100% !important;
    width: 100% !important;
    overflow: hidden;
    padding: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Messages */
.messages-pane {
    font-family: Consolas, monospace;
    font-size: 12px;
    padding: 6px;
}

.msg-row {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 10px;
    padding: 4px 6px;
    white-space: pre-wrap;
    border-radius: 3px;
    margin-bottom: 2px;
    color: var(--mud-palette-text-primary, #E0E0E0) !important;
    background: var(--mud-palette-surface, #1E1E1E) !important;
}

.msg-time {
    opacity: 0.7;
    color: var(--mud-palette-text-primary, #E0E0E0) !important;
}

.msg-text {
    word-break: break-word;
    color: var(--mud-palette-text-primary, #E0E0E0) !important;
}

/* Message severity colors */
.msg-row.info {
    background-color: rgba(33, 150, 243, 0.08) !important;
    border-left: 3px solid #2196F3 !important;
}

.msg-row.success {
    background-color: rgba(76, 175, 80, 0.08) !important;
    border-left: 3px solid #4CAF50 !important;
}

.msg-row.warning {
    background-color: rgba(255, 152, 0, 0.08) !important;
    border-left: 3px solid #FF9800 !important;
}

.msg-row.error {
    background-color: rgba(244, 67, 54, 0.08) !important;
    border-left: 3px solid #f44336 !important;
    font-weight: 500;
}

/* Tree styling */
.tree-row {
    padding: 4px 8px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    overflow: visible;
}

    .tree-row:hover {
        background: var(--mud-palette-action-default-hover);
    }

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

.tree-icon {
    display: inline-block;
    width: 22px;
}

/* Optional debug pre */
.debug {
    background: #111;
    color: #0f0;
    padding: 10px;
    margin-top: 8px;
    max-height: 200px;
    overflow: auto;
    font-family: Consolas, monospace;
    font-size: 12px;
    border: 1px solid #444;
}

/* Tree spinner removed - now using MudProgressCircular */

/* =========================
   MudBlazor Component Overrides
   =========================

   Minimal overrides to prevent width overflow while letting MudBlazor handle its own scrolling.
*/

/* Prevent horizontal overflow only - let MudBlazor handle vertical */
.mud-table-container,
.mud-table-root,
.mud-table {
    max-width: 100% !important;
    min-width: 0 !important;
}

/* MudDataGrid sizing: avoid nested scrollbars and keep the grid within its parent */
.mud-data-grid {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.mud-data-grid .mud-table-container {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}

/* MudToolBar: Prevent toolbar from forcing parent expansion */
.mud-toolbar {
    max-width: 100% !important;
    min-width: 0 !important;
    flex-wrap: nowrap !important;
}

/* Stored procedure compare view */
.diff-view {
    border: 1px solid var(--mud-palette-divider, #e0e0e0);
    border-radius: 4px;
    height: 60vh;
    overflow: hidden;
    font-family: Consolas, monospace;
    font-size: 12px;
    background: var(--mud-palette-surface, #ffffff);
}

.diff-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    height: 100%;
}

.diff-pane {
    overflow-y: auto;
    overflow-x: auto;
}

.diff-pane-right {
    overflow-x: hidden;
}

.diff-row {
    display: grid;
    grid-template-columns: 48px 1fr;
    border-bottom: 1px solid var(--mud-palette-divider, #e0e0e0);
    min-width: max-content;
}

.diff-line-number {
    text-align: right;
    padding: 2px 6px;
    color: var(--mud-palette-text-secondary, #666666);
    background: rgba(0, 0, 0, 0.02);
    user-select: none;
}

.diff-cell {
    padding: 2px 6px;
    white-space: pre;
    overflow: visible;
}

.diff-left-only .diff-cell,
.diff-left-only .diff-line-number {
    background: rgba(244, 67, 54, 0.08);
}

.diff-right-only .diff-cell,
.diff-right-only .diff-line-number {
    background: rgba(76, 175, 80, 0.08);
}

/* SQL Operations Toolbar - Remove gap above to stick to environment toolbar */
.sql-operations-toolbar {
    margin-top: -10px !important;
}

/* SQL Operations Toolbar (Standalone) - When environment toolbar is collapsed, don't adjust margin */
.sql-operations-toolbar-standalone {
    /* No margin adjustment needed */
}

/* =========================
   Tab Styling (Squared Appearance)
   ========================= */

/* Make MudTabs more squared and less rounded */
.mud-tabs .mud-tab {
    border-radius: 0 !important;
    min-height: 36px;
    padding: 6px 12px;
}

.mud-tabs .mud-tab-active {
    border-bottom: 2px solid var(--mud-palette-primary) !important;
}

/* Remove default border radius from tab panels */
.mud-tabs .mud-tabs-toolbar {
    border-radius: 0 !important;
}

