:root {
  --bg: #f3f0ea;
  --bg2: #e8e2d8;
  --panel: #fffcf7;
  --ink: #1a1c18;
  --muted: #5c6358;
  --line: #d4cdc0;
  --accent: #0f6b4c;
  --accent2: #0a4f38;
  --warn: #9a3412;
  --ok: #166534;
  --err: #991b1b;
  --radius: 10px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, #d8ebe1 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, #efe6d4 0%, transparent 50%),
    var(--bg);
  line-height: 1.45;
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.brand {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}

.top h1 {
  margin: 0.2rem 0 0.35rem;
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sub {
  margin: 0;
  color: var(--muted);
  max-width: 36rem;
  font-size: 0.95rem;
}

.badge {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 0.75rem;
  border-radius: 999px;
  background: var(--bg2);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.badge.on {
  background: #dcfce7;
  color: var(--ok);
  border-color: #86efac;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem 1.4rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 0 rgba(255,255,255,0.7) inset;
}

.panel.muted { opacity: 0.55; pointer-events: none; }
.panel.active { opacity: 1; pointer-events: auto; }

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1.05rem;
  font-weight: 600;
}

.panel h3 {
  margin: 1.35rem 0 0.45rem;
  font-size: 0.98rem;
  font-weight: 600;
}

.sql-jobs {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}

.sql-jobs.empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.sql-job {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  text-align: left;
  width: 100%;
}

.sql-job .status.done { color: var(--ok); }
.sql-job .status.error { color: var(--err); }
.sql-job .status.running,
.sql-job .status.queued { color: var(--accent); }

.grid-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
}

@media (max-width: 640px) {
  .grid-form { grid-template-columns: 1fr; }
  .span2 { grid-column: auto !important; }
  .top { flex-direction: column; }
}

.span2 { grid-column: span 2; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

label.check {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  align-self: end;
  padding-bottom: 0.35rem;
  font-weight: 500;
  color: var(--ink);
}

input, select, button, textarea {
  font: inherit;
}

input, select, textarea {
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 0.95rem;
}

textarea {
  width: 100%;
  min-height: 4.5rem;
  resize: vertical;
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.45;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-color: var(--accent);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1rem;
  margin-bottom: 1rem;
  align-items: end;
}

.grow { flex: 1 1 220px; }

.actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:hover:not(:disabled) {
  background: var(--bg2);
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent2);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent2);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  background: var(--err);
  border-color: #7f1d1d;
  color: #fff;
}

.btn.danger:hover:not(:disabled) {
  background: #7f1d1d;
}

.picker-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
  margin: 0.85rem 0 0.35rem;
}

.check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.35rem 0.75rem;
  max-height: 280px;
  overflow: auto;
  padding: 0.75rem;
  margin: 0 0 1rem;
  background: #faf7f2;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.check-grid.empty {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
}

.check-grid label {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-weight: 500;
  color: var(--ink);
  font-size: 0.8rem;
  font-family: var(--mono);
}

.warn-check {
  color: var(--warn);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.maint-table-wrap {
  max-height: 320px;
  overflow: auto;
  margin-top: 0.75rem;
}

.maint-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.maint-table td {
  text-align: left;
  padding: 0.4rem 0.35rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.maint-table td:first-child {
  white-space: nowrap;
  width: 1%;
}

.maint-table .bad { color: var(--err); }
.maint-table .quiet { color: var(--muted); }

.msg {
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  min-height: 1.2em;
}

.msg.ok { color: var(--ok); }
.msg.err { color: var(--err); }

.schema {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 0.85rem;
  margin-bottom: 1rem;
  background: #faf7f2;
  font-family: var(--mono);
  font-size: 0.78rem;
  max-height: 220px;
  overflow: auto;
}

.schema.empty { color: var(--muted); font-family: var(--font); font-size: 0.9rem; }

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

.schema th, .schema td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.schema th { color: var(--muted); font-weight: 600; }

.key {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: #dbeafe;
  color: #1e40af;
  margin-left: 0.35rem;
}

.key.pri { background: #fef3c7; color: #92400e; }

.upload-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.file-btn span {
  display: inline-block;
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
}

.file-btn span:hover { background: var(--bg2); }

.file-name {
  font-size: 0.85rem;
  color: var(--muted);
  font-family: var(--mono);
}

.file-name.err {
  color: var(--err);
}

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

.map-box.hidden, .unique-box.hidden, .progress.hidden, .result.hidden { display: none; }

.map-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.map-table th {
  background: var(--bg2);
  text-align: left;
  padding: 0.55rem 0.75rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.map-table td {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--line);
  vertical-align: middle;
}

.map-table select {
  width: 100%;
  font-size: 0.85rem;
}

.preview-chip {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.unique-box {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
  padding: 0.75rem;
  background: #faf7f2;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.unique-box label {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
  color: var(--ink);
  font-size: 0.85rem;
}

.progress { margin-top: 1rem; }

.bar {
  height: 8px;
  background: var(--bg2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.bar i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), #2dd4a0);
  border-radius: 999px;
  transition: width 0.2s ease;
}

.bar.indeterminate i {
  width: 30%;
  transition: none;
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}

#progressText {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.result {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 8px;
  background: #ecfdf5;
  border: 1px solid #86efac;
  font-size: 0.95rem;
}

.result.err {
  background: #fef2f2;
  border-color: #fca5a5;
}

.result strong { font-weight: 700; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.stat {
  background: rgba(255,255,255,0.7);
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
}

.stat b {
  display: block;
  font-size: 1.25rem;
  font-family: var(--mono);
  letter-spacing: -0.02em;
}

.stat span {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
