:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-soft: #f0f4f7;
  --text: #16202a;
  --muted: #667382;
  --line: #dce3e9;
  --line-strong: #c6d1da;
  --accent: #0f8b8d;
  --accent-dark: #08696d;
  --accent-soft: #dff3f2;
  --blue: #2662d9;
  --green: #16825d;
  --amber: #b86900;
  --red: #c33434;
  --shadow: 0 18px 55px rgba(27, 43, 57, 0.12);
  --radius: 8px;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background:
    linear-gradient(135deg, rgba(15, 139, 141, 0.10), transparent 34%),
    linear-gradient(315deg, rgba(38, 98, 217, 0.08), transparent 32%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  letter-spacing: 0;
}

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

button {
  border: 0;
}

svg {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.app-shell {
  width: min(1540px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  position: relative;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  width: 46px;
  height: 46px;
  padding: 8px;
  border: 1px solid rgba(15, 139, 141, 0.26);
  border-radius: var(--radius);
  background: linear-gradient(145deg, #ffffff, #e4f2f1);
  box-shadow: 0 10px 26px rgba(15, 139, 141, 0.16);
}

.brand-mark span {
  align-self: end;
  display: block;
  border-radius: 3px;
  background: var(--accent);
}

.brand-mark span:nth-child(1) {
  height: 14px;
}

.brand-mark span:nth-child(2) {
  height: 25px;
  background: var(--blue);
}

.brand-mark span:nth-child(3) {
  height: 19px;
  background: var(--amber);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
  font-weight: 760;
}

h2 {
  font-size: 17px;
  line-height: 1.25;
  font-weight: 740;
}

.brand p,
.panel-heading p,
#statusLine {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.top-actions,
.form-actions,
.result-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 0.88fr) minmax(520px, 1.12fr);
  grid-template-areas:
    "request result"
    "history result";
  gap: 18px;
  align-items: start;
}

.request-panel,
.result-panel,
.history-panel {
  border: 1px solid rgba(198, 209, 218, 0.86);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.request-panel {
  grid-area: request;
}

.result-panel {
  grid-area: result;
  min-width: 0;
}

.history-panel {
  grid-area: history;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading.compact {
  align-items: center;
}

.result-heading {
  align-items: center;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.mode-pill span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(22, 130, 93, 0.14);
}

.control-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.span-2 {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.field > span,
.switch-field span {
  color: #314252;
  font-size: 12px;
  font-weight: 720;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fbfcfd;
  color: var(--text);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 96px;
  padding: 11px 12px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(15, 139, 141, 0.14);
}

.secret-row,
.inline-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.secret-row input {
  flex: 1;
}

.inline-input {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fbfcfd;
  padding-right: 12px;
}

.inline-input:focus-within {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(15, 139, 141, 0.14);
}

.inline-input input {
  border: 0;
  background: transparent;
  box-shadow: none;
}

.inline-input span {
  color: var(--muted);
  font-size: 12px;
}

.switch-field {
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.switch-field input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background-color 120ms ease, border-color 120ms ease;
  user-select: none;
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.icon-button:active {
  transform: translateY(1px);
}

.primary-button {
  min-width: 138px;
  padding: 0 18px;
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 12px 24px rgba(15, 139, 141, 0.22);
  font-weight: 760;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button,
.ghost-button {
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: #243443;
  font-weight: 700;
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.ghost-button {
  background: rgba(255, 255, 255, 0.7);
}

.ghost-button.small {
  min-height: 34px;
  padding: 0 11px;
  font-size: 12px;
}

.icon-button {
  flex: 0 0 40px;
  width: 40px;
  min-width: 40px;
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: #314252;
}

.icon-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  padding: 0 18px;
  background: var(--line);
}

.metric-strip div {
  display: grid;
  gap: 4px;
  padding: 14px 12px;
  background: #ffffff;
}

.metric-strip span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.metric-strip strong {
  overflow: hidden;
  color: var(--text);
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 14px 18px 0;
}

.tab-button {
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius) var(--radius) 0 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 740;
}

.tab-button.active {
  border-color: var(--line-strong);
  border-bottom-color: #ffffff;
  background: #ffffff;
  color: var(--accent-dark);
}

.tab-content {
  display: none;
  padding: 0 18px 18px;
}

.tab-content.active {
  display: block;
}

.output-block {
  overflow: auto;
  min-height: 470px;
  max-height: 66vh;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line-strong);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  background: #101820;
  color: #eaf2f4;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.62;
  white-space: pre-wrap;
  word-break: break-word;
}

#tab-answer .output-block {
  background: #ffffff;
  color: #1c2935;
}

.info-band {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  margin: 0 18px 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.info-band div {
  display: grid;
  gap: 6px;
  padding: 13px 14px;
  background: #f7fafb;
}

.info-band strong {
  font-size: 12px;
  color: #263747;
}

.info-band span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

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

.history-empty {
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 9px 12px;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.history-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.history-item strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item span {
  color: var(--muted);
  font-size: 12px;
}

.history-item p {
  grid-column: 1 / -1;
  overflow: hidden;
  color: #314252;
  font-size: 12px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(380px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid rgba(22, 130, 93, 0.25);
  border-radius: var(--radius);
  background: #ffffff;
  color: #1e352d;
  box-shadow: 0 16px 38px rgba(25, 42, 52, 0.18);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  border-color: rgba(195, 52, 52, 0.28);
  color: #5b1f1f;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "request"
      "result"
      "history";
  }

  .output-block {
    min-height: 360px;
    max-height: 58vh;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 22px, 1540px);
    padding-top: 12px;
  }

  .topbar,
  .panel-heading,
  .result-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .form-actions {
    width: 100%;
  }

  .top-actions > *,
  .form-actions > * {
    flex: 1 1 145px;
  }

  .brand {
    align-items: flex-start;
  }

  h1 {
    font-size: 21px;
  }

  .control-grid,
  .metric-strip,
  .info-band {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .metric-strip {
    gap: 0;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab-button {
    flex: 0 0 auto;
  }

  .output-block {
    min-height: 300px;
    font-size: 12px;
  }

  .toast {
    right: 11px;
    bottom: 11px;
  }
}
