:root {
  --bg0: #04111c;
  --bg1: #07203a;
  --ink: #e8f4ff;
  --dim: #6f97b5;
  --teal: #2fd3c0;
  --blue: #3aa0ff;
  --gold: #ffcf6b;
  --lane-draft: #3a5d7a;
  --lane-review: #3aa0ff;
  --lane-sent: #ffcf6b;
  --lane-signed: #2fd3c0;
}

* { box-sizing: border-box; }

/* ---------- Scrollbars (theme-matched) ---------- */
* { scrollbar-width: thin; scrollbar-color: rgba(58,160,255,0.45) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: linear-gradient(var(--blue), var(--teal));
  border-radius: 8px; border: 2px solid transparent; background-clip: padding-box;
  opacity: .5;
}
::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(var(--teal), var(--blue));
  background-clip: padding-box;
}
::-webkit-scrollbar-corner { background: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(120% 100% at 50% 0%, var(--bg1), var(--bg0));
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
}

#current {
  position: fixed;
  inset: 0;
  z-index: 0;
  opacity: 0.55;
}

.hidden { display: none !important; }

/* ---------- Login ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(2, 10, 18, 0.7);
  backdrop-filter: blur(6px);
}
.login-card {
  display: flex; flex-direction: column; gap: 14px;
  padding: 38px 34px; width: 320px;
  background: rgba(10, 30, 50, 0.65);
  border: 1px solid rgba(90, 180, 230, 0.25);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), inset 0 0 40px rgba(58,160,255,0.08);
}
.brand { font-size: 30px; font-weight: 800; letter-spacing: 6px; }
.sub { color: var(--dim); margin-top: -8px; letter-spacing: 2px; }
.login-card input, .sign-pop input {
  background: rgba(4, 18, 30, 0.8);
  border: 1px solid rgba(90, 180, 230, 0.3);
  color: var(--ink); padding: 12px 14px; border-radius: 10px; font-size: 15px;
  outline: none;
}
.login-card input:focus, .sign-pop input:focus { border-color: var(--blue); }
.login-card button {
  background: linear-gradient(120deg, var(--blue), var(--teal));
  color: #021018; border: 0; padding: 12px; border-radius: 10px;
  font-weight: 700; cursor: pointer; font-size: 15px;
}
.err { color: #ff8aa0; font-size: 13px; min-height: 16px; }

/* ---------- App shell ---------- */
#app { position: relative; z-index: 2; height: 100vh; display: flex; flex-direction: column; }

header {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 22px; border-bottom: 1px solid rgba(90,180,230,0.12);
  /* solid translucent bg instead of backdrop blur — avoids per-frame
     re-blur of the animated canvas behind it (flicker). */
  background: rgba(5, 18, 31, 0.72);
}
.title { font-weight: 800; letter-spacing: 3px; white-space: nowrap; }
.logo { color: var(--ink); }
.dim { color: var(--dim); font-weight: 500; margin-left: 6px; letter-spacing: 1px; }

.projects { display: flex; gap: 8px; overflow-x: auto; flex: 1; padding: 2px; scrollbar-width: thin; }
.proj {
  white-space: nowrap; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  background: rgba(12, 36, 58, 0.6); border: 1px solid rgba(90,180,230,0.18);
  color: var(--dim); font-size: 13px; transition: all .25s;
}
.proj:hover { color: var(--ink); border-color: rgba(90,180,230,0.5); }
.proj.active {
  color: #021018; font-weight: 700;
  background: linear-gradient(120deg, var(--blue), var(--teal));
  border-color: transparent;
}

