:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e5e7eb;
  --line-soft: #f0f0f0;
  --text: #1a1a1a;
  --muted: #6b7280;
  --muted-soft: #9ca3af;
  --primary: #4f6cff;
  --primary-dark: #3b5bef;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

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

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

.header h1 {
  font-size: 18px;
  font-weight: 700;
  color: #111;
}

.config-btn {
  padding: 6px 14px;
  background: #f3f4f6;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  color: #374151;
}

.config-btn:hover {
  background: #e5e7eb;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 900px) {
  .main {
    flex-direction: row;
  }

  .panel-left {
    width: 430px;
    min-width: 390px;
    flex-shrink: 0;
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
  }

  .panel-right {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
  }
}

@media (max-width: 899px) {
  .panel-left,
  .panel-right {
    width: 100%;
  }

  .main {
    overflow-y: auto;
  }

  .panel-right {
    min-height: 60vh;
  }
}

.panel-left {
  background: var(--panel);
  overflow-y: auto;
}

.panel-right {
  background: var(--bg);
  overflow: hidden;
}

.section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
}

.section:last-child {
  border-bottom: none;
}

.section h2 {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 8px 0 4px;
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select {
  width: 100%;
  padding: 9px 12px;
  background: var(--panel);
  border: 1px solid #d1d5db;
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 108, 255, 0.1);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

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

.row > * {
  flex: 1;
}

.compact-top {
  margin-top: 8px;
}

.actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
}

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

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #7c5cff);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.92;
}

.btn-secondary {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid var(--line);
}

.btn-secondary:hover:not(:disabled) {
  background: #e5e7eb;
}

.btn-sm {
  width: auto;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
}

.btn-danger:hover {
  background: #fecaca;
}

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

.upload-area {
  border: 2px dashed #d1d5db;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  color: var(--muted);
  font-size: 13px;
}

.upload-area:hover {
  border-color: var(--primary);
}

.upload-area input {
  display: none;
}

.preview-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.preview-item {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #f5f6f8;
  flex-shrink: 0;
}

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

.preview-item .del {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}

.preview-meta {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  word-break: break-all;
}

.section-collapsible {
  padding-top: 0;
}

.section-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  margin: 0 -20px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.section-summary::-webkit-details-marker {
  display: none;
}

.summary-arrow {
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--muted-soft);
  border-bottom: 2px solid var(--muted-soft);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

.section-collapsible[open] .summary-arrow {
  transform: rotate(225deg);
}

.section-body {
  padding-top: 4px;
}

.file-chip-row {
  display: none;
}

.file-chip-row.show {
  display: block;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f9fafb;
  font-size: 12px;
  color: #374151;
}

.file-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-chip-del {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.size-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.size-chip {
  padding: 7px 4px;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  text-align: center;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  color: #374151;
}

.size-chip:hover {
  border-color: var(--primary);
}

.size-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.custom-size {
  display: none;
  margin-top: 8px;
  gap: 8px;
}

.custom-size.show {
  display: flex;
}

.status {
  display: none;
  margin: 12px 20px 0;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
}

.status.show {
  display: block;
}

.status.info {
  background: #eff6ff;
  color: #1d4ed8;
}

.status.error {
  background: #fef2f2;
  color: var(--danger);
}

.status.success {
  background: #f0fdf4;
  color: #16a34a;
}

.right-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.tab {
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.right-body {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-pane {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  padding: 16px 20px;
}

.tab-pane.active {
  display: block;
}

#tabResult {
  padding: 0;
}

.result-viewer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.result-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
  overflow: hidden;
}

.result-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: var(--shadow);
  background: #fff;
}

.result-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.result-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
}

.result-label {
  padding: 5px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 12px;
  font-weight: 600;
}

.result-thumbs {
  display: flex;
  align-items: center;
  gap: 6px;
}

.thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  flex-shrink: 0;
  background: #eee;
}

.thumb.active {
  border-color: var(--primary);
}

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

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

@media (min-width: 1200px) {
  .history-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  }
}

.hcard {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  transition: box-shadow 0.15s;
}

.hcard:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.07);
}

.hcard-img {
  position: relative;
  aspect-ratio: 1;
  background: var(--bg);
  overflow: hidden;
  cursor: pointer;
}

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

.hcard-count {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 2px 7px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 11px;
}

.hcard-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  opacity: 0;
  background: rgba(0, 0, 0, 0.45);
  transition: opacity 0.15s;
}

.hcard:hover .hcard-overlay {
  opacity: 1;
}

.ob {
  padding: 6px 10px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  color: #374151;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.ob:hover {
  background: #fff;
}

.ob.primary {
  background: var(--primary);
  color: #fff;
}

.ob.primary:hover {
  background: var(--primary-dark);
}

.hcard-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 8px;
  padding: 10px 12px;
}

.hcard-prompt {
  font-size: 12px;
  color: #374151;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-all;
}

.hcard-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--muted-soft);
}

.meta-left {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.meta-tag {
  padding: 2px 6px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 600;
  flex-shrink: 0;
}

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

.hcard-del {
  color: #d1d5db;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px;
}

.hcard-del:hover {
  color: #ef4444;
}

.history-actions {
  padding: 16px 0;
  text-align: center;
}

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted-soft);
  font-size: 14px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.3);
}

.modal-overlay.show {
  display: flex;
}

.modal {
  width: 90%;
  max-width: 420px;
  padding: 24px;
  border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

.modal h2 {
  font-size: 16px;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.modal-actions .btn {
  flex: 1;
}

.img-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.85);
  cursor: pointer;
}

.img-modal.show {
  display: flex;
}

.img-modal img {
  max-width: 95vw;
  max-height: 95vh;
  border-radius: 8px;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 300;
  transform: translateX(-50%);
  padding: 10px 18px;
  border-radius: 8px;
  background: #111;
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.show {
  opacity: 0.92;
}

@media (max-width: 640px) {
  .header {
    padding: 12px 16px;
  }

  .section,
  .right-header,
  .tab-pane {
    padding-left: 16px;
    padding-right: 16px;
  }

  .row,
  .result-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .actions-row,
  .result-actions {
    justify-content: stretch;
  }

  .result-actions .btn-sm,
  .actions-row .btn-sm {
    width: 100%;
  }

  .section-summary {
    margin-left: -16px;
    margin-right: -16px;
    padding-left: 16px;
    padding-right: 16px;
  }

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