:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2125;
  --muted: #6b7480;
  --line: #e1e4e8;
  --bubble: #dff1ea;
  --bubble-text: #12261f;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171a;
    --surface: #1e2125;
    --text: #e6e8eb;
    --muted: #8d96a1;
    --line: #2c3036;
    --bubble: #234a3f;
    --bubble-text: #e4f3ed;
    --accent: #58b79c;
    --accent-text: #0c1a16;
    --danger: #ef7b6e;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { height: 100dvh; display: flex; flex-direction: column; }
.col { width: 100%; max-width: 780px; margin: 0 auto; padding: 0 16px; }

/* ---------- 頂端列 ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--line); padding-top: env(safe-area-inset-top); }
.top .col { display: flex; align-items: center; gap: 8px; height: 52px; }
.search { flex: 1; min-width: 0; position: relative; }
.search input {
  width: 100%; height: 36px; padding: 0 34px 0 12px;
  border: 1px solid var(--line); border-radius: 18px; background: var(--bg);
}
.search .clear { position: absolute; right: 4px; top: 4px; width: 28px; height: 28px; border-radius: 50%; color: var(--muted); }
.chip {
  flex: none; height: 36px; padding: 0 12px; border-radius: 18px;
  border: 1px solid var(--line); color: var(--muted); font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }

/* ---------- 訊息列表 ---------- */
.list { flex: 1; overflow-y: auto; overflow-anchor: none; padding: 12px 0 8px; }
.hint { text-align: center; color: var(--muted); font-size: 14px; padding: 24px 0; }
.day { text-align: center; margin: 14px 0 8px; }
.day span { font-size: 12px; color: var(--muted); background: var(--line); padding: 2px 10px; border-radius: 10px; }

.msg { position: relative; display: flex; flex-direction: column; align-items: flex-end; margin: 6px 0; }
.row { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.meta { flex: none; font-size: 11px; color: var(--muted); text-align: right; line-height: 1.3; padding-bottom: 2px; font-variant-numeric: tabular-nums; }
.bubble {
  min-width: 0; max-width: min(100%, 600px);
  background: var(--bubble); color: var(--bubble-text);
  border-radius: 16px 16px 4px 16px; padding: 8px 12px; box-shadow: var(--shadow);
  cursor: pointer; overflow: hidden;
}
.msg.pending .bubble { opacity: .55; }
.msg.pinned .bubble { box-shadow: inset 3px 0 0 var(--accent), var(--shadow); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.body a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.imgs { display: grid; gap: 4px; margin: 2px -6px 4px; grid-template-columns: repeat(2, 1fr); width: min(320px, 66vw); }
.imgs.one { grid-template-columns: 1fr; }
.imgs:last-child { margin-bottom: -2px; }
.imgs button { display: block; border-radius: 10px; overflow: hidden; background: rgba(0, 0, 0, .08); }
.imgs img { display: block; width: 100%; height: auto; }
.imgs:not(.one) img { aspect-ratio: 1; object-fit: cover; height: 100%; }

.card {
  display: flex; gap: 10px; margin: 6px -4px 0; padding: 8px; border-radius: 10px; max-width: 440px;
  background: var(--surface); color: var(--text); text-decoration: none; border: 1px solid var(--line);
}
.card img { flex: none; width: 72px; height: 72px; object-fit: cover; border-radius: 6px; }
.card .t { min-width: 0; }
.card .title { font-size: 14px; font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .desc { font-size: 12px; color: var(--muted); line-height: 1.4; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .site { font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.actions { display: flex; gap: 2px; margin-top: 2px; }
.actions button { font-size: 13px; color: var(--muted); padding: 6px 10px; border-radius: 8px; min-height: 32px; }
.actions button:hover { background: var(--line); color: var(--text); }
.actions .danger:hover { color: var(--danger); }

.edit { width: min(600px, 100%); }
.edit textarea {
  width: 100%; min-height: 80px; resize: vertical; padding: 8px 12px;
  border: 2px solid var(--accent); border-radius: 12px; background: var(--surface);
}

/* ---------- 輸入區 ---------- */
.composer { background: var(--surface); border-top: 1px solid var(--line); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); }
.composer .col { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; max-height: 40dvh; height: 40px;
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 20px; background: var(--bg);
}
.icon-btn { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { background: var(--line); }
.icon-btn svg { width: 22px; height: 22px; }
.send { background: var(--accent); color: var(--accent-text); }
.send:hover { background: var(--accent); filter: brightness(1.08); }
.send:disabled { opacity: .4; cursor: default; }
.picked { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; }
.picked div { position: relative; flex: none; }
.picked img { display: block; width: 64px; height: 64px; object-fit: cover; border-radius: 8px; }
.picked button {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--text); color: var(--bg); font-size: 14px; line-height: 22px;
}

/* ---------- 其他 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 20px; font-size: 14px;
  display: flex; gap: 12px; align-items: center; max-width: calc(100vw - 32px); z-index: 20;
}
.toast button { color: inherit; font-weight: 600; text-decoration: underline; }

.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .9); display: grid; place-items: center; z-index: 30; cursor: zoom-out; }
.lightbox img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }

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

.login { height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: min(340px, 100%); display: grid; gap: 12px; }
.login h1 { font-size: 22px; margin: 0 0 4px; text-align: center; }
.login input { height: 46px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.login button { height: 46px; border-radius: 12px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.login button:disabled { opacity: .5; }
.login .err { color: var(--danger); font-size: 14px; text-align: center; min-height: 1.5em; margin: 0; }

/* 桌機：滑鼠移上去才浮出操作列，浮在下一則上方，不推擠版面 */
@media (hover: hover) and (min-width: 700px) {
  .msg > .actions {
    display: none; position: absolute; top: calc(100% - 4px); right: 0; z-index: 5;
    background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 2px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
  }
  .msg:hover > .actions, .msg.active > .actions { display: flex; }
}
/* 手機：點一下訊息才展開操作列 */
@media (hover: none), (max-width: 699px) {
  .msg:not(.active) > .actions { display: none; }
}
