:root {
  --bg: #f4f7f6;
  --ink: #132428;
  --muted: #5f7176;
  --card: #ffffff;
  --border: #d7e2df;
  --accent: #0b8f7a;
  --accent-2: #ef7f1a;
  --danger: #be3c2c;
  --mono: 'IBM Plex Mono', monospace;
  --sans: 'Space Grotesk', sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 21, 23, 0.36);
  backdrop-filter: blur(2px);
}

.auth-gate.hidden {
  display: none;
}

.auth-gate-card {
  width: min(460px, calc(100vw - 32px));
  background: #ffffff;
  border: 1px solid #d7e2df;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 18px 40px rgba(15, 35, 36, 0.18);
}

.auth-gate-card h2 {
  margin: 0 0 8px;
}

.auth-gate-card p {
  margin: 0 0 12px;
  color: var(--muted);
}

body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  background: radial-gradient(circle at 12% 0%, #d9f7f0 0%, transparent 34%),
    radial-gradient(circle at 90% 12%, #ffd9b3 0%, transparent 30%),
    var(--bg);
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
}

.bg-shape {
  position: fixed;
  pointer-events: none;
  filter: blur(70px);
  opacity: 0.26;
}

.bg-shape-a {
  top: -90px;
  left: -40px;
  width: 340px;
  height: 300px;
  background: #2ac8a9;
}

.bg-shape-b {
  right: -60px;
  top: 240px;
  width: 260px;
  height: 220px;
  background: #ff9952;
}

.topbar {
  max-width: 1400px;
  margin: 20px auto 0;
  padding: 18px 20px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  animation: fadeIn 0.45s ease-out;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.4vw, 2rem);
  letter-spacing: 0.01em;
}

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

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

.chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 999px;
  background: #e6f8f4;
  border: 1px solid #b3e5da;
  font-size: 0.82rem;
}

.chip-muted {
  background: #fff;
  border-color: var(--border);
  color: var(--muted);
}

.layout {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px 12px;
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
  min-height: calc(100vh - 118px);
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 10px 24px rgba(12, 37, 40, 0.07);
  min-height: 0;
  min-width: 0;
}

.nav-card {
  position: sticky;
  top: 16px;
  height: fit-content;
}

.nav-card h2 {
  margin: 0 0 10px;
}

.nav-btn {
  width: 100%;
  text-align: left;
  background: #f2f8f7;
  border: 1px solid #d8e8e3;
  color: var(--ink);
  border-radius: 12px;
  padding: 11px 12px;
  margin-bottom: 7px;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
}

.nav-btn:hover {
  transform: translateX(2px);
}

.nav-btn.active {
  background: #dff6f1;
  border-color: #97d8c9;
  font-weight: 700;
}

.quick {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}

.quick h3 {
  margin: 0 0 9px;
  font-size: 0.92rem;
}

.content {
  display: grid;
  gap: 16px;
  overflow: visible;
  min-width: 0;
}

.tab {
  display: none;
  animation: slideIn 0.28s ease;
}

.tab.active {
  display: block;
  min-width: 0;
}

.panel-grid {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
  align-items: start;
  min-width: 0;
}

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

.panel-grid-1 {
  grid-template-columns: 1fr;
}

h2 {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.card-subhead {
  margin-top: 10px;
}

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

input,
textarea,
button,
select {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--border);
}

input,
textarea,
select {
  padding: 10px;
  background: #fff;
  color: var(--ink);
  min-width: 120px;
  flex: 1;
}

textarea {
  width: 100%;
  min-height: 128px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.82rem;
}

button {
  border: none;
  padding: 10px 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

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

button.ghost {
  background: #f2f6f5;
  color: var(--ink);
  border: 1px solid var(--border);
}

button.warn {
  background: var(--danger);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}

.metric {
  background: #f5fbf9;
  border: 1px solid #d8eee8;
  border-radius: 12px;
  padding: 8px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric strong {
  font-size: 1.1rem;
}

.bar-track {
  height: 10px;
  border-radius: 999px;
  background: #edf3f1;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.table-wrap {
  max-height: clamp(260px, calc(100vh - 430px), 520px);
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

.table-wrap-stats {
  height: clamp(360px, calc(100vh - 410px), 680px);
  max-height: clamp(360px, calc(100vh - 410px), 680px);
  overflow-y: auto;
  overflow-x: auto;
}

.coverage-table td:last-child {
  min-width: 210px;
}

.rate-cell {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.card-coverage {
  min-height: 0;
}

#tab-materializer .panel-grid.panel-grid-2 > .card {
  min-height: 280px;
}

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

#tab-schema-fix .table-wrap table {
  width: 100%;
  min-width: 0;
  table-layout: auto;
}

#tab-schema-fix .table-wrap th,
#tab-schema-fix .table-wrap td {
  white-space: normal;
  word-break: break-word;
}

#tab-schema-fix .table-wrap {
  overflow-x: scroll;
  padding-bottom: 6px;
  width: 100%;
  display: block;
  box-sizing: border-box;
  max-width: 100%;
}

thead {
  background: #f3f8f7;
}

.table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}

th,
td {
  text-align: left;
  padding: 9px 8px;
  border-bottom: 1px solid #ecf1ef;
  vertical-align: top;
}

tbody tr:hover {
  background: #f9fcfb;
}

.table-wrap tbody tr.managed-row td {
  background: #e7f8ef;
}

#scanTable tr[data-table-id] {
  cursor: pointer;
}

.mono {
  font-family: var(--mono);
  font-size: 0.78rem;
}

