:root {
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-soft: #eef3f5;
  --line: #d9e2e6;
  --line-strong: #b8c7ce;
  --text: #142027;
  --muted: #667780;
  --accent: #0f8f72;
  --accent-strong: #08745c;
  --accent-soft: #e0f5ef;
  --danger: #b42318;
  --danger-soft: #fff0ed;
  --warning: #8a5a00;
  --warning-soft: #fff7df;
  --ok: #08745c;
  --ok-soft: #e7f7f1;
  --code-bg: #101820;
  --code-text: #d8f6e8;
  --focus: rgba(15, 143, 114, 0.22);
  --shadow: 0 10px 26px rgba(20, 32, 39, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100svh;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

button {
  touch-action: manipulation;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100svh;
  margin: 0 auto;
  padding: 12px 12px 86px;
}

.app-header {
  display: none;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  line-height: 1.08;
}

h2 {
  font-size: 22px;
  line-height: 1.12;
}

h3 {
  font-size: 16px;
  line-height: 1.2;
}

.view-tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 -8px 22px rgba(20, 32, 39, 0.1);
  backdrop-filter: blur(14px);
}

.view-tabs button,
.edit-nav button,
.ghost-button,
.primary-button,
.fab-button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-weight: 780;
  cursor: pointer;
}

.view-tabs button {
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

.view-tabs button.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.screen-head {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -12px -12px 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 247, 249, 0.94);
  backdrop-filter: blur(12px);
}

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

.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0 12px;
}

.ghost-button:not(:disabled):active,
.primary-button:not(:disabled):active,
.fab-button:not(:disabled):active {
  transform: translateY(1px);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  background: var(--accent);
  color: #ffffff;
  padding: 0 16px;
}

.primary-button:not(:disabled):hover,
.ghost-button:not(:disabled):hover {
  border-color: var(--line-strong);
}

.primary-button:not(:disabled):hover {
  background: var(--accent-strong);
}

button:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.field-stack,
.option-panel label,
.form-grid label,
.inline-form label,
.node-fields label,
.group-row label {
  display: grid;
  gap: 6px;
}

.field-stack > span,
.option-panel span,
.form-grid span,
.node-fields span,
.group-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
}

input[type="text"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
}

input[type="text"],
select {
  min-height: 44px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 12px;
}

.input-area {
  min-height: 38svh;
  font: 13px/1.55 ui-monospace, "SFMono-Regular", Consolas, monospace;
}

