/* =========================================================================
   Universal Database Connector — stylesheet
   Designed & developed by Continuum AI · continuumai.io · Powered by Midas
   ========================================================================= */

:root {
  --bg: #0a0c12;
  --bg-raised: #0e111a;
  --bg-sidebar: #0c0f16;
  --bg-surface: #141824;
  --bg-surface-hover: #1a2030;
  --bg-input: #10141d;

  --border: #202634;
  --border-soft: #171b26;

  --text: #e8eaf1;
  --text-dim: #9aa2b6;
  --text-faint: #5c6478;

  --accent: #5b6eea;
  --accent-hover: #7686f2;
  --accent-soft: rgba(91, 110, 234, 0.14);
  --accent-contrast: #ffffff;

  --success: #35d399;
  --danger: #f0645f;
  --danger-soft: rgba(240, 100, 95, 0.12);
  --warning: #eab308;

  --radius-sm: 4px;
  --radius-md: 7px;
  --radius-lg: 10px;

  --font-sans: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* aliases expected verbatim by app.js's inline styles — keep in sync */
  --sans: var(--font-sans);
  --text-muted: var(--text-faint);

  --shadow-modal: 0 24px 60px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-card: 0 10px 24px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 34px); /* leaves room for the footer credit bar */
  min-height: 480px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

::selection { background: var(--accent-soft); color: var(--text); }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: var(--radius-sm); }

