:root {
  color-scheme: light;
  --bg: #f3f8fc;
  --panel: #ffffff;
  --panel-2: #eaf6ff;
  --line: #c9d8e6;
  --line-soft: #e1ebf3;
  --text: #132436;
  --muted: #637589;
  --cyan: #0ea5c6;
  --green: #159947;
  --amber: #b97814;
  --red: #dc3545;
  --violet: #6d5bd0;
  --shadow: 0 18px 60px rgba(17, 55, 89, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, #e9f7ff 0, #f7fbfe 300px),
    var(--bg);
  color: var(--text);
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

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

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

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(14, 165, 198, 0.45);
  background: #e8f8ff;
  box-shadow: inset 0 0 20px rgba(14, 165, 198, 0.12);
  color: var(--cyan);
  font-weight: 800;
  border-radius: 8px;
}

.brand h1 {
  font-size: 16px;
  line-height: 1.1;
  margin: 0;
}

.brand span {
  color: var(--muted);
  font-size: 12px;
}

.nav-tabs {
  display: flex;
  gap: 8px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5faff;
}

.nav-tab {
  min-width: 80px;
  border: 0;
  color: var(--muted);
  background: transparent;
  padding: 9px 14px;
  border-radius: 6px;
}

.nav-tab.active {
  color: var(--text);
  background: var(--panel-2);
  box-shadow: inset 0 0 0 1px rgba(14, 165, 198, 0.2);
}

main {
  padding: 18px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  margin-bottom: 14px;
}

.toolbar-grid {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(180px, 2fr) repeat(4, minmax(100px, 1fr));
  gap: 10px;
}

label span,
.panel-title span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  color: var(--text);
  background: #f8fbfe;
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

input,
select {
  height: 38px;
  padding: 0 11px;
}

textarea {
  min-height: 180px;
  resize: vertical;
  padding: 11px;
  line-height: 1.5;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(14, 165, 198, 0.72);
  box-shadow: 0 0 0 3px rgba(14, 165, 198, 0.12);
}

.toolbar-actions,
.form-actions,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn,
.ghost-btn,
.danger-btn,
.primary-btn,
.icon-text-btn {
  min-height: 36px;
  border-radius: 6px;
  border: 1px solid var(--line);
  padding: 0 12px;
  color: var(--text);
  background: #ffffff;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.icon-btn {
  width: 38px;
  padding: 0;
  color: var(--cyan);
}

.icon-text-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--green);
}

.primary-btn {
  color: #ffffff;
  background: var(--cyan);
  border-color: var(--cyan);
  font-weight: 700;
}

.danger-btn {
  color: var(--red);
}

.ghost-btn.active {
  color: #ffffff;
  background: var(--green);
  border-color: var(--green);
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.8fr);
  gap: 14px;
  align-items: start;
}

.rules-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.72fr);
  gap: 14px;
  align-items: start;
}

.rules-layout table {
  min-width: 0;
  table-layout: fixed;
}

.rules-layout th:nth-child(1),
.rules-layout td:nth-child(1) {
  width: 58px;
}

.rules-layout th:nth-child(2),
.rules-layout td:nth-child(2) {
  width: 96px;
}

.rules-layout th:nth-child(3),
.rules-layout td:nth-child(3) {
  width: 82px;
}

.rules-layout th:nth-child(5),
.rules-layout td:nth-child(5) {
  width: 122px;
}

.rules-layout th:nth-child(6),
.rules-layout td:nth-child(6) {
  width: 178px;
}

.rules-layout .row-actions {
  flex-wrap: wrap;
}

.rules-layout .row-actions button {
  min-height: 34px;
  padding: 0 9px;
}

.panel {
  overflow: hidden;
}

.panel-title {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line-soft);
}

