:root {
  --bg: #0b0d12;
  --bg-soft: #11141c;
  --panel: #151926;
  --panel-2: #1b2030;
  --border: #252b3d;
  --border-soft: #1e2434;
  --text: #e8ecf6;
  --muted: #8a93a8;
  --faint: #5b6378;
  --accent: #6c8cff;
  --accent-2: #9d7bff;
  --good: #38d39f;
  --warn: #ffb454;
  --bad: #ff6b7a;
  --gold: #ffd166;
  --silver: #c6cede;
  --bronze: #e8a87c;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(108, 140, 255, 0.12), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(157, 123, 255, 0.10), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  width: 42px; height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  gap: 3px;
  box-shadow: var(--shadow);
}
.logo-dot { width: 5px; height: 16px; background: rgba(255,255,255,0.92); border-radius: 4px; }
.logo-dot:nth-child(2) { height: 22px; }
.logo-dot:nth-child(3) { height: 11px; }
.brand-text h1 { margin: 0; font-size: 22px; letter-spacing: 0.08em; font-weight: 700; }
.brand-text p { margin: 2px 0 0; font-size: 12px; color: var(--muted); letter-spacing: 0.18em; text-transform: uppercase; }

.sync {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
}
.sync-led { width: 9px; height: 9px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 0 rgba(56,211,159,0.6); }
.sync.busy .sync-led { background: var(--warn); animation: pulse 1.1s infinite; }
.sync.error .sync-led { background: var(--bad); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,180,84,0.55); }
  70% { box-shadow: 0 0 0 8px rgba(255,180,84,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,180,84,0); }
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  padding: 38px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .18s, background .18s, transform .12s;
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); }
.dropzone.drag {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(108,140,255,0.14), var(--bg-soft));
  transform: scale(1.006);
}
.dz-icon { color: var(--accent); }
.dz-text strong { display: block; font-size: 17px; }
.dz-text span { display: block; font-size: 13px; color: var(--muted); margin-top: 4px; }
.dz-types { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.chip {
  font-size: 11px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border-soft);
  padding: 4px 10px; border-radius: 999px;
  letter-spacing: .04em;
}

