:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #eef3ef;
  --ink: #17201b;
  --muted: #69736d;
  --line: #dfe5df;
  --teal: #0f766e;
  --green: #2f7d4f;
  --amber: #b97912;
  --red: #b42318;
  --coal: #22302a;
  --shadow: 0 18px 50px rgba(22, 32, 27, 0.10);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}

a {
  color: inherit;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

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

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

.brand,
.nav a,
.ghost-button,
.text-button,
.primary-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand {
  text-decoration: none;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: #d7eadf;
  color: #143d2a;
  font-weight: 900;
  letter-spacing: 0;
}

.brand strong {
  display: block;
  font-size: 1rem;
}

.brand small {
  color: #b8c7bf;
  font-size: 0.78rem;
}

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

.nav a {
  color: #dce5df;
  text-decoration: none;
  min-height: 42px;
  padding: 0 12px;
  border-radius: var(--radius);
}

.nav a.active,
.nav a:hover {
  background: #24362e;
  color: #ffffff;
}

.logout-form {
  margin-top: auto;
}

.content {
  min-width: 0;
  padding: 26px clamp(18px, 3vw, 42px) 54px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.eyebrow,
.source {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 2.4vw, 2.7rem);
  line-height: 1.04;
}

h2 {
  font-size: 1.02rem;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  white-space: nowrap;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.metric {
  min-height: 96px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: grid;
  align-content: space-between;
}

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

.metric strong {
  font-size: 2rem;
  line-height: 1;
}

.filterbar,
.admin-strip,
.form-panel,
.table-panel,
.run-item,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filterbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px 44px;
  gap: 10px;
  padding: 10px;
  margin-bottom: 18px;
  box-shadow: none;
}

.searchbox {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: var(--radius);
  padding: 0 12px;
}

.searchbox input,
.filterbar select,
.grid-form input,
.grid-form select,
.note-form input,
.run-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
}

.searchbox input {
  border: 0;
  background: transparent;
  outline: 0;
  min-width: 0;
}

.listing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}

.listing-card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: grid;
  grid-template-rows: 188px minmax(0, 1fr);
  box-shadow: var(--shadow);
}

.listing-media {
  position: relative;
  background: #dfe8e1;
  overflow: hidden;
}

.listing-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-placeholder {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(23, 32, 27, 0.06) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 32, 27, 0.06) 1px, transparent 1px),
    #dfe8e1;
  background-size: 28px 28px;
}

.media-placeholder span {
  width: 68px;
  height: 68px;
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--teal);
  display: grid;
  place-items: center;
  font-size: 1.4rem;
  font-weight: 900;
  box-shadow: 0 12px 24px rgba(22, 32, 27, 0.14);
}

.score-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  min-width: 46px;
  height: 34px;
  padding: 0 10px;
  border-radius: var(--radius);
  display: inline-grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-weight: 850;
}

.listing-body {
  min-width: 0;
  padding: 16px;
  display: grid;
  gap: 12px;
  align-content: start;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.card-head h2 a {
  text-decoration: none;
}

.card-head h2 a:hover {
  color: var(--teal);
}

.status-pill {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 5px 9px;
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-weight: 800;
  background: var(--surface-2);
  color: var(--coal);
  white-space: nowrap;
}

.status-match .status-pill,
.status-pill.ok {
  background: #dff1e5;
  color: #175e37;
}

.status-review .status-pill {
  background: #fff1d5;
  color: #84510c;
}

.status-reject .status-pill,
.status-pill.off {
  background: #f8dedb;
  color: #8d2118;
}

.area-line,
.summary,
.error-line {
  margin: 0;
  color: var(--muted);
}

.area-line {
  display: flex;
  gap: 7px;
  align-items: center;
  min-width: 0;
}

.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.facts span {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--coal);
  background: #fbfcfb;
  min-width: 0;
}

.summary {
  line-height: 1.42;
}

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

