:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --line: #e6e8ee;
  --text: #1d2433;
  --muted: #687385;
  --soft: #f0f3f8;
  --accent: #d89b22;
  --accent-dark: #9a6410;
  --green: #3d8b68;
  --blue: #3569c9;
  --red: #c54747;
  --shadow: 0 12px 36px rgba(20, 28, 45, 0.08);
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 0;
  cursor: pointer;
}

.app {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #ffffff;
  color: var(--text);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #f2bf42, #7db08a);
  display: grid;
  place-items: center;
  color: #111827;
  font-weight: 900;
}

.brand-title {
  font-weight: 800;
  line-height: 1.1;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.nav-section {
  margin: 18px 0 8px;
  padding: 0 10px;
  color: #9aa3b2;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-button {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  border-radius: 9px;
  background: transparent;
  color: #4b5563;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: #fff7df;
  color: #8a5a0d;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(242, 191, 66, 0.18);
  color: #9a6410;
  font-size: 11px;
  font-weight: 700;
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 18px;
  align-items: start;
  margin-bottom: 18px;
}

.page-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

.page-subtitle {
  margin: 7px 0 0;
  color: var(--muted);
  max-width: 780px;
}

.settings {
  width: min(760px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 0.72fr) minmax(170px, 0.9fr) auto auto auto;
  gap: 10px;
  align-items: end;
}

.connection-status {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
}

.connection-status strong {
  font-size: 12px;
  white-space: nowrap;
}

.connection-status span {
  color: var(--muted);
  line-height: 1.4;
}

.connection-status.success {
  border-color: #bbf7d0;
  background: #f0fdf4;
  color: #166534;
}

.connection-status.failure {
  border-color: #fecaca;
  background: #fff1f2;
  color: #9f1239;
}

.layout {
  display: grid;
  grid-template-columns: minmax(360px, 460px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

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

.panel-title {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
}

.panel-body {
  padding: 18px;
}

.form-grid {
  display: grid;
  gap: 14px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: #4b5563;
  font-size: 12px;
  font-weight: 800;
}

.field small {
  color: var(--muted);
  line-height: 1.5;
}

.input,
.select,
.textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 10px 11px;
  outline: none;
  min-height: 42px;
}

.textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.5;
}

.textarea.listing-output {
  min-height: 300px;
  white-space: pre-wrap;
}

.textarea.analysis-textarea {
  min-height: 170px;
}

.input:focus,
.select:focus,
.textarea:focus {
  border-color: #d89b22;
  box-shadow: 0 0 0 3px rgba(216, 155, 34, 0.13);
}

.file-zone {
  border: 1px dashed #c9ced8;
  background: #fbfcfe;
  border-radius: 8px;
  padding: 13px;
  display: grid;
  gap: 10px;
}

.file-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.preview {
  aspect-ratio: 1;
  border-radius: 7px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--soft);
  position: relative;
}

.preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.preview button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(17, 24, 39, 0.75);
  color: white;
}

.preview-tools {
  position: absolute;
  left: 4px;
  right: 4px;
  bottom: 4px;
  display: flex;
  gap: 4px;
}

.preview .preview-tools button {
  position: static;
  width: 26px;
  height: 24px;
  border-radius: 6px;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.btn {
  min-height: 40px;
  padding: 0 13px;
  border-radius: 8px;
  background: var(--soft);
  color: var(--text);
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  text-decoration: none;
}

.btn:hover {
  filter: brightness(0.98);
}

.btn.primary {
  background: #f2bf42;
  color: #1d2433;
}

.btn.dark {
  background: #1f2937;
  color: white;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
}

.btn.ghost.active {
  border-color: #d89b22;
  background: #fff7df;
  color: #755016;
}

.btn.danger {
  background: #fee2e2;
  color: var(--red);
}

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

.segmented {
  display: flex;
  padding: 4px;
  border-radius: 8px;
  background: var(--soft);
  gap: 4px;
}

.segmented button {
  flex: 1;
  min-height: 34px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segmented button.active {
  background: white;
  color: var(--text);
  box-shadow: 0 1px 5px rgba(20, 28, 45, 0.1);
}

.check-row {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 9px;
  color: #374151;
  font-size: 13px;
  font-weight: 800;
}

.check-row input {
  width: 16px;
  height: 16px;
  accent-color: #d89b22;
}

.check-grid {
  display: grid;
  gap: 8px;
}

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

.workflow-step {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 8px;
  color: var(--muted);
  display: grid;
  gap: 5px;
  align-content: center;
}

.workflow-step span {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--soft);
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 900;
}

.workflow-step strong {
  font-size: 12px;
}

.workflow-step.active {
  border-color: #f0d999;
  background: #fff7df;
  color: #755016;
}

.workflow-step.active span {
  background: #f2bf42;
  color: #1d2433;
}

.plan-box {
  border: 1px solid #d8e2f0;
  background: #f8fbff;
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
}

.plan-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
}

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

