/* ================================================================
   Email Automation V2 - Web UI Styles
   ================================================================ */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f9fafb;
  --border: #d9dee5;
  --border-strong: #bcc7d3;
  --text: #171717;
  --text-muted: #5f6874;
  --primary: #171717;
  --primary-hover: #2d2d2d;
  --accent: #0b65b9;
  --accent-soft: #eef6ff;
  --success: #2e7d32;
  --error: #c62828;
  --warning: #f57f17;
  --radius: 8px;
  --shadow: 0 10px 28px rgba(17, 24, 39, 0.08);
  --shadow-soft: 0 1px 2px rgba(17, 24, 39, 0.08);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---- Header ---- */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: #111;
  color: #fff;
  border-bottom: 1px solid #2b2b2b;
}

.header-kicker {
  color: #b7c7d8;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.header h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 1.2;
}

.health-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #e6edf5;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  padding: 6px 10px;
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

.health-dot.error {
  background: var(--error);
}

/* ---- Main layout ---- */
.main {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 24px;
  padding: 28px 28px 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.left-panel {
  align-self: start;
}

/* ---- Panels ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--text-muted);
  padding: 18px 20px 10px;
}

.panel-title span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
}

.panel-body {
  padding: 8px 20px 22px;
}

/* ---- Drop zone ---- */
.drop-zone {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.2s;
  color: var(--text-muted);
  background: var(--surface-soft);
}

.drop-zone:hover,
.drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-1px);
}

.drop-title {
  color: var(--text);
  font-weight: 700;
  margin-bottom: 3px;
}

.drop-subtitle {
  color: var(--text-muted);
  font-size: 12px;
}

.drop-zone input[type="file"] {
  display: none;
}

.upload-info {
  margin-top: 12px;
  font-size: 13px;
}

.upload-info .filename {
  font-weight: 600;
  color: var(--text);
  display: block;
  margin-bottom: 4px;
}

.upload-meta {
  color: var(--accent);
  margin-bottom: 2px;
  font-weight: 600;
}

.upload-languages {
  color: var(--text-muted);
  font-size: 12px;
}

/* ---- Template selection ---- */
.template-list {
  max-height: 260px;
  overflow-y: auto;
}

.template-loading {
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 0;
}

.template-option {
  display: block;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
  background: #fff;
}

.template-option:hover {
  border-color: var(--accent);
  background: #f9fbfd;
  box-shadow: var(--shadow-soft);
}

.template-option.recommended {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.template-option input[type="radio"] {
  margin-right: 8px;
  vertical-align: middle;
}

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

.template-badges {
  display: flex;
  align-items: center;
  gap: 4px;
}

.recommended-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid #b8d8f6;
  background: #fff;
  border-radius: var(--radius);
  padding: 1px 6px;
}

.template-name {
  font-weight: 600;
  font-size: 13px;
  word-break: break-word;
}

.template-score {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius);
}

.template-score.high {
  background: #e8f5e9;
  color: var(--success);
}

.template-score.med {
  background: #fff8e1;
  color: var(--warning);
}

.template-score.low {
  background: #ffebee;
  color: var(--error);
}

.template-detail {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  padding-left: 24px;
}

/* ---- Form controls ---- */
.form-group {
  margin-bottom: 12px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.form-group select,
.form-group input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
}

.form-group select:focus,
.form-group input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---- Buttons ---- */
.btn {
  display: inline-block;
  min-height: 42px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  width: 100%;
}

.btn-primary:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  background: #999;
  cursor: not-allowed;
}

.btn-download {
  background: var(--accent);
  color: #fff;
  margin-top: 12px;
}

.btn-download:hover {
  background: #0055aa;
  transform: translateY(-1px);
}

/* ---- Result panel ---- */
.result-section {
  display: none;
}

.result-section.visible {
  display: block;
}

.result-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 16px;
  font-weight: 700;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.status-dot.completed {
  background: var(--success);
}

.status-dot.failed {
  background: var(--error);
}

.status-dot.pending {
  background: var(--warning);
}

.result-meta {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: grid;
  gap: 6px;
}

.result-meta span {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
  word-break: break-word;
}

.result-errors {
  background: #fff5f5;
  border: 1px solid #ffcdd2;
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--error);
}

/* ---- Section label ---- */
.section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ---- Image edits ---- */
.image-edits-section {
  margin-bottom: 16px;
}

.image-edits-summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.edit-stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 10px;
}

