:root {
  --app-bg: #eef3f8;
  --app-surface: #ffffff;
  --app-surface-soft: #f7f9fc;
  --app-text: #162032;
  --app-muted: #5f6f86;
  --app-border: #d7e0eb;
  --app-accent: #0f6cbd;
  --app-accent-deep: #0a4f8a;
  --app-success: #16794d;
  --app-shadow: 0 14px 34px rgba(15, 32, 55, 0.08);
  --editor-panel-height: 34rem;
}

html {
  font-size: 15px;
  min-height: 100%;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(15, 108, 189, 0.08), transparent 32%),
    linear-gradient(180deg, #f7f9fc 0%, var(--app-bg) 100%);
  color: var(--app-text);
  display: flex;
  flex-direction: column;
}

body.theme-dark {
  --app-bg: #0f1723;
  --app-surface: #152233;
  --app-surface-soft: #1c2d42;
  --app-text: #e8f0fa;
  --app-muted: #9fb1c8;
  --app-border: #2a405b;
  --app-accent: #4ba3ff;
  --app-accent-deep: #8bc2ff;
  --app-success: #29a36a;
  --app-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

body.theme-dark .text-muted,
body.theme-dark .text-muted.small {
  color: var(--app-muted) !important;
}

body.theme-dark .alert-success {
  background-color: #183a2e;
  border-color: #2a6b55;
  color: #daf5e8;
}

body.theme-dark .alert-danger {
  background-color: #472028;
  border-color: #8a3a48;
  color: #ffe0e6;
}

body.theme-dark .alert-info {
  background-color: #1f3951;
  border-color: #315374;
  color: #ddebff;
}

body.theme-dark .alert-warning {
  background-color: #4a3c1f;
  border-color: #8d6f30;
  color: #fff0cc;
}

main {
  width: 100%;
}

body > .container,
body > .container-fluid {
  flex: 1 0 auto;
}

.app-shell {
  max-width: 1320px;
}

.app-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
}

.helper-select {
  min-width: 10rem;
  width: 10rem;
}

.active-connection-select {
  min-width: 20rem;
  max-width: 30rem;
}

.add-connection-header {
  padding-top: 0.75rem !important;
  padding-bottom: 0.75rem !important;
}

.add-connection-toggle {
  min-width: 5.5rem;
}

.session-card-body {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  align-items: center;
}

.session-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  justify-content: flex-end;
}

.session-switch-form {
  display: flex;
  gap: 0.55rem;
  align-items: center;
}

.session-action-button {
  min-height: 2.45rem;
  padding: 0.5rem 0.9rem;
  border-radius: 0.7rem;
}

.app-navbar {
  background: linear-gradient(135deg, #16212f 0%, #21344b 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 24px rgba(9, 18, 30, 0.18);
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.8rem;
  color: #f8fbff;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.app-brand:hover,
.app-brand:focus {
  color: #f8fbff;
}

.app-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.15rem;
  height: 2.15rem;
  border-radius: 0.65rem;
  background: linear-gradient(135deg, #38a3ff 0%, #0f6cbd 100%);
  color: #fff;
  font-size: 0.85rem;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.app-logout-button {
  border-color: rgba(255, 255, 255, 0.35);
}

.app-nav-toggle {
  border-color: rgba(255, 255, 255, 0.35);
  color: #f8fbff;
}

.app-nav-toggle:hover,
.app-nav-toggle:focus {
  color: #f8fbff;
  background-color: rgba(255, 255, 255, 0.08);
}

.page-hero {
  padding: 1.5rem 1.75rem;
  border: 1px solid rgba(15, 108, 189, 0.15);
  border-radius: 0.9rem;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96) 0%, rgba(244, 249, 255, 0.95) 100%);
  box-shadow: var(--app-shadow);
}

.page-hero-kicker {
  margin-bottom: 0.4rem;
  color: var(--app-accent-deep);
  font-size: 0.77rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.page-hero-title {
  margin: 0 0 0.45rem;
  font-size: 2rem;
  font-weight: 700;
}

.page-hero-copy {
  color: var(--app-muted);
  max-width: 52rem;
}

.btn:focus,
.btn:active:focus,
.btn-link.nav-link:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 0.12rem #ffffff, 0 0 0 0.25rem rgba(15, 108, 189, 0.24);
}

textarea.form-control {
  min-height: 22rem;
  resize: vertical;
}

.card {
  border: 1px solid var(--app-border);
  border-radius: 0.9rem;
  overflow: hidden;
}

.editor-results-stack {
  display: grid;
  gap: 0.85rem;
  --editor-panel-height: 34rem;
}

.editor-results-stack > .app-card:first-child {
  min-height: var(--editor-panel-height);
}

.split-handle {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(15, 108, 189, 0.12), rgba(15, 108, 189, 0.3), rgba(15, 108, 189, 0.12));
  cursor: row-resize;
}

body.is-resizing {
  user-select: none;
  cursor: row-resize;
}

.app-card {
  box-shadow: var(--app-shadow);
  background: var(--app-surface);
}

