:root {
  color-scheme: light;
  --brand-900: #071a2d;
  --brand-800: #0f2d45;
  --brand-700: #244d63;
  --stone-500: #64748b;
  --latte-400: #0f766e;
  --latte-300: #14b8a6;
  --latte-200: #ccfbf1;
  --paper-100: #f4fafc;
  --paper-50: #fbfdff;

  --page-bg:
    radial-gradient(circle at 48% -10%, rgba(20, 184, 166, 0.18) 0%, rgba(20, 184, 166, 0) 34%),
    radial-gradient(circle at 92% 12%, rgba(3, 105, 161, 0.12) 0%, rgba(3, 105, 161, 0) 30%),
    linear-gradient(135deg, #fbfdff 0%, #f1f7fb 48%, #e3f1f3 100%);
  --surface: rgba(255, 255, 255, 0.9);
  --surface-elevated: rgba(255, 255, 255, 0.96);
  --surface-muted: rgba(239, 247, 250, 0.84);
  --control: rgba(255, 255, 255, 0.86);
  --control-hover: rgba(255, 255, 255, 0.98);
  --line: rgba(7, 26, 45, 0.13);
  --line-strong: rgba(7, 26, 45, 0.28);
  --text: #13293d;
  --text-strong: #071a2d;
  --muted: #52677a;
  --muted-2: #7a8b9a;
  --accent: #0f766e;
  --accent-contrast: #ffffff;
  --accent-hover: #0b5f59;
  --warm: #0369a1;
  --warm-contrast: #ffffff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --success-soft: rgba(15, 118, 110, 0.12);
  --focus-border: rgba(15, 118, 110, 0.58);
  --focus-ring: rgba(20, 184, 166, 0.22);
  --progress-track: rgba(7, 26, 45, 0.1);
  --log-text: #17324a;
  --shadow-lg: 0 28px 80px rgba(7, 26, 45, 0.14);
  --shadow-md: 0 14px 34px rgba(7, 26, 45, 0.1);
  --shadow-sm: 0 8px 20px rgba(7, 26, 45, 0.08);
  --scroll-track: rgba(7, 26, 45, 0.07);
  --scroll-thumb: rgba(15, 118, 110, 0.42);
  --scroll-border: #ffffff;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --page-bg:
    radial-gradient(circle at 46% -10%, rgba(20, 184, 166, 0.22) 0%, rgba(20, 184, 166, 0) 36%),
    radial-gradient(circle at 92% 8%, rgba(56, 189, 248, 0.12) 0%, rgba(56, 189, 248, 0) 30%),
    linear-gradient(135deg, #05111f 0%, #071a2d 50%, #0f2d45 100%);
  --surface: rgba(7, 26, 45, 0.86);
  --surface-elevated: rgba(9, 32, 52, 0.94);
  --surface-muted: rgba(5, 17, 31, 0.82);
  --control: rgba(226, 242, 247, 0.08);
  --control-hover: rgba(226, 242, 247, 0.14);
  --line: rgba(162, 218, 224, 0.17);
  --line-strong: rgba(162, 218, 224, 0.34);
  --text: #eaf6fb;
  --text-strong: #ffffff;
  --muted: #b8cbd5;
  --muted-2: #8399a8;
  --accent: #2dd4bf;
  --accent-contrast: #031a1b;
  --accent-hover: #5eead4;
  --warm: #38bdf8;
  --warm-contrast: #061523;
  --danger: #f87171;
  --danger-hover: #fca5a5;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --success-soft: rgba(45, 212, 191, 0.14);
  --focus-border: rgba(45, 212, 191, 0.68);
  --focus-ring: rgba(45, 212, 191, 0.18);
  --progress-track: rgba(226, 242, 247, 0.1);
  --log-text: #e7f7fb;
  --shadow-lg: 0 30px 90px rgba(0, 0, 0, 0.48);
  --shadow-md: 0 16px 42px rgba(0, 0, 0, 0.36);
  --shadow-sm: 0 10px 24px rgba(0, 0, 0, 0.28);
  --scroll-track: rgba(226, 242, 247, 0.07);
  --scroll-thumb: rgba(45, 212, 191, 0.38);
  --scroll-border: #071a2d;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--page-bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Microsoft YaHei UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(255, 255, 255, 0.028) 1px, transparent 1px);
  background-size: 56px 56px;
  mask-image: linear-gradient(180deg, black, transparent 92%);
}

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

button,
label[for] {
  touch-action: manipulation;
}

button:focus-visible,
label[for]:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 0;
  border-color: var(--focus-border);
  box-shadow: 0 0 0 4px var(--focus-ring);
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface-elevated);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(24px) saturate(1.08);
  padding: 32px;
}

