:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #17191c;
  --muted: #66707a;
  --line: #d9dee5;
  --accent: #007c70;
  --accent-dark: #005f56;
  --danger: #b42318;
  --warning: #9a6700;
  --ok: #177245;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

a {
  color: var(--accent-dark);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  min-height: 64px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.nav {
  display: flex;
  flex: 1;
  gap: 16px;
  min-width: 0;
}

.nav a {
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

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

.page {
  margin: 0 auto;
  max-width: 1480px;
  padding: 28px 24px 48px;
}

.login-shell {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: calc(100vh - 80px);
}

.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  max-width: 420px;
  padding: 28px;
  width: 100%;
}

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

.section-head h1,
.login-panel h1 {
  font-size: 28px;
  line-height: 1.2;
  margin: 0 0 8px;
}

.section-head p,
.login-panel p,
.action-panel p {
  color: var(--muted);
  margin: 0;
}

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

.metrics {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 18px;
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: block;
  padding: 16px;
}

.metric:hover {
  border-color: var(--accent);
  text-decoration: none;
}

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

.metric strong {
  display: block;
  font-size: 30px;
  margin-top: 4px;
}

.metric.danger strong {
  color: var(--danger);
}

.table-panel,
.action-panel,
.filter-band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 18px;
}

.table-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 14px 16px;
}

.table-header h2,
.action-panel h2,
.unit-picker h2 {
  font-size: 18px;
  margin: 0;
}

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

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

.wide-table {
  min-width: 1780px;
}

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

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

tbody tr:hover {
  background: #f1f8f6;
}

.empty {
  color: var(--muted);
  padding: 28px 14px;
  text-align: center;
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.error-cell {
  color: var(--danger);
  max-width: 520px;
  white-space: normal;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 6px;
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 8px;
  white-space: nowrap;
}

.status-pending,
.status-processing,
.status-queued {
  background: #e8f6f3;
  border-color: #a9d9d1;
  color: var(--accent-dark);
}

.status-failed,
.status-api_failed,
.status-partial_failed,
.status-skipped {
  background: #fff0ee;
  border-color: #f3b5ae;
  color: var(--danger);
}

.status-uncertain,
.status-existing,
.status-suppressed {
  background: #fff7e6;
  border-color: #e3c071;
  color: var(--warning);
}

.status-success,
.ok {
  background: #eaf7ef;
  border-color: #b9ddc6;
  color: var(--ok);
}

.muted-pill {
  background: #f0f2f4;
  color: var(--muted);
}

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

.filters {
  align-items: end;
  grid-template-columns: minmax(180px, 1fr) minmax(260px, 2fr) 180px auto;
  padding: 16px;
}

.date-filters {
  grid-template-columns: minmax(180px, 220px) minmax(180px, 220px) auto auto;
}

.form-grid {
  padding: 16px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  font-weight: 700;
  gap: 6px;
}

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

textarea {
  min-height: 110px;
  resize: vertical;
}

.checkbox-line {
  align-items: center;
  display: flex;
  flex-direction: row;
  gap: 8px;
}

.checkbox-line input {
  min-height: auto;
  width: auto;
}

.unit-picker {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.unit-list {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 12px;
}

.button {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  font-weight: 700;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  text-decoration: none;
  white-space: nowrap;
}

.button:hover {
  text-decoration: none;
}

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

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

.button.secondary {
  background: #ffffff;
  border-color: var(--line);
  color: var(--text);
}

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

.button.full {
  width: 100%;
}

.link-button {
  background: transparent;
  border: 0;
  color: var(--danger);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 0;
}

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

.center-link {
  display: block;
  font-weight: 700;
  text-align: center;
}

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

.flash {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}

.flash.success {
  background: #eaf7ef;
  border-color: #b9ddc6;
}

.flash.error {
  background: #fff0ee;
  border-color: #f3b5ae;
}

.flash.warning {
  background: #fff7e6;
  border-color: #e3c071;
}

@media (max-width: 920px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 14px;
  }

  .nav {
    flex-wrap: wrap;
  }

  .logout-form {
    width: 100%;
  }

  .metrics,
  .filters,
  .unit-list {
    grid-template-columns: 1fr;
  }

  .section-head {
    flex-direction: column;
  }
}
