:root {
  --bg: #f6f6f8;
  --surface: #ffffff;
  --surface-2: #f1f1f4;
  --border: #e3e3e8;
  --text: #1c1c22;
  --muted: #6b6b76;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --success: #1f8a4c;
  --side-bg: #1e1b3a;
  --side-text: #c9c6e6;
  --side-strong: #ffffff;
  --side-hover: #2c2852;
  --side-active: #4f46e5;
  --shadow: 0 1px 2px rgba(20, 20, 40, .06), 0 2px 8px rgba(20, 20, 40, .04);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121218;
    --surface: #1b1b23;
    --surface-2: #24242e;
    --border: #2e2e3a;
    --text: #ececf1;
    --muted: #9a9aa8;
    --accent: #7c74ff;
    --accent-soft: #26244a;
    --danger: #ff6b5b;
    --success: #4cc47f;
    --side-bg: #15132a;
    --side-hover: #24214a;
    --side-active: #5b52f0;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; }
.sidebar {
  width: 260px; flex-shrink: 0; background: var(--side-bg); color: var(--side-text);
  display: flex; flex-direction: column; padding: 16px 10px; overflow-y: auto;
}
.main { flex: 1; min-width: 0; overflow-x: hidden; display: flex; flex-direction: column; }
.view { flex: 1; overflow-y: auto; padding: 28px 32px 80px; }
.view > * { max-width: 820px; margin-left: auto; margin-right: auto; }
.topbar { display: none; }
.app.picking .sidebar, .app.picking .topbar { display: none !important; }
.scrim { display: none; }

@media (max-width: 760px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 30; transform: translateX(-100%);
    transition: transform .2s ease; box-shadow: 4px 0 24px rgba(0,0,0,.25);
  }
  .app.menu-open .sidebar { transform: none; }
  .app.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
  .topbar {
    display: flex; align-items: center; gap: 8px; padding: 10px 12px;
    background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .topbar-title { font-weight: 650; }
  .view { padding: 18px 16px 80px; }
}

/* ---------- sidebar ---------- */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: var(--side-strong); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--side-active); color: #fff;
  display: grid; place-items: center; font-weight: 750;
}
.brand-name { font-weight: 700; font-size: 16px; }
.brand-sub { font-size: 12px; opacity: .7; }
.nav-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 14px 10px 6px; opacity: .6;
}
.nav-link {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px;
  color: var(--side-text); font-size: 14.5px;
}
.nav-link:hover { background: var(--side-hover); text-decoration: none; }
.nav-link.active { background: var(--side-active); color: #fff; }
.nav-link .hash { opacity: .55; width: 14px; text-align: center; }
.nav-link .count { margin-left: auto; font-size: 12px; opacity: .65; }
.nav-link .dot { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: #fff; }
.side-foot {
  margin-top: auto; padding: 12px 10px 4px; display: flex; align-items: center; gap: 10px;
  border-top: 1px solid rgba(255,255,255,.08); color: var(--side-strong); font-size: 14px;
}
.side-foot .email { font-size: 12px; color: var(--side-text); opacity: .7; overflow: hidden; text-overflow: ellipsis; }

/* ---------- generic ---------- */
h1 { font-size: 26px; line-height: 1.25; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.section { margin-top: 28px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }
.loading, .empty { color: var(--muted); padding: 40px 0; text-align: center; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border);
  background: var(--surface); padding: 7px 14px; border-radius: 9px; cursor: pointer; font-size: 14px;
  font-weight: 550;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.link-btn {
  background: none; border: 0; padding: 2px 4px; cursor: pointer; color: var(--muted); font-size: 13px;
  border-radius: 6px;
}
.link-btn:hover { color: var(--text); background: var(--surface-2); }
.link-btn.danger:hover { color: var(--danger); }
.icon-btn {
  background: none; border: 0; padding: 6px; border-radius: 8px; cursor: pointer; color: inherit;
  display: inline-grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); }

input[type=text], input[type=url], textarea, select {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 9px;
  padding: 8px 11px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 44px; }

.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; display: inline-grid; place-items: center;
  font-size: 13px; font-weight: 700; color: #fff;
}
.avatar.sm { width: 24px; height: 24px; font-size: 11px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 999px;
  background: var(--surface-2); font-size: 13px;
}
.chip .role { color: var(--muted); }
.tag {
  display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--accent-soft);
  color: var(--accent); font-size: 12px; font-weight: 600;
}
.tag.plain { background: var(--surface-2); color: var(--muted); }

