:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #1f2528;
  --muted: #6c7478;
  --line: #dfe4de;
  --accent: #176b5b;
  --accent-2: #b7472a;
  --accent-3: #d9a72f;
  --soft: #eaf3ef;
  --shadow: 0 12px 28px rgba(31, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

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

.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(31, 37, 40, 0.34);
  z-index: 15;
}

.nav-backdrop[hidden] {
  display: none;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #fbfcfa;
  padding: 16px 14px;
  position: sticky;
  top: 0;
  min-height: 100vh;
  overflow: visible;
}

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

.mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: white;
  font-weight: 800;
  font-size: 20px;
}

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

h1 {
  font-size: 18px;
  line-height: 1.1;
}

.brand p,
.table-toolbar p,
.panel-head span {
  color: var(--muted);
}

.sheet-nav {
  display: grid;
  gap: 3px;
}

.nav-btn {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 7px 9px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  gap: 2px;
}

.nav-btn:hover {
  background: #eef2ed;
}

.nav-btn.active {
  background: var(--soft);
  border-color: #bdd7ce;
}

.nav-btn small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.15;
}

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

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

.topbar-title {
  min-width: 0;
}

.mobile-nav-toggle {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  place-items: center;
  flex: 0 0 auto;
}

.mobile-nav-toggle svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.eyebrow {
  color: var(--accent);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 4px;
}

h2 {
  font-size: 28px;
}

.db-pill {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--muted);
  white-space: nowrap;
}

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

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

.metric {
  padding: 14px;
  min-height: 82px;
}

.metric span {
  display: block;
  color: var(--muted);
  margin-bottom: 8px;
}

.metric strong {
  font-size: 22px;
  line-height: 1.1;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.metrics[hidden],
.dashboard[hidden],
.is-hidden {
  display: none !important;
}

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

.panel.wide {
  grid-column: 1 / -1;
}

.panel-head,
.table-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.panel-head {
  margin-bottom: 14px;
}

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

.bar-row {
  display: grid;
  grid-template-columns: minmax(120px, 210px) minmax(120px, 1fr) 84px;
  align-items: center;
  gap: 10px;
}

.compact .bar-row {
  grid-template-columns: minmax(160px, 360px) minmax(120px, 1fr) 86px;
}

.bar-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.bar-fill {
  height: 100%;
  background: var(--accent);
}

.bar-row:nth-child(3n + 2) .bar-fill {
  background: var(--accent-2);
}

.bar-row:nth-child(3n) .bar-fill {
  background: var(--accent-3);
}

.bar-value {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-section {
  overflow: hidden;
}

.table-toolbar {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.primary-action {
  min-height: 38px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  padding: 8px 12px;
  white-space: nowrap;
}

.primary-action:hover {
  background: #12594c;
}

input,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 10px;
  min-height: 38px;
}

input {
  width: 260px;
}

.filter-menu {
  position: relative;
  flex: 0 0 auto;
}

.filter-btn {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.filter-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.filter-menu.active .filter-btn {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

.filter-menu.disabled .filter-btn {
  opacity: 0.55;
}

.filter-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  min-width: 168px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 6px;
  z-index: 4;
  display: none;
}

.filter-menu.open .filter-popover {
  display: grid;
  gap: 2px;
}

.filter-popover button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  min-height: 34px;
  padding: 7px 9px;
  text-align: left;
  white-space: nowrap;
}

.filter-popover button:hover,
.filter-popover button.selected {
  background: var(--soft);
}

.table-content {
  display: block;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  max-height: none;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

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

th {
  position: sticky;
  top: 0;
  background: #f9faf7;
  z-index: 1;
  cursor: pointer;
  color: #30383b;
  font-weight: 700;
}

td {
  color: #30383b;
}

.has-color {
  min-width: 148px;
}

.color-chip {
  display: inline-grid;
  grid-template-columns: 18px auto auto;
  align-items: center;
  gap: 7px;
  max-width: 100%;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px 3px 4px;
  background: #fff;
  vertical-align: middle;
}

.color-swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(31, 37, 40, 0.18);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.32);
}

.color-label {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 82px;
}

.color-code {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.model-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 86px;
  max-width: 160px;
  align-items: center;
}

.model-color-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid rgba(31, 37, 40, 0.2);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
  flex: 0 0 auto;
}

.photo-link {
  border: 0;
  background: transparent;
  color: #0645ad;
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-variant-numeric: tabular-nums;
}

.photo-link:hover {
  color: #0b0080;
}

.photo-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 37, 40, 0.62);
}

