:root {
  --bg: #edf2f8;
  --bg-deep: #dfe8f3;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: #ffffff;
  --panel-soft: #f7fafc;
  --panel-tint: #f2f6fb;
  --readonly-bg: #eef3f9;
  --ink: #0f2238;
  --ink-soft: #244261;
  --muted: #637a92;
  --brand-blue: #004a98;
  --brand-blue-strong: #0d3768;
  --brand-blue-soft: #dbe8f8;
  --accent: #ff8c00;
  --accent-strong: #d97300;
  --accent-soft: #fff0dd;
  --success: #217a4b;
  --success-soft: #e7f6ed;
  --danger: #b02a37;
  --danger-soft: #fde8ea;
  --line: #d4deea;
  --line-strong: #bdcadb;
  --shadow: 0 22px 52px rgba(13, 55, 104, 0.09), 0 10px 22px rgba(13, 55, 104, 0.05);
  --shadow-soft: 0 12px 28px rgba(15, 34, 56, 0.06);
  --radius: 24px;
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 14px;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(0, 74, 152, 0.12), transparent 32%),
    radial-gradient(circle at top right, rgba(255, 140, 0, 0.11), transparent 26%),
    linear-gradient(180deg, #f7f9fc 0%, #eef3f8 52%, #e6edf6 100%);
  font-family: "Aptos", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.38;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.16) 1px, transparent 1px);
  background-size: 36px 36px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.28), transparent 72%);
}

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

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(0, 74, 152, 0.14);
}

.white {
  color: white;
}

.app-shell {
  width: min(1560px, calc(100% - 40px));
  margin: 0 auto;
  padding: 32px 0 48px;
  position: relative;
  z-index: 1;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.72fr) minmax(320px, 0.78fr);
  gap: 20px;
  align-items: stretch;
}

.hero-copy,
.toolbar,
.form-panel,
.output-panel,
.messages {
  background: var(--panel);
  border: 1px solid rgba(189, 202, 219, 0.82);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.hero-copy {
  padding: 34px 38px;
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: flex-start;
  position: relative;
  overflow: hidden;
}

.hero-copy::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: linear-gradient(90deg, var(--brand-blue), var(--accent));
}

.hero-copy::after {
  content: "";
  position: absolute;
  right: -72px;
  top: -72px;
  width: 240px;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(0, 74, 152, 0.18), rgba(0, 74, 152, 0));
  pointer-events: none;
}

.hero-card {
  padding: 26px 28px;
  background:
    radial-gradient(circle at top right, rgba(255, 255, 255, 0.18), transparent 28%),
    linear-gradient(160deg, #0d3768 0%, #004a98 58%, #0d5db8 100%);
  border-radius: var(--radius);
  box-shadow: 0 24px 56px rgba(0, 74, 152, 0.22);
  position: relative;
  overflow: hidden;
}

.hero-card::after {
  content: "";
  position: absolute;
  right: -52px;
  bottom: -70px;
  width: 190px;
  height: 190px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 140, 0, 0.34), rgba(255, 140, 0, 0));
  pointer-events: none;
}

.eyebrow {
  margin: 0 0 10px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--brand-blue);
  font-weight: 700;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Aptos Display", "Aptos", "Segoe UI", Arial, sans-serif;
  letter-spacing: -0.02em;
}

h1 {
  font-size: clamp(2.2rem, 4vw, 3.35rem);
  line-height: 0.98;
  color: var(--brand-blue-strong);
}

.hero-copy h2 {
  margin-top: 10px;
  font-size: clamp(1.05rem, 2vw, 1.3rem);
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0;
}

.subtitle {
  max-width: 70ch;
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.65;
}

.subtitle:empty {
  display: none;
}

.hero-card p {
  margin: 0 0 12px;
  line-height: 1.6;
  position: relative;
  z-index: 1;
}

.toolbar {
  display: grid;
  gap: 16px;
  padding: 18px;
  margin-top: 18px;
}

.filename-settings,
.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
}

.filename-settings {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  padding: 18px;
  border: 1px solid rgba(0, 74, 152, 0.12);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(248, 250, 253, 0.96), rgba(239, 245, 251, 0.96));
}