.option-panel,
.edit-stage {
  display: grid;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.option-panel {
  grid-template-columns: 1fr;
}

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

small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.sticky-actions {
  position: sticky;
  bottom: 72px;
  z-index: 25;
  display: grid;
  gap: 8px;
  margin: 12px -4px 0;
  padding: 8px 4px;
  background: linear-gradient(180deg, rgba(245, 247, 249, 0), rgba(245, 247, 249, 0.96) 28%);
}

.action-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.action-grid .ghost-button {
  min-width: 0;
  padding: 0 8px;
  font-size: 12px;
}

.notice,
.validation-banner,
.validation-details,
.diff-panel,
.warnings {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.45;
}

.notice.error,
.validation-banner.error {
  border-color: #ffd0c8;
  background: var(--danger-soft);
  color: var(--danger);
}

.validation-banner.warning {
  border-color: #ffe4a3;
  background: var(--warning-soft);
  color: var(--warning);
}

.validation-banner.ok {
  border-color: #bdebd8;
  background: var(--ok-soft);
  color: var(--ok);
}

.validation-details,
.diff-panel {
  background: var(--surface);
}

.validation-details h3,
.diff-panel h3 {
  margin-bottom: 8px;
}

.validation-details ul {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.validation-details li[data-severity="error"] {
  color: var(--danger);
}

.validation-details li[data-severity="warning"] {
  color: var(--warning);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stats div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px;
}

.stats span,
.stats small {
  display: block;
}

.stats span {
  font-size: 22px;
  font-weight: 840;
  line-height: 1;
}

.stats small {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 820;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.warnings h3 {
  margin-bottom: 8px;
}

.warnings ul {
  margin: 0;
  padding-left: 18px;
}

.diff-panel {
  margin-top: 12px;
}

.diff-viewer {
  max-height: 48svh;
  margin: 0;
  overflow: auto;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  font: 12px/1.55 ui-monospace, "SFMono-Regular", Consolas, monospace;
  padding: 12px;
  white-space: pre;
}

.diff-added {
  color: #8ff0bd;
}

.diff-removed {
  color: #ffb7ad;
}

.yaml-preview,
.compact-editor,
.mini-editor {
  background: var(--code-bg);
  color: var(--code-text);
  font: 12px/1.55 ui-monospace, "SFMono-Regular", Consolas, monospace;
}

.yaml-preview {
  min-height: calc(100svh - 285px);
  white-space: pre;
  overflow: auto;
}

.compact-editor {
  min-height: calc(100svh - 250px);
}

.mini-editor {
  min-height: 88px;
}

.edit-nav {
  position: sticky;
  top: 64px;
  z-index: 15;
  display: flex;
  gap: 8px;
  margin: 0 -12px;
  padding: 8px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 247, 249, 0.96);
  scrollbar-width: none;
}

.edit-nav::-webkit-scrollbar {
  display: none;
}

.edit-nav button {
  flex: 0 0 auto;
  min-width: 84px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
  padding: 0 12px;
}

.edit-nav button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.edit-panel {
  display: none;
}

.edit-panel.active {
  display: block;
}

.panel-title {
  display: grid;
  gap: 4px;
  margin-bottom: 12px;
}

.panel-title p,
.empty-state {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.item-list {
  display: grid;
  gap: 10px;
}

.node-row,
.group-row {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 12px;
}

.node-row-head {
  display: grid;
  gap: 8px;
}

.node-row-head strong {
  width: fit-content;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 5px 8px;
  text-transform: uppercase;
}

.node-fields,
.form-grid,
.group-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.check-row,
.checkbox-row {
  display: flex !important;
  min-height: 44px;
  align-items: center;
  gap: 8px !important;
  color: var(--text);
  font-size: 13px;
  font-weight: 760;
}

.check-row input,
.checkbox-row input {
  width: 18px;
  height: 18px;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.advanced-inline {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 10px;
}

.preset-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.tool-launcher {
  width: 100%;
  margin-bottom: 12px;
}

.field-divider {
  grid-column: 1 / -1;
  height: 1px;
  margin: 4px 0;
  background: var(--line);
}

details {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 780;
}

.file-button {
  text-align: center;
}

.fab-container {
  display: none;
}

.bottom-sheet[hidden] {
  display: none;
}

.bottom-sheet {
  position: fixed;
  inset: 0;
  z-index: 80;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 32, 39, 0.42);
}

.sheet-panel {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: min(82svh, 620px);
  overflow: auto;
  border-radius: 14px 14px 0 0;
  background: var(--surface);
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 50px rgba(20, 32, 39, 0.2);
}

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

.sheet-grid {
  display: grid;
  gap: 10px;
}

.sheet-grid label {
  display: grid;
  gap: 6px;
}

.sheet-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
}

.toast {
  position: fixed;
  right: 12px;
  bottom: 86px;
  left: 12px;
  z-index: 60;
  border-radius: 8px;
  background: var(--text);
  color: #ffffff;
  font-size: 13px;
  font-weight: 760;
  padding: 12px 14px;
  text-align: center;
  box-shadow: var(--shadow);
}

.toast.error {
  background: var(--danger);
}

.toast.hidden {
  display: none;
}

@media (min-width: 720px) {
  .app-shell {
    padding: 24px 24px 32px;
  }

  .app-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
  }

  .protocol-strip {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    max-width: 420px;
  }

  .protocol-strip span {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font-size: 12px;
    font-weight: 780;
    padding: 7px 9px;
  }

  .view-tabs {
    position: sticky;
    top: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 16px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }

  .screen-head {
    position: static;
    margin: 0 0 16px;
    padding: 0;
    border: 0;
    background: transparent;
    backdrop-filter: none;
  }

  .option-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .input-area {
    min-height: 280px;
  }

  .sticky-actions {
    position: static;
    margin: 14px 0 0;
    padding: 0;
    background: transparent;
  }

  .yaml-preview {
    min-height: 56svh;
  }

  .edit-nav {
    top: 62px;
    margin: 0 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .edit-stage {
    min-height: 560px;
  }

  .node-row-head {
    grid-template-columns: auto auto 1fr;
    align-items: center;
  }

  .row-actions {
    justify-content: end;
  }

  .node-fields,
  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .inline-form {
    grid-template-columns: minmax(0, 1fr) minmax(160px, 220px) auto;
    align-items: center;
  }

  .advanced-inline {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .advanced-inline .ghost-button {
    grid-column: auto;
  }

  .edit-panel[data-edit-panel="providers"] .inline-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(120px, 160px) minmax(110px, 140px) minmax(100px, 120px) auto;
  }

  .preset-actions {
    grid-template-columns: repeat(2, max-content);
  }

  .sheet-panel {
    right: 24px;
    bottom: 24px;
    left: auto;
    width: min(560px, calc(100vw - 48px));
    border-radius: 12px;
    padding: 16px;
  }

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

}

@media (min-width: 1040px) {
  .view-panel[data-view="convert"].active,
  .view-panel[data-view="yaml"].active {
    max-width: 820px;
    margin: 0 auto;
  }

  .view-panel[data-view="edit"].active {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 16px;
  }

  .view-panel[data-view="edit"] .screen-head {
    grid-column: 1 / -1;
  }

  .edit-nav {
    position: sticky;
    top: 76px;
    display: grid;
    align-self: start;
    overflow: visible;
  }

  .edit-nav button {
    width: 100%;
    justify-content: flex-start;
  }

  .edit-stage {
    margin-top: 0;
  }
}