.header-right { display: flex; gap: 8px; }
.ghost {
  background: transparent; color: var(--dim); border: 1px solid rgba(90,180,230,0.2);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; transition: all .2s;
}
.ghost:hover { color: var(--ink); border-color: var(--blue); }
.ghost.on { color: #021018; background: var(--gold); border-color: transparent; font-weight: 700; }
#box-chip.on { background: var(--teal); }
.hint { font-size: 11px; color: var(--dim); line-height: 1.5; }

/* ---------- River ---------- */
.river { flex: 1; display: flex; gap: 0; padding: 18px; overflow: hidden; }
.lane {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  position: relative; border-radius: 16px; margin: 0 7px;
  background: linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0));
}
.lane::before {
  content: ""; position: absolute; inset: 0; border-radius: 16px;
  border: 1px solid rgba(90,180,230,0.08); pointer-events: none;
}
.lane-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; font-size: 12px; letter-spacing: 2px; text-transform: uppercase;
  color: var(--dim);
}
.lane-dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 12px currentColor; }
.lane[data-lane="draft"]  .lane-dot { color: var(--lane-draft); background: var(--lane-draft); }
.lane[data-lane="review"] .lane-dot { color: var(--lane-review); background: var(--lane-review); }
.lane[data-lane="sent"]   .lane-dot { color: var(--lane-sent); background: var(--lane-sent); }
.lane[data-lane="signed"] .lane-dot { color: var(--lane-signed); background: var(--lane-signed); }
.lane-count { margin-left: auto; opacity: .7; }

.lane-body { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 6px 10px 18px; scrollbar-width: thin; }

/* ---------- Card ---------- */
.card {
  position: relative; margin: 10px 2px; padding: 14px 14px 12px;
  border-radius: 14px; cursor: pointer;
  /* Fully opaque-ish gradient (no backdrop-filter): blurring the moving canvas
     behind every animated card caused per-frame repaint flicker. */
  background: linear-gradient(155deg, rgb(20, 46, 72), rgb(11, 29, 47));
  border: 1px solid rgba(120,190,240,0.18);
  box-shadow: 0 10px 26px rgba(0,0,0,0.35);
  transform: translateZ(0);
  will-change: transform;
}
.card:hover { border-color: rgba(120,190,240,0.55); }
.card .doc-name { font-weight: 600; font-size: 14px; line-height: 1.3; word-break: break-word; }
.card .doc-meta { color: var(--dim); font-size: 11px; margin-top: 8px; display: flex; gap: 8px; flex-wrap: wrap; }
.card .tag {
  font-size: 10px; padding: 2px 7px; border-radius: 6px;
  background: rgba(90,180,230,0.12); color: var(--blue); letter-spacing: .5px;
}
.card .tag.src-up { background: rgba(47,211,192,0.15); color: var(--teal); }
.card .tag.src-gen { background: rgba(255,207,107,0.15); color: var(--gold); }
.card .edge {
  position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 3px;
  background: var(--blue); box-shadow: 0 0 12px var(--blue);
}
.card[data-lane="sent"] .edge { background: var(--gold); box-shadow: 0 0 12px var(--gold); }
.card[data-lane="signed"] .edge { background: var(--teal); box-shadow: 0 0 12px var(--teal); }
.card.demo .doc-name::after { content: " (demo)"; color: var(--gold); font-size: 10px; font-weight: 400; }

.card .ripple {
  position: absolute; inset: 0; border-radius: 14px; pointer-events: none;
  box-shadow: 0 0 0 0 rgba(255,207,107,0.6);
}

.empty {
  color: var(--dim); font-size: 12px; text-align: center; padding: 30px 10px; opacity: .6;
  font-style: italic;
}

/* ---------- Document modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 80;
  display: flex; align-items: center; justify-content: center;
  /* near-opaque solid (no backdrop-filter): blurring the animated canvas behind
     the overlay caused the previewer to flicker. */
  background: rgba(3, 12, 20, 0.95);
  padding: 24px;
}
.modal-card {
  display: flex; flex-direction: column;
  width: min(900px, 96vw); height: min(86vh, 900px);
  background: rgba(10, 28, 46, 0.98);
  border: 1px solid rgba(120,190,240,0.28); border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6); overflow: hidden; position: relative;
}
.modal-close {
  position: absolute; top: 12px; right: 14px; z-index: 2;
  background: rgba(8,22,38,0.8); color: var(--ink); border: 1px solid rgba(120,190,240,0.25);
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 18px; line-height: 1;
}
.modal-head { padding: 18px 20px 12px; border-bottom: 1px solid rgba(120,190,240,0.12); }
.modal-title { font-weight: 700; font-size: 16px; word-break: break-word; padding-right: 40px; }
.modal-sub { color: var(--dim); font-size: 12px; margin-top: 6px; }
.modal-sub .m-supplier { color: var(--teal); font-weight: 600; }