.plan-list {
  display: grid;
  gap: 9px;
}

.plan-item {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr);
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
}

.plan-item > span {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #eef2ff;
  color: var(--blue);
  font-weight: 900;
  font-size: 12px;
}

.plan-item p {
  margin: 4px 0;
  color: #4b5563;
  font-size: 12px;
}

.plan-item small {
  color: var(--muted);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.preset {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: #4b5563;
  font-weight: 800;
}

.preset.active {
  border-color: #d89b22;
  background: #fff7df;
  color: #755016;
}

.sub-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 12px;
  display: grid;
  gap: 12px;
}

.sub-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sub-panel-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.inline-toggle {
  min-height: 26px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: #455266;
  font-size: 12px;
  font-weight: 800;
}

.inline-toggle:hover {
  border-color: #c7ceda;
  background: #f8fafc;
}

.ocr-table {
  display: grid;
  gap: 10px;
}

.ocr-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 10px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ocr-row small {
  grid-column: 1 / -1;
  color: var(--muted);
}

.swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}

.swatch {
  aspect-ratio: 1;
  min-height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.45);
}

.swatch.active {
  outline: 3px solid rgba(216, 155, 34, 0.22);
  border-color: #d89b22;
}

.crop-stage-wrap {
  width: 100%;
  display: grid;
  place-items: center;
  background: #eef2f7;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.crop-stage {
  position: relative;
  width: min(100%, 760px);
  max-height: 420px;
  overflow: hidden;
  background:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  border-radius: 8px;
  cursor: grab;
  touch-action: none;
}

.crop-stage:active {
  cursor: grabbing;
}

.crop-stage img {
  width: 100%;
  height: 100%;
  display: block;
  transform-origin: center;
  will-change: transform;
}

.crop-stage-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(17, 24, 39, .16);
}

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

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

.intent-card {
  min-height: 74px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 10px;
  display: grid;
  align-content: start;
  gap: 6px;
  text-align: left;
}

.intent-card strong {
  font-size: 13px;
}

.intent-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.intent-card.active {
  border-color: #d89b22;
  background: #fff7df;
  box-shadow: 0 0 0 3px rgba(216, 155, 34, 0.12);
}

.module-card {
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--text);
  padding: 10px;
  display: grid;
  gap: 6px;
  text-align: left;
}

.module-card strong {
  font-size: 13px;
}

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

