:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --panel: #ffffff;
  --panel-soft: #f0f6f3;
  --text: #18201f;
  --muted: #65706d;
  --line: #dce3df;
  --line-strong: #c7d2cc;
  --accent: #0f766e;
  --accent-strong: #0b5f59;
  --accent-soft: #d8f2ed;
  --warn: #996b05;
  --danger: #b42318;
  --shadow: 0 16px 36px rgba(20, 32, 29, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(250px, 320px) minmax(0, 1fr);
  grid-template-rows: 72px minmax(0, 1fr);
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #15211f;
  color: #eff8f5;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.15;
}

.brand p,
.toolbar-title p,
.empty-state p,
.query-actions span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.topbar-actions,
.toolbar-controls,
.query-actions,
.pager {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
  font-weight: 650;
  white-space: nowrap;
}

.button:hover:not(:disabled) {
  border-color: #9bb5ad;
  background: #fbfdfc;
}

.button.primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.button.primary:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.button.ghost {
  background: transparent;
}

.icon-button {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.icon-button:hover {
  color: var(--text);
  border-color: var(--line);
  background: var(--panel-soft);
}

.sidebar {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  overflow: auto;
}

.drop-zone {
  display: grid;
  gap: 6px;
  min-height: 112px;
  align-content: center;
  justify-items: center;
  padding: 20px;
  border: 1px dashed #9bb5ad;
  border-radius: 8px;
  background: var(--panel-soft);
  color: var(--accent-strong);
  text-align: center;
  outline: none;
}

.drop-zone span {
  color: var(--muted);
  font-size: 13px;
}

.drop-zone.dragging,
.drop-zone:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.side-section {
  display: grid;
  gap: 10px;
}

.side-section.grow {
  flex: 1 1 auto;
  min-height: 220px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.section-heading h2,
.toolbar-title h2,
.query-editor label {
  font-size: 14px;
  line-height: 1.3;
  font-weight: 800;
}

.badge {
  min-width: 28px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}

.meta-list {
  display: grid;
  gap: 9px;
  margin: 0;
}

.meta-list div {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 10px;
  align-items: baseline;
}

.meta-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.meta-list dd {
  min-width: 0;
  margin: 0;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field {
  min-height: 36px;
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  padding: 0 10px;
  outline: none;
}

.field:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.field.compact {
  width: auto;
  min-width: 116px;
}

.search-field {
  width: min(320px, 34vw);
}

.table-list,
.schema-list {
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.table-list.empty,
.schema-list.empty {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
}

.table-item,
.schema-item {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 10px 11px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
}

.table-item:last-child,
.schema-item:last-child {
  border-bottom: 0;
}

.table-item:hover,
.schema-item:hover {
  background: #f8fbf9;
}

.table-item.active,
.schema-item.active {
  background: var(--accent-soft);
}

.item-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 750;
}

.item-detail {
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 18px;
  gap: 12px;
  overflow: hidden;
}

.tabs {
  display: flex;
  gap: 6px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.tab {
  height: 38px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  font-weight: 800;
}

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

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

.view {
  min-width: 0;
  min-height: 0;
  display: none;
}

.view.active {
  display: grid;
}

#browseView {
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.view-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.toolbar-title {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.toolbar-title h2 {
  font-size: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-controls {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.data-wrap {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.data-table th,
.data-table td {
  max-width: 360px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px 10px;
  vertical-align: top;
  text-align: left;
}

.data-table th:last-child,
.data-table td:last-child {
  border-right: 0;
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef5f2;
  color: #26312f;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.data-table tbody tr:hover td {
  background: #fbfdfc;
}

.header-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  text-align: left;
  font-weight: inherit;
}

.sort-token {
  color: var(--muted);
  font-size: 11px;
}

.cell {
  display: block;
  min-width: 64px;
  max-height: 82px;
  overflow: hidden;
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.cell.null {
  color: #8b9692;
  font-style: italic;
}

.cell.blob {
  color: var(--warn);
}

.cell-button {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}

.empty-state {
  min-height: 100%;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 7px;
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.empty-state h3 {
  color: var(--text);
  font-size: 17px;
}

.pager {
  justify-content: flex-end;
  color: var(--muted);
  font-size: 13px;
}

.query-layout {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.query-editor {
  display: grid;
  gap: 8px;
}

#sqlInput {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 12px;
  background: #101917;
  color: #eef7f4;
  outline: none;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}

#sqlInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.query-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.query-results {
  box-shadow: none;
}

.schema-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 12px;
}

.schema-sql {
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #101917;
  color: #edf8f4;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  min-width: min(420px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  border-radius: 8px;
  padding: 12px 14px;
  background: #15211f;
  color: white;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 20;
  font-size: 13px;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: var(--danger);
}

.cell-dialog {
  width: min(720px, calc(100vw - 32px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

.cell-dialog::backdrop {
  background: rgba(12, 18, 17, 0.36);
}

.cell-dialog form {
  display: grid;
  max-height: min(720px, calc(100vh - 48px));
  background: var(--panel);
}

.cell-dialog header,
.cell-dialog footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.cell-dialog footer {
  border-top: 1px solid var(--line);
  border-bottom: 0;
  justify-content: flex-end;
}

.cell-dialog h2 {
  font-size: 15px;
}

.cell-dialog pre {
  margin: 0;
  min-height: 180px;
  overflow: auto;
  padding: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .button {
    flex: 1;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    max-height: 44vh;
  }

  .workspace {
    min-height: 70vh;
    overflow: visible;
  }

  .view-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-controls {
    justify-content: stretch;
  }

  .toolbar-controls > * {
    flex: 1 1 148px;
  }

  .search-field {
    width: 100%;
  }

  .schema-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(140px, 220px) minmax(280px, 1fr);
  }
}
