/* ═══════════════════════════════════════════════════════════════════════
   Tool pages (code generator, converter, explainer, ...).

   One workspace: the input panel on the left, the result panel on the right
   (stacked on phones). The main input comes first in the form; options
   (files, GitHub, Agent mode) sit under it and the action button closes the
   panel. Everything is scoped to .tool-page so the rest of the site keeps its
   own look.
   ═══════════════════════════════════════════════════════════════════════ */

.tool-page {
  --tp-surface: #ffffff;
  --tp-surface-2: #f5f7fa;
  --tp-surface-3: #eef1f6;
  --tp-border: #e3e7ee;
  --tp-border-strong: #cfd6e0;
  --tp-text: #111827;
  --tp-muted: #556070;
  --tp-faint: #8792a2;
  --tp-accent: #0066cc;
  --tp-accent-hover: #0055aa;
  --tp-accent-text: #0062c4;
  --tp-accent-soft: rgba(0, 102, 204, 0.08);
  --tp-ring: 0 0 0 3px rgba(0, 102, 204, 0.16);
  --tp-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 10px 30px rgba(16, 24, 40, 0.06);
  --tp-radius: 16px;
  --tp-radius-sm: 10px;
  color: var(--tp-text);
}

.dark-theme .tool-page {
  --tp-surface: #0a1628;
  --tp-surface-2: #0d1b30;
  --tp-surface-3: #12233d;
  --tp-border: #1b2b44;
  --tp-border-strong: #2a3d5a;
  --tp-text: #e6ebf3;
  --tp-muted: #a0aec2;
  --tp-faint: #73839b;
  --tp-accent: #0a72d9;
  --tp-accent-hover: #1a84ee;
  --tp-accent-text: #5aaaff;
  --tp-accent-soft: rgba(90, 170, 255, 0.12);
  --tp-ring: 0 0 0 3px rgba(90, 170, 255, 0.22);
  --tp-shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 12px 32px rgba(0, 0, 0, 0.28);
}

