:root {
  color-scheme: light;
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --ink: #111827;
  --muted: #64748b;
  --line: #dbe3ee;
  --line-strong: #c6d0dd;
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #e6f4f1;
  --accent: #b94a32;
  --warn: #b45309;
  --ok: #15803d;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.09);
  --small-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #f8fafc 0, #eef2f6 280px), var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

button {
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 32px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid rgba(219, 227, 238, 0.78);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 5;
}

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

.language-toggle {
  width: 92px;
  min-height: 36px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.language-toggle .active {
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-radius: 6px;
  padding: 4px 6px;
}

.language-divider {
  color: #b0bdca;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 23px;
  line-height: 1.2;
  letter-spacing: 0;
}

h1 span {
  color: var(--brand-dark);
}

.topbar p,
.status,
.provider-meta,
.metric,
.history-meta,
#resultCount {
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(0, 1fr);
  gap: 20px;
  padding: 22px;
  max-width: 1500px;
  margin: 0 auto;
}

.composer,
.results {
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(219, 227, 238, 0.95);
  border-radius: 8px;
  box-shadow: var(--small-shadow);
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  align-self: start;
}

.results {
  min-height: 560px;
  padding: 18px;
}

.field-label,
.section-head h2 {
  font-weight: 750;
  font-size: 14px;
  color: #243447;
}

textarea {
  width: 100%;
  min-height: 190px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdff;
  color: var(--ink);
  line-height: 1.55;
  box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.02);
}

textarea::placeholder {
  color: #94a3b8;
}

textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.18);
  outline-offset: 2px;
}

.upload-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.file-button,
button {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  border-radius: 8px;
  cursor: pointer;
  min-height: 40px;
}

.file-button {
  display: grid;
  place-items: center;
  font-weight: 750;
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-color: #b9ddd7;
  min-height: 40px;
  height: 40px;
  padding: 0 8px;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  line-height: 1.15;
  font-size: 12px;
}

.file-button:hover,
.ghost-button:hover,
.language-toggle:hover,
.mini-actions button:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: #f8fafc;
}

.file-button input {
  display: none;
}

.image-preview {
  min-height: 48px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  color: var(--muted);
  overflow: hidden;
  background: #fbfdff;
}

.image-preview img {
  width: 64px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  flex: 0 0 auto;
}

.run-row {
  display: grid;
  grid-template-columns: 74px minmax(180px, 1fr) 54px;
  gap: 10px;
  align-items: stretch;
}

.timeout-control {
  min-height: 54px;
  display: grid;
  grid-template-columns: minmax(42px, 1fr) auto;
  align-items: center;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 6px;
  background: #ffffff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  white-space: nowrap;
}

.timeout-label {
  display: none;
}

.timeout-control input {
  width: 100%;
  min-width: 42px;
  border: 0;
  border-radius: 5px;
  padding: 6px 2px;
  background: transparent;
  color: var(--ink);
  text-align: right;
  font-weight: 800;
}

.run-button {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
  font-weight: 850;
  min-height: 54px;
  padding: 0 28px;
  font-size: 15px;
  white-space: nowrap;
  box-shadow: 0 12px 22px rgba(15, 118, 110, 0.22);
}

.run-button:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
  transform: translateY(-1px);
}

.run-button:disabled {
  opacity: 0.58;
  cursor: wait;
  transform: none;
  box-shadow: none;
}

.stop-button {
  position: relative;
  width: 54px;
  min-height: 54px;
  background: #fff4f0;
  border-color: #f0c3b7;
}

.stop-button::before {
  content: "";
  position: absolute;
  inset: 15px;
  border-radius: 4px;
  background: var(--accent);
}

.stop-button:hover:not(:disabled) {
  background: #ffe9e2;
  border-color: #e39b88;
  transform: translateY(-1px);
}

.stop-button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.status {
  min-height: 20px;
  font-size: 13px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 4px;
}

.mini-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mini-actions button,
.ghost-button,
.icon-button {
  padding: 8px 10px;
}

#addProviderButton {
  min-width: 38px;
  font-size: 20px;
  line-height: 1;
  font-weight: 800;
  color: var(--brand-dark);
  background: var(--brand-soft);
  border-color: #b9ddd7;
}

.ghost-button {
  font-weight: 750;
  color: var(--brand-dark);
  border-color: #b9ddd7;
  background: #ffffff;
}

.top-actions .ghost-button {
  width: 132px;
}

.provider-list {
  display: grid;
  gap: 8px;
}

.provider-item {
  display: grid;
  grid-template-columns: auto 1fr 34px;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px;
  background: var(--panel-soft);
}

.provider-config-button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #ffffff;
  color: var(--brand-dark);
  font-size: 19px;
  line-height: 1;
  display: inline-grid;
  place-items: center;
}

.provider-config-button:hover {
  background: var(--brand-soft);
  border-color: #b9ddd7;
}

.provider-config-button.active {
  background: var(--brand-soft);
  border-color: var(--brand);
}

