:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: #f4f5f6;
  color: #181a1d;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: #f4f5f6;
}

button, input, select, textarea {
  font: inherit;
  letter-spacing: 0;
}

button, select, summary { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid #dfe2e5;
  background: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 19px;
  font-weight: 750;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: #ffffff;
  background: #e44f3f;
}

.brand-mark svg { width: 20px; height: 20px; }

.topbar-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.server-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #636a70;
  font-size: 13px;
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e4a83f;
}

.server-state.online .state-dot { background: #16836d; }
.server-state.offline .state-dot { background: #c5372d; }
.server-state.online .state-dot {
  animation: onlinePulse 1.35s ease-in-out infinite;
}

@keyframes onlinePulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(22, 131, 109, 0.35); }
  50% { opacity: 0.45; box-shadow: 0 0 0 5px rgba(22, 131, 109, 0); }
}

.logout-button { width: 34px; height: 34px; }

.workspace {
  width: min(1500px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(380px, 1.08fr) minmax(300px, 0.72fr) minmax(360px, 1fr);
  min-height: calc(100vh - 64px);
}

.workspace > section {
  min-width: 0;
  padding: 28px 24px 32px;
  background: #ffffff;
}

.workspace > section + section { border-left: 1px solid #dfe2e5; }
.controls-panel { background: #fafafa !important; }

.section-heading {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}

.section-heading > div {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-heading h1, .section-heading h2 {
  margin: 0;
  min-width: 0;
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0;
}

.step-number {
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid #cfd3d7;
  border-radius: 50%;
  color: #61676d;
  font-size: 12px;
  font-weight: 700;
}

.icon-button {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid #d4d8dc;
  border-radius: 6px;
  color: #34383c;
  background: #ffffff;
  text-decoration: none;
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease;
}

.icon-button:hover {
  border-color: #9ea5ab;
  background: #f5f6f7;
}

.icon-button svg { width: 18px; height: 18px; }
.icon-button.disabled { pointer-events: none; opacity: 0.36; }

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

.dropzone {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  min-height: 290px;
  overflow: hidden;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px dashed #b9bec3;
  border-radius: 6px;
  color: #596066;
  background: #f8f9fa;
  transition: border-color 150ms ease, background 150ms ease;
}

.dropzone:hover, .dropzone.dragging {
  border-color: #e44f3f;
  background: #fff7f5;
}

.dropzone img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
  object-fit: contain;
  background: #101214;
}

.dropzone.has-image img { display: block; }
.dropzone.has-image .drop-placeholder { display: none; }

.drop-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
}

.drop-placeholder svg {
  width: 30px;
  height: 30px;
  color: #e44f3f;
}

.drop-placeholder strong { font-size: 14px; }
.drop-placeholder small { color: #858c92; font-size: 11px; }

.image-label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  display: none;
  padding: 6px 9px;
  border-radius: 4px;
  color: #ffffff;
  background: rgba(16, 18, 20, 0.82);
  font-size: 11px;
  font-weight: 650;
}

.dropzone.has-image .image-label { display: block; }
.field { margin-bottom: 20px; }

.field > label {
  display: block;
  margin-bottom: 8px;
  color: #4f555b;
  font-size: 12px;
  font-weight: 650;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid #d8dce0;
  border-radius: 6px;
  background: #eceeef;
}

.mode-selector { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.segment {
  min-width: 0;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 7px 8px;
  border: 0;
  border-radius: 4px;
  color: #5c6268;
  background: transparent;
  font-size: 12px;
  font-weight: 650;
}

.segment svg { width: 16px; height: 16px; }

.segment.active {
  color: #202326;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(26, 30, 34, 0.12);
}

input, textarea, select {
  width: 100%;
  border: 1px solid #cfd4d8;
  border-radius: 6px;
  color: #202326;
  background: #ffffff;
  outline: none;
}

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

textarea {
  min-height: 76px;
  resize: vertical;
  padding: 10px 12px;
}

input:focus, textarea:focus, select:focus {
  border-color: #16836d;
  box-shadow: 0 0 0 3px rgba(22, 131, 109, 0.12);
}

.select-wrap { position: relative; }

.select-wrap > svg:first-child {
  position: absolute;
  z-index: 1;
  left: 12px;
  top: 12px;
  width: 18px;
  height: 18px;
  color: #6b7177;
}

.select-wrap > svg:last-child {
  position: absolute;
  right: 12px;
  top: 13px;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.select-wrap select {
  appearance: none;
  padding: 0 38px;
  text-overflow: ellipsis;
}

.input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 7px;
}

.advanced {
  margin: 3px 0 22px;
  border-top: 1px solid #dfe2e5;
  border-bottom: 1px solid #dfe2e5;
}

.advanced summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #555c62;
  cursor: pointer;
  font-size: 12px;
  font-weight: 650;
  list-style: none;
}

.advanced summary::-webkit-details-marker { display: none; }
.advanced summary svg { width: 16px; height: 16px; }
.advanced-fields { padding: 2px 0; }

.actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.primary-button, .stop-button {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 750;
}

.primary-button {
  border: 1px solid #d94334;
  color: #ffffff;
  background: #e44f3f;
}

.primary-button:hover { background: #d94334; }
.primary-button:disabled { cursor: wait; opacity: 0.55; }

.stop-button {
  padding: 0 14px;
  border: 1px solid #cfd4d8;
  color: #b02d25;
  background: #ffffff;
}

.stop-button:not(:disabled):hover {
  border-color: #b02d25;
  background: #fff4f3;
}

.stop-button:disabled {
  cursor: default;
  color: #9ba1a6;
  opacity: 0.65;
}

.primary-button svg, .stop-button svg { width: 18px; height: 18px; }
.job-status { margin-top: 16px; }

.status-row {
  display: flex;
  justify-content: space-between;
  margin-bottom: 7px;
  color: #555c62;
  font-size: 12px;
}

.progress-track {
  height: 5px;
  overflow: hidden;
  border-radius: 3px;
  background: #dfe3e5;
}

.progress-track span {
  display: block;
  width: 38%;
  height: 100%;
  border-radius: inherit;
  background: #16836d;
  animation: progress 1.25s ease-in-out infinite alternate;
}

@keyframes progress {
  from { transform: translateX(-60%); }
  to { transform: translateX(220%); }
}

.error-box {
  margin-top: 14px;
  padding: 10px 12px;
  border-left: 3px solid #c5372d;
  color: #8f2721;
  background: #fff2f1;
  font-size: 12px;
  line-height: 1.45;
}

.result-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 5;
  min-height: 420px;
  overflow: hidden;
  display: grid;
  place-items: center;
  border: 1px solid #d9dde0;
  border-radius: 6px;
  background: #eceeef;
}

.result-stage > img {
  width: 100%;
  height: 100%;
  display: none;
  object-fit: contain;
  background: #101214;
}

.result-stage.has-result > img { display: block; }
.result-stage.has-result .result-empty { display: none; }

.result-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: #7b8288;
  font-size: 13px;
}

.result-empty svg { width: 34px; height: 34px; color: #16836d; }
.saved-path {
  margin-top: 10px;
  overflow-wrap: anywhere;
  color: #5f666c;
  font-size: 11px;
  line-height: 1.4;
}
.history { margin-top: 18px; }

.history-title {
  margin-bottom: 9px;
  color: #555c62;
  font-size: 12px;
  font-weight: 650;
}

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

.history-item {
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  padding: 0;
  border: 1px solid #d4d8dc;
  border-radius: 4px;
  background: #eceeef;
}

.history-item img { width: 100%; height: 100%; object-fit: cover; }

.login-page {
  display: grid;
  place-items: center;
  padding: 20px;
  background: #f4f5f6;
}

.login-shell {
  width: min(390px, 100%);
  padding: 28px;
  border: 1px solid #d9dde0;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 16px 48px rgba(24, 26, 29, 0.1);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 28px;
  font-size: 21px;
  font-weight: 750;
}

.login-form > label {
  display: block;
  margin-bottom: 8px;
  color: #4f555b;
  font-size: 12px;
  font-weight: 650;
}

.password-field {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 7px;
  margin-bottom: 12px;
}

.password-field > svg {
  position: absolute;
  z-index: 1;
  left: 12px;
  top: 12px;
  width: 18px;
  height: 18px;
  color: #6b7177;
}

.password-field input { padding-left: 40px; }
.login-form .primary-button { width: 100%; }
.login-form .error-box { margin-top: 12px; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: minmax(360px, 1fr) minmax(310px, 0.8fr); }
  .result-panel {
    grid-column: 1 / -1;
    border-top: 1px solid #dfe2e5;
    border-left: 0 !important;
  }
  .result-stage {
    width: min(680px, 100%);
    aspect-ratio: 16 / 10;
    min-height: 360px;
    margin: 0 auto;
  }
}

@media (max-width: 720px) {
  .topbar { height: 56px; padding: 0 14px; }
  .workspace { display: block; min-height: calc(100vh - 56px); }
  .workspace > section { padding: 22px 14px 26px; }
  .workspace > section + section { border-top: 1px solid #dfe2e5; border-left: 0; }
  .image-grid { gap: 8px; }
  .dropzone { min-height: 220px; }
  .mode-selector .segment { flex-direction: column; gap: 3px; min-height: 54px; }
  .actions { grid-template-columns: 1fr; }
  .stop-button { min-height: 42px; }
  .result-stage { min-height: 320px; aspect-ratio: 4 / 5; }
  .server-state { max-width: 150px; }
  .server-state span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .login-shell { padding: 22px; }
}