.photo-modal[hidden] {
  display: none;
}

.photo-modal-frame {
  max-width: min(980px, 100%);
  max-height: min(780px, calc(100dvh - 48px));
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(31, 37, 40, 0.28);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.photo-modal img {
  display: block;
  max-width: 100%;
  max-height: min(780px, calc(100dvh - 48px));
  width: auto;
  height: auto;
  object-fit: contain;
}

.photo-modal-close {
  position: fixed;
  top: 14px;
  right: 14px;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 8px;
  background: rgba(31, 37, 40, 0.72);
  color: #fff;
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.photo-modal-close:hover {
  background: rgba(31, 37, 40, 0.9);
}

body.modal-open {
  overflow: hidden;
}

.file-chip {
  display: inline-block;
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fbfcfa;
  color: #30383b;
  padding: 4px 9px;
  margin: 2px 5px 2px 0;
}

.model-name-cell {
  min-width: 280px;
  position: relative;
}

.model-name-input {
  width: min(420px, 100%);
  min-height: 34px;
  padding: 7px 9px;
  border-color: #ccd5d0;
  background: #fff;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}

.model-name-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.14);
}

.model-name-input.saved {
  border-color: var(--accent);
  background: var(--soft);
}

.model-name-input.error {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(183, 71, 42, 0.12);
}

.model-name-menu {
  position: absolute;
  top: calc(100% - 4px);
  left: 10px;
  width: min(420px, calc(100% - 20px));
  max-height: 210px;
  overflow: auto;
  display: grid;
  gap: 2px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 5;
}

.model-name-menu[hidden] {
  display: none;
}

.model-name-menu button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  min-height: 32px;
  padding: 7px 9px;
  text-align: left;
  white-space: nowrap;
}

.model-name-menu button:hover {
  background: var(--soft);
}

.model-name-empty {
  color: var(--muted);
  padding: 8px 9px;
}

.check-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  cursor: pointer;
}

.check-cell input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.check-cell span {
  width: 18px;
  height: 18px;
  border: 1px solid #a7b2ad;
  border-radius: 5px;
  background: #fff;
  display: grid;
  place-items: center;
  transition: background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.check-cell span::after {
  content: "";
  width: 8px;
  height: 5px;
  border-left: 2px solid white;
  border-bottom: 2px solid white;
  transform: rotate(-45deg) translateY(-1px);
  opacity: 0;
}

.check-cell input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
}

.check-cell input:checked + span::after {
  opacity: 1;
}

.check-cell:focus-within span {
  box-shadow: 0 0 0 3px rgba(23, 107, 91, 0.18);
}

tr:hover td {
  background: #fbfcfa;
}

.empty {
  padding: 26px;
  color: var(--muted);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 16px;
}

.pager button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: white;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.pager button:disabled {
  opacity: 0.4;
  cursor: default;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(86vw, 320px);
    min-height: 100dvh;
    max-height: 100dvh;
    overflow: auto;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    border-right: 0;
    border-bottom: 0;
    box-shadow: 18px 0 38px rgba(31, 37, 40, 0.18);
  }

  .app.nav-open .sidebar {
    transform: translateX(0);
  }

  .sheet-nav {
    grid-template-columns: 1fr;
  }

  .mobile-nav-toggle {
    display: grid;
  }

  .topbar {
    align-items: flex-start;
    justify-content: flex-start;
  }

  .topbar .db-pill {
    margin-left: auto;
  }

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

@media (max-width: 640px) {
  body {
    font-size: 13px;
  }

  .main {
    padding: 12px;
  }

  .metrics,
  .dashboard {
    grid-template-columns: 1fr;
  }

  .topbar,
  .toolbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    margin-bottom: 12px;
  }

  .topbar .db-pill {
    grid-column: 1 / -1;
    margin-left: 0;
    width: max-content;
    max-width: 100%;
  }

  h2 {
    font-size: 24px;
    line-height: 1.1;
  }

  .table-toolbar {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 76px;
    gap: 8px;
  }

  input {
    width: 100%;
  }

  .filter-btn {
    width: 100%;
  }

  .filter-popover {
    width: min(240px, calc(100vw - 24px));
  }

  .primary-action {
    grid-column: 1 / -1;
  }

  .photo-modal {
    padding: 12px;
  }

  .photo-modal-frame,
  .photo-modal img {
    max-height: calc(100dvh - 24px);
  }

  table {
    min-width: 680px;
  }

  .bar-row,
  .compact .bar-row {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .bar-value {
    text-align: left;
  }

  .pager {
    justify-content: center;
  }
}
