:root {
  color-scheme: light;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #d9e1ec;
  --text: #18212f;
  --muted: #64748b;
  --primary: #1267d8;
  --primary-strong: #0b4da2;
  --success: #16845b;
  --danger: #c93434;
  --warning: #a15c08;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

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

.shell {
  min-height: 100vh;
  padding: 0;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.result-subtitle,
.key-meta,
.empty-state span {
  color: var(--muted);
}

.status-pill,
.result-summary,
.result-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

.status-pill.ok,
.result-badge.ok {
  border-color: #b9ead7;
  background: #edfdf6;
  color: var(--success);
}

.status-pill.busy {
  border-color: #b8d4ff;
  background: #eef6ff;
  color: var(--primary);
}

.status-pill.error,
.result-badge.error {
  border-color: #ffd0d0;
  background: #fff1f1;
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 12px;
  min-height: 100vh;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  min-height: 100vh;
}

.results-panel {
  min-height: 100vh;
  padding: 16px;
}

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

h2 {
  font-size: 16px;
  line-height: 1.25;
}

label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-weight: 600;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  padding: 9px 10px;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease;
}

textarea {
  resize: vertical;
  min-height: 136px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #8cb7f6;
  box-shadow: 0 0 0 3px rgba(18, 103, 216, 0.14);
}

input[readonly] {
  background: var(--surface-soft);
  color: var(--muted);
}

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

.key-meta {
  min-height: 32px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 8px 10px;
  line-height: 1.45;
}

.reference-hint {
  margin-top: -8px;
  color: var(--muted);
  font-size: 12px;
}

.reference-preview {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 8px;
}

.reference-preview[hidden] {
  display: none;
}

.reference-preview img {
  width: 64px;
  height: 64px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  object-fit: cover;
}

.reference-info {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.reference-info strong,
.reference-info span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.actions {
  display: flex;
  gap: 10px;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    color 120ms ease,
    opacity 120ms ease;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.primary {
  flex: 1;
  background: var(--primary);
  color: #ffffff;
}

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

.secondary {
  background: var(--surface-soft);
  border-color: var(--border);
  color: #334155;
}

.secondary {
  padding: 0 14px;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.secondary:hover:not(:disabled) {
  border-color: #afbdd0;
  background: #eef2f7;
}

.empty-state {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 320px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  text-align: center;
}

.results-list {
  display: grid;
  gap: 14px;
}

.result-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

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

.result-title {
  font-size: 15px;
  line-height: 1.35;
}

.result-subtitle {
  margin-top: 3px;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.image-tile {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #eef2f7;
}

.image-tile img {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #ffffff;
}

.image-fallback {
  display: block;
  padding: 8px 10px;
  color: var(--primary);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.image-fallback {
  color: var(--muted);
}

.image-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 10px;
}

.image-actions a {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.image-actions .download-link {
  flex: 0 0 auto;
  border: 1px solid #b8d4ff;
  border-radius: 999px;
  background: #eef6ff;
  color: var(--primary);
  padding: 4px 10px;
  font-weight: 700;
}

.image-actions .download-link:hover {
  border-color: #8cb7f6;
  background: #e8f1ff;
}

details {
  margin-top: 12px;
}

summary {
  cursor: pointer;
  color: #334155;
  font-weight: 700;
}

pre {
  overflow: auto;
  max-height: 280px;
  margin: 10px 0 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
  color: #dbeafe;
  padding: 12px;
  font-size: 12px;
  line-height: 1.55;
}

@media (max-width: 860px) {
  .shell {
    padding: 0;
  }

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

  .results-panel {
    min-height: 420px;
  }

  .control-panel {
    min-height: auto;
  }
}

@media (max-width: 520px) {
  .grid-2,
  .actions {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .primary,
  .secondary {
    width: 100%;
  }

  .reference-preview {
    grid-template-columns: 56px minmax(0, 1fr);
  }

  .reference-preview img {
    width: 56px;
    height: 56px;
  }

  .reference-preview .small-button {
    grid-column: 1 / -1;
  }
}
