:root {
  --bg: #f4ede2;
  --bg-soft: #efe4d5;
  --panel: rgba(255, 251, 245, 0.9);
  --panel-2: #f8f1e6;
  --panel-3: #fffaf3;
  --text: #1f2937;
  --muted: #5f6b7c;
  --muted-2: #7e8998;
  --line: rgba(120, 97, 72, 0.16);
  --line-2: rgba(120, 97, 72, 0.1);
  --accent: #0f766e;
  --accent-2: #d97706;
  --accent-soft: rgba(15, 118, 110, 0.12);
  --success: #1d8f67;
  --warn: #d97706;
  --danger: #cc5a5a;
  --code-bg: #101827;
  --code-keyword: #c4b5fd;
  --code-string: #bef264;
  --code-comment: #93a2c1;
  --code-var: #facc15;
  --shadow: 0 18px 50px rgba(55, 42, 27, 0.12);
  --shadow-soft: 0 10px 26px rgba(55, 42, 27, 0.08);
  --radius: 22px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: "Sarabun", "Noto Sans Thai", sans-serif;
  background:
    radial-gradient(circle at top left, rgba(15, 118, 110, 0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(217, 119, 6, 0.14), transparent 24%),
    linear-gradient(180deg, #fbf6ee 0%, #f4ede2 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.15) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.18), transparent 80%);
}

.wrap {
  position: relative;
  max-width: 1520px;
  margin: 0 auto;
  padding: 28px;
}

.utility-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 18px 22px;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background: linear-gradient(135deg, rgba(255, 250, 243, 0.96), rgba(249, 241, 230, 0.92));
  box-shadow: var(--shadow-soft);
}

.utility-copy {
  display: grid;
  gap: 4px;
  max-width: 640px;
}

.utility-kicker {
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

.utility-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.45;
}

.utility-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

button, .btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, background .16s ease;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.35) inset;
}

button:hover, .btn:hover {
  transform: translateY(-1px);
  border-color: rgba(15, 118, 110, 0.28);
  box-shadow: 0 10px 18px rgba(55, 42, 27, 0.08);
}

button:active, .btn:active {
  transform: translateY(0);
}

.btn-primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent), #15998f);
  color: #f8fffe;
}

.btn-primary:hover {
  border-color: transparent;
}

.btn-danger {
  background: rgba(204, 90, 90, 0.08);
  border-color: rgba(204, 90, 90, 0.22);
  color: #a64040;
}

.btn-success {
  background: rgba(29, 143, 103, 0.1);
  border-color: rgba(29, 143, 103, 0.22);
  color: #166246;
}

.btn-warning {
  background: rgba(217, 119, 6, 0.1);
  border-color: rgba(217, 119, 6, 0.2);
  color: #9a5200;
}

.btn-icon {
  min-width: 38px;
  padding: 9px;
  justify-content: center;
}

.icon { width: 16px; height: 16px; flex-shrink: 0; }
.icon-sm { width: 14px; height: 14px; }
.icon-lg { width: 22px; height: 22px; }

.main-layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.sidebar,
.toolbar,
.panel-header,
.step,
.empty,
dialog {
  backdrop-filter: blur(10px);
}

.sidebar {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 16px;
  padding: 18px;
  max-height: calc(100vh - 36px);
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(180deg, rgba(255, 252, 246, 0.96), rgba(247, 239, 228, 0.94));
  box-shadow: var(--shadow);
}

.sidebar-head {
  display: grid;
  gap: 6px;
}

.sidebar-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.sidebar-title {
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.tab-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tab-node {
  display: grid;
  gap: 6px;
}

.tab-btn,
.tab-group {
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border-radius: 16px;
  border: 1px solid transparent;
  background: transparent;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  color: var(--text);
}

.tab-btn:hover,
.tab-group:hover {
  background: rgba(255, 255, 255, 0.68);
}

.tab-group {
  font-weight: 700;
}

.tab-group .group-chevron {
  margin-left: auto;
  margin-top: 2px;
  color: var(--muted-2);
  transition: transform .2s ease;
}

.tab-group.collapsed .group-chevron {
  transform: rotate(-90deg);
}

.tab-icon {
  width: 32px;
  height: 32px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.14), rgba(217, 119, 6, 0.12));
  color: var(--accent);
}

.tab-label {
  flex: 1;
  min-width: 0;
  white-space: normal;
  line-height: 1.35;
  font-size: 14px;
  font-weight: 600;
}

.tab-count {
  margin-left: auto;
  min-width: 28px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(31, 41, 55, 0.06);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.tab-btn.active {
  border-color: rgba(15, 118, 110, 0.2);
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.14), rgba(217, 119, 6, 0.08));
  box-shadow: 0 10px 18px rgba(15, 118, 110, 0.08);
}

