@import url("https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700;750&display=swap");

:root {
  color-scheme: light;
  --bg: #f8fafc;
  --paper: #fff;
  --ink: #111827;
  --muted: #64748b;
  --line: #e5e7eb;
  --accent: #111827;
  --accent-ink: #fff;
  --warn: #b45309;
  --warn-bg: #fff7ed;
  --ok: #166534;
  --header: #f9fafb;
  --group: #f3f4f6;
}

* { box-sizing: border-box; }

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

main {
  width: 100%;
  padding: 28px 20px 56px;
}

.auth-shell {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 10px;
  max-width: 440px;
  padding: 28px;
  width: 100%;
}

.auth-button {
  margin-top: 22px;
  width: 100%;
}

.auth-divider {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 12px;
  gap: 12px;
  margin: 20px 0;
}

.auth-divider::before,
.auth-divider::after {
  background: var(--line);
  content: "";
  height: 1px;
  flex: 1;
}

.auth-error { color: #b91c1c; }

header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
  margin-bottom: 18px;
}

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

h2 {
  margin: 0;
  font-size: 16px;
}

.sub {
  color: var(--muted);
  margin-top: 7px;
  font-size: 14px;
}

.actions {
  display: flex;
  gap: 10px;
}

button,
.button {
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font: inherit;
  font-weight: 700;
  min-height: 38px;
  padding: 8px 12px;
  text-decoration: none;
}

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

.button.secondary {
  background: var(--paper);
  color: var(--accent);
}

.secondary-button {
  background: var(--paper);
  color: var(--accent);
}

.stats {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0;
  margin-bottom: 16px;
}

.load-error {
  align-items: start;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  display: grid;
  gap: 8px;
  grid-column: 1 / -1;
  line-height: 1.4;
  padding: 14px;
}

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

.load-error button {
  justify-self: start;
}

.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-left-width: 0;
  border-radius: 0;
  color: inherit;
  cursor: default;
  display: block;
  font: inherit;
  padding: 10px 10px;
  text-align: left;
  min-width: 0;
}

.stat:disabled {
  cursor: default;
  opacity: 1;
}

.stat-button {
  cursor: pointer;
}

.stat-button:hover {
  background: var(--header);
}

.stat-right {
  text-align: right;
}

.stat:first-child {
  border-left-width: 1px;
  border-bottom-left-radius: 8px;
  border-top-left-radius: 8px;
}

.stat:last-child {
  border-bottom-right-radius: 8px;
  border-top-right-radius: 8px;
}

.stat strong {
  display: block;
  font-size: 18px;
}

.stat span {
  color: var(--muted);
  font-size: 11px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.controls input,
.controls select {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  min-height: 38px;
  padding: 8px 10px;
}

.controls input {
  min-width: min(420px, 100%);
}

section {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 14px;
  overflow: hidden;
}

.section-title,
summary {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  list-style: none;
  padding: 14px 16px;
}

summary {
  cursor: pointer;
}

summary::-webkit-details-marker {
  display: none;
}

.title {
  font-weight: 750;
}

.badge {
  background: #f3f4f6;
  border-radius: 999px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 750;
  padding: 3px 9px;
}

.admin-layout {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 16px;
}

.admin-layout-single {
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
}

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

.admin-panel-full {
  grid-column: 1 / -1;
}

.admin-panel h3 {
  font-size: 15px;
  margin: 0 0 12px;
}

.admin-button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.admin-form {
  display: flex;
  gap: 10px;
  align-items: end;
}

.admin-field {
  display: block;
  flex: 1 1 auto;
}

.admin-field span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 6px;
}

.admin-field input {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font: inherit;
  min-height: 38px;
  padding: 8px 10px;
  width: 100%;
}

.admin-note,
.admin-empty,
.admin-meta {
  color: var(--muted);
  font-size: 12px;
}

.admin-note {
  margin: 12px 0 0;
}

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

.admin-row {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
}

.admin-email {
  font-weight: 600;
}

.admin-remove-button {
  white-space: nowrap;
}

.admin-result {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  padding: 10px 12px;
}

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

.digest-preview {
  display: grid;
  gap: 16px;
}

