:root {
  color-scheme: light;
  --bg: #f6f7f3;
  --panel: #ffffff;
  --ink: #1e2524;
  --muted: #66716d;
  --line: #d9ded8;
  --accent: #236b5a;
  --accent-dark: #184b40;
  --soft: #edf4f1;
  --warn: #8b5e1c;
}

* {
  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;
}

.topbar {
  align-items: center;
  background: #173b35;
  color: #fff;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px);
}

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

.top-actions a {
  color: #e8f1ee;
  font-weight: 750;
  text-decoration: none;
}

.top-actions form {
  margin: 0;
}

.topbar h1 {
  font-size: 28px;
  line-height: 1.1;
  margin: 0 0 6px;
}

.topbar p {
  color: #d6e2de;
  margin: 0;
}

main {
  margin: 0 auto;
  max-width: 1180px;
  padding: 24px clamp(14px, 3vw, 32px) 48px;
}

button,
.secondary,
.pagination a {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-weight: 650;
  min-height: 40px;
  padding: 8px 14px;
  text-decoration: none;
}

button {
  background: var(--panel);
}

.primary,
.status-panel button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

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

.filters {
  align-items: end;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr)) auto auto;
  gap: 14px;
  padding: 16px;
}

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

input,
select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  min-height: 40px;
  min-width: 0;
  padding: 8px 10px;
}

.check {
  align-items: center;
  display: flex;
  font-size: 14px;
  min-height: 40px;
}

.check input {
  min-height: auto;
}

.list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.email-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.email-card.status-paid {
  background: #edf8ef;
  border-color: #9bd0a5;
}

.email-card.status-waived {
  background: #fff0f0;
  border-color: #e4a2a2;
}

.email-card.status-under-review {
  background: #fff;
}

.email-main {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) 290px;
}

.meta,
.count {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

h2 {
  font-size: 18px;
  line-height: 1.3;
  margin: 5px 0 8px;
  overflow-wrap: anywhere;
}

.sender {
  color: var(--accent-dark);
  font-weight: 700;
  margin: 0 0 8px;
  overflow-wrap: anywhere;
}

.preview {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.status-panel {
  border-left: 1px solid var(--line);
  padding-left: 18px;
}

.status-panel form {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.attachments a {
  background: var(--soft);
  border: 1px solid #c8ddd5;
  border-radius: 6px;
  color: var(--accent-dark);
  font-weight: 700;
  max-width: 100%;
  overflow-wrap: anywhere;
  padding: 8px 10px;
  text-decoration: none;
}

.attachments span {
  color: var(--muted);
  font-weight: 600;
  margin-left: 6px;
}

details {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 12px;
}

summary {
  color: var(--warn);
  cursor: pointer;
  font-weight: 800;
}

.history {
  color: var(--muted);
  line-height: 1.7;
  margin: 10px 0 0;
  padding-left: 22px;
}

.history strong {
  color: var(--ink);
}

.history span {
  margin-left: 8px;
}

.empty {
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 32px;
  text-align: center;
}

.pagination {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 22px;
}

.pagination .disabled {
  opacity: 0.45;
  pointer-events: none;
}

.auth-page {
  align-items: center;
  display: flex;
  min-height: 100vh;
  padding: 24px;
}

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

.login-panel h1 {
  margin: 0 0 8px;
}

.login-panel p {
  color: var(--muted);
  margin: 0 0 20px;
}

.google-button {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 44px;
  padding: 10px 14px;
  text-decoration: none;
  width: 100%;
}

.notice {
  background: #fff3d8;
  border: 1px solid #e3c06e;
  border-radius: 6px;
  color: #735011;
  margin-bottom: 16px;
  padding: 10px 12px;
}

.table-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 18px;
  overflow-x: auto;
}

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

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

th {
  background: #eef2ed;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td input[type="email"],
td input[type="text"] {
  width: 100%;
}

.center {
  text-align: center;
}

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

.actions form {
  margin: 0;
}

.danger {
  background: #a83939;
  border-color: #a83939;
  color: #fff;
}

pre {
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  margin: 0;
  max-width: 460px;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 980px) {
  .filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .email-main {
    grid-template-columns: 1fr;
  }

  .status-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 14px;
  }
}

@media (max-width: 620px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

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