:root {
  color-scheme: light;
  --bg: #f4f7f9;
  --panel: #ffffff;
  --ink: #222831;
  --muted: #647282;
  --line: #cfd8e3;
  --field: #f8fafc;
  --blue: #1071e5;
  --blue-dark: #0c55ac;
  --green-zone: #e3fae3;
  --yellow-zone: #fcfcca;
  --archive-zone: #cfe4ff;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 28px;
}

.workspace {
  max-width: 1180px;
  margin: 0 auto;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.builder-menu {
  display: flex;
  gap: 8px;
  margin-bottom: 22px;
  padding: 6px;
  background: #e9eef5;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.import-status {
  margin: -10px 0 18px;
  padding: 11px 14px;
  color: #14532d;
  background: #ecfdf3;
  border: 1px solid #86efac;
  border-radius: 6px;
  font-size: 14px;
}

.import-status.error {
  color: #7f1d1d;
  background: #fef2f2;
  border-color: #fca5a5;
}

.builder-tab {
  min-height: 36px;
  padding: 0 16px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.builder-tab.active {
  color: #ffffff;
  background: var(--blue);
}

.builder-tab:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

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

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

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

h3 {
  margin: 2px 0 -4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

.panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.wide-panel {
  grid-column: 1 / -1;
}

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

label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: #344150;
  font-size: 13px;
  font-weight: 650;
}

input {
  width: 100%;
  height: 40px;
  padding: 0 11px;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
}

textarea {
  width: 100%;
  min-height: 220px;
  padding: 11px;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: none;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.45;
}

input:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(16, 113, 229, 0.14);
}

.primary-action,
.secondary-action,
.row-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 750;
}

.primary-action {
  min-width: 164px;
  height: 44px;
  padding: 0 18px;
  color: #fff;
  background: var(--blue);
}

.primary-action:hover {
  background: var(--blue-dark);
}

.secondary-action {
  height: 34px;
  padding: 0 14px;
  color: var(--blue-dark);
  background: #eaf3ff;
}

.row-action {
  width: 34px;
  height: 34px;
  color: #7c2d12;
  background: #fff1e8;
}

.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 0 14px;
  color: #fff;
  background: var(--blue);
  border-radius: 6px;
  font-size: 14px;
  font-weight: 750;
  text-decoration: none;
}

.download-link:hover {
  background: var(--blue-dark);
}

.output-panel {
  border-color: rgba(16, 113, 229, 0.35);
}

.section-title-row,
.list-row,
.connection-row,
.modality-row,
.workstation-row,
.endpoint-editor {
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title-row {
  justify-content: space-between;
}

.list-editor,
.table-editor {
  display: grid;
  gap: 10px;
}

.list-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 34px;
}

.connection-row,
.modality-row,
.workstation-row {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 0.7fr 34px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.hl7-interface-list {
  display: grid;
  gap: 16px;
}

.hl7-interface-card {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.hl7-interface-card.orm {
  border-top: 4px solid #6c8ebf;
}

.hl7-interface-card.oru {
  border-top: 4px solid #d6b656;
}

.hl7-interface-card h3 {
  margin: 0;
  font-size: 17px;
}

.hl7-node {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.7fr 0.9fr auto 34px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.hl7-children {
  display: grid;
  grid-column: 1 / -1;
  gap: 10px;
  margin: 10px 0 0 24px;
  padding-left: 14px;
  border-left: 2px solid var(--line);
}

.hl7-children:empty {
  display: none;
}

.tree-editor {
  display: grid;
  gap: 10px;
}

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

.helper-text {
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 820px) {
  .app-shell {
    padding: 18px;
  }

  .topbar,
  .builder-menu,
  .form-grid,
  .two-column,
  .connection-row,
  .modality-row,
  .workstation-row,
  .hl7-node,
  .button-row,
  .endpoint-editor {
    grid-template-columns: 1fr;
  }

  .button-row {
    display: grid;
    justify-content: stretch;
  }

  .topbar {
    display: grid;
  }

  .topbar-actions {
    display: grid;
  }

  h1 {
    font-size: 28px;
  }

  .primary-action,
  .topbar-actions .secondary-action {
    width: 100%;
  }
}