.module-card small {
  color: #8a5a0d;
  font-size: 11px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.module-card.active {
  border-color: #d89b22;
  background: #fff7df;
  box-shadow: 0 0 0 3px rgba(216, 155, 34, 0.12);
}

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

.custom-module {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 9px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.custom-module small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.notice {
  border: 1px solid #f0d999;
  background: #fff7df;
  color: #755016;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}

.warning {
  border-color: #fecaca;
  background: #fff1f2;
  color: #9f1239;
}

.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.download-toolbar {
  border: 1px solid var(--line);
  background: #fbfcfe;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.download-toolbar strong,
.download-toolbar span {
  display: block;
}

.download-toolbar span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.current-result {
  border: 1px solid var(--line);
  background: #fbfcfe;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
  display: grid;
  grid-template-columns: minmax(160px, 280px) minmax(0, 1fr);
  gap: 14px;
}

.current-media {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--soft);
  overflow: hidden;
}

.current-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.current-meta {
  display: grid;
  align-content: start;
  gap: 10px;
}

.current-meta p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 8;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.task-card {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
}

.task-card.selected,
.queue-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(244, 191, 78, 0.25);
}

.task-media {
  position: relative;
  aspect-ratio: 1;
  background: linear-gradient(135deg, #edf2f7, #f8fafc);
  display: grid;
  place-items: center;
  color: var(--muted);
  font-weight: 800;
  text-align: center;
  padding: 14px;
}

.task-select {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 3;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(148, 163, 184, 0.7);
  box-shadow: 0 8px 22px rgba(24, 34, 48, 0.14);
  cursor: pointer;
}

.task-select input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.task-select span {
  width: 16px;
  height: 16px;
  border-radius: 5px;
  border: 2px solid #94a3b8;
  background: #fff;
}

.task-select input:checked + span {
  border-color: #173f35;
  background: var(--accent);
  position: relative;
}

.task-select input:checked + span::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid #173f35;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.task-select.inline {
  position: static;
  width: 26px;
  height: 26px;
  flex: 0 0 26px;
  border-radius: 7px;
  box-shadow: none;
  background: #fff;
}

.task-select.inline span {
  width: 15px;
  height: 15px;
}

.task-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.task-meta {
  padding: 11px;
  display: grid;
  gap: 8px;
}

.task-title {
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-prompt {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 52px;
}

.task-warning {
  border: 1px solid #fed7aa;
  background: #fff7ed;
  color: #9a3412;
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 12px;
  line-height: 1.45;
}

.status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 900;
  background: #eef2ff;
  color: var(--blue);
}

.status.running {
  background: #fef3c7;
  color: #92400e;
}

.status.success {
  background: #dcfce7;
  color: #166534;
}

.status.failure {
  background: #fee2e2;
  color: var(--red);
}

.empty {
  border: 1px dashed #c9ced8;
  border-radius: 8px;
  min-height: 360px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
  background: #fbfcfe;
}

.queue-overlay {
  position: fixed;
  inset: 0;
  z-index: 45;
  background: rgba(17, 24, 39, .42);
  display: grid;
  justify-content: end;
}

.queue-panel {
  width: min(720px, 100vw);
  height: 100vh;
  background: #fff;
  border-left: 1px solid var(--line);
  box-shadow: -20px 0 60px rgba(17, 24, 39, .18);
  padding: 18px;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 14px;
}

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

.queue-header h2 {
  margin: 0;
  font-size: 20px;
}

.queue-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.queue-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.queue-stats div,
.queue-remote {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 10px;
}

.queue-stats strong {
  display: block;
  font-size: 20px;
}

.queue-stats span,
.queue-remote span,
.queue-meta {
  color: var(--muted);
  font-size: 12px;
}

.queue-remote {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.queue-panel .download-toolbar {
  margin-bottom: 0;
}

.queue-remote span {
  display: block;
  margin-top: 4px;
}

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

.queue-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr);
  gap: 12px;
}

.queue-thumb {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--muted);
  font-weight: 900;
}