.app-card .card-header {
  padding: 0.95rem 1.1rem;
  background: linear-gradient(180deg, var(--app-surface-soft) 0%, #f1f5f9 100%);
  border-bottom: 1px solid var(--app-border);
  color: #21344b;
  font-weight: 700;
}

.script-runner-header {
  padding-top: 0.65rem !important;
  padding-bottom: 0.65rem !important;
}

.app-card .card-body {
  padding: 1.15rem;
}

.form-label {
  color: #31445d;
  font-weight: 600;
  font-size: 0.92rem;
}

.form-control,
.form-select {
  border-color: var(--app-border);
  border-radius: 0.7rem;
  background-color: #fcfdff;
  min-height: 2.9rem;
}

.btn {
  border-radius: 0.7rem;
  font-weight: 600;
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    color 0.18s ease,
    box-shadow 0.18s ease,
    transform 0.12s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--app-accent) 0%, #2487df 100%);
  border-color: var(--app-accent);
  color: #fff;
}

.btn-success {
  background: linear-gradient(135deg, var(--app-success) 0%, #1f8f5d 100%);
  border-color: var(--app-success);
  color: #fff;
}

.btn:hover {
  transform: translateY(-1px);
}

.app-warning-banner {
  border: 1px solid #f0d38a;
  border-radius: 0.85rem;
  background: linear-gradient(90deg, #fff4cf 0%, #fff8e5 100%);
}

.sql-script-editor {
  line-height: 1.5;
  white-space: pre;
  background: transparent;
}

.result-page-size {
  width: 5.5rem;
}

.query-tabs-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.query-tabs-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.query-tabs-tools .btn-sm,
.query-tabs-tools .form-select-sm {
  height: 2rem;
}

.query-tabs-tools .form-select-sm {
  min-height: 2rem;
  padding-top: 0.2rem;
  padding-bottom: 0.2rem;
}

.query-tabs-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.query-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.3rem 0.2rem 0.6rem;
  border: 1px solid var(--app-border);
  border-radius: 999px;
  background: var(--app-surface-soft);
}

.query-tab.is-active {
  border-color: rgba(15, 108, 189, 0.3);
  background: rgba(15, 108, 189, 0.12);
}

.query-tab-button,
.query-tab-close {
  border: 0;
  background: transparent;
  color: inherit;
}

.query-tab-close {
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 999px;
}

.sql-editor-shell {
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  border: 1px solid var(--app-border);
  border-radius: 0.8rem;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(15, 108, 189, 0.05), rgba(15, 108, 189, 0.02));
}

.sql-editor-lines {
  padding: 0.85rem 0.6rem;
  background: rgba(15, 108, 189, 0.08);
  color: var(--app-muted);
  text-align: right;
  overflow: hidden;
  font: 0.95rem/1.5 Consolas, "Courier New", monospace;
}

.sql-editor-lines span {
  display: block;
}

.sql-editor-stage {
  position: relative;
  min-height: 22rem;
}

.sql-editor-highlight,
.sql-editor-input {
  margin: 0;
  padding: 0.85rem 1rem;
  width: 100%;
  min-height: 22rem;
  font: 0.95rem/1.5 Consolas, "Courier New", monospace;
  white-space: pre-wrap;
  overflow: auto;
}

.sql-editor-highlight {
  position: absolute;
  inset: 0;
  pointer-events: none;
  color: #24384f;
}

.sql-editor-input {
  position: relative;
  z-index: 1;
  border: 0;
  border-radius: 0;
  color: transparent;
  caret-color: var(--app-text);
  text-shadow: 0 0 0 var(--app-text);
  background: transparent;
}

.sql-editor-input:focus {
  box-shadow: none;
}

.sql-token-keyword {
  color: #0f6cbd;
  font-weight: 700;
}

.sql-token-string {
  color: #a43e2f;
}

.sql-token-number {
  color: #7357ff;
}

.sql-token-comment {
  color: #6d7d92;
  font-style: italic;
}

body.theme-dark .sql-editor-highlight {
  color: #d9e8f8;
}

body.theme-dark .sql-token-keyword {
  color: #7fc0ff;
}

body.theme-dark .sql-token-string {
  color: #ffb98e;
}

body.theme-dark .sql-token-number {
  color: #b8a7ff;
}

body.theme-dark .sql-token-comment {
  color: #7f93ad;
}

.sql-autocomplete-panel {
  position: absolute;
  right: 1rem;
  bottom: 1rem;
  z-index: 3;
  display: none;
  width: 14rem;
  max-height: 14rem;
  overflow: auto;
  border: 1px solid var(--app-border);
  border-radius: 0.7rem;
  background: var(--app-surface);
  box-shadow: var(--app-shadow);
}

.sql-autocomplete-panel.is-visible {
  display: block;
}

.sql-autocomplete-item {
  display: block;
  width: 100%;
  padding: 0.55rem 0.8rem;
  border: 0;
  background: transparent;
  text-align: left;
  color: inherit;
}

.sql-autocomplete-item:hover {
  background: rgba(15, 108, 189, 0.08);
}

.execution-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.result-tabs {
  border-bottom-color: var(--app-border);
}