.modal-preview {
  flex: 1; min-height: 0; background: #0a1622; position: relative;
  display: flex; align-items: center; justify-content: center;
}
.preview-frame { width: 100%; height: 100%; border: 0; object-fit: contain; background: #0a1622; }
img.preview-frame { object-fit: contain; }
.preview-loading, .no-preview {
  color: var(--dim); font-size: 13px; text-align: center; padding: 20px; line-height: 1.6;
}
.no-preview .ghost { display: inline-block; margin-top: 10px; text-decoration: none; }

.modal-foot {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px;
  border-top: 1px solid rgba(120,190,240,0.12); flex-wrap: wrap;
}
.signer-label {
  flex: 1; min-width: 180px; display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: var(--dim); letter-spacing: .5px;
}
.signer-label input {
  background: rgba(4, 18, 30, 0.8); border: 1px solid rgba(90,180,230,0.3);
  color: var(--ink); padding: 10px 12px; border-radius: 9px; font-size: 14px; outline: none;
}
.signer-label input:focus { border-color: var(--blue); }
.modal-actions { display: flex; gap: 8px; }
.primary {
  background: linear-gradient(120deg, var(--gold), #ff9f5b); color: #1a1000;
  border: 0; padding: 11px 16px; border-radius: 9px; font-weight: 700; cursor: pointer; font-size: 14px;
}
.primary:disabled { background: rgba(120,190,240,0.18); color: var(--dim); cursor: default; }

.status {
  position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: var(--dim); z-index: 40; pointer-events: none;
  transition: opacity .3s;
}

/* live indicator */
.live {
  font-size: 12px; color: #5c7a90; letter-spacing: 1px; padding: 6px 8px;
  transition: color .3s;
}
.live.on { color: var(--teal); }
.live.on::first-letter { animation: pulseDot 1.6s ease-in-out infinite; }
@keyframes pulseDot { 0%,100% { opacity: .4; } 50% { opacity: 1; } }

/* toasts */
.toasts {
  position: fixed; top: 70px; right: 18px; z-index: 70;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: rgba(12,34,54,0.96); border: 1px solid rgba(47,211,192,0.4);
  border-left: 3px solid var(--teal);
  color: var(--ink); padding: 10px 14px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.45); max-width: 320px;
}
.toast .ev { color: var(--teal); font-weight: 600; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  html, body { overflow: auto; }

  header {
    flex-wrap: wrap; gap: 10px; padding: 10px 12px;
    position: sticky; top: 0; z-index: 10;
    background: rgba(4, 17, 28, 0.92); backdrop-filter: blur(8px);
  }
  .title { font-size: 14px; }
  .title .dim { display: none; }
  .projects { order: 3; flex-basis: 100%; -webkit-overflow-scrolling: touch; }
  .header-right { margin-left: auto; }
  /* keep buttons tappable; trim the demo label */
  .ghost, .primary { padding: 9px 12px; }

  /* River becomes vertical lanes, each a horizontally-scrolling strip */
  #app { height: auto; min-height: 100vh; }
  .river { flex-direction: column; padding: 10px; overflow: visible; height: auto; }
  .lane { margin: 8px 0; }
  .lane-body {
    display: flex; flex-direction: row; gap: 10px;
    overflow-x: auto; overflow-y: hidden; padding: 6px 4px 12px;
    scroll-snap-type: x mandatory;
  }
  .lane-body .card { min-width: 230px; max-width: 240px; margin: 0; scroll-snap-align: start; }
  .lane-body .empty { min-width: 100%; }

  /* Full-screen modal on phones */
  .modal { padding: 0; }
  .modal-card { width: 100vw; height: 100vh; border-radius: 0; border: 0; }
  .modal-foot { gap: 10px; }
  .modal-actions { width: 100%; }
  .modal-actions .primary { width: 100%; }

  .toasts { top: auto; bottom: 14px; right: 10px; left: 10px; align-items: stretch; }
  .toast { max-width: none; }
}

/* Coarse-pointer: bigger hit targets regardless of width */
@media (pointer: coarse) {
  .card { padding: 16px 14px; }
}