body.dark-theme { background-color: #001020; }

/* ── Page header ─────────────────────────────────────────────────────── */
.tool-page .tool-hero {
  background: none;
  box-shadow: none;
  border: 0;
  padding: 30px 0 18px;
  margin: 0;
}
.tool-page .tool-hero__inner { display: flex; align-items: center; gap: 16px; }
.tool-page .tool-hero__chat {
  margin-left: auto;
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid rgba(13, 143, 99, 0.35);
  border-radius: 999px;
  background: rgba(13, 143, 99, 0.06);
  color: #0b7a55;
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.tool-page .tool-hero__chat:hover { background: rgba(13, 143, 99, 0.12); border-color: rgba(13, 143, 99, 0.6); color: #0b7a55; }
.dark-theme .tool-page .tool-hero__chat { color: #4fdba6; border-color: rgba(79, 219, 166, 0.35); background: rgba(79, 219, 166, 0.06); }
.dark-theme .tool-page .tool-hero__chat:hover { color: #7ae8bf; background: rgba(79, 219, 166, 0.12); }
/* Wide screens: New Chat sits in the header, so the strip keeps room for every tool */
@media (min-width: 992px) { .tool-page .tool-tab.tab-cta { display: none; } }
@media (max-width: 991.98px) { .tool-page .tool-hero__chat { display: none; } }
.tool-page .tool-hero__logo {
  flex: 0 0 auto;
  width: 56px; height: 56px;
  display: grid; place-items: center;
  border-radius: 16px;
  background: var(--tp-surface);
  border: 1px solid var(--tp-border);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}
.tool-page .tool-hero__logo img { width: 34px; height: 34px; object-fit: contain; }
.tool-page .tool-hero h1 {
  color: var(--tp-text);
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.022em;
  line-height: 1.2;
  margin: 0 0 4px;
}
.tool-page .tool-hero .hero-lead {
  color: var(--tp-muted);
  font-size: 1rem;
  line-height: 1.55;
  max-width: 72ch;
  margin: 0;
}

/* ── Tool switcher ───────────────────────────────────────────────────── */
.tool-page .tool-switcher {
  margin: 0 0 18px;
  padding: 4px;
  border: 1px solid var(--tp-border);
  border-radius: 14px;
  background: var(--tp-surface-2);
}
.tool-page .tool-switcher__track {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.tool-page .tool-switcher__track::-webkit-scrollbar { display: none; }
/* Edge fades tell the user that more tools sit off screen. */
.tool-page .tool-switcher__track.fade-right {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 44px), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 44px), transparent);
}
.tool-page .tool-switcher__track.fade-left {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 44px);
          mask-image: linear-gradient(to right, transparent, #000 44px);
}
.tool-page .tool-switcher__track.fade-left.fade-right {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 44px, #000 calc(100% - 44px), transparent);
          mask-image: linear-gradient(to right, transparent, #000 44px, #000 calc(100% - 44px), transparent);
}
.tool-page .tool-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 11px;
  border-radius: 10px;
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--tp-muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.tool-page .tool-tab i { font-size: 0.82rem; opacity: 0.8; }
.tool-page .tool-tab:hover { color: var(--tp-text); background: var(--tp-surface-3); }
.tool-page .tool-tab.active {
  color: var(--tp-accent-text);
  background: var(--tp-surface);
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08), 0 0 0 1px var(--tp-border);
}
.tool-page .tool-tab.active i { opacity: 1; }
.tool-page .tool-tab:focus-visible { outline: none; box-shadow: var(--tp-ring); }
.tool-page .tool-tab.tab-cta { margin-left: auto; color: #0d8f63; font-weight: 600; }
.tool-page .tool-tab.tab-cta i { opacity: 1; }
.tool-page .tool-tab.tab-cta:hover { background: rgba(13, 143, 99, 0.1); color: #0b7a55; }
.dark-theme .tool-page .tool-tab.tab-cta { color: #3fd39c; }
.dark-theme .tool-page .tool-tab.tab-cta:hover { background: rgba(63, 211, 156, 0.12); color: #6be3b6; }

/* ── Workspace ───────────────────────────────────────────────────────── */
.tool-page .tool-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
/* Before the first run the empty result panel matches the input panel's
   height; after it, each panel keeps its own height (a long answer must not
   stretch the form). */
.tool-page .tool-panel--output.is-idle { align-self: stretch; }
.tool-page .tool-workspace.fullscreen-mode { grid-template-columns: minmax(0, 1fr); }

.tool-page .tool-panel {
  position: relative;
  min-width: 0;
  width: auto;
  margin: 0;
  padding: 20px 22px 22px;
  background: var(--tp-surface);
  border: 1px solid var(--tp-border);
  border-radius: var(--tp-radius);
  box-shadow: var(--tp-shadow);
}
.tool-page .tool-panel--output {
  display: flex;
  flex-direction: column;
  min-height: 460px;
}

.tool-page .tool-panel__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
  margin-bottom: 18px;
}

.tool-page .fullscreen-button {
  width: 34px; height: 34px;
  display: inline-grid; place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--tp-faint);
  transition: background-color 0.15s ease, color 0.15s ease;
}
.tool-page .fullscreen-button:hover { background: var(--tp-surface-3); color: var(--tp-text); transform: none; }
.tool-page .fullscreen-button i { color: inherit !important; font-size: 0.9rem; }
.tool-page .tool-panel--output.is-idle > .tool-panel__expand { display: none; }
.tool-page .fullscreen-button:focus-visible { outline: none; box-shadow: var(--tp-ring); }
.dark-theme .tool-page .fullscreen-button { background: transparent; color: var(--tp-faint); }
.dark-theme .tool-page .fullscreen-button:hover { background: var(--tp-surface-3); color: var(--tp-text); }
.tool-page .tool-panel--output > .tool-panel__expand { position: absolute; top: 14px; right: 14px; z-index: 2; }
/* Expand-button tooltips open toward the panel, not past the screen edge */
.tool-page .tool-panel__expand .tooltip-text { left: auto; right: 0; min-width: 0; white-space: nowrap; transform: translateY(10px); }
.tool-page .tool-panel__expand:hover .tooltip-text { transform: translateY(0); }

/* Usage chip (guests) and credit line (accounts) */
.tool-page .credit-display {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  margin: 0;
  padding: 6px 12px;
  border: 1px solid var(--tp-border);
  border-radius: 999px;
  background: var(--tp-surface-2);
  color: var(--tp-muted);
  font-size: 0.84rem;
  line-height: 1.3;
}
.dark-theme .tool-page .credit-display { background: var(--tp-surface-2); border-color: var(--tp-border); }
.tool-page .credit-display strong,
.tool-page .credit-display b { color: var(--tp-text); font-weight: 700; }
.tool-page .credit-display #remaining-credit { margin-left: 0 !important; color: var(--tp-text); font-weight: 700; }
.tool-page .credit-display a.first-btn { margin: 0 !important; padding: 2px 10px; font-size: 0.78rem; }
.tool-page .credit-display { border-radius: 14px; }
.tool-page .credit-display .quota-sep { display: none; }
.tool-page .tool-chip--guest { background: var(--tp-accent-soft); border-color: transparent; color: var(--tp-text); border-radius: 999px; }
.dark-theme .tool-page .tool-chip--guest { background: var(--tp-accent-soft); border-color: transparent; }
.tool-page .tool-chip--guest > i { color: #f59e0b; font-size: 0.8rem; }
.tool-page .tool-chip--guest a { font-weight: 600; color: var(--tp-accent-text); text-decoration: none; }
.tool-page .tool-chip--guest a:hover { text-decoration: underline; }
.tool-page .tool-chip--guest .tool-chip__sep { color: var(--tp-faint); }

/* ── Model + language row ────────────────────────────────────────────── */
.tool-page .tool-setup {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px 14px;
  margin-bottom: 18px;
}
.tool-page .tool-setup .tf-model-desc { order: 3; grid-column: 1 / -1; }

.tool-page .tf-label-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 22px;
  margin-bottom: 6px;
}
.tool-page .tf-label,
.tool-page .tool-form .form-label,
.tool-page .lang-picker-label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--tp-text);
  margin: 0;
}
.tool-page .tool-form .form-label { margin-bottom: 6px; }
.tool-page .tf-cost {
  margin-left: auto;
  font-size: 0.78rem;
  color: var(--tp-faint);
  white-space: nowrap;
}
.tool-page .tf-model-desc {
  margin: 4px 0 0;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--tp-faint);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.tool-page .tf-model-desc:empty { display: none; }

/* Info icons and "optional" tags next to labels */
.tool-page .custom-tooltip > .fa-info-circle,
.tool-page .custom-tooltip > .fa-circle-info { color: var(--tp-faint) !important; font-size: 0.78rem; vertical-align: 1px; }
.tool-page .tf-optional {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--tp-surface-3);
  color: var(--tp-faint);
  font-size: 0.7rem;
  font-weight: 500;
  font-style: normal;
  vertical-align: 1px;
}

/* Model dropdown button: reads as a select */
.tool-page .model-dropdown-container,
.tool-page .model-dropdown-container > .btn-group { display: block; width: 100%; }
.tool-page #modelDropdownButton {
  display: flex;
  align-items: center;
  width: 100%;
  height: 44px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--tp-border-strong);
  border-radius: var(--tp-radius-sm);
  background: var(--tp-surface);
  color: var(--tp-text);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
  box-shadow: none;
  position: relative;
}
.tool-page #modelDropdownButton::after {
  position: absolute;
  right: 14px;
  top: 50%;
  margin-top: -2px;
  color: var(--tp-faint);
}
.tool-page #modelDropdownButton:hover { border-color: var(--tp-faint); transform: none; }
.tool-page #modelDropdownButton:focus-visible,
.tool-page #modelDropdownButton[aria-expanded="true"] { border-color: var(--tp-accent); box-shadow: var(--tp-ring); outline: none; }
.dark-theme .tool-page #modelDropdownButton { background: var(--tp-surface-2); color: var(--tp-text); }
.tool-page #modelDropdownButton #selectedModelDisplayContent { max-width: 100%; min-width: 0; }
.tool-page #modelDropdownButton #selectedModelDisplayContent .btn-model-name { overflow: hidden; text-overflow: ellipsis; }
/* Hover-capable screens open these menus on hover (theme.css
   `.dropdown:hover .dropdown-menu`), so the menu must touch its button: any
   gap closes it while the pointer crosses. The old inline margin-top:45px
   only worked while .btn-group was inline-flex. */
