:root {
  --bg: #f7f7f5;
  --panel: #ffffff;
  --text: #1c1c1c;
  --muted: #8a8a86;
  --line: #ebebe8;
  --hover: #f1f1ee;
  --accent: #1f1f1f;
  --accent-text: #ffffff;
  --danger: #d4483b;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(0,0,0,.06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151515;
    --panel: #1d1d1d;
    --text: #ededea;
    --muted: #8d8d88;
    --line: #2a2a2a;
    --hover: #252525;
    --accent: #ededea;
    --accent-text: #151515;
    --danger: #ff6b5e;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.error { color: var(--danger); margin: 12px 0 0; font-size: 13px; }

/* ---------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.primary:hover { opacity: .88; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; height: 42px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; flex: none;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.input {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); font: inherit; outline: none;
}
.input:focus { border-color: var(--muted); }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row-end { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(360px, 100%); padding: 36px 28px 28px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
}
.login-logo { width: 52px; height: 52px; }
.login-card h1 { font-size: 20px; margin: 14px 0 6px; }
.login-card p.muted { margin: 0 0 22px; font-size: 13.5px; }
#login-setup { margin-bottom: 12px; }

/* ---------- top bar */
.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  max-width: 920px; margin: 0 auto; padding: 18px 20px 14px;
  background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 16px; }
