:root {
  --bg: #eceef2;
  --card: #ffffff;
  --text: #1f2329;
  --muted: #8a9099;
  --line: #dcdfe5;
  --accent: #2f7cf6;
  --accent-text: #ffffff;
  --btn: #f2f3f5;
  --danger: #e5484d;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181a;
    --card: #2a2b2e;
    --text: #e8e9eb;
    --muted: #8d9199;
    --line: #3a3b3f;
    --accent: #4a8cff;
    --btn: #36373b;
    --danger: #ff6369;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button {
  border: 0; border-radius: 8px; padding: 6px 12px; background: var(--btn); cursor: pointer;
}
button:active { opacity: .7; }
button:disabled { opacity: .5; }
button.primary { background: var(--accent); color: var(--accent-text); }
button.ghost { background: transparent; color: var(--muted); }
button.danger { background: var(--danger); color: #fff; }
input, textarea, select {
  border: 1px solid var(--line); border-radius: 8px; background: var(--card); padding: 8px 10px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
a { color: var(--accent); word-break: break-all; }
.offscreen { position: fixed; top: -1000px; opacity: 0; }
.err { color: var(--danger); min-height: 1.5em; margin: 0; font-size: 14px; }

/* 登录 */
.page.center { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.panel {
  background: var(--card); border-radius: 14px; padding: 24px; width: 100%; max-width: 340px;
  display: flex; flex-direction: column; gap: 12px;
}
.panel h1 { margin: 0 0 4px; font-size: 20px; text-align: center; }

/* 主界面：仿输入法剪贴板面板 */
#main { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
.bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.bar .title { color: var(--muted); font-size: 14px; }
.bar .title b { color: var(--text); }
.grid {
  flex: 1; overflow-y: auto; padding: 8px;
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; align-content: start;
}
@media (min-width: 700px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 1100px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.empty { text-align: center; color: var(--muted); }
.card {
  background: var(--card); border-radius: 10px; padding: 10px; display: flex; flex-direction: column;
  gap: 6px; min-height: 92px; cursor: pointer; overflow: hidden;
}
.card .body {
  flex: 1; white-space: pre-wrap; word-break: break-word; font-size: 14px;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.card.expanded { grid-column: 1 / -1; }
.card.expanded .body { -webkit-line-clamp: unset; display: block; }
.card.link .body { color: var(--accent); }
.card.image .body { display: flex; align-items: center; justify-content: center; max-height: 140px; }
.card.image img { max-width: 100%; max-height: 140px; border-radius: 6px; object-fit: contain; }
.card.image.expanded .body { max-height: none; }
.card.image.expanded img { max-height: 80vh; }
.meta { display: flex; align-items: center; justify-content: space-between; gap: 4px; color: var(--muted); font-size: 12px; }
.actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.actions button { padding: 3px 9px; font-size: 12px; }
.meta > span { white-space: nowrap; }

.composer {
  border-top: 1px solid var(--line); background: var(--bg); padding: 8px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer .tools { display: flex; gap: 6px; margin-bottom: 6px; }
.composer .tools button { font-size: 13px; padding: 4px 10px; }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; min-height: 40px; max-height: 160px; }
.composer .row button { height: 40px; padding: 0 16px; }

.drop-hint {
  display: none; position: fixed; inset: 0; z-index: 10; align-items: center; justify-content: center;
  background: rgba(47, 124, 246, .15); border: 3px dashed var(--accent); font-size: 18px; pointer-events: none;
}
body.dragging .drop-hint { display: flex; }

#toast {
  position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 20;
  background: rgba(0, 0, 0, .78); color: #fff; padding: 8px 16px; border-radius: 20px; font-size: 14px;
  opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; }

/* 管理后台 */
.admin { max-width: 1000px; margin: 0 auto; padding: 12px 16px 40px; }
.admin h2 { font-size: 16px; margin: 20px 0 8px; }
.admin section { background: var(--card); border-radius: 12px; padding: 14px; }
.admin .form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.admin .form-row > * { min-width: 0; }
.admin .form-row input, .admin .form-row select { flex: 1 1 140px; }
.admin table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin th, .admin td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin th { color: var(--muted); font-weight: normal; font-size: 13px; }
.admin td .preview { max-width: 420px; white-space: pre-wrap; word-break: break-word; max-height: 4.5em; overflow: hidden; }
.admin td img { max-width: 120px; max-height: 80px; border-radius: 4px; }
.admin .table-wrap { overflow-x: auto; }
.admin .hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }
.admin .toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.admin .toolbar .count { color: var(--muted); font-size: 13px; margin-right: auto; }
.admin td button { padding: 3px 8px; font-size: 12px; margin: 0 4px 4px 0; }