.tool-page #modelDropdown .dropdown-menu,
.tool-page .tf-langpair .languages-menu {
  top: 100% !important;
  left: 0;
  margin-top: 0 !important;
}

/* Language picker */
.tool-page .lang-picker { margin: 0; }
.tool-page .tool-setup .tf-field { margin-bottom: 0; }
.tool-page .lang-picker-label { margin-bottom: 6px; min-height: 22px; }
.tool-page .lang-input-wrap {
  height: 44px;
  border: 1px solid var(--tp-border-strong);
  border-radius: var(--tp-radius-sm);
  background: var(--tp-surface);
}
.dark-theme .tool-page .lang-input-wrap { background: var(--tp-surface-2); }
.dark-theme .tool-page .lang-toggle-btn { background: transparent; }
.dark-theme .tool-page .lang-input { background: transparent; border: 0; box-shadow: none; }
.tool-page .lang-input-wrap:focus-within,
.tool-page .lang-input-wrap.open { border-color: var(--tp-accent); box-shadow: var(--tp-ring); }
.tool-page .lang-input { font-size: 0.9rem; color: var(--tp-text); }
.tool-page .lang-flag, .tool-page .lang-flag-ph { width: 22px; height: 22px; }

/* ── Form ────────────────────────────────────────────────────────────── */
.tool-page .tool-form > br,
.tool-page .tool-form .tf-field > br { display: none; }
.tool-page .tf-field { margin-bottom: 18px; }
.tool-page .tf-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0 14px;
}
.tool-page .tool-form .form-control,
.tool-page .tool-form .form-select {
  border: 1px solid var(--tp-border-strong);
  border-radius: var(--tp-radius-sm);
  background-color: var(--tp-surface);
  color: var(--tp-text);
  font-size: 0.92rem;
  padding: 10px 12px;
  box-shadow: none;
}
.tool-page .tool-form .form-select { padding-right: 36px; }
.dark-theme .tool-page .tool-form .form-control,
.dark-theme .tool-page .tool-form .form-select { background-color: var(--tp-surface-2); color: var(--tp-text); border-color: var(--tp-border-strong); }
.dark-theme .tool-page .tool-form .form-select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23a0aec2' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
.tool-page .tool-form .form-control::placeholder { color: var(--tp-faint); opacity: 1; }
.tool-page .tool-form .form-control:focus,
.tool-page .tool-form .form-select:focus { border-color: var(--tp-accent); box-shadow: var(--tp-ring); }
.tool-page .tool-form textarea.form-control { line-height: 1.55; resize: vertical; }
.tool-page .tool-form textarea#text:not(.code-editor) { min-height: 150px; }