.brand img { width: 26px; height: 26px; }
.search {
  flex: 1; display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; margin-left: 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; color: var(--muted);
}
.search:focus-within { border-color: var(--muted); }
.search svg { width: 16px; height: 16px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; }
.menu-wrap { position: relative; }
.menu {
  position: fixed; min-width: 190px; padding: 6px; z-index: 30;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.menu button {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.menu button:hover { background: var(--hover); }
.menu button.danger { color: var(--danger); }
.menu svg { width: 16px; height: 16px; color: var(--muted); }
.menu button.danger svg { color: inherit; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }

/* ---------- list */
.content { max-width: 920px; margin: 0 auto; padding: 0 20px 80px; }
.summary { display: flex; justify-content: space-between; color: var(--muted); font-size: 12.5px; padding: 4px 4px 10px; }
.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.list:empty { display: none; }
.item {
  display: flex; align-items: center; gap: 14px; padding: 10px 10px 10px 14px; cursor: pointer;
  border-top: 1px solid var(--line); transition: background .12s;
}
.item:first-child { border-top: 0; }
.item:hover { background: var(--hover); }
.thumb {
  width: 40px; height: 40px; border-radius: 9px; flex: none; overflow: hidden;
  display: grid; place-items: center; font-size: 10px; font-weight: 700; letter-spacing: .02em;
  background: var(--hover); color: var(--muted); text-transform: uppercase;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb.k-image { background: #e8f1fb; color: #2f6fb5; }
.thumb.k-video { background: #f3ecfb; color: #7d4bc0; }
.thumb.k-audio { background: #fbeef3; color: #b8467a; }
.thumb.k-doc   { background: #fdf0e6; color: #c0601e; }
.thumb.k-text  { background: #ecf6ef; color: #2f8a4c; }
.thumb.k-zip   { background: #f4f1e6; color: #8a7429; }
@media (prefers-color-scheme: dark) {
  .thumb.k-image { background: #1d2a39; color: #7fb2ea; }
  .thumb.k-video { background: #2a2139; color: #b691ea; }
  .thumb.k-audio { background: #36202a; color: #ea8fb7; }
  .thumb.k-doc   { background: #362719; color: #eba26e; }
  .thumb.k-text  { background: #1d3024; color: #7fcf98; }
  .thumb.k-zip   { background: #302b1b; color: #d4bd6a; }
}
.info { flex: 1; min-width: 0; }
.name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.actions { display: flex; gap: 2px; opacity: .0; transition: opacity .12s; }
.item:hover .actions, .item:focus-within .actions { opacity: 1; }
@media (hover: none) { .actions { opacity: 1; } .act-dl { display: none !important; } }

.empty {
  width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 72px 20px; border: 1.5px dashed var(--line); border-radius: var(--radius);
  background: transparent; color: var(--muted); font: inherit; cursor: pointer; transition: border-color .15s, background .15s;
}
.empty:hover { border-color: var(--muted); background: var(--panel); }
.empty svg { width: 28px; height: 28px; margin-bottom: 6px; }
.empty strong { color: var(--text); font-weight: 500; font-size: 15px; }

/* ---------- drop overlay */
.drop {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; pointer-events: none;
  background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(4px);
}
.drop div {
  padding: 40px 60px; border: 2px dashed var(--accent); border-radius: 18px;
  font-size: 17px; font-weight: 500; background: var(--panel);
}

/* ---------- upload tray */
.uploads {
  position: fixed; right: 20px; bottom: 20px; z-index: 40; width: min(340px, calc(100vw - 40px));
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 8px;
}
.up { padding: 8px 8px; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; font-size: 13px; }
.up .n { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up .p { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.up .track { grid-column: 1 / -1; height: 3px; background: var(--hover); border-radius: 2px; overflow: hidden; }
.up .fill { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.up.done .fill { background: #3a9d5d; width: 100% !important; }
.up.fail .fill { background: var(--danger); width: 100% !important; }
.up.fail .p { color: var(--danger); }

/* ---------- toast */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 100;
  padding: 9px 16px; border-radius: 10px; background: var(--accent); color: var(--accent-text);
  font-size: 13.5px; box-shadow: var(--shadow); animation: pop .18s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 6px); } }

/* ---------- dialogs */
dialog.sheet {
  border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--panel); color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.2); max-width: calc(100vw - 24px);
}
dialog.sheet::backdrop { background: rgba(0,0,0,.35); backdrop-filter: blur(2px); }
dialog.sheet header { display: flex; align-items: center; gap: 12px; padding: 14px 14px 14px 20px; border-bottom: 1px solid var(--line); }
dialog.sheet header > :first-child { flex: 1; min-width: 0; }

.preview { width: 880px; }
.pv-title { display: flex; flex-direction: column; }
.pv-title strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pv-title span { font-size: 12.5px; }
.pv-body { display: grid; place-items: center; min-height: 200px; max-height: 66vh; overflow: auto; background: var(--bg); }
.pv-body img, .pv-body video { max-width: 100%; max-height: 66vh; display: block; }
.pv-body audio { width: min(480px, 90%); margin: 60px 0; }
.pv-body iframe { width: 100%; height: 66vh; border: 0; background: #fff; }
.pv-body pre {
  align-self: start; justify-self: stretch; margin: 0; padding: 18px 20px; font: 12.5px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word; tab-size: 4;
}
.pv-body .nopv { color: var(--muted); text-align: center; padding: 50px 20px; display: grid; gap: 10px; justify-items: center; }
.pv-body .nopv .thumb { width: 64px; height: 64px; border-radius: 14px; font-size: 13px; }
dialog.sheet footer { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; padding: 14px 16px; border-top: 1px solid var(--line); }
.link-box { flex: 1 1 300px; display: flex; gap: 6px; min-width: 0; }
.link-box input {
  flex: 1; min-width: 0; height: 34px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--bg); color: var(--muted); font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; outline: none;
}
.pv-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.ask { width: 400px; }
.ask form { padding: 22px; }
.ask h3 { margin: 0 0 6px; font-size: 16px; }
.ask p { margin: 0 0 14px; word-break: break-all; }
.ask p:empty { display: none; }

.settings { width: 480px; }
.settings-body { padding: 4px 20px 22px; }
.settings h4 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
.plain-list { list-style: none; margin: 0 0 10px; padding: 0; border: 1px solid var(--line); border-radius: 10px; }
.plain-list li { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border-top: 1px solid var(--line); }
.plain-list li:first-child { border-top: 0; }
.plain-list .info span { display: block; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--hover); color: var(--muted); margin-left: 6px; }

@media (max-width: 600px) {
  .bar { padding: 12px 14px 10px; gap: 8px; flex-wrap: wrap; }
  .brand span { display: none; }
  .search { margin-left: 0; order: 3; flex-basis: 100%; }
  #upload-btn { margin-left: auto; }
  .content { padding: 0 14px 80px; }
  .summary .hint { display: none; }
  .item { gap: 12px; padding: 10px 6px 10px 12px; }
  dialog.sheet { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 16px 16px 0 0; max-height: 92vh; }
  .pv-actions { width: 100%; }
  .pv-actions .btn { flex: 1; }
}
