.sqlite-result-scroll {
  width: 100%;
  overflow-x: auto;
  max-width: 100%;
}

.sqlite-pagination {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.sqlite-pagination button {
  width: auto;
  min-width: 0;
  padding: 0.25rem 0.65rem;
}

[data-role="sqlite-explorer"] {
  width: calc(100vw - 2rem);
  margin-left: calc(50% - 50vw + 1rem);
  box-sizing: border-box;
}

[data-role="sqlite-query-panel"] {
  width: calc(100vw - 2rem);
  margin-left: calc(50% - 50vw + 1rem);
  box-sizing: border-box;
}

.sqlite-query-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sqlite-query-editor,
.sqlite-query-output {
  min-width: 0;
}

/* Explicit overrides reserved for a future front-end layout toggle. */
.sqlite-query-layout[data-query-layout="stacked"] {
  display: flex;
  flex-direction: column;
}

.sqlite-query-layout[data-query-layout="split"] {
  display: grid;
  grid-template-columns: minmax(360px, 560px) 1fr;
  align-items: start;
  gap: 1.5rem;
}

@media (min-width: 960px) {
  .sqlite-query-layout:not([data-query-layout="stacked"]) {
    display: grid;
    grid-template-columns: minmax(360px, 560px) 1fr;
    align-items: start;
    gap: 1.5rem;
  }
}

.sqlite-result-scroll table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
}

[data-role="sqlite-table-details"] table {
  min-width: 0;
}

.sqlite-result-scroll th,
.sqlite-result-scroll td {
  padding: 0.4rem 0.55rem;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.sqlite-cell-toggle {
  display: block;
  max-width: min(28rem, 70vw);
  overflow: hidden;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Keep theme button chrome off text-only cells: no height change, no fill
   (button[type="button"] would otherwise paint --button-alt-bg), and no pill
   corners that clip the text once a value is expanded. */
:root[data-theme] [data-sqlite-viewer] .sqlite-result-scroll button.sqlite-cell-toggle {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  font-weight: inherit;
  line-height: inherit;
}

.sqlite-cell-toggle.is-expanded {
  max-width: min(48rem, 70vw);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

[data-role="sqlite-query-status"][data-state="error"] {
  color: var(--status-error);
  font-weight: 700;
}

[data-role="sqlite-effective-query"] {
  flex: 0 0 100%;
  width: 100%;
  min-width: 0;
  margin: 0;
}

[data-role="sqlite-effective-query"] summary {
  text-align: right;
}

.sqlite-query-bottom {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

[data-role="sqlite-query-pagination"] {
  flex: 0 0 auto;
  max-width: 100%;
  min-width: 0;
}

[data-role="sqlite-effective-query"] pre {
  max-width: 100%;
  overflow-x: auto;
  padding: 0.75rem;
  background: var(--input-bg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.sqlite-sort-button {
  margin: -0.4rem -0.55rem;
  padding: 0.4rem 0.55rem;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
}

[data-role="sqlite-table-preview"] th[aria-sort="ascending"] .sqlite-sort-button::after {
  content: " ▲";
}

[data-role="sqlite-table-preview"] th[aria-sort="descending"] .sqlite-sort-button::after {
  content: " ▼";
}

[data-role="sqlite-query-input"] {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  width: 100%;
  box-sizing: border-box;
}

[data-role="sqlite-query-select"] {
  width: 100%;
  box-sizing: border-box;
}

.sqlite-tabs {
  display: flex;
  gap: 0.35rem;
  margin: 0.8rem 0 0.55rem;
  border-bottom: 1px solid var(--line);
}

.sqlite-tab {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  margin-top: 0;
}

.sqlite-tab.is-active {
  background: var(--active-bg);
  color: var(--active-ink);
}

.sqlite-tab-panel[hidden] {
  display: none;
}
.sqlite-dialog {
  width: calc(100vw - 2rem);
  max-width: 1600px;
  max-height: calc(100dvh - 2rem);
  box-sizing: border-box;
  overflow: auto;
  color: inherit;
  background: var(--page-bg, Canvas);
}
.sqlite-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.sqlite-dialog-header {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: var(--page-bg, Canvas);
}
.sqlite-dialog-header h2 { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sqlite-dialog-header button { flex: 0 0 auto; width: auto; }
.sqlite-dialog [data-role="sqlite-explorer"],
.sqlite-dialog [data-role="sqlite-query-panel"] { width: 100%; margin-left: 0; }
.sqlite-dialog textarea { width: 100%; box-sizing: border-box; }
.sqlite-dialog pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.sqlite-dialog p { overflow-wrap: anywhere; }
.sqlite-dialog .sqlite-query-bottom > * { max-width: 100%; min-width: 0; }

/* Phone query dialog: dense text so a result table fits the screen, the way
   the Forte phone layout does. Every size inside the viewer follows one base
   size (8px at zoom 1); Smaller/Larger in the dialog header adjust
   --query-zoom between 0.6 and 2.5. The header keeps its normal size so Close
   and the zoom buttons stay easy to tap. */
/* Buttons styled by .zoom-buttons (site.css); shown on phones only. */
.sqlite-dialog-zoom { display: none; }
@media (max-width: 48rem) {
  .sqlite-dialog {
    width: calc(100vw - 0.5rem);
    max-height: calc(100dvh - 0.5rem);
    padding: 0.4rem;
  }
  .sqlite-dialog-header { gap: 0.4rem; }
  .sqlite-dialog-header h2 { font-size: 1rem; margin: 0; }
  .sqlite-dialog-header button {
    margin: 0;
    padding: 0.3rem 0.6rem;
  }
  .sqlite-dialog-zoom { display: inline-flex; }
  .sqlite-dialog [data-sqlite-viewer] {
    font-size: calc(8px * var(--query-zoom, 1));
    line-height: 1.3;
    gap: 0.6em;
  }
  .sqlite-dialog [data-sqlite-viewer] *,
  /* Outranks theme rules such as :root[data-theme="thermal"] .meta. */
  dialog.sqlite-dialog [data-sqlite-viewer] .meta {
    font-size: inherit;
    line-height: inherit;
  }
  /* About a dozen lines of SQL, so results start on the first screen. */
  .sqlite-dialog [data-sqlite-viewer] textarea {
    height: 16em;
  }
  .sqlite-dialog [data-sqlite-viewer] .card {
    margin: 0;
    padding: 0.6em;
  }
  .sqlite-dialog [data-sqlite-viewer] h3 { font-weight: bold; }
  .sqlite-dialog [data-sqlite-viewer] p { margin: 0.4em 0; }
  .sqlite-dialog [data-sqlite-viewer] button,
  .sqlite-dialog [data-sqlite-viewer] select,
  .sqlite-dialog [data-sqlite-viewer] textarea {
    padding: 0.3em 0.5em;
    min-height: 0;
  }
  .sqlite-dialog .sqlite-result-scroll th,
  .sqlite-dialog .sqlite-result-scroll td {
    padding: 0.25em 0.45em;
  }
  .sqlite-dialog .sqlite-cell-toggle {
    max-width: min(28em, 70vw);
  }
}