.result-tabs .nav-link {
  color: #4b5e78;
  border-radius: 0.7rem 0.7rem 0 0;
}

.result-tabs .nav-link.active {
  color: var(--app-accent-deep);
  background-color: #f7fbff;
  border-color: var(--app-border) var(--app-border) #f7fbff;
}

.result-action-col {
  width: 7rem;
  white-space: nowrap;
}

.copyable-cell {
  cursor: copy;
}

.copyable-cell.copied {
  background: rgba(41, 163, 106, 0.18);
}

.xml-plan-block {
  margin: 0;
  max-height: 30rem;
  overflow: auto;
  padding: 0.9rem;
  border: 1px solid var(--app-border);
  border-radius: 0.7rem;
  background: var(--app-surface-soft);
  font: 0.85rem/1.45 Consolas, "Courier New", monospace;
  white-space: pre;
}

.connection-summary {
  display: grid;
  gap: 0.55rem;
}

.summary-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--app-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.summary-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.summary-chip {
  display: inline-flex;
  align-items: center;
  min-height: 2rem;
  padding: 0.35rem 0.7rem;
  border: 1px solid #d6e3f0;
  border-radius: 999px;
  background: #f6faff;
  color: #24415f;
  font-size: 0.9rem;
}

.table {
  margin-bottom: 0;
}

.table thead th {
  background-color: #eff5fb;
  color: #26415d;
  font-weight: 700;
  white-space: nowrap;
}

.table td {
  vertical-align: middle;
}

.footer {
  background-color: rgba(255, 255, 255, 0.85);
  flex-shrink: 0;
}

body.theme-dark .app-navbar {
  background: linear-gradient(135deg, #08111b 0%, #102032 100%);
}

body.theme-dark .app-card,
body.theme-dark .app-warning-banner,
body.theme-dark .footer,
body.theme-dark .page-hero,
body.theme-dark .query-tab,
body.theme-dark .sql-editor-shell {
  background-color: var(--app-surface);
}

body.theme-dark .app-card .card-header,
body.theme-dark .summary-chip,
body.theme-dark .table thead th {
  background: var(--app-surface-soft);
  color: var(--app-text);
}

body.theme-dark .form-control,
body.theme-dark .form-select,
body.theme-dark .query-tab,
body.theme-dark .sql-autocomplete-panel {
  color: var(--app-text);
  background-color: #122032;
  border-color: var(--app-border);
}

body.theme-dark .sql-editor-lines {
  background: rgba(255, 255, 255, 0.03);
}

body.theme-dark .table td,
body.theme-dark .table th {
  background-color: transparent;
  color: var(--app-text);
}

body.theme-dark .form-label,
body.theme-dark .form-check-label {
  color: #dce8f7;
}

body.theme-dark .btn-primary {
  background: linear-gradient(135deg, #2a8fff 0%, #4fb0ff 100%);
  border-color: #58b6ff;
  color: #06172a;
  box-shadow: 0 10px 20px rgba(27, 128, 230, 0.32);
}

body.theme-dark .btn-primary:hover,
body.theme-dark .btn-primary:focus {
  background: linear-gradient(135deg, #3d9bff 0%, #66bcff 100%);
  border-color: #7ac6ff;
  color: #041223;
}

body.theme-dark .btn-success {
  background: linear-gradient(135deg, #24b374 0%, #38c98a 100%);
  border-color: #42d291;
  color: #041e15;
  box-shadow: 0 10px 20px rgba(20, 163, 104, 0.3);
}

body.theme-dark .btn-success:hover,
body.theme-dark .btn-success:focus {
  background: linear-gradient(135deg, #2ec181 0%, #4fda9d 100%);
  border-color: #68e5af;
  color: #032016;
}

body.theme-dark .btn-outline-secondary {
  color: #dceaff;
  border-color: #6f8aad;
  background-color: rgba(163, 190, 220, 0.08);
}

body.theme-dark .btn-outline-secondary:hover,
body.theme-dark .btn-outline-secondary:focus {
  color: #ffffff;
  border-color: #90abd0;
  background-color: rgba(163, 190, 220, 0.2);
}

.validation-summary-valid {
  display: none;
}

.auto-dismiss-alert {
  overflow: hidden;
  transition:
    opacity 0.4s ease,
    transform 0.4s ease,
    max-height 0.4s ease,
    margin 0.4s ease,
    padding 0.4s ease;
  max-height: 8rem;
}

.auto-dismiss-alert.is-hiding {
  opacity: 0;
  transform: translateY(-8px);
  max-height: 0;
  margin-top: 0;
  margin-bottom: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-width: 0;
}

@media (max-width: 767.98px) {
  .active-connection-select {
    min-width: 100%;
    max-width: 100%;
  }

  .session-card-body,
  .session-controls,
  .session-switch-form {
    width: 100%;
  }

  .session-controls {
    justify-content: stretch;
    gap: 0.45rem;
  }

  .session-controls form {
    width: 100%;
  }

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

  .page-hero {
    padding: 1.2rem 1rem;
  }

  .page-hero-title {
    font-size: 1.65rem;
  }

  .app-card .card-body {
    padding: 1rem;
  }
}