.edit-stat.ok { border-color: #a5d6a7; background: #f1f8e9; color: var(--success); }
.edit-stat.warn { border-color: #ffe082; background: #fffde7; color: var(--warning); }
.edit-stat.err { border-color: #ef9a9a; background: #ffebee; color: var(--error); }

.image-edits-list {
  margin-top: 8px;
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.image-edits-list .edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
}

.image-edits-list .edit-row:last-child { border-bottom: none; }
.image-edits-list .edit-row .filename { flex: 1; color: var(--text-muted); }
.image-edits-list .edit-row .confidence { color: var(--text-muted); }

/* ---- QA section ---- */
.qa-section {
  margin-bottom: 16px;
}

.qa-badge-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.qa-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--radius);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

.qa-badge.pass { background: #e8f5e9; color: var(--success); border: 1px solid #a5d6a7; }
.qa-badge.review { background: #fffde7; color: var(--warning); border: 1px solid #ffe082; }
.qa-badge.fail { background: #ffebee; color: var(--error); border: 1px solid #ef9a9a; }

.qa-issue-count {
  font-size: 12px;
  color: var(--text-muted);
}

.qa-issues-list {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 12px;
}

.qa-issue {
  display: flex;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}

.qa-issue:last-child { border-bottom: none; }

.qa-issue .issue-severity {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
  margin-top: 1px;
}

.issue-severity.error { background: #ffebee; color: var(--error); }
.issue-severity.warning { background: #fffde7; color: var(--warning); }
.issue-severity.info { background: #e3f2fd; color: #1565c0; }

.qa-issue .issue-text { flex: 1; color: var(--text); }
.qa-issue .issue-context { color: var(--text-muted); font-family: monospace; font-size: 11px; word-break: break-all; }

/* ---- Toggle link ---- */
.toggle-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 0;
  display: inline-block;
}

/* ---- Process log ---- */
.process-log-panel {
  margin-top: 16px;
}

.process-log-details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.process-log-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

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

.process-log-details summary::before {
  content: "+";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  margin-right: 4px;
  flex: 0 0 auto;
}

.process-log-details[open] summary::before {
  content: "-";
}

.process-log-details summary span:first-child {
  flex: 1;
}

.process-log-count {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.process-log-list {
  border-top: 1px solid var(--border);
}

.process-log-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.process-log-item:last-child {
  border-bottom: none;
}

.process-log-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.process-log-heading strong {
  font-size: 13px;
}

.process-log-stage {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  border: 1px solid #c5def5;
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.process-log-item ul {
  list-style: none;
  display: grid;
  gap: 5px;
}

.process-log-item li {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

/* ---- Extracted Excel data (Blueprint) ---- */
.excel-data-list {
  border-top: 1px solid var(--border);
  padding: 8px 0;
}

.excel-data-details {
  border-bottom: 1px solid var(--border);
}

.excel-data-details:last-child {
  border-bottom: none;
}

.excel-data-details summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

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

.excel-data-details summary::before {
  content: "+";
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--accent);
  margin-right: 6px;
  flex: 0 0 auto;
}

.excel-data-details[open] summary::before {
  content: "-";
}

.excel-data-summary-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.excel-data-summary-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.excel-data-summary-meta {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.excel-data-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: var(--radius);
  background: #f6f7f9;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}

.excel-data-chip.primary {
  background: var(--accent-soft);
  border-color: #c5def5;
  color: var(--accent);
}

.excel-data-body {
  padding: 0 16px 12px 42px;
  display: grid;
  gap: 10px;
}

.excel-data-kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 10px;
  align-items: start;
}

.excel-data-k {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.excel-data-v {
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.excel-data-v.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 11px;
  color: var(--text-muted);
}

.excel-data-list ul {
  list-style: none;
  display: grid;
  gap: 5px;
  padding-left: 0;
  margin: 0;
}

.excel-data-list li {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

/* ---- Preview iframe ---- */
.preview-frame-wrapper {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.preview-frame-wrapper h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.preview-frame {
  width: 100%;
  height: 600px;
  border: none;
}

/* ---- Loading spinner ---- */
.spinner {
  display: none;
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.spinner.visible {
  display: block;
}

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

.spinner::before {
  content: "";
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-bottom: 8px;
}

/* ---- Job history ---- */
.history-section {
  padding: 12px 28px 28px;
  max-width: 1400px;
  margin: 0 auto;
}

.history-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
  padding: 10px 14px;
  box-shadow: var(--shadow-soft);
}

.history-table-wrapper {
  display: none;
  margin-top: 8px;
}

.history-table-wrapper.open {
  display: block;
}

.history-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.history-table th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  background: var(--surface-soft);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  letter-spacing: 0;
}

.history-table td {
  padding: 8px 12px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.history-table tr:last-child td {
  border-bottom: none;
}

.history-table tr:hover td {
  background: #fafafa;
  cursor: pointer;
}

.history-table .status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-badge.completed {
  background: #e8f5e9;
  color: var(--success);
}

.status-badge.failed {
  background: #ffebee;
  color: var(--error);
}

.status-badge.pending {
  background: #fff8e1;
  color: var(--warning);
}

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ---- Responsive ---- */
@media (max-width: 800px) {
  .header {
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
  }

  .main {
    grid-template-columns: 1fr;
    padding: 18px 16px;
    gap: 16px;
  }

  .history-section {
    padding: 0 16px 20px;
  }

  .template-info,
  .process-log-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .process-log-details summary {
    align-items: flex-start;
  }
}