.chips span {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--coal);
  font-size: 0.78rem;
  font-weight: 700;
}

.chips .warning {
  background: #fff1d5;
  color: #84510c;
}

.card-actions,
.note-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.note-form {
  min-width: 0;
}

.icon-button,
.ghost-button,
.text-button,
.primary-button {
  border: 0;
  border-radius: var(--radius);
  min-height: 42px;
  text-decoration: none;
}

.icon-button {
  width: 42px;
  justify-content: center;
  background: var(--surface-2);
  color: var(--coal);
}

.icon-button:hover,
.icon-button.selected {
  background: #d7eadf;
  color: var(--teal);
}

.text-button {
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.ghost-button {
  width: 100%;
  justify-content: center;
  background: #24362e;
  color: #ffffff;
  padding: 0 12px;
}

.primary-button {
  justify-content: center;
  background: var(--teal);
  color: #ffffff;
  padding: 0 16px;
  font-weight: 800;
}

.primary-button:hover {
  background: #0b5f59;
}

.primary-button.is-busy::after {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-top-color: #ffffff;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.flash {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-weight: 700;
}

.flash-success {
  background: #dff1e5;
  color: #175e37;
}

.flash-error {
  background: #f8dedb;
  color: #8d2118;
}

.admin-strip {
  padding: 12px;
  margin-bottom: 18px;
  box-shadow: none;
}

.run-form {
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: 360px;
}

.table-panel {
  overflow-x: auto;
  margin-bottom: 18px;
}

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

th,
td {
  text-align: left;
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0;
}

td form {
  margin: 0;
}

.form-panel {
  padding: 18px;
  margin-bottom: 18px;
}

.form-panel h2 {
  margin-bottom: 14px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 12px;
  align-items: end;
}

.grid-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
}

.run-list {
  display: grid;
  gap: 12px;
}

.run-item {
  padding: 16px;
  box-shadow: none;
}

.run-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
}

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

.run-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.run-metrics span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  border-radius: var(--radius);
  background: var(--surface-2);
  font-weight: 750;
}

.empty-state {
  min-height: 220px;
  grid-column: 1 / -1;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  color: var(--muted);
}

.empty-state svg {
  width: 42px;
  height: 42px;
}

svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  flex: 0 0 auto;
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(23, 32, 27, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 32, 27, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 34px 34px;
}

.login-shell {
  width: min(100%, 430px);
  min-width: 0;
}

.login-panel {
  min-width: 0;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  overflow: hidden;
}

.login-panel .brand-mark {
  margin-bottom: 18px;
}

.login-panel h1 {
  margin-bottom: 22px;
  max-width: 100%;
  overflow-wrap: anywhere;
  hyphens: auto;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  color: var(--muted);
  font-weight: 750;
  font-size: 0.86rem;
}

.login-form input {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
}

.login-form .primary-button {
  margin-top: 8px;
  min-height: 48px;
}

@media (max-width: 1080px) {
  .metric-grid {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }

  .grid-form {
    grid-template-columns: repeat(2, minmax(150px, 1fr));
  }
}

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

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

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

  .nav a {
    justify-content: center;
  }

  .nav a span,
  .ghost-button span {
    display: none;
  }

  .logout-form {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 44px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

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

@media (max-width: 560px) {
  .login-body {
    padding: 14px;
  }

  .login-panel {
    padding: 22px;
  }

  .login-panel h1 {
    font-size: clamp(1.45rem, 9vw, 2rem);
    line-height: 1.08;
  }

  .content {
    padding: 18px 12px 36px;
  }

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

  .listing-card {
    grid-template-rows: 168px minmax(0, 1fr);
  }

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

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

  .run-form,
  .run-item {
    grid-template-columns: 1fr;
  }

  .run-form {
    display: grid;
    max-width: none;
  }

  .run-metrics {
    justify-content: flex-start;
  }
}
