/* ========================================================================
   Reporting Analyzer — UI Styles
   ======================================================================== */

* {
  box-sizing: border-box;
}

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e9f2;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-soft: #475569;
  --text-mute: #94a3b8;

  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #dbeafe;

  --success: #059669;
  --success-soft: #d1fae5;
  --warning: #d97706;
  --warning-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;

  --current: #2563eb;
  --previous: #7c3aed;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow:    0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10);

  --radius: 12px;
  --radius-sm: 8px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 28px 60px;
}

.hidden { display: none !important; }

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #4f46e5 100%);
  border-radius: 16px;
  padding: 28px 32px;
  margin-bottom: 28px;
  color: #fff;
  box-shadow: var(--shadow-lg);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand-icon {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(6px);
  font-size: 24px;
}

.brand-title {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  margin: 4px 0 0;
  font-size: 14px;
  opacity: 0.85;
  font-weight: 400;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.status-pill i { font-size: 9px; }
.status-pill.status-idle i  { color: #fbbf24; }
.status-pill.status-ready i { color: #86efac; }
.status-pill.status-error i { color: #fca5a5; }

/* ---------- Sections ---------- */
.upload-section,
.controls-section,
.report-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 28px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.section-title {
  margin: 0 0 6px 0;
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.section-title i { color: var(--primary); }

.section-subtitle {
  margin: 0 0 12px 0;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.section-subtitle i { color: var(--warning); }

.section-help {
  color: var(--text-soft);
  margin: 0 0 20px 0;
  font-size: 13px;
}

/* ---------- Upload Cards ---------- */
.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.upload-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all 0.18s ease;
}

.upload-card.has-file {
  background: #f0f9ff;
  border-color: #bae6fd;
}

.upload-card.optional {
  border-style: dashed;
}

.optional-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: #e0e7ff;
  color: #4338ca;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: 1px;
}

.upload-card-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.upload-num {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.upload-card.has-file .upload-num {
  background: var(--success);
}

.upload-card-head h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.upload-card-head p {
  margin: 2px 0 0 0;
  font-size: 12px;
  color: var(--text-soft);
}

.upload-drop {
  position: relative;
  display: block;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  padding: 18px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s ease;
}

.upload-drop:hover {
  border-color: var(--primary);
  background: #f0f6ff;
}

.upload-drop.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.upload-card.has-file .upload-drop {
  border-color: var(--success);
  background: #ecfdf5;
}

.upload-drop input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-drop-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.upload-drop-inner i {
  font-size: 22px;
  color: var(--text-mute);
}

.upload-card.has-file .upload-drop-inner i { color: var(--success); }

.upload-drop-text {
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 500;
}

.upload-status {
  font-size: 12px;
  color: var(--text-mute);
  padding: 6px 8px;
  background: #fff;
  border-radius: 6px;
  border: 1px solid var(--border);
  word-break: break-all;
  min-height: 28px;
  display: flex;
  align-items: center;
}

.upload-status.ok {
  color: var(--success);
  background: var(--success-soft);
  border-color: #a7f3d0;
  font-weight: 500;
}

.upload-status.err {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #fecaca;
  font-weight: 500;
}

/* ---------- Controls ---------- */
.controls-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
  margin-top: 16px;
}

.control {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 160px;
}

.control-grow { flex: 1; min-width: 200px; }

.control label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.control select,
.control input {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #fff;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: border-color 0.18s ease;
}

.control select:focus,
.control input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.control-actions {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(37, 99, 235, 0.3);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.35);
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--primary);
  color: var(--primary);
}

.btn-ghost {
  background: transparent;
  color: var(--text-soft);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

/* Warning button — used for the "Send Test" action so it stands out from
   both Send to Team (primary blue) and Preview (secondary). */
.btn-warning {
  background: #f59e0b;
  color: #ffffff;
  border-color: #d97706;
}
.btn-warning:hover:not(:disabled) {
  background: #d97706;
  border-color: #b45309;
}

/* TEST MODE banner inside the email preview modal. */
.modal-test-banner {
  margin: 0 0 14px;
  padding: 10px 12px;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-left: 4px solid #d97706;
  border-radius: 6px;
  font-size: 13px;
  color: #92400e;
  line-height: 1.45;
}
.modal-test-banner i { margin-right: 6px; color: #b45309; }
.modal-test-banner code {
  background: #fde68a;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
}

/* ---------- Error box ---------- */
.error-box {
  margin-top: 16px;
  padding: 12px 16px;
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
}

/* ---------- Report ---------- */
.report-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

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

/* ---------- Send-to-Team confirmation banner ---------- */
.send-confirm {
  margin-bottom: 16px;
  padding: 12px 16px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: var(--radius-sm);
  color: #065f46;
  font-size: 13px;
  font-weight: 500;
}
.send-confirm.hidden { display: none; }
.send-confirm i { margin-right: 8px; }

/* ---------- Email Preview Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal-card {
  background: #fff;
  width: 100%;
  max-width: 880px;
  max-height: 92vh;
  border-radius: var(--radius-md, 12px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Iframe that renders the live email body — needs an explicit height
   so the chart, insights and metric tables are visible in the preview. */
.email-body-frame {
  display: block;
  width: 100%;
  height: 620px;
  border: 0;
  background: #ffffff;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e2e8f0;
  background: #f8fafc;
}
.modal-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #0f172a;
}
.modal-header h3 i { margin-right: 8px; color: #3b82f6; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: #64748b;
  padding: 4px 8px;
  border-radius: 4px;
}
.modal-close:hover { background: #e2e8f0; color: #0f172a; }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-hint {
  margin: 0 0 16px;
  padding: 10px 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  font-size: 13px;
  color: #1e40af;
}

.email-preview-fields {
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  margin-bottom: 16px;
  overflow: hidden;
}
.email-field {
  display: flex;
  border-bottom: 1px solid #e2e8f0;
  font-size: 13px;
}
.email-field:last-child { border-bottom: none; }
.email-label {
  flex: 0 0 110px;
  padding: 10px 12px;
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  border-right: 1px solid #e2e8f0;
}
.email-value {
  padding: 10px 12px;
  color: #0f172a;
  word-break: break-word;
  flex: 1;
}

.email-body-wrap {
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
}
.email-label-block {
  padding: 8px 12px;
  background: #f8fafc;
  font-weight: 600;
  color: #475569;
  font-size: 13px;
  border-bottom: 1px solid #e2e8f0;
}
.email-body {
  margin: 0;
  padding: 14px 16px;
  background: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  color: #0f172a;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
}

.period-labels {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-soft);
}

.period-labels strong { color: var(--text); }

.tables-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 1100px) {
  .tables-grid { grid-template-columns: 1fr; }
}

.table-wrap {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.table-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.table-pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #fff;
}

.table-pill-current { background: var(--current); }
.table-pill-previous { background: var(--previous); }

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 580px;
}