button { font-family: inherit; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------------------------------------------------------------- titlebar */

.titlebar {
  flex: 0 0 auto;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.titlebar__brand { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.titlebar__mark { display: inline-flex; color: var(--accent); position: relative; top: 1px; flex: 0 0 auto; }

.titlebar__name {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.titlebar__badge {
  margin-left: 9px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--text-faint);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 20px;
  vertical-align: middle;
}

.titlebar__status {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- layout */

.workspace { flex: 1 1 auto; display: flex; min-height: 0; }

.sidebar {
  flex: 0 0 270px;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.sidebar__head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px 9px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

.sidebar__tree {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 0 12px;
}

.empty-hint {
  margin: 10px 12px;
  padding: 14px 12px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.5;
}

/* ---------------------------------------------------------------- connection tree */
/* Hierarchy: .conn-node (connection) > .tree-children > .schema-row (database)
   + sibling .tree-children > .table-row (table). Nesting compounds the
   indentation automatically; a guide line marks each level. */

.conn-row,
.schema-row,
.table-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.conn-row:hover,
.schema-row:hover,
.table-row:hover { background: var(--bg-surface-hover); color: var(--text); }

.conn-row.is-active,
.table-row.is-active {
  background: var(--accent-soft);
  color: var(--text);
}
.table-row.is-active .table-row__name { font-weight: 600; }

.conn-row__chevron,
.schema-row > svg:first-child {
  flex: 0 0 auto;
  color: var(--text-faint);
  transition: transform 140ms ease;
}
.conn-row__chevron.is-open { transform: rotate(90deg); }

.conn-row__dot {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
}
.conn-row__dot.is-connected { background: var(--success); box-shadow: 0 0 0 3px rgba(53, 211, 153, 0.15); }
.conn-row__dot.is-error { background: var(--danger); box-shadow: 0 0 0 3px rgba(240, 100, 95, 0.15); }

.conn-row__name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; }

.conn-row__type {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-faint);
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conn-row__gear {
  flex: 0 0 auto;
  display: flex;
  color: var(--text-faint);
  opacity: 0.5;
  padding: 3px;
  border-radius: var(--radius-sm);
}
.conn-row:hover .conn-row__gear { opacity: 1; }
.conn-row__gear:hover { background: var(--bg-surface); color: var(--text); }

/* database (schema) rows reuse .table-row__icon for their cylinder glyph */
.schema-row { padding-left: 12px; font-weight: 500; color: var(--text-dim); }
.schema-row > span:last-child { overflow: hidden; text-overflow: ellipsis; }

.table-row__icon { flex: 0 0 auto; color: var(--text-faint); }
.schema-row:hover .table-row__icon,
.table-row:hover .table-row__icon { color: var(--accent-hover); }
.table-row.is-active .table-row__icon { color: var(--accent); }

.table-row__name { overflow: hidden; text-overflow: ellipsis; }

.table-row__badge {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.02em;
  color: var(--text-faint);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
}

/* indentation + connecting guide line, one level per nested .tree-children */
.tree-children {
  position: relative;
  padding-left: 17px;
  margin-left: 15px;
  border-left: 1px solid var(--border-soft);
}

.tree-loading,
.tree-error {
  padding: 6px 14px 6px 30px;
  font-size: 12px;
  color: var(--text-faint);
}
.tree-error { color: var(--danger); }

/* ---------------------------------------------------------------- buttons */

.btn {
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn--sm { padding: 5px 10px; font-size: 12px; }

.btn--icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  color: var(--text-dim);
  background: transparent;
}
.btn--icon:hover { background: var(--bg-surface-hover); color: var(--text); }

.btn--ghost { background: transparent; border-color: var(--border); color: var(--text-dim); }
.btn--ghost:hover { border-color: var(--accent); color: var(--text); }
.btn--ghost:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--ghost:disabled:hover { border-color: var(--border); color: var(--text-dim); }

.btn--primary { background: var(--accent); color: var(--accent-contrast); }
.btn--primary:hover { background: var(--accent-hover); }

/* ---------------------------------------------------------------- main panel */

.mainpanel { flex: 1 1 auto; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.tabstrip {
  flex: 0 0 auto;
  display: flex;
  min-height: 0;
  border-bottom: 1px solid var(--border);
  background: var(--bg-raised);
  overflow-x: auto;
}
.tabstrip:empty { display: none; }

.tab {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px 0 12px;
  height: 36px;
  font-size: 12.5px;
  color: var(--text-dim);
  border-right: 1px solid var(--border);
  cursor: pointer;
  position: relative;
}
.tab:hover { color: var(--text); background: var(--bg-surface); }
.tab.is-active { color: var(--text); background: var(--bg); }
.tab.is-active::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--accent);
}
.tab__icon { flex: 0 0 auto; color: var(--text-faint); }
.tab.is-active .tab__icon { color: var(--accent); }
.tab span[title] { overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.tab__close {
  flex: 0 0 auto;
  display: flex;
  color: var(--text-faint);
  padding: 3px;
  border-radius: var(--radius-sm);
  opacity: 0.6;
}
.tab__close:hover { opacity: 1; background: var(--bg-surface-hover); color: var(--text); }

.tabcontent {
  flex: 1 1 auto;
  overflow: auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.statusbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  padding: 5px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-faint);
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
}

/* ---------------------------------------------------------------- welcome / hero */

.welcome {
  max-width: 780px;
  padding: 56px 48px;
  animation: welcome-in 420ms ease-out both;
}

@keyframes welcome-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.welcome__intro h1 { font-size: 30px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 12px; }
.welcome__intro p { color: var(--text-dim); font-size: 14px; line-height: 1.65; max-width: 56ch; margin: 0 0 22px; }
.welcome__intro .btn--primary { padding: 9px 16px; font-size: 13px; }

.db-showcase { margin-top: 44px; }
.db-showcase__label { font-size: 12px; font-weight: 600; color: var(--text-faint); margin: 0 0 14px; }
.db-showcase__grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 760px) { .db-showcase__grid { grid-template-columns: repeat(2, 1fr); } }

.db-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 20px 12px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}
.db-card:hover,
.db-card:focus-visible {
  transform: translateY(-2px);
  border-color: var(--db-color, var(--accent));
  background: var(--bg-surface-hover);
  box-shadow: var(--shadow-card);
}
.db-card__icon { width: 40px; height: 40px; filter: drop-shadow(0 4px 10px var(--db-color-soft, transparent)); }
.db-card__name { font-size: 12.5px; font-weight: 600; color: var(--text); }
.db-card__kind { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-faint); }

/* ---------------------------------------------------------------- pane (table / query view) */

.pane {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 20px 0;
}

.pane__breadcrumb {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-faint);
  padding-bottom: 10px;
}
.pane__breadcrumb-part.is-current { color: var(--text); font-weight: 600; }
.pane__breadcrumb-sep { flex: 0 0 auto; color: var(--text-faint); opacity: 0.6; }

.pane__toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.pane__toolbar .btn--ghost.is-active,
.pane__toolbar .btn--ghost[aria-pressed="true"] { border-color: var(--accent); color: var(--text); background: var(--accent-soft); }
.pane__toolbar-spacer { flex: 1 1 auto; }
.pane__meta { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); white-space: nowrap; }

