:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --ink: #172126;
  --muted: #63717a;
  --line: #d9e0e4;
  --line-strong: #a9b6bd;
  --teal: #0f766e;
  --blue: #2563eb;
  --blue-soft: #e9f0ff;
  --teal-soft: #e6f4f1;
  --shadow: 0 12px 32px rgba(23, 33, 38, 0.08);
  --topbar-height: 92px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", Arial, sans-serif;
}

button {
  border: 1px solid transparent;
  font: inherit;
  cursor: pointer;
  transition:
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.toolbox-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
}

.toolbox-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: minmax(250px, 0.9fr) minmax(560px, 1.45fr) minmax(210px, 0.7fr) auto;
  align-items: center;
  gap: 12px;
  min-height: var(--topbar-height);
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(246, 247, 248, 0.97);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
}

.brand-copy {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--teal);
  color: white;
  font-size: 22px;
  font-weight: 850;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.18);
}

.brand h1,
.brand p {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
  letter-spacing: 0;
  white-space: nowrap;
}

.brand p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.brand-meta span {
  border: 1px solid #c8d8d5;
  border-radius: 999px;
  padding: 3px 7px;
  background: var(--teal-soft);
  color: var(--teal);
  font-size: 11px;
  font-weight: 850;
  line-height: 1.2;
}

.tool-switch {
  display: inline-grid;
  grid-template-columns: repeat(5, minmax(108px, 1fr));
  gap: 4px;
  width: min(100%, 780px);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: 0 8px 20px rgba(23, 33, 38, 0.04);
}

.tool-btn,
.ghost-btn {
  border-radius: 7px;
  font-size: 14px;
  font-weight: 800;
}

.tool-btn {
  display: grid;
  align-content: center;
  gap: 2px;
  min-height: 44px;
  padding: 5px 12px;
  background: transparent;
  color: var(--muted);
  text-align: left;
  min-width: 0;
}

.tool-btn strong,
.tool-btn span {
  display: block;
  line-height: 1.1;
}

.tool-btn span {
  color: inherit;
  font-size: 11px;
  opacity: 0.82;
}

.tool-btn.is-active {
  background: var(--blue);
  color: white;
  box-shadow: 0 7px 16px rgba(37, 99, 235, 0.24);
}

.tool-btn:hover:not(.is-active) {
  background: #f6f9fc;
  color: var(--ink);
}

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

.tool-context {
  display: grid;
  gap: 4px;
  min-width: 0;
  border: 1px solid #cbd5e1;
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 9px 11px;
  background: white;
  box-shadow: 0 8px 20px rgba(23, 33, 38, 0.04);
}

.tool-context span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.tool-context strong,
.tool-context p {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-context strong {
  color: var(--ink);
  font-size: 15px;
}

.tool-context p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.ghost-btn {
  height: 38px;
  padding: 0 13px;
  border-color: var(--line-strong);
  background: white;
  color: var(--ink);
}

.ghost-btn:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.ghost-btn:hover {
  border-color: #8aa0ad;
  background: #fbfcfd;
  box-shadow: 0 7px 16px rgba(23, 33, 38, 0.06);
}

button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.23);
  outline-offset: 1px;
}

.tool-frame-wrap {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: #f8fafc;
}

.loading-bar {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 100%;
  height: 3px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease;
}

.loading-bar::before {
  content: "";
  display: block;
  width: 45%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--blue));
  transform: translateX(-100%);
}

.tool-frame-wrap.is-loading .loading-bar {
  opacity: 1;
}

.tool-frame-wrap.is-loading .loading-bar::before {
  animation: loading-slide 900ms ease-in-out infinite;
}

#toolFrame {
  display: block;
  width: 100%;
  height: calc(100vh - var(--topbar-height));
  height: calc(100dvh - var(--topbar-height));
  min-height: 360px;
  border: 0;
  background: #f6f7f8;
}

@keyframes loading-slide {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(230%);
  }
}

@media (max-width: 1380px) {
  .toolbox-topbar {
    grid-template-columns: minmax(250px, 0.8fr) minmax(0, 1.4fr);
    align-items: stretch;
    gap: 10px;
  }

  .tool-switch {
    width: 100%;
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .tool-btn {
    text-align: center;
  }

  .tool-context {
    grid-column: 1 / 2;
  }

  .top-actions {
    grid-column: 2 / 3;
    align-content: stretch;
  }

  .top-actions button {
    flex: 1;
  }
}

@media (max-width: 920px) {
  .toolbox-topbar {
    grid-template-columns: 1fr;
  }

  .tool-context,
  .top-actions {
    grid-column: auto;
  }
}

@media (max-width: 760px) {
  .tool-switch {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .tool-context {
    border-left-width: 1px;
  }
}

@media (max-width: 520px) {
  .toolbox-topbar {
    padding: 10px;
  }

  .brand h1 {
    font-size: 18px;
  }

  .brand p {
    font-size: 12px;
    white-space: normal;
  }

  .brand-meta span {
    font-size: 10px;
  }

  .tool-btn,
  .ghost-btn {
    padding: 0 9px;
  }

  .tool-btn {
    min-height: 42px;
    padding: 5px 8px;
    text-align: center;
  }

  .tool-btn span {
    font-size: 10px;
  }

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

  .top-actions {
    grid-template-columns: 1fr;
  }
}
