/* ============================================================
   CapIQ Hyperlinker V1
   Calm, minimal single-column page (720px) inspired by Linear
   / Stripe. Warm paper bg, near-black ink, single indigo accent,
   semantic green/amber/red for status only. Inter for UI,
   JetBrains Mono for data labels and meta.
   ============================================================ */

/* ----- design tokens --------------------------------------------------- */
:root {
  --bg:        #fafaf7;
  --surface:   #ffffff;
  --surface2:  #f5f4ef;
  --line:      #e7e5dd;
  --line-soft: #efede6;

  --ink:  #15140f;
  --ink2: #3a3934;
  --ink3: #76746c;
  --ink4: #a6a39a;

  --accent:    #2c3e8c;
  --accent-bg: #eef0fa;

  --ok:     #2f7d4a;
  --ok-bg:  #eaf3ec;
  --warn:   #a86b00;
  --warn-bg:#fbf1dc;
  --bad:    #b73a2a;
  --bad-bg: #fbece8;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

/* ----- reset / base ---------------------------------------------------- */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
::selection { background: rgba(44, 62, 140, 0.13); }

@keyframes capiq-spin  { to { transform: rotate(360deg); } }
@keyframes capiq-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(47,125,74,0.40); }
  70%  { box-shadow: 0 0 0 8px rgba(47,125,74,0); }
  100% { box-shadow: 0 0 0 0 rgba(47,125,74,0); }
}

/* ----- shell ----------------------------------------------------------- */
.page {
  min-height: 100vh;
  background: var(--bg);
}
.column {
  max-width: 720px;
  margin: 0 auto;
  padding: 0 32px 96px;
}

/* ----- header ---------------------------------------------------------- */
.hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 56px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ink);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--surface);
  display: grid; place-items: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.3px;
}
.brand-name {
  font-family: var(--sans);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.1px;
}
.brand-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink4);
  margin-left: 8px;
}
.nav {
  display: flex;
  align-items: center;
  gap: 18px;
}
.nav a {
  font-size: 13px;
  color: var(--ink3);
}
.nav a:hover { color: var(--ink2); text-decoration: none; }
.nav-divider {
  width: 1px; height: 14px;
  background: var(--line);
}
.nav-user {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px;
  color: var(--ink2);
}

/* ----- typography utilities ------------------------------------------- */
.eyebrow {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--ink3);
}
.eyebrow-warn { color: var(--warn); }
.eyebrow-bad  { color: var(--bad); }

.title-xl {
  font-family: var(--sans);
  font-size: 40px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.8px;
  color: var(--ink);
  margin: 0;
}
.title-lg {
  font-family: var(--sans);
  font-size: 32px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.6px;
  color: var(--ink);
  margin: 0;
}
.lead {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink3);
  margin: 14px 0 36px;
  max-width: 520px;
}
.muted   { color: var(--ink3); }
.muted-2 { color: var(--ink2); }
.mono    { font-family: var(--mono); }

/* ----- pills ----------------------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface2);
  color: var(--ink2);
  border: 1px solid var(--line);
}
.pill-accent { background: var(--accent-bg); color: var(--accent); border-color: transparent; }
.pill-ok     { background: var(--ok-bg);     color: var(--ok);     border-color: transparent; }
.pill-warn   { background: var(--warn-bg);   color: var(--warn);   border-color: transparent; }
.pill-bad    { background: var(--bad-bg);    color: var(--bad);    border-color: transparent; }

.dot {
  width: 6px; height: 6px;
  border-radius: 999px;
  display: inline-block;
  flex-shrink: 0;
  background: var(--ink3);
}
.dot-ok   { background: var(--ok); }
.dot-warn { background: var(--warn); }
.dot-bad  { background: var(--bad); }
.dot.pulse { animation: capiq-pulse 1.6s infinite; }

/* ----- buttons --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 16px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .08s, color .12s;
  text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(0.5px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-sm { padding: 8px 12px;  font-size: 13px; }
.btn-lg { padding: 14px 20px; font-size: 14.5px; }

.btn-primary {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}
.btn-primary:hover { background: #2a2924; border-color: #2a2924; color: var(--surface); }

.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
}
.btn-ghost:hover { background: var(--surface2); }

.btn-danger {
  background: var(--bad);
  color: #fff;
  border-color: var(--bad);
}
.btn-danger:hover { background: #9a3022; border-color: #9a3022; color: #fff; }

.btn-on-ink {
  background: var(--surface);
  color: var(--ink);
  border: none;
  border-radius: 7px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 500;
}
.btn-on-ink:hover { background: #f0eee7; color: var(--ink); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

/* ----- flashes --------------------------------------------------------- */
.flashes { margin-bottom: 24px; }
.flash {
  font-family: var(--sans);
  font-size: 13.5px;
  background: var(--warn-bg);
  color: var(--warn);
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid rgba(168,107,0,0.18);
  margin-bottom: 8px;
}

