.db-view-switch {
  display: inline-flex;
  gap: 4px;
  width: fit-content;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 4px;
}

.db-view-switch button {
  min-height: 34px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 850;
}

.db-view-switch button.active {
  background: var(--blue);
  color: #ffffff;
}

.db-usage-filter {
  display: grid;
  grid-template-columns: minmax(260px, 420px) auto auto;
  gap: 8px;
  align-items: end;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
}

.db-usage-filter label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.db-usage-filter label span,
.db-usage-filter div span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.db-usage-filter select {
  min-height: 42px;
}

.db-usage-filter div {
  min-width: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 8px 10px;
}

.db-usage-filter strong {
  display: block;
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}

.relation-panel {
  display: grid;
  gap: 10px;
}

.relation-toolbar {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr);
  align-items: center;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px 12px;
}

.relation-toolbar div {
  display: grid;
  gap: 2px;
}

.relation-toolbar strong {
  color: var(--text);
  font-size: 18px;
  line-height: 1;
}

.relation-toolbar span,
.relation-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.relation-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: grid;
  align-items: center;
  justify-items: center;
  gap: 3px;
  border: 1px solid rgba(205, 215, 229, 0.92);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.94);
  padding: 4px;
  box-shadow: 0 8px 18px rgba(31, 45, 68, 0.09);
}

.relation-controls button {
  min-width: 24px;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font-size: 10px;
  font-weight: 850;
  padding: 0;
}

.relation-controls button:hover {
  border-color: rgba(37, 99, 235, 0.36);
  color: var(--blue);
}

.relation-controls span {
  min-width: 30px;
  color: var(--text);
  font-size: 10px;
  font-weight: 850;
  text-align: center;
}

.relation-controls input[type="range"] {
  width: 16px;
  height: 66px;
  accent-color: var(--blue);
  direction: rtl;
  margin: 2px 0;
  writing-mode: vertical-lr;
}

.relation-canvas {
  position: relative;
  overflow: hidden;
  min-height: 560px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(rgba(226, 233, 242, 0.42) 1px, transparent 1px),
    linear-gradient(90deg, rgba(226, 233, 242, 0.42) 1px, transparent 1px),
    #fbfcfe;
  background-size: 24px 24px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.relation-canvas.is-panning {
  cursor: grabbing;
}

.relation-space {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
}

.relation-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.relation-line-halo {
  fill: none;
  stroke: rgba(255, 255, 255, 0.96);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 8;
}

.relation-line-main {
  fill: none;
  stroke: #2563eb;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.relation-line.inferred .relation-line-main {
  stroke: #8b98ac;
  stroke-dasharray: 7 7;
}

.relation-line.self-reference .relation-line-main {
  stroke: #0f9f6e;
  stroke-width: 3.5;
}

.relation-line.self-reference.inferred .relation-line-main {
  stroke: #0f9f6e;
  stroke-dasharray: 8 6;
}

.relation-port {
  fill: #ffffff;
  stroke: #2563eb;
  stroke-width: 2;
}

.relation-line.inferred .relation-port {
  stroke: #8b98ac;
}

.relation-line.self-reference .relation-port {
  fill: #ecfdf5;
  stroke: #0f9f6e;
}

.relation-line path + text,
.relation-line text {
  fill: #1f2d44;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 6px;
  font-size: 11px;
  font-weight: 850;
  text-anchor: middle;
}

.relation-line.self-reference text {
  fill: #08764f;
  text-anchor: start;
}

.relation-line.self-reference .relation-self-label {
  font-size: 10px;
  font-weight: 900;
}

.relation-lines marker path {
  fill: #2563eb;
}

#relation-arrow-self path {
  fill: #0f9f6e;
}

.relation-table {
  position: absolute;
  z-index: 1;
  display: grid;
  gap: 7px;
  width: 250px;
  min-height: 158px;
  border: 1px solid rgba(205, 215, 229, 0.96);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  padding: 12px;
  color: var(--text);
  cursor: grab;
  text-align: left;
  box-shadow: 0 14px 34px rgba(31, 45, 68, 0.1);
  pointer-events: auto;
  touch-action: none;
}

.relation-table:hover {
  border-color: rgba(38, 74, 130, 0.26);
  box-shadow: 0 18px 42px rgba(31, 45, 68, 0.14);
}

.relation-table:active {
  cursor: grabbing;
}

.relation-table strong {
  overflow: hidden;
  font-size: 14px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relation-table small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.relation-table div {
  display: grid;
  gap: 4px;
}

.relation-table span,
.relation-table em {
  overflow: hidden;
  color: #42506a;
  font-size: 12px;
  font-style: normal;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relation-table span.primary {
  color: var(--blue);
}

.relation-table span.foreign {
  color: var(--amber);
}

.sql-panel {
  display: grid;
  gap: 14px;
}

.sql-console {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 14px;
}

.sql-editor-field,
.sql-console-actions label {
  display: grid;
  gap: 6px;
}

.sql-editor-field span,
.sql-console-actions span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.sql-editor-field textarea {
  height: 180px;
  min-height: 180px;
  resize: none;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #0f172a;
  color: #e5eefb;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
  outline: none;
}

.sql-console-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 10px;
}

.sql-console-actions input {
  width: 96px;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 0 10px;
}

.sql-console-actions button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: #ffffff;
  padding: 0 18px;
  font-size: 13px;
  font-weight: 850;
}