.auth-logo {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  box-shadow: var(--shadow-md);
  margin-bottom: 18px;
}

.auth-input {
  width: 100%;
  height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--control);
  color: var(--text);
  padding: 0 14px;
}

.auth-submit {
  width: 100%;
  margin-top: 16px;
}

.auth-error {
  min-height: 20px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

.app-shell {
  width: min(1440px, calc(100vw - 40px));
  margin: 0 auto;
  padding: 18px 0 40px;
}

.topbar {
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 0 18px;
}

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

.brand-logo {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
  flex: 0 0 auto;
}

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

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

h1 {
  color: var(--text-strong);
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1.05;
  font-weight: 780;
  white-space: nowrap;
}

h2 {
  color: var(--text-strong);
  font-size: 18px;
  line-height: 1.2;
  font-weight: 780;
}

.eyebrow,
.section-kicker {
  color: var(--warm);
  font-size: 12px;
  font-weight: 780;
  text-transform: uppercase;
}

.section-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--muted-2);
  letter-spacing: 0.06em;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
  flex-wrap: wrap;
}

.model-control {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  min-height: 48px;
  padding: 5px 6px 5px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(18px) saturate(1.08);
}

.model-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.model-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0;
  min-width: 0;
}

.model-option {
  min-height: 38px;
  border: 0;
  border-radius: 999px;
  padding: 0 16px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  font-weight: 760;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.model-option:hover {
  color: var(--text);
  background: var(--control-hover);
}

.model-option.active {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 10px 24px var(--primary-shadow, rgba(0, 0, 0, 0.24));
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px 5px 6px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(18px);
  cursor: pointer;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
}

.theme-toggle:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: var(--control-hover);
}

.theme-toggle-track {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: center;
  width: 60px;
  height: 30px;
  border-radius: 999px;
  background: var(--control);
  border: 1px solid var(--line);
  overflow: hidden;
}

.theme-icon {
  position: relative;
  z-index: 1;
  width: 16px;
  height: 16px;
  justify-self: center;
  color: var(--muted);
}

.theme-toggle-knob {
  position: absolute;
  z-index: 0;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.22);
  transition: transform 0.2s ease;
}

.theme-toggle-text {
  width: 28px;
  text-align: center;
  font-size: 12px;
  font-weight: 760;
  color: var(--muted);
}

html[data-theme="dark"] .theme-toggle-knob {
  transform: translateX(30px);
}

html[data-theme="dark"] .theme-icon-dark,
html:not([data-theme="dark"]) .theme-icon-light {
  color: var(--accent-contrast);
}

.workspace {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(380px, 0.82fr);
  gap: 0;
  align-items: stretch;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(24px) saturate(1.08);
}

.panel {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.input-panel,
.monitor-panel {
  padding: 24px;
}

.input-panel {
  background: linear-gradient(180deg, var(--surface-elevated), transparent);
}

.monitor-panel {
  min-height: 690px;
  border-left: 1px solid var(--line);
  background: var(--surface-muted);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.pill,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--control);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 760;
  white-space: nowrap;
}

.status.running,
.status.completed {
  color: var(--text-strong);
  background: var(--success-soft);
}

.status.stopped {
  color: var(--muted);
  background: var(--control);
}

.status.failed {
  color: var(--danger);
  background: var(--danger-soft);
}

.file-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 14px;
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--control);
  margin-bottom: 12px;
  transition: background 0.18s ease, border-color 0.18s ease;
}

.file-row:hover {
  background: var(--control-hover);
  border-color: var(--line-strong);
}

.file-row.compact {
  margin-bottom: 20px;
}

.native-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.file-meta {
  min-width: 0;
}

.file-meta strong,
.file-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-meta strong {
  color: var(--text-strong);
  font-size: 15px;
  font-weight: 780;
}

.file-meta span,
.field-label,
.cost-note {
  color: var(--muted);
  font-size: 12px;
}

.field-label {
  display: block;
  margin: 16px 0 8px;
  font-weight: 760;
}

