:root {
  --ink: #1d2939;
  --muted: #667085;
  --line: #e4e7ec;
  --surface: #fff;
  --canvas: #f4f7fb;
  --brand: #155eef;
  --brand-dark: #004eeb;
  --brand-soft: #eff6ff;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --danger: #b42318;
  --danger-dark: #912018;
  --danger-bg: #fef3f2;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --radius: 14px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; min-width: 320px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid #b2ddff;
  outline-offset: 2px;
}

[hidden] { display: none !important; }
.app-shell { width: 100%; max-width: 1220px; margin: auto; padding: 22px 20px 44px; }
.topbar, .actions-panel, .section-heading, .wizard-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.topbar { margin-bottom: 14px; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.55rem, 3vw, 2rem); letter-spacing: -.03em; }
h2 { margin-bottom: 6px; font-size: 1.2rem; }
h3 { margin-bottom: 8px; font-size: 1rem; }
p, .eyebrow { color: var(--muted); }
.eyebrow {
  margin-bottom: 4px;
  font-size: .77rem;
  font-weight: 750;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.connection { font-size: .875rem; color: var(--muted); text-align: right; }
.connection.is-ok { color: var(--ok); }
.connection.is-error { color: var(--danger); }

.card, .actions-panel, .wizard {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 2px 7px rgba(16, 24, 40, .045);
}
.card { padding: 18px; }
.banner {
  border: 1px solid #d0d5dd;
  border-radius: 11px;
  background: #f9fafb;
  color: #344054;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: .9rem;
}
.banner-warning { border-color: #fedf89; background: var(--warn-bg); color: #7a2e0e; }
.banner-info { border-color: #b2ddff; background: #eff8ff; color: #1849a9; }
.banner-success { border-color: #abefc6; background: var(--ok-bg); color: #05603a; }

.mode-banner {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 17px 19px;
  border: 2px solid;
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.mode-readonly { border-color: #84caff; background: #eff8ff; color: #1849a9; }
.mode-live { border-color: #fda29b; background: var(--danger-bg); color: #912018; }
.mode-lock {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: currentColor;
  background: rgba(255, 255, 255, .75);
  font-size: 1.25rem;
}
.mode-label { display: block; margin-bottom: 1px; font-size: .74rem; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; }
.mode-banner strong { display: block; font-size: clamp(1.35rem, 3vw, 1.75rem); letter-spacing: -.025em; }
.mode-banner p { margin: 2px 0 0; color: currentColor; font-size: .9rem; }

.launch-gate {
  max-width: 720px;
  min-height: 280px;
  margin: clamp(40px, 10vh, 100px) auto;
  padding: clamp(24px, 5vw, 48px);
  display: flex;
  align-items: flex-start;
  gap: 22px;
}
.launch-gate h1 { margin-bottom: 12px; }
.launch-gate p:not(.eyebrow) { max-width: 560px; line-height: 1.6; }
.gate-icon {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  flex: 0 0 auto;
  border-radius: 18px;
  background: linear-gradient(145deg, #2e90fa, #155eef);
  color: #fff;
  font-weight: 800;
  font-size: .92rem;
  box-shadow: 0 8px 20px rgba(21, 94, 239, .2);
}

.wizard { margin: 18px 0; overflow: hidden; }
.wizard-heading { padding: 18px 20px 12px; }
.wizard-heading h2 { margin-bottom: 0; }
.wizard-progress {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 700;
  font-size: .8rem;
}
.wizard-steps {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  padding: 0 12px;
  list-style: none;
  border-bottom: 1px solid var(--line);
}
.wizard-step {
  width: 100%;
  min-height: 78px;
  display: grid;
  grid-template-columns: 30px 1fr;
  grid-template-rows: auto auto;
  column-gap: 9px;
  align-items: center;
  padding: 13px 9px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  text-align: left;
  color: var(--muted);
}
.wizard-step > span {
  grid-row: 1 / span 2;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #f2f4f7;
  color: #475467;
  font-weight: 750;
  font-size: .8rem;
}
.wizard-step strong { align-self: end; color: var(--ink); font-size: .88rem; }
.wizard-step small { align-self: start; color: var(--muted); font-size: .72rem; }
.wizard-step small.step-ok { color: var(--ok); }
.wizard-step small.step-warning { color: var(--warn); }
.wizard-step.is-active { border-bottom-color: var(--brand); background: linear-gradient(to top, #eff6ff, transparent 65%); }
.wizard-step.is-active > span { background: var(--brand); color: #fff; }
.wizard-panel { padding: 20px; animation: appear .16s ease; }
.wizard-panel-head { align-items: flex-start; margin-bottom: 15px; }
.wizard-panel-head p { margin-bottom: 0; font-size: .9rem; }
.wizard-nav {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.setup-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 11px; }
.setup-grid-two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mini-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fcfcfd;
}
.mini-card span, .mini-card small { display: block; color: var(--muted); font-size: .76rem; }
.mini-card strong { display: block; margin: 5px 0; overflow-wrap: anywhere; }
.inline-form, .period-form {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 11px;
  margin-top: 15px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fcfcfd;
}
.inline-form .field { flex: 1 1 280px; }
.period-form .field { min-width: 150px; }
.discovery-card { margin-top: 14px; }
.safe-note {
  margin-top: 14px;
  padding: 11px 13px;
  border-left: 3px solid #84caff;
  background: #f5faff;
  color: #344054;
  font-size: .85rem;
}
.mapping-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; }
.mapping-summary article, .dry-counters article {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fcfcfd;
}
.mapping-summary span, .mapping-summary small, .dry-counters span { display: block; color: var(--muted); font-size: .76rem; }
.mapping-summary strong { display: block; margin: 4px 0; font-size: 1.2rem; }
.dry-counters { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 14px 0; }
.dry-counters strong { display: block; margin-top: 4px; font-size: 1.45rem; }
.records-summary { display: flex; align-items: baseline; gap: 7px; margin: 16px 0 9px; }
.records-summary strong { font-size: 1.55rem; }
.records-summary span { color: var(--muted); font-size: .85rem; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 11px; }
.pagination span { color: var(--muted); font-size: .84rem; }
.masked-value { font-weight: 650; letter-spacing: .015em; }

.actions-panel { padding: 17px 18px; margin-bottom: 15px; }
.actions-panel h2 { margin-bottom: 4px; }
.actions-panel p { margin-bottom: 0; font-size: .9rem; }
.action-buttons, .form-actions, .pilot-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.button {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 13px;
  font-weight: 650;
  font-size: .88rem;
}
.button:disabled { cursor: not-allowed; opacity: .52; }
.button-primary { background: var(--brand); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--brand-dark); }
.button-secondary { background: #fff; border-color: #d0d5dd; color: #344054; }
.button-secondary:hover:not(:disabled) { background: #f9fafb; }
.button-danger { background: var(--danger); color: #fff; }
.button-danger:hover:not(:disabled) { background: var(--danger-dark); }
.button-link { background: transparent; color: var(--brand); padding-left: 0; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 22px; }
.kpi { padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: 11px; }
.kpi span { display: block; color: var(--muted); font-size: .78rem; margin-bottom: 5px; }
.kpi strong { font-size: 1rem; }
.tabs, .mapping-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; scrollbar-width: thin; }
.tab, .mapping-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 11px 13px;
  font-weight: 650;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab.is-active, .mapping-tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel { animation: appear .15s ease; }
.overview-grid { display: grid; grid-template-columns: 1fr 1.5fr; gap: 16px; }
.key-values { margin: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; }
.key-values dt { color: var(--muted); }
.key-values dd { margin: 0; font-weight: 650; text-align: right; overflow-wrap: anywhere; }
.event-list { padding-left: 18px; margin: 0; }
.event-list li { margin: 0 0 10px; font-size: .9rem; }

.table-card { padding: 0; overflow: hidden; }
.table-wrap { max-width: 100%; overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-size: .76rem; letter-spacing: .02em; font-weight: 750; background: #fcfcfd; }
tbody tr:last-child td { border-bottom: 0; }
code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; color: #344054; font-size: .82rem; }
.status {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 750;
  background: #f2f4f7;
  color: #344054;
}
.status.success, .status.done, .status.connected, .status.ok { background: var(--ok-bg); color: var(--ok); }
.status.error, .status.failed, .status.disconnected { background: var(--danger-bg); color: var(--danger); }
.status.pending, .status.running, .status.dry-run { background: #eff8ff; color: #175cd3; }

.mapping-form, .settings-form, .pilot-summary { margin-top: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.field label { font-size: .84rem; font-weight: 650; }
.field input, .field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
}
.field-help { color: var(--muted); font-size: .76rem; }
.form-actions { margin-top: 18px; }
.pilot-lock { margin-top: 14px; }
.pilot-actions { justify-content: flex-end; margin-top: 12px; }
.explicit-confirm {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 18px 0 14px;
  padding: 13px;
  border: 1px solid #fedf89;
  border-radius: 9px;
  background: var(--warn-bg);
  color: #7a2e0e;
  font-size: .88rem;
  line-height: 1.45;
}
.explicit-confirm input, .pilot-radio { width: 18px; height: 18px; accent-color: var(--brand); }

dialog {
  width: min(440px, calc(100vw - 28px));
  max-width: 440px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 16px 42px rgba(16, 24, 40, .2);
  padding: 0;
}
dialog::backdrop { background: rgba(16, 24, 40, .4); }
dialog form { padding: 22px; }
dialog p { line-height: 1.5; }
.toast-region {
  position: fixed;
  z-index: 20;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  max-width: min(420px, calc(100vw - 36px));
}
.toast {
  background: #101828;
  color: #fff;
  padding: 12px 14px;
  border-radius: 9px;
  font-size: .88rem;
  box-shadow: 0 6px 18px rgba(16, 24, 40, .2);
}
.toast.error { background: #7a271a; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

@keyframes appear {
  from { opacity: .45; transform: translateY(2px); }
}

@media (max-width: 840px) {
  .wizard-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .wizard-step:nth-child(-n+2) { border-bottom-color: var(--line); }
  .setup-grid, .mapping-summary, .dry-counters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .app-shell { padding: 14px 11px 30px; }
  .topbar, .actions-panel, .section-heading, .wizard-panel-head { align-items: flex-start; flex-direction: column; }
  .connection { text-align: left; }
  .action-buttons { width: 100%; }
  .action-buttons .button { flex: 1; }
  .kpis, .overview-grid, .form-grid { grid-template-columns: 1fr; }
  .section-heading .button, .wizard-panel-head .button { align-self: stretch; }
  .wizard-heading { padding: 16px 15px 10px; }
  .wizard-panel { padding: 16px 14px; }
  .wizard-steps { padding: 0 7px; }
  .launch-gate { margin: 22px auto; flex-direction: column; }
}

@media (max-width: 500px) {
  .wizard-steps { grid-template-columns: 1fr; }
  .wizard-step { min-height: 62px; }
  .wizard-step:nth-child(n) { border-bottom: 1px solid var(--line); }
  .wizard-step.is-active { border-left: 3px solid var(--brand); }
  .setup-grid, .setup-grid-two, .mapping-summary, .dry-counters { grid-template-columns: 1fr; }
  .mode-banner { align-items: flex-start; padding: 15px; }
  .mode-lock { width: 36px; height: 36px; }
  .wizard-nav .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
