:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --panel: #ffffff;
  --line: #dedbd2;
  --ink: #17201c;
  --muted: #66736d;
  --accent: #0f7c6b;
  --accent-dark: #095f52;
  --blue: #2563eb;
  --amber: #9a5a12;
  --red: #b42318;
  --green-soft: #dff4ee;
  --amber-soft: #fff1d6;
  --blue-soft: #e8efff;
  --red-soft: #ffe8e5;
  --shadow: 0 18px 50px rgba(38, 40, 36, 0.1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

button,
input {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  padding: 0 16px;
  font-weight: 700;
  cursor: pointer;
}

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

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

button.secondary {
  background: #fff;
  color: var(--accent-dark);
}

button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

button.ghost:hover {
  color: var(--ink);
}

.shell {
  min-height: 100vh;
}

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

.loading-box,
.login-box {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.loading-box span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 750;
}

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

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

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

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
}

input:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(15, 124, 107, 0.15);
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.dashboard {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 20px 0 24px;
}

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

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

.metric {
  min-height: 84px;
  display: grid;
  align-content: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

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

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

.metric.wide strong {
  font-size: 18px;
}

.status-strip {
  min-height: 44px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfbfa;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.table-wrap {
  position: relative;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: auto;
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fbfbfa;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

td {
  font-size: 13px;
}

tbody tr:hover {
  background: #faf8f3;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.subtle {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.badge.completed {
  background: var(--green-soft);
  color: var(--accent-dark);
}

.badge.matched_waiting_receipt {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge.waiting,
.badge.queued {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.error {
  background: var(--red-soft);
  color: var(--red);
}

.badge.email-sent {
  background: var(--green-soft);
  color: var(--accent-dark);
}

.badge.email-pending {
  background: var(--blue-soft);
  color: var(--blue);
}

.badge.email-error {
  background: var(--red-soft);
  color: var(--red);
}

.receipt-link {
  display: inline-grid;
  grid-template-columns: 48px auto;
  align-items: center;
  gap: 9px;
  color: var(--accent-dark);
  font-weight: 800;
  text-decoration: none;
}

.receipt-link img {
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
  background: #f1f1ef;
}

.empty {
  padding: 34px;
  color: var(--muted);
  text-align: center;
  font-weight: 750;
}

@media (max-width: 820px) {
  .dashboard {
    padding: 16px;
  }

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

  .actions {
    width: 100%;
    justify-content: stretch;
  }

  .actions button {
    flex: 1 1 130px;
  }

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

  h1 {
    font-size: 24px;
  }
}
