:root {
  --bg: #f4efe6;
  --panel: rgba(255, 252, 246, 0.9);
  --panel-strong: #fffaf2;
  --ink: #1f1a17;
  --muted: #6d645e;
  --line: rgba(52, 39, 29, 0.12);
  --accent: #bd4f2d;
  --accent-deep: #8f351a;
  --accent-soft: rgba(189, 79, 45, 0.12);
  --shadow: 0 24px 60px rgba(63, 40, 23, 0.12);
  --success: #2d7a4f;
  --warning: #b58900;
  --error: #c9362d;
  --confidence-high: #2d7a4f;
  --confidence-medium: #b58900;
  --confidence-low: #c9362d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(204, 101, 58, 0.22), transparent 26rem),
    radial-gradient(circle at right center, rgba(166, 135, 73, 0.2), transparent 22rem),
    linear-gradient(180deg, #f8f3eb 0%, var(--bg) 100%);
  font-family: "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.8), rgba(255, 244, 236, 0.95));
  border-bottom: 1px solid var(--line);
  padding: 12px 28px;
}

.header-content {
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 14px;
  color: #fff7ee;
  font-size: 1.6rem;
  font-weight: 800;
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.28), transparent 45%),
    linear-gradient(145deg, #b54726, #7f2d17);
  box-shadow: 0 8px 18px rgba(120, 46, 22, 0.22);
}

.brand-info h1 {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.2;
}

.brand-info p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.header-status {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 0.85rem;
}

.status-indicator {
  color: var(--success);
  font-weight: 600;
}

.model-info {
  color: var(--muted);
}

/* 3-Column Layout */
.layout-3col {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.05fr) minmax(300px, 0.95fr);
  gap: 24px;
  padding: 24px;
  flex: 1;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* Panels */
.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-upload {
  position: relative;
}

.panel-upload::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(189, 79, 45, 0.09), transparent 40%),
    linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.35));
  pointer-events: none;
}

.panel-header,
.stack,
.file-list-block,
.result-block,
.toolbar,
.form-grid,
.summary-content {
  position: relative;
  z-index: 1;
}

.panel-header {
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.5), transparent);
}

.panel-header h1,
.panel-header h2 {
  margin: 0;
  font-size: 1.5rem;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-deep);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.panel-copy {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.9rem;
}

/* Form Elements */
.stack,
.file-list-block,
.result-block,
.toolbar,
.form-grid,
.summary-content {
  padding: 20px 24px 24px;
}

.stack {
  display: grid;
  gap: 14px;
}

.dropzone {
  display: grid;
  gap: 8px;
  padding: 20px;
  border: 1.5px dashed rgba(143, 53, 26, 0.32);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(255, 244, 236, 0.95));
  cursor: pointer;
  transition: all 0.2s;
}

.dropzone:hover {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.85), rgba(255, 244, 236, 1));
  border-color: rgba(143, 53, 26, 0.5);
}

.dropzone-secondary {
  background: linear-gradient(180deg, rgba(255, 249, 241, 0.82), rgba(245, 238, 227, 0.92));
}

.dropzone input {
  display: none;
}

.dropzone-title {
  font-size: 1rem;
  font-weight: 700;
}

.dropzone-subtitle {
  color: var(--muted);
  font-size: 0.85rem;
}

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

.field span,
.fieldset-radio legend {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  border: 1px solid rgba(60, 44, 31, 0.15);
  border-radius: 12px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 12px 14px;
  font: inherit;
  font-size: 0.95rem;
}

.field textarea {
  resize: vertical;
  min-height: 50px;
}

.field select {
  appearance: none;
}

.fieldset-radio {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  display: grid;
  gap: 8px;
}

.fieldset-radio label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  cursor: pointer;
}

/* Buttons */
.primary-button,
.secondary-button,
.ghost-button {
  border: 0;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #d47848);
  color: white;
}

.primary-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(189, 79, 45, 0.3);
}

.secondary-button {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

.secondary-button:hover {
  background: rgba(189, 79, 45, 0.2);
}

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

.ghost-button:hover {
  border-color: var(--muted);
  color: var(--ink);
}

/* Section Headers */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.section-head h2 {
  margin: 0;
  font-size: 0.95rem;
}

.section-head span {
  color: var(--muted);
  font-size: 0.85rem;
}

/* File List */
.file-list,
.preview-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.file-item,
.preview-card,
.summary-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.68);
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
}