.toolbar-actions {
  justify-content: flex-start;
  padding: 4px 2px 0;
}

.file-chip,
button {
  min-height: 48px;
}

.file-chip {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 16px;
  background: var(--panel-strong);
  border: 1px solid rgba(189, 202, 219, 0.9);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  font-weight: 700;
  color: var(--brand-blue-strong);
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease;
}

.file-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(0, 74, 152, 0.28);
  box-shadow: 0 14px 28px rgba(13, 55, 104, 0.1);
}

.file-chip input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.filename-field {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  min-width: 190px;
  font-weight: 700;
  color: var(--brand-blue-strong);
}

.filename-field span {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.filename-field input,
.filename-field select,
.field input[type="text"],
.field input[type="number"],
.field textarea,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  color: var(--ink);
  padding: 12px 14px;
  transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.filename-field input:hover,
.filename-field select:hover,
.field input[type="text"]:hover,
.field input[type="number"]:hover,
.field textarea:hover,
.field select:hover {
  border-color: rgba(0, 74, 152, 0.26);
}

.filename-field input[readonly],
.field input[readonly],
.field textarea[readonly] {
  background: var(--readonly-bg);
  color: var(--muted);
}

button {
  border: 1px solid rgba(189, 202, 219, 0.92);
  border-radius: 16px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 12px 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 140ms ease, box-shadow 140ms ease, border-color 140ms ease, background-color 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 14px 28px rgba(13, 55, 104, 0.12);
  border-color: rgba(0, 74, 152, 0.24);
}

button.primary {
  color: #fff;
}

#btn-generate {
  background: linear-gradient(180deg, #0d5db8 0%, #004a98 100%);
  border-color: #003f82;
}

#btn-download {
  background: linear-gradient(180deg, #ffa12f 0%, #e67e00 100%);
  border-color: #c96c00;
}

#btn-reset {
  background: linear-gradient(180deg, #ffffff 0%, #f4f7fb 100%);
  border-color: rgba(0, 74, 152, 0.16);
  color: var(--brand-blue-strong);
}

.messages {
  display: none;
  margin-top: 18px;
  padding: 16px 18px;
  line-height: 1.55;
}

.messages.is-visible {
  display: block;
}

.messages strong {
  display: block;
}

.messages.error {
  background: rgba(253, 232, 234, 0.96);
  border-color: rgba(176, 42, 55, 0.16);
  box-shadow: 0 10px 26px rgba(176, 42, 55, 0.08);
}

.messages.success {
  background: rgba(231, 246, 237, 0.98);
  border-color: rgba(33, 122, 75, 0.16);
  box-shadow: 0 10px 26px rgba(33, 122, 75, 0.08);
}

.messages ul {
  margin: 10px 0 0 18px;
  padding: 0;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(380px, 0.75fr);
  gap: 20px;
  margin-top: 20px;
}

.form-panel,
.output-panel {
  min-width: 0;
  padding: 22px;
  overflow: hidden;
}

.output-panel {
  position: sticky;
  top: 18px;
  align-self: start;
}

.panel-head {
  margin-bottom: 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(189, 202, 219, 0.58);
}

.panel-head p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

#builder-form {
  display: grid;
  gap: 16px;
}

.node {
  border: 1px solid rgba(189, 202, 219, 0.82);
  border-radius: 20px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
  box-shadow: var(--shadow-soft);
}

.node details,
details.node {
  border-radius: inherit;
}

details.node > summary {
  list-style: none;
  cursor: pointer;
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: linear-gradient(180deg, rgba(249, 251, 254, 0.95), rgba(244, 248, 252, 0.95));
  position: relative;
  transition: background-color 140ms ease;
}

details.node > summary:hover {
  background: linear-gradient(180deg, rgba(246, 250, 255, 0.98), rgba(239, 245, 252, 0.98));
}

details.node > summary::-webkit-details-marker {
  display: none;
}

details.node > summary::after {
  content: "";
  width: 11px;
  height: 11px;
  margin-left: 2px;
  border-right: 2px solid var(--brand-blue);
  border-bottom: 2px solid var(--brand-blue);
  transform: rotate(45deg);
  transform-origin: center;
  opacity: 0.72;
  transition: transform 140ms ease, opacity 140ms ease;
}

