:root {
  --bg: #f2f5f7;
  --surface: #ffffff;
  --surface-2: #eef4f3;
  --line: #c8d5d2;
  --text: #20323a;
  --muted: #5f747a;
  --brand: #0b7a75;
  --brand-2: #2f9f93;
  --accent: #b16b3b;
  --shadow: 0 10px 32px rgba(13, 34, 38, 0.08);
}

:root[data-theme='dark'] {
  --bg: #11191d;
  --surface: #18242a;
  --surface-2: #1e2f36;
  --line: #32484e;
  --text: #dce8e7;
  --muted: #9fb2b7;
  --brand: #32b3aa;
  --brand-2: #2f8f88;
  --accent: #d08c57;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Manrope', 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 0%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 45%),
    radial-gradient(circle at 95% 25%, color-mix(in srgb, var(--accent) 20%, transparent), transparent 35%),
    var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
}

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

.brand-wrap p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}

.brand-home,
.brand-mark[data-route] {
  cursor: pointer;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: linear-gradient(140deg, var(--brand), var(--brand-2));
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
}

.top-nav {
  display: flex;
  gap: 8px;
}

button,
input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  padding: 7px 10px;
  font: inherit;
}

button { cursor: pointer; }

.top-nav button.active {
  border-color: var(--brand);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand) 55%, transparent);
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
}

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
}

.main {
  padding: 10px;
}

.hero {
  max-width: 1080px;
  margin: 0 auto 12px;
  text-align: center;
  padding: 18px 10px 8px;
  animation: fade-in 0.5s ease;
}

.pill {
  display: inline-block;
  border: 1px solid var(--brand);
  border-radius: 999px;
  padding: 6px 12px;
  letter-spacing: 0.12em;
  font-weight: 700;
  font-size: 12px;
  color: var(--brand);
}

.hero h1 {
  margin: 10px 0 4px;
  font-size: clamp(28px, 3.4vw, 44px);
  line-height: 1.04;
}

.hero p {
  color: var(--muted);
  margin: 0 0 10px;
}

.search-hero {
  display: grid;
  grid-template-columns: 1fr 52px;
  gap: 8px;
  max-width: 980px;
  margin: 0 auto;
  padding: 7px;
  border: 1px solid color-mix(in srgb, var(--brand) 50%, var(--line));
  border-radius: 24px;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
}

.search-hero input {
  border-radius: 14px;
  font-size: 18px;
  padding: 10px 14px;
}

.search-hero button {
  border-radius: 18px;
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  color: #fff;
  font-size: 24px;
}

.stats {
  margin-top: 8px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.stats span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 5px 10px;
  color: var(--muted);
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 10px;
}

.domain-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  padding: 12px;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.18s ease;
}

.domain-card:hover {
  transform: translateY(-2px);
}

.domain-card .glyph {
  width: 52px;
  height: 52px;
  margin: 0 auto 8px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--brand) 45%, var(--line));
  background: color-mix(in srgb, var(--brand) 16%, transparent);
  color: var(--brand);
  font-size: 17px;
  font-weight: 800;
}

.domain-card h3 {
  margin: 6px 0 4px;
}

.domain-card small {
  color: var(--muted);
}

.domain-card p {
  margin: 10px 0 0;
  color: var(--muted);
}

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 93%, transparent);
  box-shadow: var(--shadow);
}

.data-layout {
  display: grid;
  grid-template-columns: 350px 1fr;
  gap: 10px;
  height: calc(100vh - 88px);
}

.data-layout.catalog-collapsed {
  grid-template-columns: 1fr;
}

.data-layout.catalog-collapsed .catalog-panel {
  display: none;
}

.catalog-panel {
  display: grid;
  grid-template-rows: auto auto auto 1fr;
  padding: 10px;
  min-height: 0;
}

.catalog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.catalog-head h2 {
  margin: 0;
  font-size: 20px;
}

#go-import {
  font-size: 12px;
  padding: 5px 8px;
}

.catalog-panel p {
  margin: 2px 0 7px;
  color: var(--muted);
  font-size: 11px;
}

.catalog-scroll {
  overflow: auto;
  min-height: 0;
  padding-right: 2px;
}

.tree-domain,
.tree-sub {
  margin-top: 8px;
}

.tree-node {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
}

.tree-node.domain {
  font-weight: 700;
}

.tree-leaf {
  width: calc(100% - 18px);
  margin: 5px 0 0 18px;
  text-align: left;
}

.tree-leaf.selected {
  border-color: color-mix(in srgb, var(--brand) 55%, var(--line));
  background: color-mix(in srgb, var(--brand) 18%, var(--surface));
}

.workspace-panel {
  display: grid;
  grid-template-rows: auto auto 1fr;
  padding: 10px;
  min-height: 0;
}