.sql-console-actions button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.sql-helper {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.sql-helper header,
.sql-helper-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sql-helper header {
  min-height: 52px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.sql-helper h2 {
  margin: 0;
  font-size: 15px;
}

.sql-helper header button,
.sql-helper-actions button {
  min-height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--blue);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 850;
}

.sql-helper header button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.sql-helper-grid {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(0, 1fr);
  min-height: 250px;
}

.sql-helper-tables {
  display: grid;
  align-content: start;
  gap: 6px;
  max-height: 360px;
  overflow: auto;
  border-right: 1px solid var(--line);
  padding: 10px;
  background: #fbfdff;
}

.sql-helper-tables button,
.sql-column-list button {
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.sql-helper-tables button {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
}

.sql-helper-tables button.active {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.sql-helper-tables strong,
.sql-helper-toolbar strong,
.sql-column-list strong {
  font-size: 13px;
}

.sql-helper-tables span,
.sql-helper-toolbar span,
.sql-column-list span,
.sql-column-list em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.sql-helper-columns {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 12px;
}

.sql-helper-toolbar {
  min-height: 34px;
}

.sql-helper-toolbar > div:first-child {
  display: grid;
  gap: 2px;
}

.sql-helper-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.sql-helper-search {
  display: grid;
  gap: 5px;
}

.sql-helper-search span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.sql-helper-search input {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 0 10px;
}

.sql-column-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow: auto;
}

.sql-column-list button {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 8px;
  padding: 9px 10px;
  border-color: var(--line);
  background: #ffffff;
}

.sql-column-list button:hover,
.sql-helper-actions button:hover,
.sql-helper header button:hover {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.sql-column-list button strong,
.sql-column-list button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sql-column-list button span {
  grid-column: 1 / -1;
}

.sql-column-list button em {
  align-self: start;
  border-radius: 999px;
  background: #eef2f7;
  padding: 2px 6px;
}

.sql-result {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.sql-result-table-wrap {
  max-width: 100%;
  overflow: auto;
  max-height: 520px;
}

.sql-result-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.sql-result-table th,
.sql-result-table td {
  min-width: 140px;
  max-width: 360px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  overflow: hidden;
  color: #334155;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sql-result-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--muted);
  font-weight: 900;
  text-align: left;
}

.sql-result-table td {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.table-metadata-card {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 8px;
  width: min(820px, 100%);
  margin-top: 10px;
}

.table-metadata-card div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 8px 10px;
}

.table-metadata-card span,
.schema-table header .table-metadata-card span {
  display: block;
  margin: 0 0 4px;
  border-radius: 0;
  background: transparent;
  color: var(--faint);
  padding: 0;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0;
}

.table-metadata-card strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 850;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-metadata-card .metadata-type-value {
  overflow: visible;
}

.table-metadata-card .metadata-type-value .metadata-type-badge,
.schema-table header .table-metadata-card .metadata-type-value .metadata-type-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 24px;
  margin: 0;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 850;
  line-height: 1;
}

.table-metadata-card .metadata-type-value .metadata-type-badge.metadata-type-custom {
  background: #dcfce7;
  color: #047857;
}

.table-metadata-card .metadata-type-value .metadata-type-badge.metadata-type-standard {
  background: #dbeafe;
  color: #1d4ed8;
}

.table-metadata-card .metadata-type-value .metadata-type-badge.metadata-type-system {
  background: #ede9fe;
  color: #6d28d9;
}

.table-metadata-card .metadata-type-value .metadata-type-badge.metadata-type-metadata {
  background: #e7edf5;
  color: var(--muted);
}

.schema-grid {
  display: grid;
  grid-template-columns: 160px 200px 160px 90px 190px 80px 130px;
  max-width: 100%;
  overflow-x: auto;
}

.schema-head,
.schema-cell {
  min-width: 0;
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  overflow-wrap: anywhere;
}

.schema-head {
  background: #fbfcfe;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.schema-cell {
  color: #42506a;
  font-size: 13px;
}

.schema-cell.strong {
  color: var(--text);
  font-weight: 850;
}

.schema-cell.muted {
  color: var(--faint);
}

.read-value {
  display: block;
  color: #42506a;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.schema-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.schema-actions .save-row-button,
.schema-actions .ghost-row-button {
  min-height: 32px;
  border-radius: 8px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 850;
}

.schema-actions .save-row-button {
  border: 0;
  background: var(--blue);
  color: #ffffff;
}

.schema-actions .save-row-button:hover {
  background: #1d4ed8;
}

@media (max-width: 760px) {
  .schema-grid {
    grid-template-columns: 150px 180px 140px 80px 180px 70px 120px 150px 120px 150px 220px 130px;
  }

  .db-usage-filter {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .sql-helper-grid {
    grid-template-columns: 1fr;
  }

  .sql-helper-tables {
    max-height: 180px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sql-helper-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .sql-helper-actions {
    justify-content: flex-start;
  }
}
