:root {
  --bg: #f7f8fb;
  --panel: #ffffff;
  --panel-soft: #f1f4f3;
  --ink: #1c2028;
  --muted: #606978;
  --line: #d8dee8;
  --accent: #176f61;
  --accent-strong: #0f5b50;
  --accent-soft: #e4f3ef;
  --warm: #b35b28;
  --danger: #b42318;
  --danger-soft: #fff0ed;
  --shadow: 0 18px 48px rgba(28, 32, 40, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

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

.hidden {
  display: none !important;
}

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(23, 111, 97, 0.08), rgba(179, 91, 40, 0.08)),
    var(--bg);
}

.login-shell {
  width: min(100%, 440px);
}

.login-panel,
.control-panel,
.work-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.login-panel {
  padding: 32px;
}

.brand-lock,
.brand-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(23, 111, 97, 0.18);
  border-radius: var(--radius);
}

.brand-lock {
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--warm);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

.login-panel h1 {
  margin-bottom: 24px;
  font-size: 2rem;
  line-height: 1.12;
}

.login-form,
.field-group {
  display: grid;
  gap: 10px;
}

.field-group {
  margin-top: 20px;
}

.field-label {
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 750;
}

.with-icon {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

input,
select,
textarea {
  width: 100%;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

input,
select {
  min-height: 44px;
  padding: 10px 12px;
}

textarea {
  min-height: 140px;
  padding: 14px;
  line-height: 1.55;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(23, 111, 97, 0.14);
}

.primary-button,
.icon-text-button,
.icon-button,
.segment,
.model-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-height: 42px;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.primary-button {
  gap: 9px;
  width: 100%;
  padding: 12px 18px;
  color: #ffffff;
  background: var(--accent);
  font-weight: 800;
}

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

.primary-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.form-error,
.status-text.error {
  color: var(--danger);
}

.form-error {
  margin: 0;
  padding: 10px 12px;
  background: var(--danger-soft);
  border: 1px solid rgba(180, 35, 24, 0.2);
  border-radius: var(--radius);
  font-size: 0.9rem;
}

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

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

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

.brand h1 {
  font-size: clamp(1.42rem, 2vw, 2rem);
  line-height: 1.08;
}

.icon-text-button {
  gap: 8px;
  padding: 9px 12px;
  color: var(--muted);
  background: #ffffff;
  border-color: var(--line);
  font-weight: 750;
}

.icon-text-button:hover,
.icon-button:hover {
  color: var(--accent);
  border-color: rgba(23, 111, 97, 0.4);
  background: var(--accent-soft);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.control-panel,
.work-panel {
  padding: 20px;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.panel-title h2 {
  font-size: 1.02rem;
}

.panel-title svg {
  color: var(--accent);
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  background: var(--panel-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.segment {
  min-width: 0;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.segment.active {
  color: var(--accent-strong);
  background: #ffffff;
  border-color: var(--line);
  box-shadow: 0 6px 16px rgba(28, 32, 40, 0.08);
}

.counter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.counter-row.compact {
  justify-content: flex-end;
}

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

.model-option {
  min-width: 0;
  /* min-height: 62px; */
  align-items: flex-start;
  justify-content: flex-start;
  gap: 10px;
  padding: 12px;
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
  text-align: left;
}

.model-option svg {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  color: var(--warm);
  margin-top: 1px;
}

.model-option span {
  display: block;
}

.model-option span {
  font-size: 0.9rem;
  font-weight: 850;
}

.model-option.active {
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-color: rgba(23, 111, 97, 0.48);
}

.work-panel {
  position: relative;
  display: grid;
  gap: 16px;
  overflow: hidden;
}

.text-panel {
  display: grid;
  gap: 10px;
}

.textarea-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.output-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.icon-button {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  color: var(--muted);
  background: #ffffff;
  border-color: var(--line);
}

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

.run-button {
  width: auto;
  min-width: 190px;
}

.status-text {
  min-height: 22px;
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.status-text.success {
  color: var(--accent-strong);
}

.loading-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(247, 248, 251, 0.84);
  backdrop-filter: blur(6px);
}

.loader-card {
  display: grid;
  justify-items: center;
  gap: 16px;
  width: min(100%, 430px);
  padding: 26px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid rgba(23, 111, 97, 0.22);
  border-radius: var(--radius);
  box-shadow: 0 24px 70px rgba(28, 32, 40, 0.18);
  text-align: center;
}

.loader-card h2 {
  margin: 0 0 6px;
  font-size: 1.18rem;
}

.loader-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.loader-orbit {
  position: relative;
  width: 74px;
  height: 74px;
  border: 2px solid rgba(23, 111, 97, 0.14);
  border-radius: 50%;
  animation: loader-spin 1.35s linear infinite;
}

.loader-orbit::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 2px solid rgba(179, 91, 40, 0.2);
  border-radius: 50%;
}

.loader-orbit span {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 7px rgba(23, 111, 97, 0.12);
}

.loader-orbit span:nth-child(1) {
  top: -6px;
  left: 31px;
}

.loader-orbit span:nth-child(2) {
  right: 3px;
  bottom: 9px;
  width: 10px;
  height: 10px;
  background: var(--warm);
}

.loader-orbit span:nth-child(3) {
  left: 3px;
  bottom: 9px;
  width: 9px;
  height: 9px;
  background: var(--accent-strong);
}

.loader-bar {
  width: 100%;
  height: 8px;
  overflow: hidden;
  background: var(--panel-soft);
  border-radius: 999px;
}

.loader-bar span {
  display: block;
  width: 42%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--warm));
  border-radius: inherit;
  animation: loader-slide 1.15s ease-in-out infinite;
}

@keyframes loader-spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes loader-slide {
  0% {
    transform: translateX(-110%);
  }

  55% {
    transform: translateX(85%);
  }

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

@media (max-width: 1040px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .control-panel {
    order: 1;
  }

  .work-panel {
    order: 2;
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 14px;
  }

  .topbar,
  .textarea-header,
  .action-row {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 12px;
  }

  .topbar form,
  .icon-text-button,
  .run-button {
    width: 100%;
  }

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

  .output-actions {
    justify-content: space-between;
  }

  .counter-row.compact {
    justify-content: flex-start;
  }

  .login-panel,
  .control-panel,
  .work-panel {
    padding: 18px;
  }
}
