:root {
  --bg: #0f1419;
  --panel: #1a2029;
  --panel-2: #222a35;
  --text: #e6e9ef;
  --muted: #8b95a5;
  --accent: #4c8bf5;
  --border: #2c3441;
  --high: #2ec27e;
  --medium: #e0a106;
  --low: #e0533d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; }

main { max-width: 1180px; margin: 24px auto; padding: 0 16px; }
/* Upload stays comfortably narrow & centred; the review screen uses full width. */
#upload-section { max-width: 820px; margin-left: auto; margin-right: auto; }

/* Review screen: editable fields on the left, document preview on the right. */
.review-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .review-split { grid-template-columns: 1fr; }
  .review-right { position: static !important; }
}
.review-right { position: sticky; top: 16px; }
.doc-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.doc-tab {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 12px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-tab.active { color: #fff; background: var(--accent); border-color: var(--accent); }
.doc-viewer {
  background: #0c1016;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  max-height: calc(100vh - 150px);
  overflow: auto;
}
.doc-image { width: 100%; height: auto; border-radius: 4px; display: block; }
.doc-text {
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-size: 12.5px;
  margin: 0;
}
.doc-loading, .doc-noprev {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 48px 16px;
  text-align: center;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  margin-bottom: 20px;
}
.card h2 { margin-top: 0; font-size: 16px; }

.muted { color: var(--muted); font-size: 14px; }

.dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 32px;
  text-align: center;
  color: var(--muted);
  transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--accent); background: var(--panel-2); }

/* File preview grid */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin: 16px 0;
}
.file-card {
  position: relative;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.thumb {
  position: relative;
  height: 120px;
  background: #0c1016;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.thumb.clickable { cursor: zoom-in; }
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.thumb-icon { width: 44px; height: 44px; color: var(--muted); }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.thumb-open {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0, 0, 0, .6);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 12px;
  padding: 3px 7px;
  gap: 4px;
}
.file-meta {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 12px;
}
.file-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  z-index: 2;
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, .55);
  color: var(--low);
  justify-content: center;
}
.file-remove:hover { background: var(--low); color: #fff; }

/* Preview modal content */
.pdf-modal-host {
  width: 100%;
  max-height: 72vh;
  overflow: auto;
  background: #0c1016;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}
.pdf-page {
  display: block;
  margin: 0 auto 10px;
  border-radius: 3px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .5);
}
.pdf-more { text-align: center; margin: 4px 0 2px; }

/* Editable email preview modal */
.email-preview { text-align: left; }
.email-preview .ep-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  margin: 10px 2px 4px;
}
.email-preview .ep-input,
.email-preview .ep-body {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
}
.email-preview .ep-to { color: var(--muted); cursor: not-allowed; }
.email-preview .ep-message {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.email-preview .ep-frame {
  width: 100%;
  height: 420px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
}
.preview-text {
  text-align: left;
  max-height: 60vh;
  overflow: auto;
  background: #0c1016;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.actions { display: flex; align-items: center; gap: 14px; margin-top: 12px; }
.status { font-size: 14px; color: var(--muted); }

/* Extraction progress bar */
.progress-wrap { margin-top: 14px; }
.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  margin-bottom: 6px;
}
.progress-head #progress-label { display: inline-flex; align-items: center; gap: 6px; color: var(--text); }
.progress-track {
  height: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--accent), #6fa8ff);
  background-size: 200% 100%;
  transition: width .25s ease;
  animation: progress-shimmer 1.4s linear infinite;
}
@keyframes progress-shimmer {
  from { background-position: 200% 0; }
  to { background-position: 0 0; }
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
}
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary { background: var(--panel-2); color: var(--text); border: 1px solid var(--border); }
button.link {
  background: none;
  color: var(--accent);
  padding: 0;
  text-decoration: underline;
  font-size: inherit;
}

