:root {
  color-scheme: dark;
  --bg: #0c0e12;
  --rail: #11151c;
  --surface: #171b22;
  --surface-2: #1f242d;
  --surface-3: #252b35;
  --border: #303846;
  --text: #edf1f7;
  --muted: #98a3b3;
  --faint: #687385;
  --cyan: #39b7c6;
  --green: #60b16a;
  --amber: #d7a444;
  --red: #db6b6b;
  --blue: #6e9ee8;
  --violet: #a58fe6;
  --shadow: 0 18px 70px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: 0;
}

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

button,
.button-link {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  padding: 7px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}

button:hover,
.button-link:hover {
  border-color: #4a5668;
  background: #29313d;
}

button.primary,
.primary {
  background: #235d68;
  border-color: #347b88;
  color: #f3fdff;
}

button.danger {
  background: #4a2228;
  border-color: #763943;
  color: #ffd9de;
}

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

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--border);
  background: #10141a;
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  outline: none;
}

textarea {
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(57, 183, 198, 0.12);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

pre {
  margin: 0;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  background: var(--rail);
  border-right: 1px solid var(--border);
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 20px;
}

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

.brand img {
  width: 34px;
  height: 34px;
}

.brand strong {
  display: block;
  font-size: 16px;
}

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

.nav {
  display: grid;
  align-content: start;
  gap: 6px;
}

.nav-item {
  width: 100%;
  justify-content: flex-start;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.nav-item.active,
.nav-item:hover {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.sidebar-foot {
  display: grid;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.sidebar-foot a {
  color: var(--muted);
  text-decoration: none;
  font-size: 12px;
}

.sidebar-foot a:hover {
  color: var(--text);
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.topbar h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill,
.badge,
.chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  border: 1px solid var(--border);
  color: var(--muted);
  background: #10141a;
  font-size: 12px;
  white-space: nowrap;
}

.status-pill.ok,
.badge.ok {
  background: rgba(96, 177, 106, 0.14);
  border-color: rgba(96, 177, 106, 0.38);
  color: #a9e7b0;
}

.status-pill.bad,
.badge.bad {
  background: rgba(219, 107, 107, 0.14);
  border-color: rgba(219, 107, 107, 0.42);
  color: #f3b5b5;
}

.badge.warn {
  background: rgba(215, 164, 68, 0.14);
  border-color: rgba(215, 164, 68, 0.38);
  color: #f1d394;
}

.badge.info {
  background: rgba(110, 158, 232, 0.14);
  border-color: rgba(110, 158, 232, 0.36);
  color: #bcd4f8;
}

.auth-panel {
  margin-bottom: 18px;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(180px, 1.4fr) minmax(150px, 0.7fr) minmax(150px, 0.7fr) auto auto;
  gap: 12px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth-help {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 18px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric {
  min-height: 105px;
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  display: grid;
  align-content: space-between;
  overflow: hidden;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
  line-height: 1;
  overflow-wrap: anywhere;
}

.metric small {
  color: var(--faint);
}

.tool-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.tool-tile {
  min-height: 66px;
  display: grid;
  gap: 4px;
  align-content: center;
  padding: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
}

.tool-tile:hover {
  background: var(--surface-2);
  border-color: #4a5668;
}

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

.layout {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.layout.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.editor-layout {
  grid-template-columns: minmax(0, 1.2fr) minmax(360px, 0.8fr);
  align-items: start;
}

.panel {
  min-width: 0;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
}

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

.panel-head h2 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: 0.06em;
}

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

.panel-actions {
  display: flex;
  gap: 8px;
}

.toolbar {
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.toolbar label {
  min-width: 180px;
}

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

.form-stack {
  padding: 14px;
  display: grid;
  gap: 12px;
}

.inline-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.check-row {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.check-row input {
  width: auto;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.table-wrap {
  min-width: 0;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 1;
}

td {
  color: #dce3ed;
}

tr:hover td {
  background: rgba(255, 255, 255, 0.025);
}

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

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

.compact {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wrap {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.row-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
}

.row-actions button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

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

.kv {
  min-width: 0;
  display: grid;
  gap: 3px;
  padding: 10px;
  background: #11161d;
  border: 1px solid var(--border);
  border-radius: 7px;
}

.kv span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kv strong {
  overflow-wrap: anywhere;
}

.output {
  min-height: 120px;
  max-height: 320px;
  overflow: auto;
  margin: 0 14px 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #10141a;
  color: #dce3ed;
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.output.tall {
  min-height: 260px;
}

.catalog {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
}

.catalog-item {
  border: 1px solid var(--border);
  background: #11161d;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.catalog-item strong {
  overflow-wrap: anywhere;
}

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

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(760px, 96vw);
  transform: translateX(102%);
  transition: transform 180ms ease;
  background: #10141a;
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 30;
  display: grid;
  grid-template-rows: auto 1fr;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-head {
  min-height: 58px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}

.drawer-head h2 {
  margin: 0;
  font-size: 16px;
}

.drawer-body {
  min-width: 0;
  overflow: auto;
  padding: 16px;
  display: grid;
  gap: 14px;
}

.detail-block {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
}

.detail-block h3 {
  margin: 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.detail-block pre {
  padding: 12px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #dce3ed;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 40;
  min-width: 220px;
  max-width: min(480px, calc(100vw - 40px));
  padding: 11px 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #11161d;
  color: var(--text);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
  overflow-wrap: anywhere;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.empty,
.error-box {
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.error-box {
  color: #f3b5b5;
}

@media (max-width: 1180px) {
  .metric-grid,
  .tool-row,
  .catalog {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layout.two,
  .editor-layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 820px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
    grid-template-rows: auto auto auto;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .auth-panel,
  .metric-grid,
  .tool-row,
  .catalog,
  .form-grid,
  .kv-grid {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
  }

  .toolbar label,
  .toolbar button,
  .toolbar .button-link {
    width: 100%;
  }
}