.file-item.empty,
.summary-card.empty {
  color: var(--muted);
  font-style: italic;
}

/* Toolbar */
.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
  margin-bottom: 16px;
}

/* Form Grid */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  overflow-y: auto;
  max-height: calc(100vh - 300px);
  padding-right: 8px;
}

.field-large {
  grid-column: span 1;
}

.field-large:nth-child(4),
.field-large:nth-child(10),
.field-large:nth-child(12),
.field-large:nth-child(17) {
  grid-column: 1 / -1;
}

/* Summary Panel */
.panel-summary {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 249, 241, 0.9));
}

.summary-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
}

.summary-section h3 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--ink);
}

/* Status Bar */
.status-bar {
  padding: 10px 14px;
  border-radius: 10px;
  background: rgba(45, 122, 79, 0.1);
  color: var(--success);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
}

.status-bar.error {
  background: rgba(201, 54, 45, 0.1);
  color: var(--error);
}

.status-bar.warning {
  background: rgba(181, 137, 0, 0.1);
  color: var(--warning);
}

/* Summary Stats */
.summary-stats {
  margin-bottom: 10px;
  font-size: 0.9rem;
  color: var(--muted);
}

.summary-stats .stat {
  font-weight: 600;
  color: var(--ink);
}

.summary-card {
  padding: 14px;
  max-height: 200px;
  overflow-y: auto;
}

.summary-row {
  display: grid;
  gap: 3px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(52, 39, 29, 0.08);
}

.summary-row:last-child {
  border-bottom: 0;
}

.summary-row span {
  color: var(--muted);
  font-size: 0.8rem;
}

.summary-row strong {
  color: var(--ink);
  font-weight: 600;
}

/* Confidence */
.confidence-bar-container {
  margin-bottom: 12px;
}

.confidence-bar {
  height: 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.1);
  overflow: hidden;
  margin-bottom: 6px;
}

.confidence-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--confidence-high), #4caf50);
  transition: width 0.3s, background 0.3s;
}

.confidence-fill.medium {
  background: linear-gradient(90deg, var(--confidence-medium), #ffc107);
}

.confidence-fill.low {
  background: linear-gradient(90deg, var(--confidence-low), #ff5722);
}

.confidence-text {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.confidence-alerts {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.confidence-alerts li {
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(181, 137, 0, 0.15);
  color: var(--warning);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Preview Cards */
.preview-card {
  padding: 12px;
}

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

.preview-head strong {
  font-size: 0.9rem;
}

.preview-head span {
  color: var(--muted);
  font-size: 0.75rem;
}

.preview-card pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  color: #3a312b;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.4;
  max-height: 150px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.03);
  padding: 10px;
  border-radius: 8px;
}

/* Modal */
.export-modal {
  border: none;
  border-radius: 20px;
  padding: 0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  background: var(--panel);
}

.export-modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  padding: 28px;
  min-width: 320px;
}

.modal-content h3 {
  margin: 0 0 20px;
  font-size: 1.3rem;
}

.modal-content select {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 1rem;
  background: var(--panel-strong);
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Footer */
.app-footer {
  padding: 16px 28px;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.5));
}

.app-footer a {
  color: var(--accent);
  text-decoration: none;
}

.app-footer a:hover {
  text-decoration: underline;
}

/* Responsive */
@media (max-width: 1200px) {
  .layout-3col {
    grid-template-columns: 1fr 1fr;
  }
  
  .panel-summary {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  .layout-3col {
    grid-template-columns: 1fr;
    padding: 16px;
  }
  
  .header-content {
    flex-wrap: wrap;
  }
  
  .header-status {
    margin-left: 0;
    width: 100%;
    justify-content: center;
    margin-top: 12px;
  }
  
  .form-grid {
    grid-template-columns: 1fr;
  }
  
  .field-large {
    grid-column: auto;
  }
  
  .review-panel {
    padding: 16px;
  }
  
  .review-actions {
    flex-direction: column;
  }
  
  .review-actions button {
    width: 100%;
  }
  
  .correction-comparison {
    grid-template-columns: 1fr;
  }
  
  .correction-arrow {
    text-align: center;
    padding: 8px 0;
  }
  
  .review-summary {
    grid-template-columns: 1fr 1fr;
  }
}

/* Confidence highlighting on form fields */
.confidence-low {
  border-color: var(--confidence-low) !important;
  background: rgba(201, 54, 45, 0.05) !important;
}

.confidence-medium {
  border-color: var(--confidence-medium) !important;
  background: rgba(181, 137, 0, 0.05) !important;
}

.confidence-high {
  border-color: var(--confidence-high) !important;
  background: rgba(45, 122, 79, 0.05) !important;
}

/* Review Panel */
.review-panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 249, 241, 0.95), rgba(255, 244, 236, 0.9));
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px rgba(189, 79, 45, 0.08);
}

