:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #111827;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-ink: #ffffff;
  --brand-soft: #eff4ff;
  --ok: #15803d;
  --ok-soft: #ecfdf3;
  --bad: #c62828;
  --bad-soft: #fef2f2;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.05);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #131c2e;
    --surface-2: #18233a;
    --ink: #e5eaf3;
    --muted: #94a3b8;
    --line: #243049;
    --brand: #5b8def;
    --brand-ink: #0b1120;
    --brand-soft: #1a2947;
    --ok: #4ade80;
    --ok-soft: #12301f;
    --bad: #f87171;
    --bad-soft: #3a1818;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ---- top bar ---- */

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

nav {
  display: flex;
  gap: 4px;
  height: 100%;
}

nav button {
  height: 100%;
  padding: 0 14px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--muted);
  font-weight: 550;
}

nav button:hover:not(:disabled) {
  color: var(--ink);
  border-color: transparent;
}

nav button.active,
nav button.active:hover:not(:disabled) {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

main {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px;
}

/* ---- buttons ---- */

button {
  font: inherit;
  font-weight: 550;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}

button:hover:not(:disabled) {
  border-color: var(--muted);
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.45;
  cursor: default;
}

button.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

button.primary:hover:not(:disabled) {
  filter: brightness(1.08);
  border-color: var(--brand);
}

button.danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #fff;
}

button.danger-outline {
  color: var(--bad);
}

button.danger-outline:hover:not(:disabled) {
  border-color: var(--bad);
  background: var(--bad-soft);
}

/* ---- cards and stats ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card.narrow {
  max-width: 640px;
  padding: 24px 26px;
}

h2 {
  margin: 0 0 6px;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 18px 20px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: left;
}

.stat-number {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
}

.stat.ok .stat-number {
  color: var(--ok);
}

.stat.bad .stat-number {
  color: var(--bad);
}

.stat-label {
  color: var(--muted);
  font-weight: 500;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 20px 0;
}

.card .actions,
dialog .actions {
  margin: 20px 0 0;
}

.spacer {
  flex: 1;
}

/* ---- run panel ---- */

.run {
  margin-top: 20px;
  padding: 18px 20px;
  border-color: var(--brand);
  background: var(--brand-soft);
}

.run-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

#run-status {
  flex: 1;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

progress {
  width: 100%;
  height: 8px;
  margin: 14px 0 4px;
  appearance: none;
  border: 0;
  border-radius: 99px;
  overflow: hidden;
  background: var(--line);
}

progress::-webkit-progress-bar {
  background: var(--line);
}

progress::-webkit-progress-value {
  background: var(--brand);
  border-radius: 99px;
  transition: width 0.3s;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
}

/* ---- table ---- */

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

.chips {
  display: flex;
  gap: 6px;
}

.chips button {
  padding: 5px 12px;
  border-radius: 99px;
  color: var(--muted);
}

.chips button.active {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand);
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

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

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.clip {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--brand-soft);
  color: var(--brand);
}

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

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

.row-message {
  margin-top: 4px;
  color: var(--bad);
  font-size: 12px;
  white-space: pre-wrap;
}

#table-note {
  margin: 0;
  padding: 10px 16px;
}

#table-note:empty {
  display: none;
}

.empty {
  margin: 16px;
  padding: 44px 20px;
  text-align: center;
  color: var(--muted);
  border: 2px dashed var(--line);
  border-radius: 12px;
}

.empty p {
  margin: 0;
}

.empty-title {
  color: var(--ink);
  font-size: 16px;
  font-weight: 600;
}

body.dragging .card:has(#drop),
body.dragging .empty {
  border-color: var(--brand);
}

/* ---- forms ---- */

label {
  display: block;
  margin: 14px 0;
  color: var(--muted);
  font-weight: 500;
}

input[type="text"],
input[type="url"],
input[type="password"],
input[type="search"] {
  padding: 8px 11px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
}

label input {
  display: block;
  width: 100%;
  margin-top: 5px;
}

#search {
  width: 220px;
}

.hint {
  color: var(--muted);
  margin: 6px 0;
}

.pair-head,
.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.pair-head {
  margin-top: 16px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ---- footer, dialog, toast ---- */

footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 14px 28px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

footer button {
  padding: 4px 10px;
  font-size: 13px;
}

footer a {
  color: var(--brand);
}

dialog {
  width: min(520px, calc(100vw - 40px));
  padding: 22px 24px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

#dialog-text {
  margin: 0;
  font-size: 15px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 60px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--surface);
  font-weight: 550;
  box-shadow: var(--shadow);
}

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

  .topbar {
    gap: 12px;
    padding: 0 14px;
  }

  main {
    padding: 16px;
  }
}

/* ---- extension banner ---- */

.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 14px 18px;
  border: 1px solid var(--brand);
  border-radius: var(--radius);
  background: var(--brand-soft);
}

.banner p {
  flex: 1;
  min-width: 240px;
  margin: 0;
}

a.button {
  padding: 8px 14px;
  border-radius: 9px;
  font-weight: 550;
  text-decoration: none;
  white-space: nowrap;
}

a.button.primary {
  background: var(--brand);
  color: var(--brand-ink);
}

a.button:empty {
  display: none;
}

/* ---- sign in and account ---- */

.auth {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 28px;
}

.auth .card {
  width: min(420px, 100%);
}

input[type="email"] {
  padding: 8px 11px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
}

.form-error {
  margin: 8px 0 0;
  color: var(--bad);
}

.form-error:empty {
  display: none;
}

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

.tab > .card.narrow + .card.narrow {
  margin-top: 20px;
}

.steps {
  margin: 16px 0 0;
  padding-left: 20px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.user-row span:first-child {
  flex: 1;
  overflow-wrap: anywhere;
}

.user-row button {
  padding: 4px 10px;
  font-size: 13px;
}

/* ---- review and Zoho ---- */

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

.badge.draft {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
}

.review-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.review-bar button {
  padding: 5px 12px;
}

#selected-count {
  color: var(--muted);
  margin-right: 4px;
}

th.check,
td.check {
  width: 36px;
  padding-right: 0;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--brand);
}

select {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 8px 11px;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
}

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

label.inline input {
  width: 16px;
  margin: 0;
}

.pair label {
  margin: 0;
}

#sync-note:empty {
  display: none;
}

@media (max-width: 900px) {
  .stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

.table-tools h2 {
  margin: 0;
}