.result-head {
  color: var(--muted);
  margin-bottom: 8px;
}

.json {
  margin: 0;
  min-height: 110px;
  max-height: 240px;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid #172130;
  background: #101a25;
  color: #d7ecff;
  padding: 10px;
  font-family: var(--mono);
  font-size: 0.77rem;
}

.progress-wrap {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

#renameAdvanced {
  margin-bottom: 10px;
}

#renameAdvanced > summary {
  cursor: pointer;
  color: var(--muted);
  margin-bottom: 8px;
}

#tab-bq-tools .bq-main-row,
#tab-bq-tools .bq-actions-row,
#tab-bq-tools .bq-drop-row {
  gap: 12px;
  margin-bottom: 12px;
}

#tab-bq-tools .bq-actions-row button {
  min-width: 260px;
}

#tab-bq-tools .bq-drop-row input {
  flex: 1 1 420px;
}

#tab-bq-tools .bq-drop-row button {
  min-width: 300px;
}

#tab-bq-tools .advanced-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 14px;
}

#tab-bq-tools .field-stack {
  display: grid;
  gap: 8px;
}

#tab-bq-tools .field-stack > span {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: none;
  letter-spacing: 0;
}

@media (max-width: 1100px) {
  #tab-bq-tools .bq-actions-row button,
  #tab-bq-tools .bq-drop-row button {
    min-width: 0;
    width: 100%;
  }

  #tab-bq-tools .advanced-grid {
    grid-template-columns: 1fr;
  }
}

.badge {
  display: inline-flex;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  border: 1px solid;
}

.badge-yes {
  background: #e4faf2;
  border-color: #91dec5;
  color: #1c6b56;
}

.badge-no {
  background: #fff1ea;
  border-color: #f0c3aa;
  color: #7f3f20;
}

.mismatch-actions {
  display: grid;
  gap: 10px;
  min-width: 360px;
}

.mismatch-action-btn {
  padding: 6px 8px;
  font-size: 0.75rem;
}

.mismatch-action-group {
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fbfcfd;
}

.mismatch-action-title {
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

.mismatch-action-btn.action-schema {
  border-color: #e2b68e;
  background: #fff7ef;
  color: #7a3f11;
}

.mismatch-action-btn.action-cast {
  border-color: #9fc8b9;
  background: #eef8f3;
  color: #1e5e4b;
}

.mismatch-sample-wrap {
  display: grid;
  gap: 6px;
  min-width: 220px;
}

.mismatch-sample-values {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.sample-chip {
  display: inline-flex;
  border: 1px solid #d6dde3;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.7rem;
  background: #fff;
}

.mismatch-sample-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--muted);
}

#fieldDbReport {
  margin: 10px 0 12px 0;
  min-height: 64px;
}

.field-desc-actions {
  display: flex;
  gap: 4px;
  min-width: 0;
  white-space: nowrap;
}

.field-desc-btn {
  padding: 4px 7px;
  font-size: 0.72rem;
}

#tab-field-db .table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  display: block;
  width: 100%;
  max-width: 100%;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}

#tab-field-db table {
  width: max-content;
  min-width: 1100px;
  table-layout: auto;
}

#tab-field-db th,
#tab-field-db td {
  padding: 6px 7px;
  line-height: 1.25;
}

#tab-field-db th:nth-child(1),
#tab-field-db td:nth-child(1) { width: 130px; }

#tab-field-db th:nth-child(2),
#tab-field-db td:nth-child(2) { width: 170px; }

#tab-field-db th:nth-child(3),
#tab-field-db td:nth-child(3) { width: 140px; }

#tab-field-db th:nth-child(4),
#tab-field-db td:nth-child(4) { width: 120px; }

#tab-field-db th:nth-child(5),
#tab-field-db td:nth-child(5) { width: 130px; }

#tab-field-db th:nth-child(6),
#tab-field-db td:nth-child(6) {
  width: 300px;
  white-space: normal;
  word-break: break-word;
}

#tab-field-db th:nth-child(7),
#tab-field-db td:nth-child(7) {
  width: 165px;
  white-space: nowrap;
}

.field-policy-cell {
  position: relative;
}

.field-policy-btn {
  padding: 4px 8px;
  font-size: 0.72rem;
}

.field-policy-pop {
  display: none;
  position: absolute;
  left: 8px;
  top: calc(100% - 2px);
  z-index: 8;
  min-width: 320px;
  max-width: 460px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  box-shadow: 0 10px 22px rgba(12, 37, 40, 0.11);
}

.field-policy-pop.open {
  display: grid;
  gap: 5px;
}

.field-policy-pop-row {
  font-size: 0.76rem;
  line-height: 1.3;
}

.danger {
  border-color: #efc2bc;
  background: linear-gradient(180deg, #fff7f5 0%, #fff 65%);
}

#tab-materializer .danger .json {
  min-height: 60px;
  max-height: 120px;
}

.toast-zone {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: grid;
  gap: 8px;
  z-index: 40;
}

.toast {
  min-width: 230px;
  max-width: 380px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
  box-shadow: 0 8px 26px rgba(17, 31, 39, 0.15);
  animation: fadeIn 0.2s ease-out;
}

.toast.ok {
  border-color: #9cdbc9;
}

.toast.err {
  border-color: #edb7b0;
}

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

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1160px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .nav-card {
    position: static;
  }
}

@media (max-width: 900px) {
  .panel-grid-2 {
    grid-template-columns: 1fr;
  }
  .bar-row {
    grid-template-columns: 1fr;
  }
  .metric-strip {
    grid-template-columns: 1fr;
  }
}
