/* ============================================================
   Layout, panels, forms, upload, primary buttons
   ============================================================ */

/* ---- Main layout: two ops panels on a white ground ---- */
.main-layout {
  max-width: 1440px;
  margin: 1.5rem auto 3rem;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  gap: 20px;
  align-items: start;
}

/* Panels — the boxed ops surface */
.panel {
  background: var(--surface-raised);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: 1.5rem 1.75rem;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.1rem;
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--border-muted);
}

.panel-header h2 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-scan-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-chip);
  background: var(--surface-raised);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition-fast),
    border-color var(--transition-fast),
    background-color var(--transition-fast),
    transform var(--transition-fast);
}

.ai-scan-btn:hover {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
  background: var(--accent-subtle);
}

.ai-scan-btn:active { transform: translateY(1px); }

.ai-scan-btn:disabled {
  opacity: 0.65;
  cursor: wait;
  transform: none;
}

/* Scan spinner replaces the 🤖 icon while the AI is reading the photo */
.ai-scan-btn .scan-spinner {
  display: none;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.ai-scan-btn.loading .scan-spinner { display: inline-block; }
.ai-scan-btn.loading .icon { display: none; }

/* Mono status chip ("步驟 1") */
.badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.14rem 0.5rem;
  border-radius: 5px;
  background: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border-muted);
  white-space: nowrap;
}

/* ---- Presets ---- */
.preset-section { margin-bottom: 1.1rem; }

.section-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  display: block;
  margin-bottom: 8px;
}

.preset-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-btn {
  min-height: 40px;
  padding: 0.45rem 0.9rem;
  background: transparent;
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-chip);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition-fast),
    border-color var(--transition-fast),
    background-color var(--transition-fast),
    transform var(--transition-fast);
}

.preset-btn:hover {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
  background: var(--accent-subtle);
}

.preset-btn:active { transform: translateY(1px); }

/* ---- Upload dropzone ---- */
.upload-container {
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 2rem 1.25rem;
  text-align: center;
  background: var(--surface-sunken);
  cursor: pointer;
  margin-bottom: 1.1rem;
  transition: border-color var(--transition-fast),
    background-color var(--transition-fast);
}

.upload-container:hover,
.upload-container.dragover {
  border-color: var(--accent-primary);
  background: var(--accent-subtle);
}

.upload-container:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

.upload-icon-wrapper {
  width: 44px;
  height: 44px;
  margin: 0 auto 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-muted);
  background: var(--surface-raised);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.upload-container:hover .upload-icon-wrapper {
  color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.upload-icon {
  width: 22px;
  height: 22px;
}

.upload-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.upload-primary-text {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
}

.upload-link {
  color: var(--accent-primary);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.upload-sub-text {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

/* Image tray */
.image-tray {
  background: var(--bg-secondary);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-md);
  padding: 10px;
  margin-bottom: 1.1rem;
}

.tray-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.text-btn {
  background: none;
  border: none;
  color: var(--accent-primary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 8px;
  min-height: 32px;
  border-radius: var(--radius-sm);
  transition: color var(--transition-fast);
}

.text-btn:hover {
  color: var(--accent-highlight);
  text-decoration: underline;
}

.thumbnail-list {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.thumbnail-item {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-muted);
  flex-shrink: 0;
}

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

.thumbnail-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 24px;
  height: 24px;
  background: rgba(16, 24, 40, 0.75);
  color: #ffffff;
  border: none;
  border-radius: 50%;
  font-size: 12px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

.thumbnail-remove:hover { background: var(--status-bad-border); }

/* ---- Form fields ---- */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-group.full-width { grid-column: span 2; }

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.hint {
  font-size: 0.74rem;
  font-weight: 400;
  color: var(--text-muted);
}

.required { color: var(--status-bad-text); }

.form-group input,
.form-group select {
  width: 100%;
  background: var(--surface-raised);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 0.9rem;
  color: var(--text-primary);
  transition: border-color var(--transition-fast),
    box-shadow var(--transition-fast);
  outline: none;
}

.form-group input::placeholder { color: var(--text-muted); opacity: 0.7; }

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

/* ---- Primary button = solid inverted fill (ink in light, light in dark) ---- */
.btn-primary {
  width: 100%;
  min-height: 48px;
  background: var(--text-primary);
  border: 1px solid var(--text-primary);
  border-radius: var(--radius-md);
  padding: 0.7rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--bg-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: background-color var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast);
}

.btn-primary:hover {
  background: color-mix(in srgb, var(--text-primary) 85%, var(--bg-primary));
  border-color: color-mix(in srgb, var(--text-primary) 85%, var(--bg-primary));
}

.btn-primary:active { transform: translateY(1px); }

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-loader {
  width: 16px;
  height: 16px;
  border: 2px solid color-mix(in srgb, var(--bg-primary) 30%, transparent);
  border-radius: 50%;
  border-top-color: var(--bg-primary);
  animation: spin 0.8s linear infinite;
}

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

/* ---- Chain-of-thought opt-in toggle ---- */
.thought-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  min-height: 40px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.thought-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent-primary);
  cursor: pointer;
  flex-shrink: 0;
}

.thought-toggle:hover { color: var(--text-primary); }

.thought-toggle .hint { font-size: 0.7rem; }

/* ---- Reset all (start over) ---- */
.btn-reset {
  width: 100%;
  min-height: 40px;
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: color var(--transition-fast),
    border-color var(--transition-fast),
    background-color var(--transition-fast),
    transform var(--transition-fast);
}

.btn-reset:hover {
  color: var(--text-primary);
  border-color: var(--border-color);
}

.btn-reset:active { transform: translateY(1px); }

/* Armed (awaiting second click) — red is the destructive warning */
.btn-reset.confirm {
  color: var(--status-bad-text);
  border-color: var(--status-bad-border);
  background: var(--status-bad-bg);
}