details[open].node > summary::after {
  transform: rotate(-135deg);
  opacity: 1;
}

.node-summary {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.node-summary strong {
  font-size: 15px;
}

.node-summary small {
  color: var(--muted);
  line-height: 1.45;
}

.node-body {
  padding: 0 20px 20px;
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 9px;
}

.field.inline-checkboxes .field-control {
  display: grid;
  gap: 8px;
}

.field-label-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.field-label-row label {
  font-weight: 700;
  color: var(--ink-soft);
}

.tag-name {
  font-family: Consolas, "SFMono-Regular", "Courier New", monospace;
  font-size: 11px;
  background: var(--brand-blue-soft);
  color: var(--brand-blue-strong);
  padding: 5px 9px;
  border-radius: 999px;
  letter-spacing: 0.02em;
}

.badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 5px 9px;
}

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

.badge.conditional {
  background: var(--accent-soft);
  color: #8a4b00;
}

.badge.optional {
  background: #eaf1fa;
  color: var(--brand-blue);
}

.field-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.field textarea {
  resize: vertical;
  min-height: 96px;
}

.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.choice-grid label {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  border: 1px solid rgba(189, 202, 219, 0.82);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff 0%, #f9fbfd 100%);
  padding: 11px 12px;
  transition: border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
}

.choice-grid label:hover {
  border-color: rgba(0, 74, 152, 0.2);
  box-shadow: 0 10px 22px rgba(13, 55, 104, 0.06);
}

.choice-grid input {
  margin-top: 2px;
  accent-color: var(--brand-blue);
}

.repeater-toolbar,
.item-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.repeater-toolbar {
  padding: 0 20px 20px;
}

.repeater-items {
  display: grid;
  gap: 14px;
  padding: 0 20px 20px;
}

.repeater-item {
  border: 1px solid rgba(0, 74, 152, 0.14);
  border-radius: 18px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  overflow: hidden;
  box-shadow: 0 10px 22px rgba(13, 55, 104, 0.05);
}

.repeater-item .item-toolbar {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(189, 202, 219, 0.6);
  background: linear-gradient(90deg, rgba(0, 74, 152, 0.07), rgba(255, 140, 0, 0.08));
}

.repeater-item .node-body {
  padding: 16px;
}

.item-index {
  font-weight: 800;
  color: var(--brand-blue-strong);
}

#xml-output {
  width: 100%;
  min-height: 75vh;
  border-radius: 20px;
  border: 1px solid rgba(0, 74, 152, 0.22);
  padding: 18px;
  font-family: Consolas, "SFMono-Regular", "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0)),
    linear-gradient(180deg, #0f1f33 0%, #112947 100%);
  color: #d9e6f7;
  resize: vertical;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
  caret-color: var(--accent);
}

#xml-output::placeholder {
  color: rgba(217, 230, 247, 0.54);
}

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

::-webkit-scrollbar {
  width: 11px;
  height: 11px;
}

::-webkit-scrollbar-thumb {
  background: rgba(99, 122, 146, 0.34);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 1320px) {
  .filename-settings {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

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

  .output-panel {
    position: static;
  }

  #xml-output {
    min-height: 42vh;
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 1560px);
    padding-top: 16px;
  }

  .hero {
    grid-template-columns: 1fr;
  }

  .hero-copy,
  .hero-card,
  .toolbar,
  .form-panel,
  .output-panel {
    border-radius: 20px;
  }

  .hero-copy {
    padding: 28px 24px;
  }

  .hero-card {
    padding: 22px 22px 20px;
  }

  .filename-settings {
    grid-template-columns: 1fr;
    padding: 16px;
  }

  .toolbar-actions {
    padding-top: 0;
  }

  details.node > summary {
    padding: 16px;
  }

  .node-body,
  .repeater-toolbar,
  .repeater-items {
    padding-left: 16px;
    padding-right: 16px;
  }

  .repeater-item .node-body {
    padding: 14px;
  }
}

@media (max-width: 640px) {
  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .file-chip,
  .toolbar-actions button {
    width: 100%;
    justify-content: center;
  }

  .choice-grid {
    grid-template-columns: 1fr;
  }
}
