:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-strong: #eef3f6;
  --ink: #151923;
  --muted: #5f6b78;
  --line: #d8e1ea;
  --accent: #007f73;
  --accent-soft: #dff4ef;
  --coral: #d86f45;
  --blue: #3d73c5;
  --gold: #b98517;
  --shadow: 0 18px 50px rgba(17, 24, 39, 0.1);
  --radius: 8px;
  --max-width: 1240px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111419;
  --surface: #1a1f27;
  --surface-strong: #232a35;
  --ink: #f5f7fb;
  --muted: #b5bfcb;
  --line: #323b48;
  --accent: #45c7b5;
  --accent-soft: #143a36;
  --coral: #ff9b70;
  --blue: #9dbbff;
  --gold: #ffd27c;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(90deg, rgba(0, 127, 115, 0.07), transparent 34%),
    linear-gradient(180deg, rgba(216, 111, 69, 0.07), transparent 36%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem max(1rem, calc((100vw - var(--max-width)) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface), transparent 8%);
  backdrop-filter: blur(16px);
}

.brand,
.app-header nav {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}

.brand,
.app-header a {
  text-decoration: none;
}

.brand span {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--surface);
  font-weight: 900;
}

.app-header nav a,
.theme-toggle,
.filter-bar button,
.map-tools button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  min-height: 38px;
  padding: 0.55rem 0.75rem;
  text-decoration: none;
}

.filter-bar button.is-active {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.app-shell {
  width: min(var(--max-width), calc(100% - 2rem));
  margin: 0 auto;
  padding: 4rem 0 5rem;
}

.intro {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 1rem;
  align-items: end;
  margin-bottom: 1.2rem;
}

.intro > div:first-child {
  max-width: 820px;
}

.eyebrow {
  margin: 0 0 0.7rem;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 1rem;
  font-size: clamp(2.3rem, 5.4vw, 4.6rem);
  line-height: 0.98;
}

h2 {
  margin-bottom: 0.5rem;
  font-size: 1.35rem;
}

h3 {
  margin: 1rem 0 0.55rem;
  font-size: 1rem;
}

.intro p,
.detail-panel p,
.metric-grid p,
.lineage-list,
td,
.panel-heading span,
.map-search span {
  color: var(--muted);
}

.metric-grid,
.workspace-grid,
.data-grid {
  display: grid;
  gap: 1rem;
}

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

.metric-grid article,
.map-panel,
.detail-panel,
.lineage-panel,
.dictionary-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), transparent 2%);
  box-shadow: var(--shadow);
}

.metric-grid article {
  padding: 1rem;
}

.metric-grid span {
  display: block;
  color: var(--coral);
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.metric-grid p {
  margin: 0.45rem 0 0;
}

.workspace-grid {
  grid-template-columns: minmax(0, 1fr) 340px;
  align-items: start;
  margin-bottom: 1rem;
}

.data-grid {
  grid-template-columns: 360px minmax(0, 1fr);
}

.map-panel,
.detail-panel,
.lineage-panel,
.dictionary-panel {
  padding: 1rem;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.filter-bar {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.map-search {
  margin-bottom: 0.8rem;
}

.map-search label {
  display: grid;
  gap: 0.35rem;
}

.map-search span,
dt {
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.map-search input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  min-height: 42px;
  padding: 0.6rem 0.75rem;
}

.map-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  margin-bottom: 0.8rem;
}

.map-tools span {
  min-width: 64px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 900;
  text-align: center;
}

.map-tools button {
  min-width: 38px;
  padding: 0.45rem 0.65rem;
}

.map-viewport {
  position: relative;
  height: clamp(430px, 62vh, 660px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--line), transparent 78%) 1px, transparent 1px),
    linear-gradient(180deg, color-mix(in srgb, var(--line), transparent 78%) 1px, transparent 1px),
    var(--surface-strong);
  background-size: 42px 42px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.map-viewport.is-dragging {
  cursor: grabbing;
}

.flow-map {
  position: relative;
  width: 1120px;
  height: 660px;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background:
    linear-gradient(90deg, color-mix(in srgb, var(--line), transparent 78%) 1px, transparent 1px),
    linear-gradient(180deg, color-mix(in srgb, var(--line), transparent 78%) 1px, transparent 1px),
    var(--surface-strong);
  background-size: 42px 42px;
  transform-origin: 0 0;
  will-change: transform;
}

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

.flow-lines path {
  fill: none;
  stroke: color-mix(in srgb, var(--accent), var(--line) 28%);
  stroke-linecap: round;
  stroke-width: 3;
  opacity: 0.55;
}

.flow-lines path.is-active {
  stroke: var(--coral);
  opacity: 1;
  stroke-width: 4;
}

.flow-lines path.is-dimmed {
  opacity: 0.12;
}

.flow-node {
  position: absolute;
  left: var(--x);
  top: var(--y);
  display: grid;
  width: 188px;
  min-height: 98px;
  gap: 0.2rem;
  align-content: start;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface), transparent 2%);
  color: var(--ink);
  cursor: pointer;
  padding: 0.75rem;
  text-align: left;
  box-shadow: 0 10px 26px rgba(17, 24, 39, 0.09);
  transition: border-color 160ms ease, box-shadow 160ms ease, opacity 160ms ease, transform 160ms ease;
}

.flow-node:hover,
.flow-node.is-active {
  border-color: var(--coral);
  border-left-color: var(--coral);
  box-shadow: 0 16px 34px rgba(17, 24, 39, 0.14);
  transform: translateY(-2px);
}

.flow-node.is-dimmed {
  opacity: 0.35;
}

.flow-node span {
  color: var(--coral);
  font-size: 0.76rem;
  font-weight: 900;
}

.flow-node strong,
.flow-node small {
  display: block;
}

.flow-node small {
  color: var(--muted);
  font-weight: 800;
}

.detail-list {
  display: grid;
  gap: 0.65rem;
  margin: 1rem 0;
}

.detail-list div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 0.7rem;
}

dt,
dd {
  margin: 0;
}

dd {
  margin-top: 0.25rem;
  font-weight: 800;
}

.chip-list,
.field-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip-list span,
.field-list span {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.86rem;
  font-weight: 900;
  padding: 0.42rem 0.55rem;
}

.lineage-list {
  display: grid;
  gap: 0.55rem;
  margin: 0;
  padding-left: 1.2rem;
}

.lineage-list li {
  padding-left: 0.2rem;
}

.lineage-list strong {
  color: var(--ink);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 0.58rem 0.65rem;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--ink);
  color: var(--surface);
  font-size: 0.78rem;
}

tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface-strong), transparent 45%);
}

tbody tr.is-highlighted td {
  background: color-mix(in srgb, var(--accent-soft), transparent 20%);
  color: var(--ink);
}

@media (max-width: 1020px) {
  .intro,
  .workspace-grid,
  .data-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-header,
  .app-header nav,
  .panel-heading,
  .metric-grid {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .app-shell {
    padding-top: 2.5rem;
  }

  h1 {
    font-size: 2.4rem;
  }

  .filter-bar {
    justify-content: stretch;
  }

  .filter-bar button {
    flex: 1 1 auto;
  }

  .map-tools {
    justify-content: stretch;
  }

  .map-tools button {
    flex: 1 1 auto;
  }

  .map-viewport {
    height: 430px;
  }

  th,
  td {
    white-space: normal;
  }
}
