:root {
  --panel-bg: rgba(255, 255, 255, 0.06);
  --panel-border: rgba(255, 255, 255, 0.10);
  --text-main: #f8fbff;
  --text-soft: #b5c0d8;
  --text-dim: #8f9bb3;
  --field-bg: rgba(8, 15, 31, 0.55);
  --field-border: rgba(255, 255, 255, 0.10);
  --field-border-focus: rgba(124, 156, 255, 0.75);
  --chip-bg: rgba(255, 255, 255, 0.06);
  --accent: #7c9cff;
  --accent-2: #4ecdc4;
  --danger: #ff7b8c;
  --success: #64e5b3;
  --shadow-lg: 0 24px 80px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

.tool-page {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 30px 0 60px;
}

.tool-shell {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tool-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.tool-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  border-radius: 999px;
  color: var(--text-main);
  text-decoration: none;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
  transition: 0.2s ease;
}

.tool-back:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.09);
}

.tool-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: #dce6ff;
  background: var(--chip-bg);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(14px);
}

.tool-chip-active {
  background: rgba(124, 156, 255, 0.16);
  border-color: rgba(124, 156, 255, 0.36);
  color: #fff;
}

.tool-hero {
  padding: 28px 30px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.tool-hero-badge {
  display: inline-flex;
  padding: 9px 14px;
  border-radius: 999px;
  margin-bottom: 16px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #d7e0ff;
  background: rgba(124, 156, 255, 0.14);
  border: 1px solid rgba(124, 156, 255, 0.24);
}

.tool-hero h1 {
  margin: 0 0 12px;
  font-size: clamp(30px, 4vw, 52px);
  line-height: 1.02;
  letter-spacing: -0.04em;
  color: #fff;
}

.tool-hero p {
  margin: 0;
  max-width: 860px;
  color: var(--text-soft);
  font-size: 16px;
  line-height: 1.75;
}

.edit-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(380px, 0.95fr);
  gap: 24px;
  align-items: start;
}

.panel {
  border-radius: 28px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(18px);
}

.panel-main,
.panel-preview {
  padding: 24px;
}

.panel-preview {
  position: sticky;
  top: 20px;
}

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

.panel-kicker {
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.panel-head h2 {
  margin: 0;
  color: #fff;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: -0.03em;
}

.edit-section {
  margin-bottom: 22px;
}

.edit-section:last-child {
  margin-bottom: 0;
}

.edit-section-title {
  font-size: 18px;
  font-weight: 800;
  color: #fff;
  margin-bottom: 14px;
}

.edit-field {
  margin-bottom: 14px;
}

.edit-field:last-child {
  margin-bottom: 0;
}

.edit-field label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #d7dff3;
}

.edit-field input[type="text"],
.edit-field input[type="file"],
.edit-field textarea {
  width: 100%;
  border: 1px solid var(--field-border);
  border-radius: 16px;
  padding: 14px 15px;
  background: var(--field-bg);
  color: var(--text-main);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: 0.2s ease;
}

.edit-field input:focus,
.edit-field textarea:focus,
.edit-subfield input:focus {
  border-color: var(--field-border-focus);
  box-shadow: 0 0 0 4px rgba(124, 156, 255, 0.12);
}

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

.edit-note {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--text-dim);
}

.edit-file-box,
.active-functions-list,
.history-list {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(8, 15, 31, 0.45);
  border: 1px solid var(--field-border);
}

.edit-empty {
  color: var(--text-dim);
  font-size: 14px;
}

.edit-tool-card {
  position: relative;
  margin-bottom: 16px;
  padding: 18px 16px 16px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.edit-tool-card:last-child {
  margin-bottom: 0;
}

.edit-tool-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding-left: 46px;
  padding-top: 38px;
}

.edit-tool-head h3 {
  margin: 0 0 6px;
  color: #fff;
  font-size: 18px;
}

.edit-tool-head p {
  margin: 0;
  color: var(--text-soft);
  font-size: 13px;
  line-height: 1.6;
}

.tool-check-toggle {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 7;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(8, 15, 31, 0.82);
  color: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: 0.2s ease;
}

.tool-check-toggle:hover {
  transform: translateY(-1px);
  border-color: rgba(124,156,255,0.35);
}

.tool-check-toggle.is-active {
  background: rgba(100, 229, 179, 0.18);
  border-color: rgba(100, 229, 179, 0.45);
  color: #fff;
}

.tool-check-mark {
  font-size: 18px;
  font-weight: 900;
  line-height: 1;
}

.tool-status {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 700;
}

.tool-status-top {
  position: absolute;
  top: 14px;
  left: 58px;
  z-index: 7;
  margin-top: 0;
  padding: 8px 12px;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border-radius: 12px;
  font-size: 12px;
  line-height: 1;
}

.tool-status.is-active {
  background: rgba(100, 229, 179, 0.12);
  border-color: rgba(100, 229, 179, 0.30);
  color: #dfffee;
}

.tool-lock-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  border-radius: 22px;
  background: rgba(5, 10, 22, 0.38);
  backdrop-filter: blur(7px);
}

.edit-tool-card.is-disabled .tool-lock-overlay {
  display: block;
}

.ratio-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.ratio-option,
.choice-option {
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(8, 15, 31, 0.55);
  color: #fff;
  border-radius: 16px;
  cursor: pointer;
  transition: 0.2s ease;
}

