:root {
  --bg: #f6f5fa;
  --surface: #ffffff;
  --text: #1d1b26;
  --muted: #6b6880;
  --line: #e5e3ee;
  --hover: #f0eefa;
  --accent: #7c3aed;
  --accent-text: #ffffff;
  --accent-soft: #ede9fe;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 12px;
  --shadow: 0 8px 28px rgba(29, 27, 38, 0.14);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14121b;
    --surface: #1d1a27;
    --text: #ece9f6;
    --muted: #9d99b3;
    --line: #2d2a3b;
    --hover: #26223a;
    --accent: #a78bfa;
    --accent-text: #14121b;
    --accent-soft: #2e2650;
    --danger: #f87171;
    --ok: #4ade80;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input { font: inherit; color: inherit; }

.wrap { max-width: 960px; margin: 0 auto; padding: 0 16px; }

/* ---------- header ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.top .wrap { display: flex; align-items: center; gap: 16px; min-height: 56px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.logo i {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-text); font-style: normal; font-size: 15px;
}
.spacer { flex: 1; }
.meter { min-width: 150px; font-size: 12px; color: var(--muted); }
.meter .bar { height: 6px; border-radius: 3px; background: var(--line); margin-top: 4px; overflow: hidden; }
.meter .bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.meter.full .bar span { background: var(--danger); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; max-width: 260px; }
.who-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.who-text b { color: var(--text); font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-text small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  position: relative; flex: none; width: 36px; height: 36px; border-radius: 50%; overflow: hidden;
  display: grid; place-items: center; color: #fff; font-size: 15px; font-weight: 600;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; padding: 16px 0 12px; flex-wrap: wrap; }
.crumbs { flex: 1; min-width: 160px; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; font-size: 15px; }
.crumbs button {
  background: none; border: 0; padding: 4px 6px; border-radius: 6px; cursor: pointer; color: var(--muted);
  max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.crumbs button:hover { background: var(--hover); color: var(--text); }
.crumbs button:last-child { color: var(--text); font-weight: 600; }
.crumbs .sep { color: var(--muted); opacity: 0.6; }

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; min-height: 38px;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- list ---------- */
.list {
  list-style: none; margin: 0 0 32px; padding: 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; position: relative;
}
.row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--hover); }
.badge {
  flex: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  font-size: 11px; font-weight: 700; letter-spacing: 0.02em; color: #fff;
}
.badge.folder { background: var(--accent-soft); color: var(--accent); }
.badge svg { width: 22px; height: 22px; }
.name { flex: 1; min-width: 0; }
.name b { display: block; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name small { color: var(--muted); font-size: 12px; }
.chip { font-size: 11px; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 8px; }
.more { flex: none; width: 36px; height: 36px; border-radius: 8px; border: 0; background: none; cursor: pointer; font-size: 20px; line-height: 1; color: var(--muted); }
.more:hover { background: var(--line); color: var(--text); }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

.pickhint { margin: 16px 0 0; color: var(--muted); font-size: 13px; }
.row.picked { background: var(--accent-soft); }
.check {
  flex: none; width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: 14px; line-height: 1; color: var(--accent-text); background: var(--surface);
}
.check.on { background: var(--accent); border-color: var(--accent); }
.check.ghost { visibility: hidden; }
.pickbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; align-items: center; gap: 8px; padding: 12px 16px;
  background: var(--surface); border-top: 1px solid var(--line);
}
body.picking main { padding-bottom: 84px; }
.pickbar span { flex: 1; color: var(--muted); font-size: 14px; }
.list { margin-bottom: 16px; }

.drop {
  position: fixed; inset: 0; z-index: 20; display: none; place-items: center;
  background: color-mix(in srgb, var(--accent) 18%, transparent);
  border: 3px dashed var(--accent); font-size: 20px; font-weight: 600; color: var(--accent); pointer-events: none;
}
.drop.on { display: grid; }

/* ---------- menu, modal, toast ---------- */
.menu {
  position: fixed; z-index: 30; min-width: 200px; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(10, 8, 20, 0.55); display: grid; place-items: center; padding: 16px; }
.modal {
  width: 100%; max-width: 440px; max-height: 100%; overflow: auto;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 20px;
}
.modal.wide { max-width: 900px; }
.modal h2 { margin: 0 0 12px; font-size: 18px; overflow-wrap: anywhere; }
.modal p { margin: 0 0 12px; color: var(--muted); }
.modal input[type="text"], .modal input.link {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); margin-bottom: 4px;
}
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.preview { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; border-radius: 8px; }
iframe.preview { width: 100%; height: 70vh; border: 1px solid var(--line); }
pre.preview { max-width: 100%; overflow: auto; white-space: pre-wrap; background: var(--bg); padding: 12px; border: 1px solid var(--line); font: 13px/1.5 ui-monospace, Menlo, Consolas, monospace; }
audio.preview, video.preview { width: 100%; }

#toasts { position: fixed; left: 0; right: 0; bottom: 16px; z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: #25222f; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 480px; }
.toast.err { background: #b91c1c; }

.tray {
  position: fixed; right: 16px; bottom: 16px; z-index: 25; width: min(340px, calc(100% - 32px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px;
}
.tray .item { padding: 6px 0; font-size: 13px; }
.tray .item div { display: flex; justify-content: space-between; gap: 8px; }
.tray .item span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray .item span:last-child { color: var(--muted); flex: none; }
.tray .item.err span:last-child { color: var(--danger); }
.tray .pb { height: 4px; border-radius: 2px; background: var(--line); margin-top: 4px; overflow: hidden; }
.tray .pb i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px; text-align: center; }
.login .logo { justify-content: center; font-size: 22px; margin-bottom: 12px; }
.login p { color: var(--muted); margin: 0 0 16px; }
.login .err { color: var(--danger); margin-bottom: 12px; }
.login form { display: flex; gap: 8px; margin-top: 16px; }
.login input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }

@media (max-width: 560px) {
  .crumbs { flex-basis: 100%; }
  .meter { order: 3; flex-basis: 100%; }
  .who { max-width: 56%; }
  .who-text small { display: none; }
  .btn { padding: 8px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