/* Code editor */
.tool-page .code-editor-container { position: relative; }
.tool-page .CodeMirror {
  height: 240px;
  border: 1px solid var(--tp-border-strong);
  border-radius: var(--tp-radius-sm);
  font-size: 13.5px;
  line-height: 1.55;
  background: var(--tp-surface);
}
.tool-page .CodeMirror-focused { border-color: var(--tp-accent); box-shadow: var(--tp-ring); }
.tool-page .CodeMirror-gutters { border-right: 1px solid var(--tp-border); background: var(--tp-surface-2); border-radius: var(--tp-radius-sm) 0 0 var(--tp-radius-sm); }
.dark-theme .tool-page .CodeMirror { background: var(--tp-surface-2); }
.dark-theme .tool-page .CodeMirror-gutters { background: var(--tp-surface); }
.tool-page .tf-field--editor .tf-label-row { margin-bottom: 6px; }
.tool-page .clear-button {
  position: static;
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border: 1px solid var(--tp-border);
  border-radius: 999px;
  background: var(--tp-surface);
  color: var(--tp-muted);
  font-size: 0.76rem;
  font-weight: 500;
}
.tool-page .clear-button:hover { color: var(--tp-text); border-color: var(--tp-border-strong); background: var(--tp-surface-2); transform: none; }
.dark-theme .tool-page .clear-button { background: transparent; color: var(--tp-muted); }

/* Converter: From ⇄ To */
.tool-page .tf-langpair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: 0 10px;
  margin-bottom: 18px;
}
.tool-page .tf-langpair .tf-field { margin-bottom: 0; min-width: 0; }
.tool-page .tf-select-group { display: block; width: 100%; }
.tool-page .tf-select-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 44px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--tp-border-strong);
  border-radius: var(--tp-radius-sm);
  background: var(--tp-surface);
  color: var(--tp-text);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: left;
  position: relative;
}
.tool-page .tf-select-btn > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.tool-page .tf-select-btn::after { position: absolute; right: 14px; top: 50%; margin-top: -2px; color: var(--tp-faint); }
.tool-page .tf-select-btn:hover { border-color: var(--tp-faint); color: var(--tp-text); transform: none; }
.tool-page .tf-select-btn:focus-visible,
.tool-page .tf-select-btn[aria-expanded="true"] { border-color: var(--tp-accent); box-shadow: var(--tp-ring); outline: none; }
.dark-theme .tool-page .tf-select-btn { background: var(--tp-surface-2); color: var(--tp-text); }
.tool-page .tf-select-logo { width: 20px; height: 20px; object-fit: contain; flex: 0 0 auto; color: #7c3aed; }
.tool-page .tf-langpair .languages-menu { max-height: 360px; overflow-y: auto; min-width: 100%; }
.tool-page .tf-swap { padding-bottom: 4px; }
.tool-page .swap-languages-btn {
  width: 36px; height: 36px;
  display: inline-grid; place-items: center;
  padding: 0;
  border: 1px solid var(--tp-border);
  border-radius: 999px;
  background: var(--tp-surface);
  color: var(--tp-muted);
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease, transform 0.2s ease;
}
.tool-page a.swap-languages-btn:hover { color: var(--tp-accent-text); border-color: var(--tp-accent); transform: rotate(180deg); }
.tool-page .swap-languages-btn:disabled { opacity: 0.45; cursor: not-allowed; }
/* From and To sit side by side at every width, so the arrows stay horizontal
   (assistant-base.css turns the button 90° on phones for an old stacked layout) */
.tool-page .swap-languages-btn { transform: none; margin: 0; }
.tool-page a.swap-languages-btn:hover { transform: rotate(180deg); background: var(--tp-surface); }
.dark-theme .tool-page .swap-languages-btn { background: transparent; color: var(--tp-muted); }

/* Inline validation messages */
.tool-page .tool-form .alert {
  margin: 0 0 8px;
  padding: 8px 12px;
  border-radius: var(--tp-radius-sm);
  font-size: 0.84rem;
}

/* Agent mode is locked for guests, except on tools that force it on */
.tool-page .tf-switch:has(input:checked) .tf-switch__lock,
.tool-page .tf-switch:has(input:checked) .tf-switch__guest { display: none; }

/* Range with three named stops (explainer, docs) */
.tool-page .tf-range { max-width: 360px; }
.tool-page .tf-range .form-range { display: block; width: 100%; }
.tool-page .tf-range .form-range::-webkit-slider-runnable-track { background: var(--tp-surface-3); }
.tool-page .tf-range .form-range::-moz-range-track { background: var(--tp-surface-3); }
.dark-theme .tool-page .tf-range .form-range { background: transparent; border: 0; box-shadow: none; }
.tool-page .tf-range-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 0.76rem;
  color: var(--tp-faint);
}