.queue-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.queue-info {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.queue-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.queue-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.queue-title strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.queue-info p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.queue-empty {
  min-height: 220px;
}

.canvas-preview {
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .layout,
  .topbar,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .two-col {
    grid-template-columns: 1fr;
  }

  .current-result,
  .ocr-row,
  .queue-item,
  .intent-grid,
  .module-grid {
    grid-template-columns: 1fr;
  }

  .queue-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .preview-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* UI refresh: denser production workspace and clearer interaction states. */
:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #dfe4ec;
  --text: #182230;
  --muted: #667085;
  --soft: #f2f5f9;
  --accent: #e6a52e;
  --accent-dark: #875a12;
  --green: #2f7d5b;
  --blue: #285fb8;
  --red: #b83f45;
  --shadow: 0 10px 28px rgba(24, 34, 48, 0.07);
  --shadow-soft: 0 4px 14px rgba(24, 34, 48, 0.06);
}

body {
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(230, 165, 46, 0.28);
  outline-offset: 2px;
}

.app {
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  padding: 16px 10px;
  background: #fbfcfe;
}

.brand {
  min-height: 58px;
  margin-bottom: 10px;
  padding: 6px 9px 14px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: linear-gradient(135deg, #f1b83d 0%, #6aa47f 100%);
}

.brand-title {
  letter-spacing: 0;
}

.nav-section {
  margin: 16px 0 6px;
  padding: 0 9px;
  letter-spacing: 0.04em;
}

.nav-button {
  position: relative;
  min-height: 40px;
  margin: 2px 0;
  padding: 9px 10px 9px 12px;
  border-radius: 7px;
  color: #455065;
}

.nav-button::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 999px;
  background: transparent;
}

.nav-button:hover {
  background: #f3f5f8;
  color: #182230;
}

.nav-button.active {
  background: #fff5db;
  color: #7a5012;
}

.nav-button.active::before {
  background: var(--accent);
}

.main {
  padding: 18px 22px 28px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  grid-template-columns: minmax(260px, 1fr) minmax(620px, 820px);
  gap: 20px;
  align-items: center;
  margin: -18px -22px 18px;
  padding: 16px 22px 14px;
  background: rgba(244, 246, 248, 0.94);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(223, 228, 236, 0.85);
}

.page-heading {
  min-width: 0;
}

.page-kicker {
  color: #8a5a0d;
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 4px;
}

.page-title {
  font-size: 25px;
  line-height: 1.16;
}

.page-subtitle {
  margin-top: 6px;
  max-width: 680px;
  font-size: 13px;
  line-height: 1.5;
}

.settings {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.settings-grid {
  grid-template-columns: minmax(210px, 1.2fr) minmax(160px, 0.72fr) minmax(210px, 1fr) auto auto auto;
  gap: 8px;
}

.config-field label,
.field label {
  color: #344054;
}

.input,
.select,
.textarea {
  min-height: 40px;
  border-color: #d7dde7;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: #c5ccd8;
}

.input-shell {
  position: relative;
}

.input-shell .input {
  padding-right: 62px;
}

.input-action {
  position: absolute;
  top: 5px;
  right: 5px;
  min-width: 48px;
  height: 30px;
  border-radius: 6px;
  background: #f3f5f8;
  color: #344054;
  font-size: 12px;
  font-weight: 900;
}

.input-action:hover {
  background: #e8edf4;
}

.switch-field {
  min-height: 40px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #344054;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.switch-field input {
  width: 34px;
  height: 20px;
  margin: 0;
  appearance: none;
  border-radius: 999px;
  background: #cbd5e1;
  position: relative;
  transition: background 0.16s ease;
}

.switch-field input::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 2px;
  left: 2px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(24, 34, 48, 0.24);
  transition: transform 0.16s ease;
}

.switch-field input:checked {
  background: var(--accent);
}

.switch-field input:checked::after {
  transform: translateX(14px);
}

.connection-status {
  margin-top: 9px;
  min-height: 34px;
  border-radius: 8px;
}

.connection-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.layout {
  grid-template-columns: minmax(380px, 500px) minmax(0, 1fr);
  gap: 18px;
}

.panel {
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-header {
  min-height: 58px;
  padding: 14px 16px;
  background: #fbfcfe;
}

.panel-body {
  padding: 16px;
}

.file-zone {
  position: relative;
  cursor: pointer;
  border-color: #cfd6e2;
  background: linear-gradient(180deg, #fbfcfe, #f7f9fc);
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

.file-zone:hover {
  border-color: #b7c2d2;
  box-shadow: inset 0 0 0 1px rgba(230, 165, 46, 0.12);
}

.file-zone.dragging {
  border-color: var(--accent);
  background: #fff7df;
  box-shadow: 0 0 0 4px rgba(230, 165, 46, 0.15);
}

.file-zone.dragging::after {
  content: "释放上传";
  position: absolute;
  inset: 8px;
  border: 1px solid rgba(135, 90, 18, 0.22);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: #7a5012;
  font-weight: 900;
  background: rgba(255, 247, 223, 0.86);
  pointer-events: none;
}

.file-row strong {
  font-size: 13px;
}

.file-row small {
  margin-left: 6px;
  color: var(--muted);
}

.file-drop-hint {
  min-height: 28px;
  border: 1px dashed #d5dbe5;
  border-radius: 7px;
  display: grid;
  place-items: center;
  color: #788398;
  font-size: 12px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.72);
}

.file-zone.has-files .file-drop-hint {
  min-height: 24px;
}

.preview {
  border-radius: 7px;
  box-shadow: var(--shadow-soft);
}

.preview::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, transparent 58%, rgba(17, 24, 39, 0.58));
  opacity: 0;
  transition: opacity 0.16s ease;
}

.preview:hover::after {
  opacity: 1;
}

.preview button {
  z-index: 2;
  top: 5px;
  right: 5px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 900;
}

.preview-name {
  position: absolute;
  z-index: 2;
  left: 6px;
  right: 6px;
  bottom: 6px;
  color: white;
  font-size: 11px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.16s ease;
}

.preview:hover .preview-name {
  opacity: 1;
}

.btn {
  min-height: 38px;
  border-radius: 7px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) {
  filter: none;
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.btn.primary {
  background: linear-gradient(180deg, #f4bf4e, var(--accent));
}

.btn.ghost:hover:not(:disabled) {
  background: #f7f9fc;
  border-color: #c5ccd8;
}

.submit-btn {
  width: 100%;
  min-height: 44px;
}

.action-stack {
  position: sticky;
  bottom: 14px;
  z-index: 8;
  display: grid;
  gap: 10px;
  padding-top: 10px;
  background: linear-gradient(180deg, rgba(255,255,255,0), var(--panel) 32%);
}

.psd-action-stack {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.segmented {
  border: 1px solid #e1e6ee;
}

.segmented button {
  min-height: 36px;
}

.segmented button.active {
  box-shadow: var(--shadow-soft);
}

.intent-card,
.module-card,
.task-card,
.queue-item,
.plan-item,
.custom-module {
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.intent-card:hover,
.module-card:hover,
.task-card:hover,
.queue-item:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
  border-color: #c7ceda;
}

.intent-card.active,
.module-card.active {
  border-color: var(--accent);
  background: #fff7df;
}

.current-result {
  background: #fbfcfe;
  box-shadow: var(--shadow-soft);
}

.task-card {
  min-width: 0;
}

.task-media {
  position: relative;
}

.task-media span {
  line-height: 1.7;
}

.status {
  letter-spacing: 0;
}

.empty {
  background:
    linear-gradient(180deg, rgba(255,255,255,.82), rgba(248,250,252,.94)),
    repeating-linear-gradient(135deg, #f3f6fa 0, #f3f6fa 10px, #ffffff 10px, #ffffff 20px);
}

.queue-overlay {
  background: rgba(24, 34, 48, 0.42);
  backdrop-filter: blur(4px);
}

.queue-panel {
  box-shadow: -18px 0 48px rgba(24, 34, 48, 0.2);
}

.queue-stats div {
  background: #fbfcfe;
}

.queue-line strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-source {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 10px;
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
}

.chat-source-media {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  overflow: hidden;
}

.chat-source-media img,
.chat-task-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.chat-source-meta {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 7px;
}

.chat-source-meta span,
.chat-source-meta p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
}

.chat-history {
  min-height: 260px;
  max-height: 560px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 12px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.chat-history.empty-chat {
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.empty-chat strong,
.empty-chat span {
  display: block;
}

.chat-message {
  display: flex;
}

.chat-message.user {
  justify-content: flex-end;
}

.chat-bubble {
  width: min(100%, 420px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 10px;
  display: grid;
  gap: 8px;
  box-shadow: var(--shadow-soft);
}

.chat-message.user .chat-bubble {
  background: #fff7df;
  border-color: #f0d999;
}

.chat-bubble p {
  margin: 0;
  line-height: 1.55;
  white-space: pre-wrap;
}

.chat-bubble small {
  color: var(--muted);
  font-size: 11px;
}

.chat-task {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  padding: 8px;
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
}

.chat-task-media {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
  overflow: hidden;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.chat-task-meta {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 7px;
}

.chat-task-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-prompt {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 8px;
}

.chat-prompt summary {
  cursor: pointer;
  color: #455065;
  font-size: 12px;
  font-weight: 900;
}

.chat-prompt pre {
  margin: 8px 0 0;
  white-space: pre-wrap;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.chat-composer {
  display: grid;
  gap: 10px;
}

.chat-draft {
  min-height: 130px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    flex: 0 0 auto;
    border-bottom: 0;
    margin: 0 8px 0 0;
    padding: 4px 10px;
  }

  .nav-section {
    display: none;
  }

  .nav-button {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .topbar {
    position: static;
    grid-template-columns: 1fr;
    margin-top: 0;
  }

  .settings-grid {
    grid-template-columns: minmax(220px, 1fr) minmax(180px, 0.75fr) minmax(220px, 1fr) auto auto auto;
  }

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

@media (max-width: 760px) {
  .main {
    padding: 14px;
  }

  .topbar {
    margin: -14px -14px 14px;
    padding: 14px;
  }

  .page-title {
    font-size: 23px;
  }

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

  .two-col,
  .current-result,
  .chat-source,
  .chat-task,
  .ocr-row,
  .queue-item,
  .intent-grid,
  .module-grid {
    grid-template-columns: 1fr;
  }

  .queue-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .preview-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .switch-field,
  .settings-grid .btn {
    width: 100%;
  }

  .action-stack {
    bottom: 0;
  }

  .queue-panel {
    width: 100vw;
    padding: 14px;
  }
}
