:root {
  --bg: #f4efe6;
  --ink: #1c1914;
  --muted: #6b6256;
  --card: #fffdf8;
  --line: #ddd4c4;
  --accent: #1f4d3a;
  --accent-2: #c47b2b;
  --danger: #8b2e1f;
  --ok: #1f4d3a;
  --shadow: 0 18px 50px rgba(48, 38, 22, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #fff8ea, transparent 50%),
    var(--bg);
}

.page {
  width: min(1480px, calc(100% - 32px));
  margin: 36px auto 80px;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 16px 40px;
}
.login-card {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.login-card h1 { font-size: 28px; }
.login-subtitle {
  color: var(--muted);
  margin: 8px 0 24px;
}
.login-card .field { margin-bottom: 14px; }
.login-card button { width: 100%; margin-top: 8px; }
.login-error {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f8e8e4;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
  margin-bottom: 28px;
}
.top-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}
.text-btn {
  background: transparent;
  color: var(--muted);
  padding: 4px 0;
}
.page-label {
  color: var(--muted);
  font-size: 13px;
  align-self: center;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 12px;
  color: var(--accent-2);
  margin: 0 0 8px;
}

h1 {
  margin: 0;
  font-size: 42px;
  letter-spacing: -0.02em;
  font-weight: 650;
}

.lede {
  max-width: 620px;
  color: var(--muted);
  line-height: 1.45;
  margin: 10px 0 0;
}

.status {
  border: 1px solid var(--line);
  background: var(--card);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
}
.status.ok { color: var(--ok); }
.status.bad { color: var(--danger); }
.status.pending { color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 22px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-height: 190px;
  border: 1.5px dashed #c9b89a;
  border-radius: 16px;
  background: #fbf6ec;
  cursor: pointer;
  text-align: center;
  padding: 24px;
}
.dropzone.drag { background: #f3ead3; border-color: var(--accent-2); }
.dropzone input { display: none; }
.dropzone strong { font-size: 22px; }
.dropzone span, .dropzone em { color: var(--muted); font-style: normal; }

.controls {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  margin-top: 18px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 180px;
}
.field span { font-size: 14px; }
.field small { color: var(--muted); font-size: 12px; }
.field input {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

button {
  font: inherit;
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  background: var(--accent);
  color: #f7f1e6;
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.tab, .actions button {
  background: #efe7d6;
  color: var(--ink);
}
button.tab.active { background: var(--accent); color: #f7f1e6; }
.actions button.accent,
button.accent {
  background: var(--accent);
  color: #f7f1e6;
}
button.secondary {
  background: #efe7d6;
  color: var(--ink);
}

.results { margin-top: 28px; }
.hidden { display: none !important; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
}
.stat b { display: block; font-size: 28px; }
.stat span { color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 8px; margin-bottom: 12px; }
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}
.panel-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.panel-bar h2 { margin: 0; font-size: 20px; }
.actions { display: flex; gap: 8px; }

.sql-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.adds-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: auto;
  max-height: 70vh;
}
.add-row {
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.add-row:last-child { border-bottom: 0; }
.add-row-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border-radius: 0;
  padding: 8px 10px;
}
.add-row-head:hover { background: #fbf6ec; }
.add-row-head .row-expand {
  background: #efe7d6;
  color: var(--ink);
  padding: 2px 8px;
  min-width: 28px;
  flex: 0 0 auto;
}
.add-card-title {
  font-weight: 650;
}
.add-card-meta {
  color: var(--muted);
  font-size: 13px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 20, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  width: min(540px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 24px;
}
.modal h2 { margin: 0 0 8px; font-size: 22px; }
.modal-lead { color: var(--muted); line-height: 1.45; margin: 0 0 16px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.progress-track {
  height: 10px;
  background: #efe7d6;
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}
.modal-step { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.modal-name { font-weight: 650; margin: 12px 0 0; }
.progress-log {
  max-height: 160px;
  overflow: auto;
  margin: 12px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
}
.progress-log .bad { color: var(--danger); }
.progress-log .ok { color: var(--ok); }

.table-wrap { overflow: auto; }
.add-audit {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 6px 16px;
  margin: 0;
  padding: 14px 16px 8px;
}
.add-audit dt {
  color: var(--muted);
  font-size: 12px;
  padding-top: 4px;
}
.add-audit dd { margin: 0; overflow-wrap: anywhere; }
.add-audit .blank { color: #b5aa98; }
.add-audit pre,
.add-card-sql {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.4;
  background: #fbf6ec;
  border-radius: 8px;
  padding: 10px 12px;
}
.add-card-sql-wrap {
  padding: 0 16px 16px;
}
.add-card-sql-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }

.empty, .warnings { color: var(--muted); }
.warnings { margin-top: 14px; white-space: pre-wrap; }
.error {
  margin-top: 16px;
  color: var(--danger);
  background: #f8e8e4;
  border: 1px solid #e3c2ba;
  border-radius: 12px;
  padding: 12px 14px;
}

@media (max-width: 800px) {
  .top, .controls, .panel-bar { flex-direction: column; align-items: stretch; }
  .stats { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 32px; }
}