.crumbs {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 8px;
  color: var(--muted);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.crumb-btn {
  border: 0;
  background: transparent;
  color: var(--brand);
  padding: 0;
  font-size: 12px;
  text-decoration: underline;
}

.tab-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.tab-row button.active {
  border-color: var(--brand);
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
}

.workspace-body {
  overflow: auto;
  min-height: 0;
  padding: 6px;
}

.workspace-body h3 {
  margin: 2px 0 8px;
  font-size: 28px;
  line-height: 1;
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 8px;
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
}

.summary-band div {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 8px;
}

.summary-band label {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
}

.meta-card {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  background: var(--surface);
}

.meta-card h4 {
  margin: 0 0 10px;
}

.meta-grid-two {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 8px 14px;
}

.meta-grid-two span {
  color: var(--muted);
}

.tab-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.tab-actions.compact {
  margin-bottom: 4px;
}

.workspace-body p {
  margin: 4px 0 6px;
}

.table-tools {
  margin: 6px 0;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.table-tools input {
  width: min(500px, 100%);
}

.table-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: auto;
  max-height: 64vh;
}

.sql-result-wrap .table-wrap {
  max-height: 42vh;
}

.sql-query-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.sql-query-tabs button.active {
  border-color: var(--brand);
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 6px;
  text-align: left;
  white-space: nowrap;
}

.code {
  width: 100%;
  border-radius: 12px;
  padding: 10px;
  border: 1px solid color-mix(in srgb, var(--brand) 38%, var(--line));
  background: #f7fcfc;
  color: #224149;
  font-family: 'IBM Plex Mono', 'SFMono-Regular', monospace;
  font-size: 12px;
  white-space: pre-wrap;
}

:root[data-theme='dark'] .code {
  background: #102025;
  color: #c4ebe8;
}

.code.sql { color: #1f8f8a; }
.code.json { color: #9968d8; }
.code.yaml { color: #39ab67; }
.code.python { color: #d79f42; }

textarea.code {
  min-height: 180px;
  resize: vertical;
}

.nb-toolbar {
  display: flex;
  gap: 6px;
  margin: 4px 0 8px;
  flex-wrap: wrap;
}

.nb-cells {
  display: grid;
  gap: 8px;
}

.nb-cell {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 6px;
}

.nb-cell header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.nb-cell header span {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
}

.nb-cell textarea {
  min-height: 120px;
}

.syntax {
  margin-top: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.query-actions {
  margin: 10px 0;
}

.query-actions button {
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  color: #fff;
  border-color: transparent;
}

.asset-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.asset-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  margin-bottom: 4px;
}

.asset-list a {
  color: var(--brand);
  text-decoration: none;
}

.filters-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.filters-row label {
  display: grid;
  gap: 5px;
}

.kpi-grid {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 8px;
}

.designer-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 8px;
  min-height: 62vh;
}

.designer-layout.browser-collapsed {
  grid-template-columns: 1fr;
}

.designer-layout.browser-collapsed .field-browser {
  display: none;
}

.field-browser {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.field-browser.collapsed {
  grid-template-rows: auto;
}

.field-browser-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px;
  border-bottom: 1px solid var(--line);
}

.field-browser-head strong {
  font-size: 12px;
}

.field-browser-head button {
  font-size: 11px;
  padding: 4px 7px;
}

.field-browser-body {
  overflow: auto;
  padding: 6px;
}

.field-browser details {
  margin-bottom: 5px;
}

.field-browser summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.field-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  padding: 5px 7px;
  margin: 4px 0 0;
  font-size: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: grab;
}

.field-item small {
  color: var(--muted);
  font-size: 10px;
}

.designer-canvas {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

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

.page-strip button.active {
  border-color: var(--brand);
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 10%, var(--surface));
}

.visual-canvas {
  overflow: auto;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 8px;
  align-content: start;
}

.designer-visual {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 6px;
}

.designer-visual header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px;
  margin-bottom: 6px;
}

.designer-visual header input,
.designer-visual header select {
  font-size: 12px;
  padding: 5px 7px;
}

.designer-visual header button {
  font-size: 11px;
  padding: 5px 7px;
}

.visual-chart {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px;
  margin-bottom: 6px;
}

.visual-chart .viz {
  height: 92px;
}

.barpack {
  display: grid;
  gap: 4px;
}

.barrow {
  display: grid;
  grid-template-columns: 1fr 2.2fr auto;
  gap: 6px;
  align-items: center;
  font-size: 11px;
}

.barrow i {
  height: 8px;
  border-radius: 999px;
  display: block;
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
}

.barrow span {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.barrow b {
  font-size: 10px;
}

.spark {
  width: 100%;
  height: 92px;
  stroke: var(--brand);
  fill: none;
  stroke-width: 2.2;
}

.spark.area polygon {
  fill: color-mix(in srgb, var(--brand) 28%, transparent);
  stroke: none;
}

.kpi-readout {
  height: 92px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  display: grid;
  place-items: center;
}

.kpi-readout strong {
  font-size: 24px;
  line-height: 1;
}

.kpi-readout small {
  color: var(--muted);
}

.mini-table {
  max-height: 92px;
  overflow: auto;
}

.mini-table table {
  font-size: 10px;
}

.visual-wells {
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  gap: 5px;
}

.visual-wells .well {
  min-height: 34px;
  padding: 6px;
  font-size: 11px;
}

.kpi-grid article {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  background: var(--surface);
}

.kpi-grid h4 {
  margin: 0 0 6px;
  font-size: 14px;
}

.viz {
  height: 96px;
  border-radius: 10px;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--brand) 30%, transparent), transparent),
    repeating-linear-gradient(90deg, color-mix(in srgb, var(--brand-2) 16%, transparent), color-mix(in srgb, var(--brand-2) 16%, transparent) 10px, transparent 10px, transparent 18px);
}