.panel-title h2 {
  margin: 0;
  font-size: 14px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

.rules-layout table {
  min-width: 0;
  table-layout: fixed;
}

th,
td {
  border-bottom: 1px solid var(--line-soft);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  background: rgba(238, 246, 252, 0.92);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover,
tbody tr.selected {
  background: rgba(14, 165, 198, 0.08);
}

.mono {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.muted {
  color: var(--muted);
}

.url-cell {
  max-width: 420px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 0 8px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.badge.ok {
  color: var(--green);
  border-color: rgba(21, 153, 71, 0.32);
}

.badge.warn {
  color: var(--amber);
  border-color: rgba(185, 120, 20, 0.32);
}

.badge.error {
  color: var(--red);
  border-color: rgba(220, 53, 69, 0.32);
}

.badge.info {
  color: var(--cyan);
  border-color: rgba(14, 165, 198, 0.34);
}

.method {
  color: var(--cyan);
  font-weight: 700;
}

.detail-panel {
  min-height: 620px;
  max-height: calc(100vh - 132px);
  overflow: auto;
}

.empty-state {
  min-height: 420px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 16px;
  color: var(--muted);
}

.pulse-line {
  width: 150px;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--cyan), transparent);
}

.detail-content {
  padding: 14px;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kv {
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  padding: 10px;
  background: #f8fbfe;
}

.kv b {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.kv span {
  overflow-wrap: anywhere;
}

.section-title {
  margin: 18px 0 8px;
  color: var(--text);
  font-size: 12px;
  text-transform: uppercase;
}

.mini-table {
  min-width: 0;
  table-layout: fixed;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  overflow: hidden;
}

.mini-table td:first-child {
  width: 38%;
  color: var(--muted);
}

.body-toolbar {
  display: flex;
  gap: 8px;
  margin: 8px 0;
}

.body-box {
  max-height: 360px;
  overflow: auto;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #f8fbfe;
  padding: 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.body-note {
  margin-bottom: 8px;
  color: var(--muted);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  text-transform: uppercase;
}

.json-tree details {
  margin-left: 12px;
}

.json-raw {
  margin-top: 12px;
  border-top: 1px solid var(--line-soft);
  padding-top: 10px;
}

.json-raw summary {
  color: var(--cyan);
  cursor: pointer;
  margin-bottom: 8px;
}

.json-raw pre {
  margin: 0;
  white-space: pre-wrap;
}

.json-key {
  color: var(--cyan);
}

.json-string {
  color: var(--green);
}

.json-number {
  color: var(--amber);
}

.json-bool,
.json-null {
  color: var(--violet);
}

.rule-form {
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.rule-form label:nth-child(4),
.rule-form label:nth-child(5) {
  grid-column: span 2;
}

.toggle-grid,
.form-actions,
.feedback {
  grid-column: span 2;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.toggle {
  min-height: 38px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #f8fbfe;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--cyan);
}

.toggle span {
  color: var(--text);
  font-size: 12px;
  text-transform: none;
}

.feedback {
  margin: 0 14px 14px;
  min-height: 42px;
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #f8fbfe;
  color: var(--muted);
  padding: 10px;
  white-space: pre-wrap;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(243, 248, 252, 0.92);
  backdrop-filter: blur(16px);
}

.auth-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  padding: 18px;
}

.auth-panel h2 {
  margin: 0;
  font-size: 16px;
}

.auth-message {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 12px;
}

.database-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.34fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.schema-list {
  max-height: calc(100vh - 150px);
  overflow: auto;
  padding: 12px;
}

.schema-table {
  border: 1px solid var(--line-soft);
  border-radius: 6px;
  background: #f8fbfe;
  margin-bottom: 10px;
  overflow: hidden;
}

.schema-table summary {
  cursor: pointer;
  padding: 10px;
  color: var(--text);
}

.schema-columns {
  display: grid;
  gap: 6px;
  border-top: 1px solid var(--line-soft);
  padding: 10px;
}

.schema-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.sql-workbench {
  padding: 14px;
}

.sql-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.sql-actions label {
  width: 140px;
}

.sql-workbench .feedback {
  margin: 10px 0 0;
}

.db-results {
  border-top: 1px solid var(--line-soft);
  max-height: calc(100vh - 440px);
}

.db-results table {
  min-width: 980px;
}

.db-value {
  max-width: 460px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid rgba(14, 165, 198, 0.35);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  z-index: 40;
}

.hidden {
  display: none !important;
}

@media (max-width: 1120px) {
  .split-layout,
  .rules-layout,
  .database-layout {
    grid-template-columns: 1fr;
  }

  .detail-panel {
    max-height: none;
  }

  .schema-list,
  .db-results {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 14px;
  }

  main {
    padding: 12px;
  }

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

  .toolbar-grid,
  .rule-form,
  .toggle-grid,
  .kv-grid {
    grid-template-columns: 1fr;
  }

  .toggle-grid,
  .form-actions,
  .feedback,
  .rule-form label:nth-child(4),
  .rule-form label:nth-child(5) {
    grid-column: span 1;
  }

  .toolbar-actions,
  .form-actions,
  .sql-actions {
    flex-wrap: wrap;
  }

  .sql-actions label {
    width: 100%;
  }
}