/* Example prompts under the generator's input */
.tool-page .tf-examples { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 10px; }
.tool-page .tf-examples__label { font-size: 0.76rem; color: var(--tp-faint); margin-right: 2px; }
.tool-page .tf-example {
  padding: 4px 10px;
  border: 1px solid var(--tp-border);
  border-radius: 999px;
  background: var(--tp-surface);
  color: var(--tp-muted);
  font-size: 0.78rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background-color 0.15s ease;
}
.tool-page .tf-example:hover { border-color: var(--tp-accent); color: var(--tp-accent-text); background: var(--tp-accent-soft); }
.dark-theme .tool-page .tf-example { background: transparent; color: var(--tp-muted); }
.dark-theme .tool-page .tf-example:hover { color: var(--tp-accent-text); }

/* Notices inside the form */
.tool-page .tf-notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin: 0 0 18px;
  padding: 10px 12px;
  border: 1px solid var(--tp-border);
  border-radius: var(--tp-radius-sm);
  background: var(--tp-surface-2);
  color: var(--tp-muted);
  font-size: 0.84rem;
  line-height: 1.5;
}
.tool-page .tf-notice > i { margin-top: 3px; color: var(--tp-accent-text); }
.tool-page .tf-notice strong { color: var(--tp-text); }

/* ── Files and GitHub ────────────────────────────────────────────────── */
.tool-page #unifiedUpload { margin-bottom: 14px; }
.tool-page .tf-attach { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; align-items: start; }
.tool-page .unified-file-upload {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 0;
  height: 44px;
  padding: 0 14px;
  border: 1px dashed var(--tp-border-strong);
  border-radius: var(--tp-radius-sm);
  background: var(--tp-surface);
  background-image: none;
  text-align: left;
  color: var(--tp-muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.tool-page .unified-file-upload:hover,
.tool-page .unified-file-upload:focus-visible {
  border-color: var(--tp-accent);
  background: var(--tp-accent-soft);
  color: var(--tp-text);
  transform: none;
  box-shadow: none;
  outline: none;
}
.tool-page .unified-file-upload:focus-visible { box-shadow: var(--tp-ring); }
.tool-page .unified-file-upload.dragging { border-color: #16a34a; background: rgba(22, 163, 74, 0.08); transform: none; }
.dark-theme .tool-page .unified-file-upload { background: transparent; }
.tool-page .unified-file-upload > i { font-size: 0.95rem; color: var(--tp-faint); margin: 0 !important; }
.tool-page .unified-file-upload .upload-text {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 500;
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1 1 auto;
}
.tool-page .unified-file-upload .upload-text small { font-weight: 400; color: var(--tp-faint); }
.tool-page .unified-file-upload .custom-tooltip { flex: 0 0 auto; }
.tool-page .unified-file-upload .upload-error { flex-basis: 100%; }
/* Diagram to Code: the image is the main input, so the drop zone is big. */
.tool-page .tf-attach--primary { grid-template-columns: minmax(0, 1fr); }
.tool-page .tf-attach--primary .unified-file-upload {
  flex-direction: column;
  justify-content: center;
  height: auto;
  min-height: 150px;
  padding: 22px 16px;
  text-align: center;
  gap: 8px;
}
.tool-page .tf-attach--primary .unified-file-upload > i { font-size: 1.6rem; color: var(--tp-accent-text); }
.tool-page .tf-attach--primary .unified-file-upload .upload-text { white-space: normal; flex: 0 0 auto; font-size: 0.95rem; }

.tool-page .github-import {
  margin: 0;
  padding: 0 14px;
  border: 1px solid var(--tp-border);
  border-radius: var(--tp-radius-sm);
  background: var(--tp-surface);
}
.dark-theme .tool-page .github-import { background: transparent; border-color: var(--tp-border-strong); }
.tool-page .github-import summary {
  height: 42px;
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--tp-muted);
}
.tool-page .github-import[open] { padding-bottom: 12px; }
.tool-page .github-import[open] summary { color: var(--tp-text); }
.dark-theme .tool-page .github-import summary { color: var(--tp-muted); }
.tool-page .github-import summary > i { font-size: 1rem; color: var(--tp-text); }
.tool-page .github-import .gh-optional { font-style: normal; color: var(--tp-faint); }
.tool-page .github-import .gh-fields { margin-top: 2px; }
.tool-page .github-import .gh-fields .form-control { font-size: 0.86rem; padding: 8px 10px; }
.tool-page .github-import .gh-note { font-size: 0.76rem; color: var(--tp-faint); }
.tool-page .github-import[open] { grid-column: 1 / -1; }

/* ── Advanced tools (Web access, Agent mode) ─────────────────────────── */
.tool-page .tools-container {
  margin: 0 0 4px;
  border: 1px solid var(--tp-border);
  border-radius: var(--tp-radius-sm) !important;
  background: var(--tp-surface) !important;
  overflow: hidden;
}
.dark-theme .tool-page .tools-container { background: transparent !important; border-color: var(--tp-border-strong); }
.tool-page .tools-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 14px !important;
  border: 0;
  background: transparent;
  color: var(--tp-text);
  font-size: 0.88rem;
  font-weight: 600;
  text-align: left;
}
.tool-page .tools-header:hover { background: var(--tp-surface-2) !important; }
.dark-theme .tool-page .tools-header { color: var(--tp-text); }
.tool-page .tools-header .tools-header__icon { color: var(--tp-faint); }
.tool-page .tools-header .tools-header__summary { margin-left: auto; font-size: 0.76rem; font-weight: 500; color: var(--tp-faint); }
.tool-page .tools-header #toggleIcon { transform: none; color: var(--tp-faint); font-size: 0.72rem; transition: transform 0.25s ease; }
.tool-page .tools-content.show ~ * #toggleIcon,
.tool-page .tools-container.is-open #toggleIcon { transform: rotate(180deg); }
/* A closed section must also leave the tab order: its switches and links
   were focusable while invisible. Visibility flips after the close animation. */
.tool-page .tools-content { visibility: hidden; transition: max-height 0.4s cubic-bezier(0, 1, 0, 1), visibility 0s linear 0.4s; }
.tool-page .tools-content.show { visibility: visible; transition: max-height 0.6s ease-in-out, visibility 0s; }
.tool-page .tools-content-inner { padding: 0 14px 6px; }
.tool-page .tools-content-inner hr { display: none; }

.tool-page .tf-switch.form-check {
  display: flex !important;
  align-items: flex-start;
  gap: 14px;
  margin: 0;
  padding: 12px 0;
  border-top: 1px solid var(--tp-border);
}
.tool-page .tf-switch .tf-switch__text { flex: 1 1 auto; min-width: 0; }
.tool-page .tf-switch .form-check-label { font-size: 0.88rem; font-weight: 600; color: var(--tp-text); }
.tool-page .tf-switch .tf-switch__desc { display: block; margin-top: 2px; font-size: 0.8rem; line-height: 1.45; color: var(--tp-muted); }
.tool-page .tf-switch .tf-switch__desc a { white-space: nowrap; }
.tool-page .tf-switch .tf-switch__lock { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 999px; background: var(--tp-surface-3); color: var(--tp-faint); font-size: 0.7rem; font-weight: 500; }
.tool-page .tf-switch .toggle-switch { flex: 0 0 auto; width: 38px; height: 22px; margin: 2px 0 0; }
.tool-page .tf-switch .slider { border-radius: 22px; background-color: var(--tp-border-strong); }
.tool-page .tf-switch .slider:before { width: 18px; height: 18px; left: 2px; bottom: 2px; transform: none; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2); }
.tool-page .tf-switch input:checked + .slider { background-color: var(--tp-accent); }
.tool-page .tf-switch input:checked + .slider:before { transform: translateX(16px); }
.tool-page .tf-switch input:focus-visible + .slider { box-shadow: var(--tp-ring); }
.tool-page .tf-switch input:disabled + .slider { opacity: 0.5; cursor: not-allowed; }
.tool-page .tf-switch .agent-mode-hint { margin: 6px 0 0; }