.editor-wrap { flex: 0 0 auto; padding: 12px 0; }
.sql-editor {
  width: 100%;
  height: 150px;
  resize: vertical;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
}
.sql-editor:focus { outline: none; border-color: var(--accent); }

.results-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 14px;
}

.results-message {
  padding: 30px 4px;
  color: var(--text-faint);
  font-size: 12.5px;
}
.results-message.is-error { color: var(--danger); }

.grid-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }

.data-grid,
.columns-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 12.5px;
}

.data-grid thead th,
.columns-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 11.5px;
  color: var(--text-dim);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  white-space: nowrap;
  cursor: default;
}
.data-grid thead th[data-col] { cursor: pointer; }
.data-grid thead th[data-col]:hover { color: var(--text); background: var(--bg-surface-hover); }

.data-grid tbody td,
.columns-table tbody td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-soft);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.data-grid tbody tr:hover td { background: var(--bg-surface); }
.data-grid tbody td.rownum {
  font-family: var(--font-mono);
  color: var(--text-faint);
  text-align: right;
  background: var(--bg-raised);
  position: sticky;
  left: 0;
}
.data-grid tbody td.is-null { color: var(--text-faint); font-style: italic; }

.pk-badge {
  display: inline-block;
  margin-left: 6px;
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 1px 5px;
  border-radius: 3px;
  vertical-align: middle;
}

.pager {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  font-size: 12px;
  color: var(--text-dim);
}
.pager__spacer { flex: 1 1 auto; }

/* ---------------------------------------------------------------- footer credit bar */

.app-footer {
  flex: 0 0 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-faint);
}
.app-footer__left { display: flex; align-items: baseline; gap: 8px; }
.app-footer__product { font-weight: 600; color: var(--text-dim); }
.app-footer__right { display: flex; align-items: center; gap: 10px; }
.app-footer__right a { color: var(--text-dim); font-weight: 500; }
.app-footer__right a:hover { color: var(--accent-hover); }
.app-footer__divider { width: 1px; height: 11px; background: var(--border); }

/* ---------------------------------------------------------------- modal */

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 9, 0.6);
  backdrop-filter: blur(2px);
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-backdrop.is-open { display: flex; }

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
}

.modal__head { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal__head h2 { font-size: 15px; font-weight: 600; margin: 0; }
.modal__body { flex: 1 1 auto; overflow-y: auto; padding: 18px; }
.modal__foot { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-top: 1px solid var(--border); background: var(--bg-raised); }
.modal__foot-right { display: flex; gap: 8px; }

/* ---------------------------------------------------------------- form fields */

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 12px; font-weight: 500; color: var(--text-dim); margin-bottom: 6px; }

.field input[type="text"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  transition: border-color 120ms ease;
}
.field textarea { font-family: var(--font-mono); resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }

.field--checkbox { display: flex; align-items: center; gap: 8px; }
.field--checkbox input { width: auto; margin: 0; accent-color: var(--accent); }
.field--checkbox span { margin: 0; font-size: 12.5px; color: var(--text-dim); font-weight: 400; }

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; margin-bottom: 14px; }
.field--grow { flex: 1; }
.field--narrow { flex: 0 0 96px; }

.field-hint { font-size: 11.5px; color: var(--text-faint); line-height: 1.5; margin: -6px 0 14px; }
.field-hint code { font-family: var(--font-mono); background: var(--bg-input); padding: 1px 4px; border-radius: 3px; }

.advanced-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  padding: 8px 0;
  cursor: pointer;
  border-top: 1px solid var(--border-soft);
  margin-top: 4px;
}
.advanced-toggle:hover { color: var(--text); }
.advanced-toggle__chevron { transition: transform 140ms ease; }
.advanced-toggle__chevron.is-open { transform: rotate(90deg); }

.subsection { border: 1px solid var(--border-soft); border-radius: var(--radius-md); padding: 12px 12px 4px; margin: 10px 0; }
.subsection legend { padding: 0 4px; font-size: 12px; color: var(--text-dim); }

.test-result { font-size: 12px; }
.test-result:not(:empty) { padding: 9px 11px; border-radius: var(--radius-sm); margin-bottom: 14px; }
.test-result.is-ok { background: rgba(53, 211, 153, 0.1); color: var(--success); }
.test-result.is-fail { background: var(--danger-soft); color: var(--danger); }