/* ---------- home ---------- */
.principles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.principle { padding: 14px 16px; font-size: 14px; }
.principle b { display: block; font-size: 22px; color: var(--accent); line-height: 1; margin-bottom: 6px; }
@media (max-width: 760px) {
  .principles { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- space header ---------- */
.space-head { margin-bottom: 20px; }
.people { margin-top: 12px; }
.resp { margin-top: 14px; padding: 14px 18px; }
.resp summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.resp ul { margin: 10px 0 0; padding-left: 20px; }
.resp li { margin: 4px 0; font-size: 14px; }

/* ---------- composer ---------- */
.composer { padding: 14px; margin-bottom: 20px; }
.composer textarea { border: 0; padding: 4px 2px; min-height: 60px; box-shadow: none !important; }
.composer .title-input { border: 0; padding: 2px; font-weight: 650; font-size: 16px; box-shadow: none !important; }
.composer .extra { margin-top: 8px; }
.composer .bar {
  display: flex; align-items: center; gap: 6px; margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--border); flex-wrap: wrap;
}
.composer .bar select { width: auto; padding: 5px 8px; font-size: 13px; }
.composer.dragging { border-color: var(--accent); background: var(--accent-soft); }
.pending-files { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.pending-file {
  position: relative; width: 72px; height: 72px; border-radius: 9px; overflow: hidden;
  background: var(--surface-2); display: grid; place-items: center; font-size: 11px; text-align: center;
  padding: 4px; word-break: break-all; color: var(--muted);
}
.pending-file img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.pending-file button {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 12px; line-height: 1;
}

/* ---------- posts ---------- */
.post { padding: 16px 18px; margin-bottom: 14px; }
.post.pinned { border-color: var(--accent); }
.post-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.post-head .who { font-weight: 650; font-size: 14.5px; }
.post-head .when { color: var(--muted); font-size: 13px; }
.post-title { font-weight: 650; font-size: 17px; margin: 2px 0 6px; }
.post-body { word-wrap: break-word; }
.post-body p { margin: 0 0 8px; }
.post-body ul { margin: 0 0 8px; padding-left: 22px; }
.post-body code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13.5px; }
.post-body h3 { font-size: 16px; margin: 10px 0 6px; }

.link-card {
  display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin: 10px 0 4px;
  color: var(--text); background: var(--surface-2);
}
.link-card:hover { text-decoration: none; border-color: var(--accent); }
.link-card img { width: 120px; object-fit: cover; flex-shrink: 0; background: var(--border); }
.link-card .lc-text { padding: 10px 14px; min-width: 0; }
.link-card .lc-title { font-weight: 600; font-size: 14px; }
.link-card .lc-desc {
  font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.link-card .lc-host { font-size: 12px; color: var(--muted); margin-top: 2px; }
@media (max-width: 520px) { .link-card img { width: 84px; } }

.images { display: grid; gap: 6px; margin-top: 10px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.images.one { grid-template-columns: 1fr; }
.images a { display: block; border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.images img { display: block; width: 100%; max-height: 420px; object-fit: cover; }
.images.one img { object-fit: contain; max-height: 520px; }
.files { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.file {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border);
  border-radius: 9px; color: var(--text); font-size: 14px;
}
.file:hover { text-decoration: none; border-color: var(--accent); }
.file .size { margin-left: auto; color: var(--muted); font-size: 12px; }

.post-actions { display: flex; gap: 4px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.comments { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 10px; }
.comment { display: flex; gap: 8px; margin-bottom: 10px; }
.comment .c-body { font-size: 14px; flex: 1; min-width: 0; word-wrap: break-word; }
.comment .c-meta { font-size: 12.5px; color: var(--muted); }
.comment-form { display: flex; gap: 8px; }
.comment-form input { flex: 1; }

/* ---------- targets ---------- */
.target-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 760px) { .target-cols { grid-template-columns: minmax(0, 1fr); } }
.target { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.target:last-child { border-bottom: 0; }
.target input[type=checkbox] { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.target .t-main { flex: 1; min-width: 0; }
.target .t-title { font-weight: 600; font-size: 14.5px; }
.target.done .t-title { color: var(--text); }
.target .t-details { font-size: 13.5px; color: var(--muted); margin-top: 2px; white-space: pre-wrap; }
.target .t-meta { margin-top: 6px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.target select { width: auto; padding: 2px 6px; font-size: 13px; }
.target-list { padding: 0; overflow: hidden; }
.target-list h2 { padding: 14px 14px 0; margin-bottom: 6px; }
.complete-form, .note-form { display: grid; gap: 8px; margin-top: 10px; }
.done-mark {
  width: 18px; height: 18px; border-radius: 5px; background: var(--success); color: #fff; flex-shrink: 0;
  display: grid; place-items: center; font-size: 12px; font-weight: 700; margin-top: 2px;
}
.done-note {
  margin-top: 8px; padding: 8px 12px; border-left: 3px solid var(--success); background: var(--surface-2);
  border-radius: 0 8px 8px 0; font-size: 14px;
}
.done-note p:last-child, .done-note ul:last-child { margin-bottom: 0; }
.target-add { padding: 12px 14px; border-top: 1px solid var(--border); display: grid; gap: 8px; }

/* ---------- onboarding ---------- */
.onboard { max-width: 440px !important; margin-top: 10vh !important; padding: 28px; text-align: center; }
.onboard .names { display: grid; gap: 8px; margin: 20px 0; }
.onboard .names .btn { justify-content: center; padding: 11px; }
.onboard .names .pick { justify-content: flex-start; gap: 12px; text-align: left; padding: 10px 14px; }
.pick-text { display: flex; flex-direction: column; line-height: 1.3; font-weight: 400; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  transition: all .2s ease; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