/* ── Action row ──────────────────────────────────────────────────────── */
.tool-page .tool-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--tp-border);
}
.tool-page .tool-tokens { font-size: 0.8rem; color: var(--tp-faint); font-variant-numeric: tabular-nums; }
.tool-page .tool-tokens #token-count { color: var(--tp-muted); font-weight: 600; }
.tool-page .tool-actions__buttons { display: flex; gap: 8px; margin-left: auto; }
.tool-page #submit-button,
.tool-page #stop-button {
  min-height: 44px;
  padding: 10px 20px;
  border-radius: var(--tp-radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  white-space: nowrap;
}
.tool-page #submit-button {
  background: var(--tp-accent);
  border: 1px solid transparent;
  color: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.1), 0 6px 16px rgba(0, 102, 204, 0.24);
}
.tool-page #submit-button:hover { background: var(--tp-accent-hover); transform: translateY(-1px); }
.tool-page #submit-button:focus-visible { outline: none; box-shadow: var(--tp-ring); }
.tool-page #submit-button:disabled { opacity: 0.65; transform: none; box-shadow: none; }
.tool-page #submit-button i { margin-left: 4px; font-size: 0.85rem; }

.tool-page .notice-upgrade { margin: 14px 0 0; font-size: 0.84rem; }

/* ── Result panel ────────────────────────────────────────────────────── */
.tool-page #result-output { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.tool-page #result-output > h2 {
  margin: 0 0 14px;
  padding-right: 44px;
  font-size: 0.78rem !important;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--tp-faint);
}
.tool-page #result-output > .result-item { min-width: 0; color: var(--tp-text); line-height: 1.65; }
.tool-page #result-output > .result-item.result-error,
.tool-page #result-output > .result-item.result-error a { color: #b42318; }
.tool-page #result-output > .result-item.result-error {
  padding: 12px 14px;
  border: 1px solid rgba(180, 35, 24, 0.25);
  border-radius: var(--tp-radius-sm);
  background: rgba(180, 35, 24, 0.06);
}
.dark-theme .tool-page #result-output > .result-item.result-error { color: #fda29b; border-color: rgba(253, 162, 155, 0.3); background: rgba(253, 162, 155, 0.08); }
.dark-theme .tool-page #result-output > .result-item.result-error a { color: #fecdca; }