.review-header {
  margin-bottom: 16px;
}

.review-header h3 {
  margin: 0 0 6px;
  font-size: 1.1rem;
  color: var(--ink);
}

.review-subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.review-list {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.review-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.7);
  padding: 14px;
  transition: all 0.2s;
}

.review-item.corrected {
  border-color: var(--success);
  background: rgba(45, 122, 79, 0.05);
}

.review-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.review-item-header strong {
  font-size: 0.95rem;
  color: var(--ink);
}

.confidence-badge {
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(181, 137, 0, 0.15);
  color: var(--warning);
}

.confidence-badge.confidence-low {
  background: rgba(201, 54, 45, 0.15);
  color: var(--error);
}

.confidence-badge.confidence-medium {
  background: rgba(181, 137, 0, 0.15);
  color: var(--warning);
}

.confidence-badge.confidence-high {
  background: rgba(45, 122, 79, 0.15);
  color: var(--success);
}

.review-item-values {
  margin-bottom: 12px;
}

.review-value-label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.review-value-text {
  padding: 8px 12px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.03);
  font-size: 0.9rem;
  color: var(--ink);
  margin-bottom: 8px;
  border-left: 3px solid var(--warning);
}

.review-value-text.corrected {
  border-left-color: var(--success);
  background: rgba(45, 122, 79, 0.05);
  color: var(--success);
  font-weight: 600;
}

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

.small-btn {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.review-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* Review Summary in Panel */
.review-summary {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(181, 137, 0, 0.08);
  margin-bottom: 12px;
}

.review-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink);
}

/* Correction Modal */
.correction-modal {
  border: none;
  border-radius: 20px;
  padding: 0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  background: var(--panel);
  max-width: 600px;
  width: 90%;
}

.correction-content {
  padding: 0 28px 20px;
}

.correction-field-info {
  margin-bottom: 20px;
}

.correction-field-info label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.field-label-display {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--ink);
}

.correction-comparison {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 16px;
  align-items: center;
  margin-bottom: 20px;
}

.correction-side label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.correction-side textarea {
  width: 100%;
  min-height: 80px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-strong);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
  resize: vertical;
}

.correction-side textarea[readonly] {
  background: rgba(0, 0, 0, 0.03);
  color: var(--muted);
}

.correction-arrow {
  font-size: 1.5rem;
  color: var(--accent);
  font-weight: 700;
}

.correction-reason {
  margin-bottom: 20px;
}

.correction-reason label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 6px;
}

.correction-reason input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-strong);
  color: var(--ink);
  font: inherit;
  font-size: 0.95rem;
}

/* Confirmation Modal */
.confirmation-modal {
  border: none;
  border-radius: 20px;
  padding: 0;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
  background: var(--panel);
  max-width: 450px;
  width: 90%;
}

.confirmation-modal #confirmation-message {
  margin: 0 0 24px;
  color: var(--ink);
  line-height: 1.6;
}

/* Error states */
.field.invalid input,
.field.invalid textarea {
  border-color: var(--error);
  background: rgba(201, 54, 45, 0.05);
}

.error-banner {
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(201, 54, 45, 0.1);
  color: var(--error);
  margin-bottom: 16px;
}

.warning-banner {
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(181, 137, 0, 0.1);
  color: var(--warning);
  margin-bottom: 16px;
}