/* ----- idle: dropzone -------------------------------------------------- */
.dropzone {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 36px 32px;
  width: 100%;
  background: var(--surface);
  border: 1.5px dashed var(--line);
  border-radius: 12px;
  cursor: pointer;
  font-family: var(--sans);
  text-align: left;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag, .dropzone.has-file {
  border-color: var(--accent);
  background: var(--accent-bg);
}
.dropzone input[type="file"] {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}
.dz-icon {
  width: 56px; height: 56px;
  border-radius: 12px;
  background: var(--surface2);
  color: var(--ink2);
  display: grid; place-items: center;
  flex-shrink: 0;
}
.dz-body { flex: 1; min-width: 0; }
.dz-title {
  font-size: 16.5px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 4px;
}
.dz-title .browse {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.dz-sub {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink3);
}
.dz-filename {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  margin-top: 8px;
  min-height: 18px;
  display: none;
}
.dropzone.has-file .dz-filename { display: block; }

/* ----- idle: requirements grid ---------------------------------------- */
.requirements {
  margin-top: 40px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  border-top: 1px solid var(--line);
}
.requirements > div {
  padding: 20px 24px 4px 0;
  border-right: 1px solid var(--line);
}
.requirements > div:first-child { padding-left: 0; }
.requirements > div:nth-child(2) { padding-left: 24px; }
.requirements > div:last-child  { padding-left: 24px; border-right: none; }
.requirement-text {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--ink2);
  margin-top: 8px;
}

/* ----- file row -------------------------------------------------------- */
.file-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.file-thumb {
  position: relative;
  width: 38px; height: 44px;
  border-radius: 6px;
  background: var(--surface2);
  display: grid; place-items: center;
  color: var(--ink3);
  flex-shrink: 0;
  overflow: hidden;
}
.file-thumb-tag {
  position: absolute;
  bottom: 3px;
  font-family: var(--mono);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--ink3);
}
.file-meta { flex: 1; min-width: 0; }
.file-name {
  font-size: 14.5px;
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-sub {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink3);
  margin-top: 3px;
}
.file-accounts {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink4);
  margin-top: 4px;
  letter-spacing: 0.01em;
}

/* ----- progress + steps ------------------------------------------------ */
.steps { margin-top: 28px; }
.progress {
  height: 4px;
  background: var(--surface2);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 24px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width .4s ease;
}
.progress.error .progress-bar { background: var(--bad); }

.step-list { list-style: none; padding: 0; margin: 0; }
.step {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  gap: 14px;
  padding: 12px 0;
  align-items: center;
  border-bottom: 1px solid var(--line-soft);
}
.step:last-child { border-bottom: none; }
.step-glyph {
  width: 22px; height: 22px;
  border-radius: 999px;
  display: grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink4);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
}
.step.done    .step-glyph { background: var(--ok);    border-color: var(--ok);    color: #fff; }
.step.active  .step-glyph { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.step.failed  .step-glyph { background: var(--bad);   border-color: var(--bad);   color: #fff; }
.step.active  .spin       { animation: capiq-spin 1.2s linear infinite; }
.step-label {
  font-size: 14.5px;
  color: var(--ink);
  font-weight: 400;
}
.step.active  .step-label,
.step.failed  .step-label { font-weight: 500; }
.step.done    .step-label { color: var(--ink3); }
.step.failed  .step-label { color: var(--bad); }
.step-detail {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink3);
  margin-top: 2px;
}
.step-status {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink4);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.step.done    .step-status { color: var(--ok); }
.step.active  .step-status { color: var(--accent); }
.step.failed  .step-status { color: var(--bad); }

/* ----- progress meta + cancel row ------------------------------------- */
.meta-row {
  margin-top: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.meta-row .meta-text {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink3);
}

/* ----- success: stats grid -------------------------------------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 28px;
}
.stat-cell {
  padding: 20px 22px;
  border-right: 1px solid var(--line);
}
.stat-cell:last-child { border-right: none; }
.stat-value {
  font-family: var(--sans);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.6px;
  color: var(--ink);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.stat-value.ok   { color: var(--ok); }
.stat-value.warn { color: var(--warn); }

/* ----- success: download CTA ------------------------------------------ */
.download-cta {
  margin-top: 16px;
  padding: 20px;
  background: var(--ink);
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: var(--surface);
}
.download-cta-icon {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  display: grid; place-items: center;
  flex-shrink: 0;
  color: var(--surface);
}
.download-cta-body { flex: 1; min-width: 0; }
.download-cta-title { font-size: 15px; font-weight: 500; }
.download-cta-sub {
  font-family: var(--mono);
  font-size: 11.5px;
  color: #bbb8ad;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ----- success: unmatched list ---------------------------------------- */
.unmatched {
  margin-top: 28px;
}
.unmatched-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}
.unmatched-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}
.unmatched-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 16px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line-soft);
}
.unmatched-row:last-child { border-bottom: none; }
.unmatched-name { font-size: 14px; color: var(--ink); }
.unmatched-reason {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink3);
  margin-top: 2px;
}
.unmatched-link {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
}
.unmatched-empty {
  padding: 14px 18px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink3);
}

