:root {
  --bg: #f5f3ef;
  --ink: #192029;
  --muted: #69717d;
  --line: #d9d4cb;
  --panel: #fffdf9;
  --teal: #0f766e;
  --teal-dark: #115e59;
  --blue: #1d4ed8;
  --amber: #b7791f;
  --soft-blue: #e8eefb;
  --soft-teal: #e3f2ee;
  --danger: #b42318;
  --shadow: 0 18px 45px rgba(25, 32, 41, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 28px;
  padding: 28px;
  background: #17202b;
  color: #fffdf9;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

.sidebar .eyebrow {
  color: #9fb8b4;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.05;
}

h2 {
  font-size: 26px;
  line-height: 1.2;
}

h3 {
  font-size: 18px;
  line-height: 1.25;
}

.steps {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.step-button,
.ghost-button,
.primary-button,
.copy-button,
.icon-button,
.tab,
.file-button,
.ghost-link {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}

.step-button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: #e9f0ee;
  text-align: left;
}

.step-button span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.13);
}

.step-button.active {
  background: #e3f2ee;
  color: #12211f;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
}

.status-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: #fffdf9;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.wizard-grid {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 18px;
  align-items: start;
}

.panel,
.output-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 22px;
}

.section-heading {
  margin-bottom: 18px;
}

.section-heading p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.choice-grid {
  display: grid;
  gap: 12px;
}

.choice-card {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  cursor: pointer;
}

.choice-card:has(input:checked) {
  border-color: var(--teal);
  background: var(--soft-teal);
}

.choice-card small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.4;
}

.actions-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

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

label span {
  display: block;
  margin-bottom: 7px;
  color: #394150;
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #cfc8bd;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

input,
select {
  min-height: 44px;
  padding: 10px 12px;
}

textarea {
  min-height: 160px;
  padding: 12px;
  resize: vertical;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.match-box {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf7;
  padding: 14px;
  color: var(--muted);
  line-height: 1.45;
}

.match-box strong {
  color: var(--ink);
}

.match-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.match-field {
  border-left: 3px solid var(--teal);
  padding-left: 10px;
  color: var(--ink);
  white-space: pre-wrap;
}

.output-panel {
  min-height: 660px;
  padding: 0;
  overflow: hidden;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

#outputText {
  display: block;
  min-height: 594px;
  border: 0;
  border-radius: 0;
  background: #fffdf9;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 14px;
  line-height: 1.55;
  box-shadow: none;
}

.primary-button,
.copy-button {
  min-height: 40px;
  padding: 10px 16px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
}

.primary-button:hover,
.copy-button:hover {
  background: var(--teal-dark);
}

.ghost-button,
.ghost-link,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  font-weight: 750;
}

.sidebar .ghost-button {
  background: transparent;
  color: #fff;
  border-color: rgba(255, 255, 255, 0.22);
}

.compact {
  min-height: 38px;
  padding: 8px 12px;
}

.hidden {
  display: none !important;
}

dialog {
  width: min(1180px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(18, 24, 31, 0.42);
}

.dialog-shell {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  max-height: calc(100vh - 28px);
}

.dialog-header,
.dialog-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  background: #eef1f4;
  color: var(--ink);
  font-size: 26px;
  line-height: 1;
}

.tabs,
.db-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  min-height: 38px;
  padding: 8px 13px;
  background: #eef1f4;
  color: #394150;
  font-weight: 750;
}

.tab.active {
  background: var(--soft-blue);
  color: var(--blue);
}

.file-button input {
  display: none;
}

.db-tab-panel {
  min-height: 0;
  overflow: auto;
  padding: 18px 20px 22px;
}

.records-tools {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.records-tools input {
  max-width: 420px;
}

.records-list {
  display: grid;
  gap: 12px;
}

.record-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 14px;
}

.record-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.record-title {
  min-width: 0;
}

.record-title strong,
.record-title small {
  display: block;
  overflow-wrap: anywhere;
}

.record-title small {
  margin-top: 3px;
  color: var(--muted);
}

.danger-button {
  border: 1px solid #f0c9c4;
  border-radius: 8px;
  background: #fff6f5;
  color: var(--danger);
  min-height: 36px;
  padding: 8px 11px;
  cursor: pointer;
  font-weight: 750;
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.record-grid .wide {
  grid-column: span 2;
}

.record-grid .full {
  grid-column: 1 / -1;
}

.record-grid textarea {
  min-height: 86px;
}

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

.two-columns textarea,
#documentsEditor {
  min-height: 460px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: grid;
    grid-template-columns: 1fr;
    padding: 20px;
  }

  .steps {
    margin-top: 0;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .wizard-grid,
  .two-columns {
    grid-template-columns: 1fr;
  }

  .output-panel {
    min-height: 520px;
  }

  #outputText {
    min-height: 450px;
  }
}

@media (max-width: 680px) {
  .workspace {
    padding: 18px;
  }

  .topbar,
  .dialog-header,
  .dialog-toolbar,
  .record-head {
    align-items: stretch;
    flex-direction: column;
  }

  .form-grid,
  .match-grid,
  .record-grid {
    grid-template-columns: 1fr;
  }

  .record-grid .wide,
  .record-grid .full {
    grid-column: auto;
  }

  .records-tools {
    flex-direction: column;
  }
}