.writeback-preview {
  display: block;
}

.digest-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.digest-section-title {
  align-items: center;
  background: var(--header);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 10px 12px;
}

.digest-section-title h4 {
  font-size: 14px;
  margin: 0;
}

.digest-table-wrap {
  max-height: 420px;
  overflow: auto;
}

.digest-table {
  min-width: 1100px;
}

.digest-table th:nth-child(1) { width: 240px; }
.digest-table th:nth-child(2) { width: 220px; }
.digest-table th:nth-child(3) { width: 150px; }
.digest-table th:nth-child(4) { width: 130px; }
.digest-table th:nth-child(5) { width: 170px; }
.digest-table th:nth-child(6) { width: 120px; }
.digest-table th:nth-child(7) { width: 120px; }
.digest-table th:nth-child(8) { width: 260px; }
.digest-table th:last-child { width: 260px; }

.digest-table tr.digest-group-a td {
  background: #fff;
}

.digest-table tr.digest-group-b td {
  background: #f8fafc;
}

.digest-table tr.digest-customer-header td {
  border-top: 10px solid var(--paper);
  color: var(--ink);
  font-weight: 750;
}

.digest-table tr.digest-customer-header.digest-group-a td {
  background: #e5e7eb;
}

.digest-table tr.digest-customer-header.digest-group-b td {
  background: #f1f5f9;
}

.writeback-table-wrap {
  max-height: 520px;
  overflow: auto;
}

.writeback-table {
  min-width: 1180px;
}

.writeback-table th:nth-child(1) { width: 260px; }
.writeback-table th:nth-child(2) { width: 140px; }
.writeback-table th:nth-child(3) { width: 170px; }
.writeback-table th:nth-child(4) { width: 120px; }
.writeback-table th:nth-child(5) { width: 120px; }
.writeback-table th:nth-child(6) { width: 120px; }
.writeback-table th:nth-child(7) { width: 210px; }
.writeback-table th:nth-child(8) { width: 170px; }

.writeback-update td {
  background: var(--warn-bg);
}

.writeback-unchanged td {
  background: #fff;
}

.writeback-missing-stripe-customer td,
.writeback-stripe-error td,
.writeback-missing-stripe-live-mrr td {
  background: #f8fafc;
}

.table-wrap {
  max-height: calc(100vh - 260px);
  overflow: auto;
  width: 100%;
}

table {
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
  min-width: 1380px;
  width: 100%;
}

.col-company { width: 300px; }
.col-hubspot-id { width: 150px; }
.col-stripe-id { width: 165px; }
.col-product { width: 220px; }
.col-unit-price { width: 110px; }
.col-quantity { width: 90px; }
.col-contracted { width: 135px; }
.col-expected { width: 150px; }
.col-stripe-live { width: 125px; }
.col-variance { width: 135px; }

th,
td {
  border-bottom: 1px solid #ece7dc;
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
}

thead th {
  background: var(--header);
  color: var(--muted);
  font-size: 12px;
  position: sticky;
  top: 0;
  user-select: none;
  white-space: nowrap;
  z-index: 2;
}

th.sortable {
  cursor: pointer;
}

tr.group-header {
  background: var(--group);
  border-top: 18px solid var(--paper);
  font-weight: 750;
}

tr.discrepancy {
  background: var(--warn-bg);
}

tr.hidden {
  display: none;
}

.num {
  text-align: right;
  white-space: nowrap;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

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

a:hover {
  text-decoration: underline;
}

#toast {
  background: var(--ink);
  border-radius: 8px;
  bottom: 16px;
  color: white;
  display: none;
  left: 50%;
  max-width: min(760px, calc(100vw - 32px));
  padding: 10px 12px;
  position: fixed;
  transform: translateX(-50%);
}

#toast.visible {
  display: block;
}

@media (max-width: 760px) {
  header {
    align-items: flex-start;
    display: block;
  }

  .actions {
    margin-top: 14px;
  }

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

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-form {
    align-items: stretch;
    flex-direction: column;
  }

  .stat,
  .stat:first-child,
  .stat:last-child {
    border-left-width: 1px;
    border-radius: 8px;
  }
}