textarea {
  width: 100%;
  min-height: 330px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 18px;
  background: var(--control);
  color: var(--text);
  outline: none;
  font-size: 16px;
  line-height: 1.72;
  transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

textarea::placeholder {
  color: var(--muted-2);
}

.settings-grid {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 14px;
  margin-top: 4px;
}

select {
  width: 100%;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--control);
  color: var(--text);
  padding: 0 12px;
  outline: none;
}

.cost-note {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--control);
}

.action-row,
.output-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.action-row {
  margin-top: 20px;
  justify-content: flex-start;
}

.output-actions {
  margin: 16px 0 18px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 999px;
  padding: 0 18px;
  border: 1px solid transparent;
  font-weight: 780;
  cursor: pointer;
  user-select: none;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, opacity 0.16s ease, box-shadow 0.16s ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

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

.primary {
  color: var(--accent-contrast);
  background: var(--accent);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

.primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.secondary {
  color: var(--text);
  background: var(--control);
  border-color: var(--line);
}

.secondary:hover:not(:disabled) {
  background: var(--control-hover);
  border-color: var(--line-strong);
}

.ghost {
  color: var(--text);
  background: transparent;
  border-color: var(--line);
}

.ghost:hover:not(:disabled) {
  background: var(--control-hover);
}

.danger {
  color: #ffffff;
  background: var(--danger);
}

.danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.icon-button {
  width: 44px;
  min-width: 44px;
  padding: 0;
  font-size: 18px;
}

.progress-block {
  margin-top: 4px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--control);
}

.progress-top {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
  margin-bottom: 10px;
}

.progress-track {
  height: 11px;
  border-radius: 999px;
  background: var(--progress-track);
  overflow: hidden;
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.22s ease;
}

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

.metrics div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--control);
}

.metrics span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.metrics strong {
  display: block;
  margin-top: 4px;
  color: var(--text-strong);
  font-size: 20px;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-area,
.preview-text {
  width: 100%;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--control);
  color: var(--log-text);
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow: auto;
}

.log-area {
  min-height: 330px;
  max-height: 430px;
  padding: 16px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: min(54vh, 580px);
  min-height: 360px;
  max-height: 580px;
  margin-top: 18px;
  padding: 20px;
  scroll-margin-top: 96px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(24px) saturate(1.08);
}

.preview-panel .panel-header {
  flex: 0 0 auto;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.preview-text {
  flex: 1 1 auto;
  min-height: 0;
  height: clamp(220px, 34vh, 430px);
  max-height: none;
  padding: 18px;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

.preview-text::-webkit-scrollbar,
.log-area::-webkit-scrollbar {
  width: 10px;
}

.preview-text::-webkit-scrollbar-track,
.log-area::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-radius: 999px;
}

.preview-text::-webkit-scrollbar-thumb,
.log-area::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border: 2px solid var(--scroll-border);
  border-radius: 999px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

@media (max-width: 1080px) {
  .app-shell {
    width: min(100vw - 28px, 920px);
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar {
    width: 100%;
    justify-content: flex-start;
  }

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

  .monitor-panel {
    min-height: 520px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100vw - 20px, 680px);
    padding-top: 10px;
  }

  .brand {
    align-items: center;
    width: 100%;
  }

  .brand-logo {
    width: 52px;
    height: 52px;
  }

  h1 {
    font-size: 30px;
  }

  .toolbar,
  .model-control {
    align-items: stretch;
  }

  .model-control {
    width: 100%;
    flex-direction: column;
    border-radius: 22px;
    padding: 12px;
  }

  .model-switch {
    width: 100%;
    overflow-x: auto;
  }

  .model-option {
    flex: 1 0 auto;
  }

  .theme-toggle {
    flex: 1 1 auto;
  }

  .file-row,
  .settings-grid,
  .metrics {
    grid-template-columns: 1fr;
  }

  .button,
  .file-button {
    width: 100%;
  }

  .icon-button {
    width: 44px;
  }

  textarea {
    min-height: 260px;
  }

  .input-panel,
  .monitor-panel,
  .preview-panel {
    padding: 16px;
  }

  .preview-panel {
    height: min(62vh, 520px);
    min-height: 320px;
    max-height: 520px;
  }

  .preview-text {
    height: auto;
    max-height: none;
  }
}