/* Waiting for the first words of the answer */
.tool-page #result-output.is-loading::after {
  content: "Working on it…";
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 0 0 30px;
  color: var(--tp-muted);
  font-size: 0.9rem;
  background:
    radial-gradient(circle closest-side, var(--tp-accent) 92%, transparent) 0 22px / 8px 8px no-repeat,
    radial-gradient(circle closest-side, var(--tp-accent) 92%, transparent) 11px 22px / 8px 8px no-repeat;
  animation: tp-pulse 1s ease-in-out infinite;
}
.tool-page #result-output.is-loading::before {
  content: "";
  display: block;
  height: 10px;
  margin: 2px 0 10px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--tp-surface-2), var(--tp-surface-3), var(--tp-surface-2));
  background-size: 200% 100%;
  animation: tp-shimmer 1.2s linear infinite;
  order: 2;
  width: 70%;
}
@media (prefers-reduced-motion: reduce) {
  .tool-page #result-output.is-loading::after,
  .tool-page #result-output.is-loading::before { animation: none; }
}
@keyframes tp-pulse { 50% { opacity: 0.45; } }
@keyframes tp-shimmer { to { background-position: -200% 0; } }

/* Empty state, before the first run */
.tool-page .tool-empty {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px 24px;
  border: 1px dashed var(--tp-border-strong);
  border-radius: 12px;
  background:
    radial-gradient(circle at 1px 1px, var(--tp-border) 1px, transparent 0) 0 0 / 18px 18px,
    var(--tp-surface);
}
.dark-theme .tool-page .tool-empty {
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.05) 1px, transparent 0) 0 0 / 18px 18px,
    var(--tp-surface);
}
.tool-page .tool-empty__icon {
  width: 56px; height: 56px;
  display: grid; place-items: center;
  margin-bottom: 14px;
  border-radius: 16px;
  background: var(--tp-surface);
  border: 1px solid var(--tp-border);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 16px rgba(16, 24, 40, 0.06);
  color: var(--tp-accent-text);
  font-size: 1.25rem;
}
.tool-page .tool-empty__title { margin: 0 0 6px; font-size: 1.05rem; font-weight: 600; color: var(--tp-text); }
.tool-page .tool-empty__text { margin: 0; max-width: 38ch; font-size: 0.9rem; line-height: 1.55; color: var(--tp-muted); }
.tool-page .tool-empty__points {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 16px;
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  color: var(--tp-faint);
}
.tool-page .tool-empty__points i { margin-right: 5px; color: #16a34a; font-size: 0.72rem; }
.dark-theme .tool-page .tool-empty__points i { color: #4ade80; }

.tool-page .tool-continue { display: flex; justify-content: center; margin-top: 18px; }
.tool-page #continue-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border-radius: var(--tp-radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
}

/* ── About ───────────────────────────────────────────────────────────── */
.tool-page .tool-about { max-width: 760px; margin: 44px auto 0; text-align: center; }
.tool-page .tool-about__title { margin: 0 0 8px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--tp-faint); }
.tool-page #tool-about { margin: 0; color: var(--tp-muted); font-size: 0.98rem; line-height: 1.7; }
.tool-page .tool-browse { margin: 28px 0 48px; text-align: center; color: var(--tp-muted); font-size: 0.92rem; }