/* Queue */
.queue { list-style: none; margin: 14px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.queue:empty { margin: 0; }
.q-item {
  display: flex; align-items: center; gap: 12px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; font-size: 13px;
}
.q-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-bar { width: 120px; height: 6px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.q-bar > i { display: block; height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s; }
.q-status { font-size: 11px; color: var(--muted); min-width: 78px; text-align: right; }
.q-item.done .q-status { color: var(--good); }
.q-item.err .q-status { color: var(--bad); }

/* Controls */
.controls {
  display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap;
  margin: 22px 0 14px;
}
.ctrl { display: flex; flex-direction: column; gap: 6px; }
.ctrl.grow { flex: 1; min-width: 180px; }
.ctrl label { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em; }
select, input[type="search"] {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 14px; font-family: var(--sans);
  min-width: 150px;
}
select:focus, input:focus { outline: none; border-color: var(--accent); }
.ctrl-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  background: var(--panel); border: 1px solid var(--border); color: var(--text);
  border-radius: 10px; padding: 10px 14px; font-size: 13px; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover { background: var(--panel-2); border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: rgba(255,107,122,0.3); }
.btn.danger:hover { background: rgba(255,107,122,0.1); border-color: var(--bad); }

/* Stats */
.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px;
}
.stat {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px;
  min-width: 0;
}
.stat-num { font-size: 20px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat-label { font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .07em; }

/* Board */
.board { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.board-head, .rank-row {
  display: grid;
  grid-template-columns: 56px 1.4fr 2fr 110px 44px;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
}
.board-head {
  font-size: 11px; color: var(--faint); text-transform: uppercase; letter-spacing: .08em;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
}
.rank-list { list-style: none; margin: 0; padding: 0; }
.rank-row { border-bottom: 1px solid var(--border-soft); transition: background .15s; }
.rank-row:last-child { border-bottom: none; }
.rank-row:hover { background: var(--panel-2); }
.rank-row.flash { animation: flash 1s ease; }
@keyframes flash { 0% { background: rgba(108,140,255,0.22); } 100% { background: transparent; } }

.col-rank { display: flex; align-items: center; gap: 6px; }
.rank-badge {
  width: 30px; height: 30px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  background: var(--panel-2); border: 1px solid var(--border);
}
.rank-row:nth-child(1) .rank-badge { background: linear-gradient(135deg, var(--gold), #b8860b); color: #2a1e00; border: none; }
.rank-row:nth-child(2) .rank-badge { background: linear-gradient(135deg, var(--silver), #8b93a8); color: #1a1d26; border: none; }
.rank-row:nth-child(3) .rank-badge { background: linear-gradient(135deg, var(--bronze), #a9613b); color: #2a1400; border: none; }
.delta { font-size: 11px; width: 14px; text-align: center; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.same { color: var(--faint); }
.delta.new { color: var(--accent); font-weight: 700; }

.doc-name { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.doc-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: 11px; color: var(--faint); display: flex; gap: 8px; align-items: center; }
.type-badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 7px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--border-soft); color: var(--muted);
}
.type-badge.pdf { color: #ff8f8f; }
.type-badge.docx { color: #8fb4ff; }
.type-badge.image { color: #c6a0ff; }
.type-badge.markdown { color: #8fe3c2; }

.metrics { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.metric-chip {
  font-size: 11px; padding: 3px 8px; border-radius: 7px;
  background: var(--panel-2); border: 1px solid var(--border-soft); color: var(--muted);
  white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
.metric-chip b { color: var(--text); font-weight: 600; }
.metric-chip.empty { color: var(--faint); font-style: italic; background: transparent; border: none; }

.col-score { text-align: right; }
.score-val { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.score-sub { font-size: 10px; color: var(--faint); display: block; }

.col-actions { display: flex; justify-content: flex-end; }
.remove-btn {
  width: 28px; height: 28px; border-radius: 8px; border: 1px solid var(--border);
  background: transparent; color: var(--faint); cursor: pointer; line-height: 1;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
}
.remove-btn:hover { color: var(--bad); border-color: var(--bad); }

.empty { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty p { margin: 4px 0; }
.empty .muted { color: var(--faint); font-size: 13px; }

.footer { margin-top: 22px; text-align: center; font-size: 12px; color: var(--faint); }

/* Toasts */
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast {
  background: var(--panel-2); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 12px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow);
  animation: slideIn .2s ease; max-width: 320px;
}
.toast.good { border-left-color: var(--good); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad  { border-left-color: var(--bad); }
.toast.fade { animation: fadeOut .3s ease forwards; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(20px); } }

/* Account bar */
.account { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.board-switch { display: flex; align-items: center; gap: 4px; }
.board-switch select { min-width: 120px; padding: 8px 10px; font-size: 13px; }
.btn.icon { padding: 8px 11px; line-height: 1; }
.sync.offline .sync-led { background: var(--faint); }
.sync.offline { color: var(--faint); }
.sync.connecting .sync-led { background: var(--warn); animation: pulse 1.1s infinite; }
.user { display: flex; align-items: center; gap: 8px; }
.user-email { font-size: 13px; color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge {
  font-size: 10px; text-transform: uppercase; letter-spacing: .06em; padding: 3px 8px;
  border-radius: 999px; border: 1px solid var(--border); color: var(--muted); background: var(--panel-2);
}
.role-badge.owner { color: var(--gold); border-color: rgba(255,209,102,.35); }
.role-badge.editor { color: var(--good); border-color: rgba(56,211,159,.35); }
.role-badge.viewer { color: var(--silver); border-color: rgba(198,206,222,.3); }

/* Read-only mode */
body.readonly .dropzone,
body.readonly .ctrl-buttons,
body.readonly #queue { display: none; }
body.readonly .remove-btn { display: none; }

/* Buttons */
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.link { background: none; border: none; color: var(--accent); cursor: pointer; font-size: 13px; padding: 0; }
.link:hover { text-decoration: underline; }

/* Auth gate */
.auth-gate {
  position: fixed; inset: 0; z-index: 100;
  background:
    radial-gradient(1000px 500px at 80% -10%, rgba(108,140,255,.16), transparent 60%),
    radial-gradient(800px 460px at -10% 10%, rgba(157,123,255,.14), transparent 55%),
    var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 18px; padding: 30px 26px; box-shadow: var(--shadow);
}
.brand.center { justify-content: center; margin-bottom: 18px; }
.auth-card h2 { margin: 6px 0 4px; font-size: 20px; }
.auth-sub { margin: 0 0 18px; font-size: 13px; color: var(--muted); }
.auth-form { display: flex; flex-direction: column; gap: 10px; }
.auth-form input { padding: 12px 14px; font-size: 15px; }
.auth-form .btn { margin-top: 4px; padding: 12px; font-size: 15px; }
.auth-error { margin-top: 12px; padding: 10px 12px; border-radius: 10px; font-size: 13px;
  background: rgba(255,107,122,.1); border: 1px solid rgba(255,107,122,.3); color: var(--bad); }
.auth-toggle { margin-top: 16px; font-size: 13px; color: var(--muted); display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.auth-foot { margin-top: 14px; text-align: center; font-size: 12px; }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { width: 100%; max-width: 480px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 22px; box-shadow: var(--shadow); max-height: 84vh; overflow: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.invite-form { display: flex; gap: 8px; flex-wrap: wrap; }
.invite-form input { flex: 1; min-width: 160px; }
.small { font-size: 12px; margin-top: 8px; }
.members-list { list-style: none; margin: 16px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border-soft);
  border-radius: 10px; background: var(--bg-soft); }
.member-email { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-pending { font-size: 11px; color: var(--warn); }
.member-row select { padding: 6px 8px; font-size: 12px; min-width: 90px; }
.member-row .remove-btn { width: 30px; height: 30px; }
.member-owner { font-size: 12px; color: var(--gold); }

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .board-head, .rank-row { grid-template-columns: 44px 1.3fr 80px 36px; }
  .col-metrics, .metrics { display: none; }
  .user-email { display: none; }
}