/* ----- error block ----------------------------------------------------- */
.error-block {
  margin-top: 28px;
  background: var(--bad-bg);
  border: 1px solid rgba(183, 58, 42, 0.20);
  border-radius: 10px;
  padding: 20px 22px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.error-icon {
  width: 28px; height: 28px;
  border-radius: 999px;
  background: var(--bad);
  color: #fff;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.error-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.2px;
  margin-top: 6px;
}
.error-text {
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink2);
  margin-top: 8px;
  max-width: 540px;
  white-space: pre-wrap;
}
.error-text code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--line);
}
.error-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

/* On-hold variant — same shape as .error-block but warm-amber tones
   to convey "waiting" rather than "broken". */
.error-block.onhold-block {
  background: var(--warn-bg);
  border-color: rgba(168, 107, 0, 0.22);
}
.error-icon.onhold-icon {
  background: var(--warn);
  color: #fff;
}

/* On-hold state pill — uses the warn palette already in :root. */
.state-on_hold {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: transparent;
}

/* The raw error pane sits inside .error-block, hidden by default
   behind the "View raw error" button. */
.raw-error {
  margin: 14px 0 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--ink2);
  white-space: pre-wrap;
}

/* ----- activity log ---------------------------------------------------- */
.log-section { margin-top: 20px; }
.log-section-label { margin-bottom: 8px; }
.log-stream {
  margin: 0;
  padding: 14px;
  background: #0f0e0a;
  color: #c9c6bc;
  border-radius: 10px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  max-height: 260px;
  overflow: auto;
}

/* ----- account picker (per-upload) ------------------------------------ */
.accounts-picker {
  margin-top: 22px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.accounts-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.accounts-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
}
.accounts-actions a {
  color: var(--ink3);
  text-decoration: none;
}
.accounts-actions a:hover { color: var(--accent); }
.accounts-sep { color: var(--ink4); }
.accounts-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.accounts-loading,
.accounts-empty {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink3);
  padding: 4px 0;
}
.accounts-hint {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink3);
  line-height: 1.5;
}
.account-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface2);
  border: 1px solid var(--line);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink3);
  transition: background .12s, border-color .12s, color .12s;
  user-select: none;
}
.account-pill:hover {
  border-color: var(--ink4);
}
.account-pill input[type=checkbox] {
  /* The native checkbox is hidden — the .account-pill-mark is the
     visible affordance, swapped via :checked sibling state. */
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}
.account-pill-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px; height: 14px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: transparent;
  font-size: 10px;
  font-weight: 700;
}
.account-pill input[type=checkbox]:checked ~ .account-pill-mark {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--surface);
}
.account-pill:has(input:checked) {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

/* ----- modal (clear-history confirmation) ----------------------------- */

/* native <dialog> needs `display: block` when open; the default UA
   stylesheet centres it on the viewport via `margin: auto`. */
.modal {
  padding: 0;
  border: none;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(17, 17, 17, 0.18), 0 1px 0 var(--line);
  max-width: 480px;
  width: calc(100% - 40px);
  font-family: var(--sans);
}
.modal::backdrop {
  background: rgba(15, 15, 15, 0.45);
  backdrop-filter: blur(2px);
}
.modal-card {
  padding: 24px 24px 20px;
  margin: 0;
}
.modal-title {
  font-family: var(--sans);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin-bottom: 12px;
}
.modal-body {
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink2);
}
.modal-body p { margin: 0 0 10px; }
.modal-body code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface2);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--line);
  color: var(--ink2);
}
.modal-list {
  margin: 12px 0 4px;
  padding-left: 18px;
  font-size: 13px;
  color: var(--ink2);
}
.modal-list li {
  margin-bottom: 4px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink2);
}
.modal-list code { font-size: 11.5px; }
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ----- footer ---------------------------------------------------------- */
.ftr {
  margin-top: 80px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink4);
}
.ftr a { color: var(--ink4); }
.ftr a:hover { color: var(--ink3); text-decoration: none; }
.ftr-links { display: flex; gap: 16px; }

/* ----- responsive ----------------------------------------------------- */
@media (max-width: 640px) {
  .column { padding: 0 20px 64px; }
  .title-xl { font-size: 30px; }
  .title-lg { font-size: 24px; }
  .requirements { grid-template-columns: 1fr; }
  .requirements > div {
    padding: 16px 0 !important;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .requirements > div:last-child { border-bottom: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-cell { border-right: none; border-bottom: 1px solid var(--line); }
  .stat-cell:nth-child(odd) { border-right: 1px solid var(--line); }
  .stat-cell:nth-last-child(-n+2) { border-bottom: none; }
  .unmatched-row { grid-template-columns: 1fr; gap: 6px; }
}