.tab-btn.active .tab-icon {
  background: linear-gradient(135deg, var(--accent), #15998f);
  color: #f4fffd;
}

.tab-btn.active .tab-count {
  background: rgba(15, 118, 110, 0.14);
  color: var(--accent);
}

.tab-group.depth-0 {
  padding: 12px 14px;
  border: 1px solid rgba(15, 118, 110, 0.12);
  background: rgba(255, 255, 255, 0.55);
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 15px;
  letter-spacing: 0.01em;
}

.tab-group.depth-1 {
  padding: 9px 12px;
  color: #344152;
  font-size: 13.5px;
}

.tab-group.depth-1 .tab-icon,
.tab-btn.depth-2 .tab-icon,
.tab-btn.depth-3 .tab-icon {
  width: 28px;
  height: 28px;
  border-radius: 10px;
}

.tab-group.depth-1 .tab-label {
  font-weight: 700;
}

.tab-subgroup {
  display: grid;
  gap: 6px;
  margin-left: 14px;
  padding-left: 10px;
  border-left: 2px solid rgba(15, 118, 110, 0.12);
}

.tab-subgroup.depth-2 {
  margin-left: 12px;
  padding-left: 10px;
}

.tab-group.collapsed + .tab-subgroup {
  display: none;
}

.tab-btn.depth-2,
.tab-btn.depth-3 {
  padding: 9px 10px;
}

.sidebar-divider {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(15, 118, 110, 0.16), transparent);
}

.sidebar-stats {
  display: grid;
  gap: 10px;
}

.stat-mini {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 12px;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.62);
}

.stat-mini .label {
  color: var(--muted);
  font-size: 13px;
}

.stat-mini .value {
  color: var(--accent);
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 18px;
  font-weight: 700;
}

.content {
  min-width: 0;
  display: grid;
  gap: 16px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  background: rgba(255, 251, 245, 0.9);
  box-shadow: var(--shadow-soft);
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 280px;
}

.search-wrap .icon {
  position: absolute;
  top: 50%;
  left: 14px;
  transform: translateY(-50%);
  color: var(--muted-2);
  pointer-events: none;
}

input[type="text"],
textarea,
select {
  width: 100%;
  border: 1px solid rgba(120, 97, 72, 0.2);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--text);
  padding: 12px 14px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

input[type="text"]::placeholder,
textarea::placeholder {
  color: #93a0ae;
}

input[type="text"]:focus,
textarea:focus,
select:focus {
  border-color: rgba(15, 118, 110, 0.38);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.08);
  background: #fffdfa;
}

.search-wrap input {
  padding-left: 42px;
}

textarea {
  min-height: 108px;
  resize: vertical;
  line-height: 1.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
}

.panel-header {
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  flex-wrap: wrap;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background:
    linear-gradient(120deg, rgba(15, 118, 110, 0.08), transparent 30%),
    linear-gradient(180deg, rgba(255, 251, 245, 0.96), rgba(248, 241, 230, 0.9));
  box-shadow: var(--shadow-soft);
}

.panel-header-left {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.panel-header-icon {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: linear-gradient(135deg, rgba(15, 118, 110, 0.16), rgba(217, 119, 6, 0.14));
  border: 1px solid rgba(15, 118, 110, 0.16);
}

.panel-header h2 {
  margin: 0 0 6px;
  color: #14202c;
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 28px;
  line-height: 1.05;
}

.panel-header p {
  margin: 0;
  max-width: 820px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  color: var(--muted-2);
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.breadcrumb .crumb-sep {
  color: rgba(15, 118, 110, 0.35);
}

.steps {
  display: grid;
  gap: 16px;
}

.step {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  background: linear-gradient(180deg, rgba(255, 252, 247, 0.96), rgba(249, 241, 230, 0.9));
  box-shadow: var(--shadow-soft);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.step:hover {
  transform: translateY(-2px);
  border-color: rgba(15, 118, 110, 0.18);
  box-shadow: 0 20px 34px rgba(55, 42, 27, 0.12);
}

.step-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 18px 20px;
  cursor: pointer;
  user-select: none;
}

.step-header:hover {
  background: rgba(255, 255, 255, 0.34);
}

.step-left {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  min-width: 0;
  flex: 1;
}

.step-number {
  min-width: 40px;
  height: 40px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), #15998f);
  color: #f7fffd;
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 10px 18px rgba(15, 118, 110, 0.18);
}

.step-info {
  flex: 1;
  min-width: 0;
}

.step-title {
  margin-bottom: 6px;
  color: #16222f;
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.18;
}

.step-note {
  margin: 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-line;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.badge {
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid rgba(15, 118, 110, 0.16);
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.step-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.chevron {
  color: var(--muted);
  transition: transform .2s ease;
}

.step.collapsed .chevron {
  transform: rotate(-90deg);
}

.step-body {
  padding: 18px 20px 20px;
  border-top: 1px solid var(--line-2);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent);
}

.step.collapsed .step-body {
  display: none;
}

.diagram-wrap {
  margin-bottom: 14px;
  padding: 15px 16px;
  border: 1px solid rgba(15, 118, 110, 0.12);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.56);
}

.diagram-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.diagram-title {
  color: var(--accent);
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

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

pre.mermaid {
  margin: 0;
  padding: 0;
  overflow-x: auto;
  background: transparent;
  color: var(--muted);
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

pre.mermaid svg {
  max-width: 100%;
  height: auto;
}

.commands {
  display: grid;
  gap: 12px;
}

.command {
  overflow: hidden;
  border: 1px solid rgba(16, 24, 39, 0.08);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.68);
}

.command-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(16, 24, 39, 0.08);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(245, 239, 230, 0.6));
}

