:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-soft: #eef4f2;
  --text: #18201f;
  --muted: #66716e;
  --line: #d9e0dc;
  --primary: #176f62;
  --primary-strong: #0d4f47;
  --accent: #7b3f98;
  --danger: #b12a34;
  --warning: #a66000;
  --shadow: 0 18px 50px rgba(18, 28, 25, 0.08);
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  padding: 14px clamp(16px, 4vw, 40px);
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 760;
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  background: var(--primary);
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
}

.brand-mark.large {
  width: 52px;
  height: 52px;
  font-size: 15px;
}

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

.nav a {
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
}

.nav a.active,
.nav a:hover {
  color: var(--text);
  background: var(--surface-soft);
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 28px auto 60px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

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

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
}

.login-heading {
  display: grid;
  gap: 8px;
  margin-bottom: 24px;
}

.login-heading h1,
.page-head h1,
.panel h2 {
  margin: 0;
  line-height: 1.16;
}

.login-heading p {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

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

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.button:hover {
  border-color: #b8c5c0;
}

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.button.primary:hover {
  background: var(--primary-strong);
}

.button.subtle {
  background: transparent;
  box-shadow: none;
}

.button.full {
  width: 100%;
}

.button.compact {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 13px;
}

.logout-form {
  margin: 0;
}

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

.metric {
  display: grid;
  gap: 8px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  font-size: 32px;
  line-height: 1;
}

.metric .metric-small {
  font-size: 17px;
  line-height: 1.2;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.7fr);
  gap: 18px;
  margin-bottom: 18px;
}

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

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

.panel h2 {
  font-size: 18px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  gap: 9px 16px;
  margin: 0;
}

.detail-grid.wide {
  grid-template-columns: 230px minmax(0, 1fr);
}

.detail-grid dt {
  color: var(--muted);
  font-weight: 700;
}

.detail-grid dd {
  margin: 0;
  overflow-wrap: anywhere;
}

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

.status-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.status-list div:last-child {
  border-bottom: 0;
}

.badge,
.status-pill,
.mini-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.badge.success {
  background: #dff4ee;
  color: #0d5d50;
}

.badge.no_results {
  background: #edf0f5;
  color: #4d5968;
}

.badge.error,
.mini-badge.warn {
  background: #fde5e7;
  color: var(--danger);
}

.mini-badge {
  margin: 2px 3px 2px 0;
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.flash {
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  font-weight: 700;
}

.flash.success {
  border-color: #9ed6c8;
  color: #0d5d50;
}

.flash.info {
  border-color: #b6c3d5;
  color: #41526a;
}

.flash.error {
  border-color: #f1a7ad;
  color: var(--danger);
}

.form-stack {
  display: grid;
  gap: 14px;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px) auto auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  padding: 9px 10px;
  border: 1px solid #cbd6d1;
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

textarea {
  resize: vertical;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.table-link {
  color: var(--primary-strong);
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.muted {
  color: var(--muted);
}

.block {
  display: block;
}

.danger-text {
  color: var(--danger);
  font-weight: 700;
}

.empty,
.empty-cell {
  color: var(--muted);
}

.empty-cell {
  text-align: center;
  padding: 26px;
}

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

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

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

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

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

  .detail-grid,
  .detail-grid.wide {
    grid-template-columns: 1fr;
  }
}
