.app-shell {
  width: min(1640px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 36px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

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

.metric {
  min-height: 92px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.055), rgba(255, 255, 255, 0.025));
  border-radius: 8px;
  padding: 12px;
}

.metric .label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.metric .value {
  margin-top: 8px;
  font-size: clamp(1rem, 1.6vw, 1.55rem);
  font-weight: 850;
  line-height: 1.05;
}

.metric .sub {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.75rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 12px;
  align-items: stretch;
}

.viz-panel,
.detail-panel,
.data-section {
  min-width: 0;
  border: 1px solid var(--line);
  background: rgba(13, 23, 39, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.viz-panel {
  min-height: 680px;
  overflow: hidden;
}

.viz-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.view-status {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  min-height: 44px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
}

.view-status strong {
  color: var(--soft);
  font-weight: 750;
  min-width: 0;
}

.view-status span {
  white-space: nowrap;
}

.segmented {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

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

.controls label {
  display: grid;
  grid-template-columns: auto 180px;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.controls input[type="range"] {
  width: 180px;
}

.canvas-wrap {
  position: relative;
  height: 560px;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 30% 0%, rgba(73, 209, 255, 0.16), transparent 34%),
    #08111f;
  background-size: 40px 40px, 40px 40px, auto, auto;
}

#flow-canvas,
.node-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.node-layer {
  pointer-events: none;
}

.timeline {
  height: 76px;
  border-top: 1px solid var(--line);
  padding: 10px 12px;
}

.detail-panel {
  min-height: 680px;
  padding: 14px;
  overflow: hidden;
}

.panel-heading {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

#detail-body {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  color: var(--soft);
  font-size: 0.86rem;
}

.detail-grid {
  display: grid;
  gap: 8px;
}

.detail-row {
  display: grid;
  grid-template-columns: 105px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.detail-row span:first-child {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.link-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.data-section {
  margin-top: 12px;
  padding: 14px;
}

.cnt-section {
  min-width: 0;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  background: rgba(13, 23, 39, 0.92);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.cnt-metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
}

.cnt-metric {
  min-height: 86px;
}

.cnt-tables {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.cnt-tables > section {
  min-width: 0;
}

.compact-table {
  max-height: 330px;
}

.cnt-all-wrap {
  max-height: 520px;
}

.cnt-all-wrap table {
  min-width: 1080px;
}

.all-cnt-head {
  margin-top: 16px;
  align-items: flex-end;
}

.all-cnt-head > div:first-child {
  display: grid;
  gap: 4px;
}

.cnt-view-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.cnt-view-tabs button {
  min-width: 118px;
  font-size: 0.74rem;
  font-weight: 800;
}

.asset-cell {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.asset-cell strong,
.asset-cell span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-cell strong {
  color: var(--text);
  font-size: 0.78rem;
}

.asset-cell span {
  color: var(--muted);
  font-size: 0.68rem;
}

.small-note {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-bottom: 12px;
}

.search-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: min(640px, 100%);
  flex-wrap: wrap;
}

.search-tools input {
  width: min(420px, 100%);
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  padding: 0 12px;
}

.audit-button,
.audit-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  border-radius: 8px;
  font-size: 0.84rem;
  font-weight: 850;
  white-space: nowrap;
}

.audit-button {
  border-color: rgba(82, 224, 164, 0.45);
  background: rgba(82, 224, 164, 0.14);
  color: var(--text);
}

.audit-download {
  border: 1px solid rgba(73, 209, 255, 0.55);
  background: rgba(73, 209, 255, 0.12);
  color: var(--cyan);
  padding: 0 12px;
}

.audit-button[hidden],
.audit-download[hidden] {
  display: none;
}

.audit-status {
  min-width: 118px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 750;
}

.audit-dialog {
  width: min(480px, calc(100vw - 32px));
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 24px);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #101a2b;
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 0;
  overflow: hidden;
}

.audit-dialog::backdrop {
  background: rgba(2, 7, 15, 0.72);
}

.audit-dialog form {
  display: grid;
  gap: 12px;
  min-width: 0;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px;
}

.audit-dialog h2 {
  font-size: 1.15rem;
}

.audit-dialog p:not(.eyebrow) {
  color: var(--soft);
  line-height: 1.45;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.dialog-actions button {
  flex: 0 1 128px;
  min-width: 88px;
}

.tables {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 0.9fr);
  gap: 12px;
}

.tables > section {
  min-width: 0;
}

.table-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
  color: var(--muted);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.78rem;
}

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

th {
  position: sticky;
  top: 0;
  background: #111d30;
  color: var(--muted);
  font-size: 0.68rem;
  text-transform: uppercase;
  z-index: 1;
}

td {
  color: var(--soft);
}

@media (max-width: 1180px) {
  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .workspace,
  .tables,
  .cnt-tables {
    grid-template-columns: 1fr;
  }

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

  .detail-panel {
    min-height: 0;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 16px, 680px);
    padding-top: 12px;
  }

  .topbar,
  .viz-toolbar,
  .view-status,
  .section-heading,
  .all-cnt-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

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

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

  .metric {
    min-height: 82px;
  }

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

  .controls label,
  .controls input[type="range"] {
    width: 100%;
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .search-tools {
    align-items: stretch;
    justify-content: stretch;
    min-width: 0;
  }

  .cnt-view-tabs {
    justify-content: stretch;
  }

  .cnt-view-tabs button {
    flex: 1 1 160px;
  }

  .search-tools input,
  .audit-button,
  .audit-download {
    width: 100%;
  }

  .audit-dialog {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
  }

  .audit-dialog form {
    padding: 16px;
  }

  .dialog-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    justify-content: stretch;
  }

  .dialog-actions button {
    width: 100%;
    min-width: 0;
  }

  .canvas-wrap {
    height: 560px;
  }

  table {
    min-width: 860px;
  }

  th,
  td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