.command-info {
  flex: 1;
  min-width: 0;
}

.command-name {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #14202c;
  font-size: 14px;
  font-weight: 700;
}

.command-name .icon,
.command-name .icon-sm {
  color: var(--accent);
}

.command-desc {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.command-actions {
  display: flex;
  gap: 4px;
}

.copy-btn {
  min-width: 82px;
}

.copy-btn.copied {
  background: rgba(29, 143, 103, 0.14);
  border-color: rgba(29, 143, 103, 0.28);
  color: #166246;
}

.code-wrap {
  position: relative;
}

pre {
  margin: 0;
  padding: 16px 18px;
  overflow-x: auto;
  background: var(--code-bg);
  color: #dce6fb;
  font-size: 13px;
  line-height: 1.65;
  white-space: pre;
  tab-size: 2;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

pre code {
  font-family: inherit;
}

.tok-cmd { color: #7dd3fc; font-weight: 600; }
.tok-flag { color: #fde68a; }
.tok-str { color: var(--code-string); }
.tok-var { color: var(--code-var); }
.tok-com { color: var(--code-comment); font-style: italic; }

.empty {
  padding: 54px 24px;
  text-align: center;
  border: 1px dashed rgba(15, 118, 110, 0.22);
  border-radius: calc(var(--radius) + 2px);
  background: rgba(255, 251, 245, 0.82);
  color: var(--muted);
  box-shadow: var(--shadow-soft);
}

.empty .icon {
  width: 42px;
  height: 42px;
  margin-bottom: 12px;
  color: var(--muted-2);
}

.empty h3 {
  margin: 0 0 8px;
  color: #14202c;
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 20px;
}

.empty p {
  margin: 0;
  font-size: 14px;
}

dialog {
  width: min(680px, calc(100vw - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  background: rgba(255, 251, 245, 0.96);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(29, 23, 16, 0.46);
  backdrop-filter: blur(6px);
}

.modal {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.modal h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #16222f;
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 22px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-family: "Space Grotesk", "Sarabun", sans-serif;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 251, 245, 0.96);
  color: var(--text);
  box-shadow: var(--shadow);
  transform: translateX(-50%) translateY(120%);
  transition: transform .3s ease;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  border-color: rgba(29, 143, 103, 0.24);
}

.toast.success .icon {
  color: var(--success);
}

.toast.error {
  border-color: rgba(204, 90, 90, 0.24);
}

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

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

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

::-webkit-scrollbar-thumb {
  background: rgba(120, 97, 72, 0.26);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(15, 118, 110, 0.34);
}

@media (max-width: 1100px) {
  .main-layout {
    grid-template-columns: 300px minmax(0, 1fr);
  }
}

@media (max-width: 920px) {
  .wrap {
    padding: 18px;
  }

  .utility-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .main-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: none;
  }
}

@media (max-width: 640px) {
  .wrap {
    padding: 12px;
  }

  .utility-bar,
  .sidebar,
  .toolbar,
  .panel-header,
  .step-header,
  .step-body,
  .modal {
    padding-left: 14px;
    padding-right: 14px;
  }

  .toolbar {
    gap: 8px;
  }

  .search-wrap {
    min-width: 100%;
  }

  .panel-header-left,
  .step-header,
  .command-top {
    flex-direction: column;
  }

  .step-actions,
  .command-actions,
  .utility-actions,
  .modal-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .panel-header h2 {
    font-size: 24px;
  }

  .step-title {
    font-size: 18px;
  }
}

@media print {
  body {
    background: white;
    color: black;
  }

  body::before,
  .utility-bar,
  .sidebar,
  .toolbar,
  .step-actions,
  .command-actions,
  .toast {
    display: none !important;
  }

  .main-layout {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .step,
  .command,
  .diagram-wrap {
    break-inside: avoid;
    border-color: #d4d4d4;
    box-shadow: none;
    background: white;
  }

  .step.collapsed .step-body {
    display: block !important;
  }

  pre {
    background: #f5f5f5;
    color: black;
  }

  .panel-header h2,
  .step-title,
  .modal h2 {
    color: black;
  }
}