.field-pool {
  margin-top: 8px;
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.field {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--surface);
  cursor: grab;
}

.wells {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 8px;
}

.well {
  border: 1px dashed color-mix(in srgb, var(--brand) 40%, var(--line));
  border-radius: 12px;
  padding: 8px;
  min-height: 44px;
}

.search-results {
  margin: 8px auto 0;
  max-width: 980px;
  padding: 6px;
  text-align: left;
}

.match-row {
  width: 100%;
  text-align: left;
  margin-bottom: 4px;
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 8px;
  align-items: center;
  background: var(--surface-2);
}

.match-row:last-child {
  margin-bottom: 0;
}

.match-row small {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-ic {
  display: inline-grid;
  place-items: center;
  width: 16px;
  color: var(--brand);
  font-size: 12px;
}

.tree-details {
  margin-top: 4px;
}

.tree-details summary {
  list-style: none;
}

.tree-details summary::-webkit-details-marker {
  display: none;
}

.tree-node,
.tree-leaf,
.tree-item {
  font-size: 12px;
  padding: 5px 7px;
  border-radius: 9px;
}

.tree-sub .tree-node {
  margin-left: 8px;
  width: calc(100% - 8px);
}

.tree-leaf {
  width: calc(100% - 16px);
  margin: 4px 0 0 16px;
}

.tree-leaf.category {
  font-weight: 600;
}

.tree-item {
  width: calc(100% - 34px);
  margin: 3px 0 0 34px;
  text-align: left;
  background: color-mix(in srgb, var(--surface-2) 75%, var(--surface));
}

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

.chat-bubble {
  position: fixed;
  right: 18px;
  bottom: 16px;
  z-index: 80;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border-color: transparent;
  background: linear-gradient(145deg, var(--brand), var(--brand-2));
  color: #fff;
}

.chat-panel {
  position: fixed;
  right: 18px;
  bottom: 68px;
  width: min(420px, calc(100vw - 24px));
  z-index: 81;
  padding: 8px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  max-height: 72vh;
}

.chat-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.chat-log {
  overflow: auto;
  display: grid;
  gap: 6px;
  margin-bottom: 6px;
}

.chat-msg {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  background: var(--surface-2);
}

.chat-msg.user {
  background: color-mix(in srgb, var(--brand) 12%, var(--surface));
}

.chat-msg b {
  font-size: 11px;
}

.chat-msg p {
  margin: 4px 0;
  white-space: pre-wrap;
}

.chat-input-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.chat-input-row textarea {
  min-height: 64px;
}

.model-edge-grid {
  display: grid;
  gap: 5px;
}

.model-edge {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--brand) 8%, var(--surface));
  padding: 6px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 6px;
}

.model-edge b {
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-edge small {
  grid-column: 1 / -1;
  color: var(--muted);
}

.er-canvas {
  position: relative;
  min-height: 540px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--surface-2) 60%, var(--surface));
  overflow: hidden;
}

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

.er-lines line {
  stroke: color-mix(in srgb, var(--brand) 70%, var(--line));
  stroke-opacity: 0.85;
}

.er-entity {
  position: absolute;
  transform: translate(-50%, -50%);
  min-width: 180px;
  max-width: 220px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.er-entity b {
  display: block;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.er-entity small {
  color: var(--muted);
  font-size: 10px;
}

.er-note {
  position: absolute;
  left: 10px;
  bottom: 8px;
}

.er-details {
  margin-top: 8px;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1200px) {
  .home-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
  .data-layout { grid-template-columns: 1fr; height: auto; }
  .catalog-panel,
  .workspace-panel { min-height: 500px; }
  .designer-layout { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr auto; gap: 8px; }
  .top-nav { grid-column: 1 / -1; }
  .search-hero input { font-size: 16px; }
  .workspace-body h3 { font-size: 26px; }
  .home-grid { grid-template-columns: 1fr; }
  .kpi-grid,
  .wells,
  .summary-band,
  .meta-grid-two,
  .visual-canvas,
  .visual-wells { grid-template-columns: 1fr; }
}