.report-table thead th {
  background: var(--surface-2);
  font-weight: 700;
  text-align: right;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border-strong);
  color: var(--text);
  white-space: nowrap;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.report-table thead th:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface-2);
  z-index: 1;
}

.report-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.report-table tbody td:first-child {
  text-align: left;
  font-weight: 600;
  position: sticky;
  left: 0;
  background: #fff;
  color: var(--text);
}

.report-table tbody tr:hover td { background: #f8fafc; }
.report-table tbody tr:hover td:first-child { background: #f1f5f9; }

.report-table tbody tr.row-total td {
  background: #1e3a8a;
  color: #fff;
  font-weight: 700;
}
.report-table tbody tr.row-total td:first-child { background: #1e3a8a; }

.report-table tbody tr.row-derived td {
  background: #fffbeb;
  font-weight: 600;
}
.report-table tbody tr.row-derived td:first-child { background: #fffbeb; color: var(--warning); }

.report-table tbody tr.row-net td {
  background: #f0fdf4;
  font-weight: 600;
}
.report-table tbody tr.row-net td:first-child { background: #f0fdf4; color: var(--success); }

.cell-zero { color: var(--text-mute); }

/* ---------- Summary ---------- */
.summary-section {
  margin-top: 28px;
  padding: 20px;
  background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
  border: 1px solid #fde68a;
  border-radius: var(--radius);
}

.summary-content {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.summary-card {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  border: 1px solid #fde68a;
  box-shadow: var(--shadow-sm);
}

.summary-card h4 {
  margin: 0 0 6px 0;
  font-size: 12px;
  font-weight: 700;
  color: var(--warning);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.summary-card p {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
}

.summary-card strong { color: var(--primary); }

.summary-card .delta-up { color: var(--success); font-weight: 700; }
.summary-card .delta-down { color: var(--danger); font-weight: 700; }
.summary-card .delta-flat { color: var(--text-soft); font-weight: 700; }

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-mute);
}
.app-footer i { margin-right: 4px; color: var(--success); }

/* ---------- Spinner ---------- */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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