.provider-item:hover {
  border-color: var(--line-strong);
  background: #ffffff;
}

.provider-item input {
  accent-color: var(--brand);
  margin-top: 4px;
  width: 18px;
  height: 18px;
}

.provider-name {
  font-weight: 780;
  color: #1f2937;
}

.provider-title,
.result-name-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.route-tag {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border: 1px solid #badbd6;
  border-radius: 999px;
  padding: 2px 7px;
  background: #edf8f6;
  color: var(--brand-dark);
  font-size: 11px;
  font-weight: 760;
}

.provider-meta {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.45;
}

.configured {
  color: var(--ok);
  font-weight: 650;
}

.missing {
  color: var(--warn);
  font-weight: 650;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.empty-state {
  color: var(--muted);
  min-height: 320px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  background: #fbfdff;
}

.result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 14px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.result-card.failed {
  border-color: rgba(185, 74, 50, 0.45);
}

.result-card.running {
  border-color: #b9ddd7;
  background: linear-gradient(180deg, #ffffff 0, #f7fbfa 100%);
}

.result-card.stopped {
  border-color: #e5b6a8;
  background: #fffaf8;
}

.result-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}

.badge {
  white-space: nowrap;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-weight: 700;
}

.result-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.58;
  font-size: 14px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.metric {
  background: #f4f7fb;
  border: 1px solid #e8edf4;
  border-radius: 7px;
  padding: 8px;
  font-size: 12px;
}

.metric strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
  margin-top: 2px;
}

.thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.thumbs img,
.history-thumb {
  width: 72px;
  height: 54px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--line);
  cursor: zoom-in;
}

.history-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(560px, 96vw);
  height: 100vh;
  background: #ffffff;
  box-shadow: var(--shadow);
  border-left: 1px solid var(--line);
  z-index: 20;
  transform: translateX(105%);
  transition: transform 180ms ease;
  display: flex;
  flex-direction: column;
}

.history-panel.open {
  transform: translateX(0);
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.icon-button {
  width: 40px;
  font-size: 22px;
  line-height: 1;
}

.history-list {
  overflow: auto;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.settings-body {
  overflow: auto;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.settings-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.fallback-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
  color: #243447;
  font-size: 13px;
  font-weight: 650;
}

.toggle-row input,
.fallback-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
}

.save-settings-button {
  min-height: 40px;
  padding: 8px 12px;
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
  font-weight: 760;
}

.save-settings-button:hover {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.secondary-save {
  background: #ffffff;
  border-color: #b9ddd7;
  color: var(--brand-dark);
}

.secondary-save:hover {
  background: var(--brand-soft);
  border-color: #9cccc4;
}

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

.advanced-config {
  display: none !important;
}

.settings-item {
  display: grid;
  gap: 7px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.settings-item strong,
.settings-item small {
  display: block;
}

.settings-item small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.settings-item input,
.settings-item select,
.settings-item textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--ink);
}

.settings-item textarea {
  min-height: 130px;
  resize: vertical;
}

.settings-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.danger-button {
  min-height: 42px;
  border-color: #e5b6a8;
  background: #fff4f0;
  color: #9f341f;
  font-weight: 760;
}

.danger-button:hover {
  background: #ffe9e2;
  border-color: #dc8f7c;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  background: #ffffff;
}

.history-prompt {
  line-height: 1.45;
  max-height: 86px;
  overflow: auto;
}

.history-result {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(12, 16, 22, 0.74);
  display: none;
  place-items: center;
  z-index: 40;
  padding: 22px;
}

.lightbox.open {
  display: grid;
}

.lightbox img {
  max-width: 94vw;
  max-height: 90vh;
  border-radius: 8px;
  background: #ffffff;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.54);
  z-index: 60;
}

.modal-backdrop.open {
  display: grid;
}

.unlock-modal {
  width: min(460px, 96vw);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
  padding: 18px;
  display: grid;
  gap: 12px;
}

.unlock-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.unlock-tabs button {
  min-height: 38px;
}

.unlock-tabs button.active {
  background: var(--brand-soft);
  border-color: #b9ddd7;
  color: var(--brand-dark);
  font-weight: 760;
}

.unlock-pane {
  display: grid;
  gap: 10px;
}

.captcha-box {
  display: grid;
  gap: 8px;
}

.hidden {
  display: none;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--brand-dark);
  min-height: auto;
  padding: 4px;
  font-weight: 760;
}

.skip-note {
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 900px) {
  .topbar {
    padding: 16px;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .composer {
    width: 100%;
  }
}

@media (max-width: 520px) {
  .topbar,
  .section-head,
  .upload-row {
    align-items: stretch;
    flex-direction: column;
    display: flex;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .upload-row {
    grid-template-columns: 1fr;
  }

  .file-button {
    width: 100%;
  }

  .run-row {
    grid-template-columns: 74px minmax(0, 1fr) 54px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }
}
