/* Capmex — single stylesheet. Calm, premium, ink accent, 8px grid. */

:root {
  --ink: #10233b;
  --ink-soft: #3a4a5f;
  --muted: #6b7889;
  --line: #e4e8ee;
  --line-strong: #d3d9e2;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --accent: #1b3a6b;
  --accent-hover: #16305a;
  --accent-soft: #eef2f8;
  --danger: #a4282a;
  --danger-soft: #fbecec;
  --success: #1f6b46;
  --focus: #2f6df0;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-none: none;
  --maxw-narrow: 720px;
  --maxw-wide: 960px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Layout ---------- */

.wrap {
  width: 100%;
  margin: 0 auto;
  padding: 32px 20px 80px;
}
.wrap-narrow { max-width: var(--maxw-narrow); }
.wrap-wide { max-width: var(--maxw-wide); }

.stack { display: flex; flex-direction: column; gap: 16px; }
.inline { display: inline; margin: 0; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.flash-data { display: none; }

/* ---------- Top bar ---------- */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: var(--maxw-wide);
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.topbar-nav {
  display: flex;
  gap: 4px;
  margin-left: 8px;
  flex-wrap: wrap;
}
.navlink {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}
.navlink:hover { color: var(--ink); background: var(--accent-soft); }
.navlink-active { color: var(--accent); font-weight: 600; }
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.chip {
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  padding: 4px 10px;
  border-radius: 999px;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Auth / setup / status ---------- */

.page-auth { display: flex; min-height: 100vh; }
.auth-wrap, .status-wrap {
  margin: auto;
  width: 100%;
  max-width: 400px;
  padding: 24px;
}
.auth-card, .status-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
}
.wordmark {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.auth-sub { color: var(--muted); font-size: 14px; margin: 4px 0 24px; }
.auth-title { font-size: 18px; margin: 0 0 8px; }
.auth-lead { color: var(--ink-soft); font-size: 14px; margin: 0 0 20px; }
.status-code { font-size: 40px; font-weight: 700; margin: 24px 0 4px; color: var(--ink); }
.status-msg { color: var(--muted); margin: 0; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.field-help { font-size: 12px; color: var(--muted); }
.input {
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input::placeholder { color: #9aa5b4; }
.input:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(47, 109, 240, 0.18);
}
.select { appearance: none; background-image: none; cursor: pointer; }

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-soft); }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn-danger { color: var(--danger); border-color: #e6c9c9; }
.btn-danger:hover { background: var(--danger-soft); }

.linkbtn {
  font: inherit;
  font-size: 14px;
  color: var(--muted);
  background: none;
  border: none;
  padding: 6px 4px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.linkbtn:hover { color: var(--ink); }
.linkbtn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Alerts ---------- */

.alert {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  margin-bottom: 18px;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid #eccccc; }
.alert-credential {
  background: var(--accent-soft);
  border: 1px solid var(--line-strong);
  color: var(--ink);
}
.cred-label { font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; }
.cred-body { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cred-user { font-weight: 600; }
.cred-pw {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 14px;
  user-select: all;
}

/* ---------- Drop zone ---------- */

.dropzone {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 44px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.dropzone.is-drag {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone-icon { color: var(--accent); margin-bottom: 12px; }
.dropzone-headline { font-size: 16px; font-weight: 600; margin: 0 0 6px; color: var(--ink); }
.dropzone-hint { font-size: 13px; color: var(--muted); margin: 0; }

/* ---------- Batch summary + session banner ---------- */

.batch-summary {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-top: 16px;
}
.batch-summary[hidden] { display: none; }
.batch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.batch-text { font-size: 13px; color: var(--ink-soft); font-weight: 600; }
.batch-bar {
  height: 8px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
}
.batch-bar-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width .2s ease;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--danger-soft);
  border: 1px solid #eccccc;
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 14px;
  padding: 12px 14px;
  margin-bottom: 20px;
}
.banner[hidden] { display: none; }
.banner a { color: var(--danger); font-weight: 600; text-underline-offset: 3px; }

.upload-retry { margin-left: 8px; flex-shrink: 0; }

.muted-note { font-size: 13px; color: var(--muted); margin: 10px 4px 0; }

/* ---------- Upload progress rows ---------- */

.upload-list { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.upload-row {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}
.upload-row-top { display: flex; align-items: center; gap: 10px; }
.upload-name {
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.upload-status { font-size: 13px; color: var(--muted); flex-shrink: 0; }
.upload-row.is-done .upload-status { color: var(--success); }
.upload-row.is-error { border-color: #eccccc; background: var(--danger-soft); }
.upload-row.is-error .upload-status { color: var(--danger); }
.progress {
  height: 6px;
  background: var(--line);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 10px;
}
.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: 999px;
  transition: width .15s ease;
}
.upload-row.is-done .progress-bar { background: var(--success); }
.upload-row.is-done .progress, .upload-row.is-error .progress { display: none; }

/* ---------- Sections & doc list ---------- */

.panel-section { margin-top: 36px; }
.section-title { font-size: 15px; font-weight: 600; margin: 0 0 14px; color: var(--ink); }

.picker-row { display: flex; justify-content: flex-end; margin-top: 10px; }

.doc-list { display: flex; flex-direction: column; }
.doc-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.doc-row:last-child { border-bottom: none; }
.doc-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.doc-name { color: var(--ink); text-decoration: none; }
a.doc-name:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
a.doc-name:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.doc-meta { font-size: 13px; color: var(--muted); flex-shrink: 0; display: flex; gap: 6px; }
.doc-path { color: var(--muted); font-weight: 400; }
.empty { color: var(--muted); font-size: 14px; padding: 24px 4px; }

.doc-link { color: var(--ink); text-decoration: none; }
.doc-link:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.doc-link:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Cards / stats / toolbar ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 24px;
}
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-value { font-size: 22px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.stat-label { font-size: 13px; color: var(--muted); margin-top: 4px; }

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.toolbar .input { width: auto; flex: 1; min-width: 180px; }
.toolbar .select { flex: 0 0 auto; min-width: 160px; }
.date-field {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.date-label { font-size: 13px; color: var(--muted); }
.date-field .input { width: auto; flex: 0 0 auto; min-width: 0; }
.filter-summary {
  margin: -8px 0 20px;
  font-size: 13px;
  color: var(--muted);
}

.form-inline {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-inline .field { flex: 1; min-width: 180px; }

/* ---------- Tables ---------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow-x: auto;
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 620px; }
.table th, .table td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.table thead th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  background: #fbfcfd;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafbfc; }
.cell-name { font-weight: 500; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-num, .cell-date { color: var(--ink-soft); white-space: nowrap; }
.col-actions { text-align: right; }
.row-actions { display: inline-flex; gap: 8px; justify-content: flex-end; }
.empty-cell { text-align: center; color: var(--muted); padding: 32px 16px; }

.badge {
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
}
.badge-on { background: #e7f2ec; color: var(--success); }
.badge-off { background: #f0f1f3; color: var(--muted); }

/* ---------- Preview modal ---------- */

.modal { position: fixed; inset: 0; z-index: 40; }
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 35, 59, 0.55);
}
.modal-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  width: min(920px, calc(100vw - 32px));
  height: min(82vh, 900px);
  margin: 6vh auto 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.modal-title {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}
.modal-close {
  font: inherit;
  font-size: 20px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  cursor: pointer;
}
.modal-close:hover { color: var(--ink); background: var(--accent-soft); }
.modal-close:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.modal-body {
  flex: 1;
  position: relative;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}
.modal-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: var(--muted);
}
.modal-body iframe.preview-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}
.modal-body img.preview-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}
body.modal-open { overflow: hidden; }

/* ---------- "No preview" page (inside the iframe) ---------- */

.page-nopreview { display: flex; min-height: 100vh; background: var(--bg); }
.nopreview-wrap { margin: auto; width: 100%; max-width: 420px; padding: 24px; }
.nopreview-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 32px 28px;
  text-align: center;
}
.nopreview-icon { color: var(--muted); margin-bottom: 12px; }
.nopreview-msg { font-size: 15px; font-weight: 600; color: var(--ink); margin: 0 0 12px; }
.nopreview-meta { font-size: 13px; color: var(--muted); margin: 0 0 20px; line-height: 1.7; }

/* ---------- Toasts ---------- */

.toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 50;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  min-width: 220px;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity .18s ease, transform .18s ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr; }
  .topbar-inner { gap: 10px; }
  .topbar-nav { order: 3; width: 100%; margin-left: 0; }
  .topbar-right { margin-left: auto; }
  .chip { max-width: 45vw; }
  .wrap { padding: 24px 16px 64px; }
  .form-inline .btn { flex: 1; }
}

@media (max-width: 380px) {
  .auth-card, .status-card { padding: 24px 18px; }
  .dropzone { padding: 32px 16px; }
}