/* Small laptops (992-1199px): two panels side by side leave the input panel
   about 450px wide, too narrow for files and GitHub on one row. */
@media (min-width: 992px) and (max-width: 1199.98px) {
  .tool-page .tf-attach { grid-template-columns: minmax(0, 1fr); }
  /* Full width, so the selected model shows its effort level, not "…" */
  .tool-page .tool-setup { grid-template-columns: minmax(0, 1fr); gap: 14px; }
}
/* Keep "Import from GitHub" on one line, but not its tooltip: a hidden
   one-line tooltip still widened the page. */
.tool-page .github-import summary { white-space: nowrap; }
.tool-page .github-import summary .tooltip-text { white-space: normal; }

/* ── Tablet and phone ────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .tool-page .tool-workspace { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .tool-page .tool-panel--output { min-height: 0; }
  /* Before the first run the result panel has nothing to show on a
     stacked layout; the submit handler un-hides it (inline display). */
  .tool-page .tool-panel--output.is-idle { display: none; }
  #form-fullscreen-toggle, #result-fullscreen-toggle { display: none !important; }
  .tool-page .tool-panel--output > .tool-panel__expand { display: none; }
}

@media (max-width: 767.98px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  .tool-page .tf-langpair { grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 0 8px; }
  .tool-page .tf-select-btn { padding-left: 10px; font-size: 0.86rem; }
  .tool-page .container { padding-left: 14px; padding-right: 14px; }
  .tool-page .tool-hero { padding: 20px 0 14px; }
  .tool-page .tool-hero__inner { align-items: flex-start; gap: 12px; }
  .tool-page .tool-hero__logo { width: 44px; height: 44px; border-radius: 12px; }
  .tool-page .tool-hero__logo img { width: 26px; height: 26px; }
  .tool-page .tool-hero h1 { font-size: 1.45rem; }
  .tool-page .tool-hero .hero-lead { font-size: 0.92rem; }
  .tool-page .tool-switcher { margin-bottom: 14px; border-radius: 12px; }
  .tool-page .tool-tab { padding: 8px 10px; font-size: 0.82rem; }
  .tool-page .tool-panel { padding: 16px 14px 16px; border-radius: 14px; }
  .tool-page .tool-panel__bar { margin-bottom: 14px; }
  .tool-page .credit-display { font-size: 0.8rem; }
  .tool-page .tool-setup { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .tool-page .tool-setup .tf-model-desc { display: none; }
  .tool-page .tools-header .tools-header__summary { display: none; }
  .tool-page .tools-header #toggleIcon { margin-left: auto; }
  .tool-page .tf-example { padding: 6px 12px; flex: 0 0 auto; }
  .tool-page .tf-examples { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-right: -14px; padding-right: 14px; }
  .tool-page .tf-examples::-webkit-scrollbar { display: none; }
  .tool-page .tool-chip--guest a { padding: 4px 0; }
  .tool-page .tf-attach { grid-template-columns: minmax(0, 1fr); }
  .tool-page .CodeMirror { height: 220px; }
  .tool-page .tool-actions { flex-direction: column-reverse; align-items: stretch; gap: 10px; }
  .tool-page .tool-actions__buttons { margin-left: 0; }
  .tool-page .tool-actions__buttons > button { flex: 1 1 auto; }
  .tool-page #submit-button, .tool-page #stop-button { width: 100%; }
  .tool-page .tool-tokens { text-align: center; }
  .tool-page .tool-about { margin-top: 32px; text-align: left; }
  .tool-page .tf-range { max-width: none; }
  /* The model menu spans the screen instead of hanging off its button. */
  .tool-page #modelDropdown .dropdown-menu { min-width: 0; width: auto; max-width: none; right: 0; }
}

@media (max-width: 400px) {
  /* The usage chip wraps to two lines here: a pill shape no longer fits */
  .tool-page .tool-chip--guest { border-radius: 12px; }
  .tool-page .tool-chip--guest .tool-chip__sep { display: none; }
  .tool-page .github-import .gh-optional { display: none; }
}
