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

:root {
  --accent:    #1d4ed8;
  --accent-h:  #1e40af;
  --surface:   #ffffff;
  --bg:        #f1f5f9;
  --border:    #e2e8f0;
  --text:      #0f172a;
  --muted:     #64748b;
  --success:   #15803d;
  --success-bg:#dcfce7;
  --error:     #b91c1c;
  --error-bg:  #fee2e2;
  --warn-bg:   #fefce8;
  --warn:      #a16207;
  --radius:    10px;
  --shadow:    0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
}

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

/* ── Header ── */
.header {
  background: var(--accent);
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.header-inner {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  height: 100%;
  position: relative;
}
.logo { color: #fff; font-size: 16px; font-weight: 600; letter-spacing: .01em; }

/* ── Layout ── */
.main {
  margin: 32px 0;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 0;
}
#panel-upload { max-width: 1052px; margin-left: auto; margin-right: auto; }

/* ── Tabs (in header) ── */
.tabs-bar {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: 0;
  height: 100%;
  display: flex;
}
.tab {
  display: flex;
  align-items: center;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0 18px;
  font-size: 14px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s;
  border-radius: 0;
  white-space: nowrap;
  height: 100%;
}
.tab:hover {
  color: rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.08);
}
.tab.active {
  color: #fff;
  border-bottom-color: #fff;
}

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
}

/* ── Drop zone ── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: border-color .18s, background .18s;
  text-align: center;
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent);
  background: #eff6ff;
}
.drop-icon {
  width: 40px; height: 40px;
  color: var(--muted);
  margin-bottom: 4px;
}
.drop-label { font-weight: 500; color: var(--text); }
.drop-sub   { color: var(--muted); font-size: 13px; }
.browse-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

/* ── Steps ── */
.step {
  padding: 20px 0;
  border-top: 1px solid var(--border);
}
.step:first-child { border-top: none; padding-top: 0; }
.step[hidden] { display: none; }
.step-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
}
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Step 2 two-column layout ── */
.step-2-inner {
  display: flex;
  gap: 0;
  align-items: flex-start;
}
.file-list-col {
  flex: 0 0 auto;
  padding-right: 20px;
  border-right: 1px solid var(--border);
}
.preview-col { flex: 1; min-width: 0; padding-left: 20px; }
.preview-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 6px;
}
.pdf-preview {
  display: block;
  width: 100%;
  height: 440px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
}

/* ── File list ── */
.file-list {
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 6px 10px;
  align-items: center;
  justify-content: start;
}
.file-row { display: contents; }
.file-row-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  border: 1.5px dashed var(--border);
  border-radius: 4px;
  padding: 3px 10px;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.file-row-name:hover { border-color: var(--accent); }
.file-row-name.active { border-color: var(--accent); color: var(--accent); border-style: solid; }
.file-remove-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 0;
  cursor: pointer;
  transition: color .15s;
}
.file-remove-btn:hover { color: var(--error); }

/* ── Invoice type select ── */
.invoice-type-select {
  font-size: 13px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 6px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  justify-content: center;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 6px 12px;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }
.btn-sm { font-size: 13px; padding: 5px 10px; }
.btn-danger { background: var(--error-bg); color: var(--error); border: 1px solid #fecaca; }
.btn-danger:hover:not(:disabled) { background: #fecaca; }

/* ── Status ── */
.status {
  margin-top: 14px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.status.success { background: var(--success-bg); color: var(--success); }
.status.error   { background: var(--error-bg);   color: var(--error);   }
.status.loading { background: var(--warn-bg);     color: var(--warn);    }

/* ── Invoices section ── */
.invoices-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.invoices-header .card-title { margin-bottom: 0; }

.quarter-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding-left: 16px;
}
.quarter-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--muted);
  transition: color .15s, background .15s, border-color .15s;
  line-height: 1.6;
}
.quarter-badge:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: #eff6ff;
}
.quarter-badge.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.invoices-preview-section {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
}
.invoices-preview-section[hidden] { display: none; }
.invoices-pdf-preview { height: 520px; }

.loading, .empty {
  text-align: center;
  padding: 40px;
  color: var(--muted);
  font-size: 13px;
}

/* ── Table ── */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  padding: 5px 14px;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th.sortable { padding: 0; }
.sort-btn,
.emails-sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 5px 14px;
  background: none;
  border: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}
.sort-btn:hover,
.emails-sort-btn:hover { color: var(--text); }
.sort-btn.active,
.emails-sort-btn.active { color: var(--accent); }
.sort-icon { font-size: 10px; opacity: 0.3; line-height: 1; }
.sort-btn:hover .sort-icon,
.emails-sort-btn:hover .sort-icon { opacity: 0.7; }
.sort-btn.active .sort-icon,
.emails-sort-btn.active .sort-icon { opacity: 1; }
.data-table td {
  padding: 5px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: #f8fafc; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #dbeafe;
  color: #1e40af;
}
.badge-email  { background: #dcfce7; color: #15803d; }
.badge-manual { background: #fef3c7; color: #92400e; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.no-extract { color: var(--muted); font-style: italic; font-size: 12px; }
.actions { display: flex; gap: 6px; }

.row-active td { background: #eff6ff !important; }

.attachment-tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  white-space: nowrap;
  margin: 1px 2px 1px 0;
}
.attachment-tag-green {
  background: #dcfce7;
  border-color: #86efac;
  color: #166534;
}
.attachment-tag-red {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #991b1b;
}
.attachment-list { white-space: normal; max-width: 280px; }

/* ── Email preview ── */
.email-preview { font-size: 13px; }
.email-meta-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 8px 14px;
  margin-bottom: 20px;
  align-items: start;
}
.email-meta-key {
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  padding-top: 1px;
}
.email-body-section { margin-bottom: 24px; }
.email-attachments-preview { padding-top: 24px; border-top: 1px solid var(--border); }
.email-body-text {
  font-family: inherit;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 14px;
  max-height: 420px;
  overflow-y: auto;
  line-height: 1.6;
  color: var(--text);
}

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

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay[hidden] { display: none; }
.modal-dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  padding: 28px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.modal-desc {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}
.modal-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0 14px;
}
.modal-section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: 10px;
}
.modal-settings-checks {
  margin-bottom: 20px;
}
.modal-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.modal-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .15s;
}
.modal-input:focus { border-color: var(--accent); }
.modal-status {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
}
.modal-status.success { background: var(--success-bg); color: var(--success); }
.modal-status.error   { background: var(--error-bg);   color: var(--error);   }
.modal-status.loading { background: var(--warn-bg);     color: var(--warn);    }
.modal-status[hidden] { display: none; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.btn-primary-sm {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn-primary-sm:hover:not(:disabled) { background: var(--accent-h); }
.btn-primary-sm:disabled { opacity: .45; cursor: not-allowed; }

.col-hidden { display: none !important; }

.btn.icon-only { padding: 5px 6px; }

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.preview-header .preview-label { margin-bottom: 0; }

.col-settings-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 16px;
  margin-bottom: 20px;
}
.col-check-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  cursor: pointer;
}
.col-check-label input { cursor: pointer; }
.col-check-all {
  grid-column: 1 / -1;
  font-weight: 600;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 2px;
}

@media (max-width: 640px) {
  .main { padding: 0 12px; margin: 16px auto; }
  .card { padding: 20px 16px; }
}