.ratio-option {
  min-width: 92px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
}

.ratio-option:hover,
.choice-option:hover {
  transform: translateY(-1px);
  border-color: rgba(124,156,255,0.40);
}

.ratio-option.is-selected,
.choice-option.is-selected {
  background: rgba(124,156,255,0.18);
  border-color: rgba(124,156,255,0.55);
}

.ratio-option span {
  font-size: 12px;
  font-weight: 800;
}

.ratio-icon {
  background: #fff;
  border-radius: 4px;
}

.ratio-1-1 { width: 34px; height: 34px; }
.ratio-4-3 { width: 40px; height: 30px; }
.ratio-3-4 { width: 30px; height: 40px; }
.ratio-4-5 { width: 30px; height: 38px; }
.ratio-9-16 { width: 24px; height: 42px; }
.ratio-16-9 { width: 46px; height: 26px; }

.choice-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.choice-options-column {
  flex-direction: column;
}

.choice-option {
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 800;
  text-align: left;
}

.edit-subfield {
  margin-top: 14px;
}

.edit-subfield.is-hidden {
  display: none;
}

.edit-subfield label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  color: #d7dff3;
}

.edit-subfield input {
  width: 100%;
  border: 1px solid var(--field-border);
  border-radius: 16px;
  padding: 14px 15px;
  background: var(--field-bg);
  color: var(--text-main);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: 0.2s ease;
}

.edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.ig-btn {
  border: 0;
  border-radius: 16px;
  padding: 14px 18px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  transition: 0.2s ease;
}

.ig-btn:hover {
  transform: translateY(-2px);
}

.ig-btn-primary {
  color: #fff;
  background: linear-gradient(135deg, #6e8cff 0%, #4ecdc4 100%);
}

.ig-btn-secondary {
  color: #ecf3ff;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--panel-border);
}

.ig-btn[disabled] {
  opacity: 0.55;
  cursor: default;
  transform: none !important;
}

.edit-run-status {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  padding: 10px 14px;
  border-radius: 999px;
  color: #eef3ff;
  font-size: 12px;
  font-weight: 800;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
}

.edit-run-status.is-running {
  background: rgba(124, 156, 255, 0.16);
  border-color: rgba(124, 156, 255, 0.36);
}

.edit-run-status.is-success {
  background: rgba(100, 229, 179, 0.16);
  border-color: rgba(100, 229, 179, 0.36);
}

.edit-run-status.is-error {
  background: rgba(255, 123, 140, 0.16);
  border-color: rgba(255, 123, 140, 0.36);
}

.preview-stack {
  display: grid;
  gap: 18px;
  grid-auto-flow: column;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.preview-card-title {
  margin-bottom: 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 800;
}

.preview-box {
  min-height: 220px;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(8, 15, 31, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.preview-empty {
  color: var(--text-dim);
  font-size: 14px;
  padding: 18px;
  text-align: center;
}

.history-block {
  margin-top: 22px;
}

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

.history-item {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 10px;
  border-radius: 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
}

.history-item-thumb {
  aspect-ratio: 3 / 4;
  border-radius: 12px;
  overflow: hidden;
  background: rgba(255,255,255,0.04);
}

.history-item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-item-meta strong {
  display: block;
  color: #fff;
  font-size: 13px;
  margin-bottom: 4px;
}

.history-item-meta span {
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.5;
}

.active-item {
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  color: #eef3ff;
  font-size: 13px;
  margin-bottom: 8px;
}

.active-item:last-child {
  margin-bottom: 0;
}

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

  .panel-preview {
    position: static;
  }
}

@media (max-width: 760px) {
  .tool-page {
    width: min(100%, calc(100% - 20px));
    padding: 18px 0 40px;
  }

  .tool-topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .tool-topbar-right {
    justify-content: flex-start;
  }

  .tool-hero,
  .panel-main,
  .panel-preview {
    padding: 18px;
    border-radius: 22px;
  }

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

  .tool-hero h1 {
    font-size: 32px;
  }

  .edit-tool-head {
    padding-left: 44px;
    padding-top: 42px;
  }

  .tool-status-top {
    left: 54px;
    right: 14px;
    width: auto;
  }

  .ratio-options,
  .choice-options {
    gap: 10px;
  }
}
.prompt-preview-wrap {
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(8, 15, 31, 0.45);
}

#promptPreviewTextarea {
  width: 100%;
  min-height: 280px;
  border: 0;
  outline: none;
  resize: vertical;
  padding: 14px 16px;
  background: rgba(8, 15, 31, 0.72);
  color: #fff;
  font-size: 12px;
  line-height: 1.65;
  font-family: Consolas, "SFMono-Regular", monospace;
}
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.25) transparent;
}
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.2);
  border-radius: 999px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.4);
}
.selected-history-info {
  margin-top: -8px;
  margin-bottom: 16px;
  color: var(--text-soft);
  font-size: 12px;
  line-height: 1.5;
}

.history-item {
  cursor: pointer;
  border: 1px solid rgba(255,255,255,0.08);
  transition: 0.2s ease;
}

.history-item:hover {
  transform: translateY(-1px);
  border-color: rgba(124,156,255,0.35);
}

.history-item.is-selected {
  border-color: rgba(124,156,255,0.65);
  background: rgba(124,156,255,0.12);
  box-shadow: 0 0 0 3px rgba(124,156,255,0.10);
}
.preview-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}