:root {
  --bg: #f6f7f2;
  --surface: #ffffff;
  --surface-2: #eef2f4;
  --ink: #1b2328;
  --muted: #6b747c;
  --line: #dce2e6;
  --green: #2f8f68;
  --blue: #2d6cdf;
  --orange: #c87925;
  --red: #c84b4b;
  --teal: #168b8f;
  --violet: #7556b8;
  --shadow: 0 12px 34px rgba(27, 35, 40, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: #20282b;
  color: #f9fbf7;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #e7c45a;
  color: #20282b;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  color: #b8c4c7;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a {
  color: #c9d4d7;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 7px;
}

.nav a.active,
.nav a:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #ffffff;
}

.db-state {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
}

.db-state span,
.db-state strong {
  display: block;
}

.db-state span {
  color: #b8c4c7;
  font-size: 12px;
}

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

.view {
  display: none;
}

.view.active {
  display: block;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

.topbar p,
.panel-head span,
.metric span,
.metric small {
  color: var(--muted);
}

.filters {
  display: flex;
  align-items: end;
  gap: 10px;
}

.filters label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.filters input {
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  background: var(--surface);
  color: var(--ink);
}

.filters button {
  height: 38px;
  border: 0;
  border-radius: 7px;
  padding: 0 18px;
  background: var(--ink);
  color: white;
  cursor: pointer;
}

.notice {
  padding: 12px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
}

.notice.error {
  color: #8f1f1f;
  background: #ffe9e4;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  min-height: 128px;
  padding: 16px;
  display: grid;
  align-content: space-between;
  border-top: 4px solid var(--blue);
}

.metric strong {
  font-size: 30px;
  line-height: 1;
  letter-spacing: 0;
}

.accent-green { border-top-color: var(--green); }
.accent-blue { border-top-color: var(--blue); }
.accent-orange { border-top-color: var(--orange); }
.accent-red { border-top-color: var(--red); }
.accent-teal { border-top-color: var(--teal); }
.accent-violet { border-top-color: var(--violet); }
.accent-yellow { border-top-color: var(--yellow); }

.grid {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}

.grid.two {
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.8fr);
}

.view:not(#view-overview) .grid.two,
.view:not(#view-overview) .grid.three {
  grid-template-columns: 1fr;
}

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

.panel {
  min-width: 0;
  padding: 16px;
}

.panel.wide {
  min-height: 390px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  font-size: 16px;
}

.detail-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.detail-head h2 {
  font-size: 22px;
}

.detail-head span {
  color: var(--muted);
}

canvas {
  width: 100%;
  display: block;
}

.table-wrap {
  overflow-x: auto;
}

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

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

th:first-child,
td:first-child {
  text-align: left;
}

td {
  min-width: 120px;
  max-width: 420px;
  white-space: normal;
  overflow-wrap: anywhere;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
}

.quality-list {
  display: grid;
  gap: 8px;
}

.quality-item,
.coverage div {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--surface-2);
}

.quality-item strong[data-ok="true"] {
  color: var(--green);
}

.quality-item strong[data-ok="false"] {
  color: var(--red);
}

.coverage {
  display: grid;
  gap: 10px;
}

.detail-table-panel {
  margin-top: 14px;
}

.detail-table-panel.loading {
  opacity: 0.72;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--muted);
}

.pager button,
.pager select {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 10px;
}

.pager button {
  cursor: pointer;
}

.pager button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.pager label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.rank-list {
  display: grid;
  gap: 10px;
}

.rank-item {
  position: relative;
  overflow: hidden;
  min-height: 42px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 7px;
  background: var(--surface-2);
}

.rank-item span,
.rank-item strong {
  position: relative;
  z-index: 1;
}

.rank-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-item i {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: rgba(47, 143, 104, 0.14);
}

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

  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 16px;
  }

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

  .db-state {
    display: none;
  }

  .main {
    padding: 16px;
  }

  .topbar {
    display: grid;
  }

  .filters {
    flex-wrap: wrap;
    align-items: end;
  }

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

@media (max-width: 520px) {
  .nav {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .filters label,
  .filters button {
    width: 100%;
  }

  .filters input {
    width: 100%;
  }
}