.fields { display: grid; gap: 14px; margin: 16px 0; }
.field-row { display: flex; flex-direction: column; gap: 4px; }
.field-row label {
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.field-row input, .field-row textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.field-row.conf-low input, .field-row.conf-low textarea { border-color: var(--low); }
.field-row.conf-medium input, .field-row.conf-medium textarea { border-color: var(--medium); }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-high { background: rgba(46,194,126,.18); color: var(--high); }
.badge-medium { background: rgba(224,161,6,.18); color: var(--medium); }
.badge-low { background: rgba(224,83,61,.18); color: var(--low); }

.source-note { margin: 0; font-size: 12px; color: var(--muted); }

.notes {
  background: rgba(224,161,6,.1);
  border: 1px solid var(--medium);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}
.notes ul { margin: 6px 0 0; padding-left: 18px; }

.error { color: var(--low); font-size: 13px; }

/* ─── Toast system ────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 11px 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45);
  color: var(--text);
  font-size: 14px;
  opacity: 0;
  transform: translateX(24px);
  transition: opacity .25s ease, transform .25s ease;
}
.toast.toast-in { opacity: 1; transform: none; }
.toast.toast-out { opacity: 0; transform: translateX(24px); }
.toast-success { border-left-color: var(--high); }
.toast-error { border-left-color: var(--low); }
.toast-info { border-left-color: var(--accent); }
.toast-icon { width: 18px; height: 18px; flex: 0 0 auto; margin-top: 1px; }
.toast-success .toast-icon { color: var(--high); }
.toast-error .toast-icon { color: var(--low); }
.toast-info .toast-icon { color: var(--accent); }
.toast-msg { flex: 1; line-height: 1.4; word-break: break-word; }
.toast-close {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0;
  cursor: pointer;
  flex: 0 0 auto;
}
.toast-close:hover { color: var(--text); }
@media (max-width: 480px) {
  .toast-container { left: 12px; right: 12px; max-width: none; }
}

/* ─── Results screen ──────────────────────────────────────────────────────── */
.results-list { display: grid; gap: 8px; }
.result-row {
  display: grid;
  grid-template-columns: 210px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.result-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.result-value {
  font-size: 14px;
  color: var(--text);
  word-break: break-word;
  user-select: all;            /* one click selects the whole value */
}
.result-value.empty { color: var(--muted); font-style: italic; }
.copy-btn {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--accent);
  padding: 6px 12px;
  font-size: 13px;
  white-space: nowrap;
}
.copy-btn:hover:not(:disabled) { background: var(--accent); color: #fff; }
.copy-btn.copied { background: var(--high); border-color: var(--high); color: #fff; }
.copy-btn:disabled { opacity: .4; cursor: not-allowed; }
@media (max-width: 640px) {
  .result-row { grid-template-columns: 1fr; gap: 6px; }
  .result-row .copy-btn { justify-self: start; }
}

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card label { font-size: 13px; font-weight: 600; margin-top: 8px; }
.login-card input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 9px 11px;
  font-size: 14px;
}
.login-card button { margin-top: 12px; }
.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}
.login-logo .icon { width: 40px; height: 40px; color: var(--accent); }
.login-logo-img { height: 44px; width: auto; }

/* ─── Icons ───────────────────────────────────────────────────────────────── */
.icon { width: 20px; height: 20px; vertical-align: -4px; }
.icon-sm { width: 15px; height: 15px; vertical-align: -2px; }
.topbar h1 { display: flex; align-items: center; gap: 8px; }
.topbar h1 .icon { color: var(--accent); }
.brand-mark { width: 26px; height: 26px; border-radius: 6px; }
button { display: inline-flex; align-items: center; gap: 6px; }
button.link { display: inline-flex; align-items: center; gap: 4px; }
button.link.danger { color: var(--low); }

/* Step number badges in section headings */
.card h2 { display: flex; align-items: center; gap: 9px; }
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

/* Dropzone icon */
.dropzone-icon {
  width: 40px;
  height: 40px;
  color: var(--muted);
  margin-bottom: 8px;
}
.dropzone.drag .dropzone-icon { color: var(--accent); }

/* File list rows as flex with remove on the right */
.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.file-list li > span:first-child { display: inline-flex; align-items: center; gap: 6px; }

/* ─── SweetAlert2 dark theme ───────────────────────────────────────────────── */
.swal2-popup {
  background: var(--panel) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  border-radius: 10px !important;
}
.swal2-title, .swal2-html-container { color: var(--text) !important; }
.swal2-styled.swal2-confirm {
  background: var(--accent) !important;
  border-radius: 6px !important;
  box-shadow: none !important;
}
.swal2-styled.swal2-cancel {
  background: var(--panel-2) !important;
  border: 1px solid var(--border) !important;
  border-radius: 6px !important;
  box-shadow: none !important;
}
.swal2-toast {
  background: var(--panel) !important;
  border: 1px solid var(--border) !important;
  color: var(--text) !important;
}
.swal2-toast .swal2-title { color: var(--text) !important; }
