:root {
  --bg: #f5fbf5; --surface: #ffffff; --surface2: #e8f0ea; --surface3: #dce7df;
  --text: #171d19; --muted: #5b6a60; --border: #d3dfd6;
  --primary: #1f6c45; --on-primary: #ffffff; --primary-soft: #c9ecd5; --on-soft: #0b3a22;
  --danger: #b3261e; --danger-soft: #fbe2df; --warn: #8a5a00; --warn-soft: #fdf0d2;
  --mine: #d4f0dc; --theirs: #ffffff;
  --radius: 16px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1512; --surface: #171f1a; --surface2: #202a23; --surface3: #29352d;
    --text: #dfe6e0; --muted: #98a79d; --border: #2b3830;
    --primary: #8fd6aa; --on-primary: #00391f; --primary-soft: #1d4a32; --on-soft: #c9ecd5;
    --danger: #ffb4ab; --danger-soft: #4a1f1b; --warn: #f3c46b; --warn-soft: #3d2e10;
    --mine: #1d4a32; --theirs: #202a23;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }

/* layout */
.shell { display: flex; min-height: 100dvh; }
.side {
  width: 248px; flex: none; padding: 16px 12px; position: sticky; top: 0; height: 100dvh; overflow-y: auto;
  border-right: 1px solid var(--border); background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 16px; font-weight: 700; font-size: 17px; }
.brand img { width: 32px; height: 32px; border-radius: 10px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.nav-group { margin: 10px 10px 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 999px; color: var(--text);
  text-decoration: none; position: relative;
}
.nav-link:hover { background: var(--surface2); }
.nav-link.on { background: var(--primary-soft); color: var(--on-soft); font-weight: 600; }
.nav-link .ico { width: 22px; text-align: center; }
.badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger);
  color: #fff; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center;
}
@media (prefers-color-scheme: dark) { .badge { color: #3a0904; } }
.main { flex: 1; min-width: 0; padding: 20px 24px 40px; }
.page { max-width: 860px; margin: 0 auto; }
.top { display: flex; align-items: center; gap: 12px; margin: 4px 0 18px; flex-wrap: wrap; }
.top h1 { font-size: 24px; margin: 0; flex: 1; min-width: 0; }
.bottom-nav { display: none; }

@media (max-width: 900px) {
  .side { display: none; }
  .side.open {
    display: block; position: fixed; inset: 0 auto 0 0; z-index: 30; width: min(300px, 86vw); box-shadow: var(--shadow);
    background: var(--surface);
  }
  .scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 29; }
  .main { padding: 14px 16px calc(84px + env(safe-area-inset-bottom)); }
  .top h1 { font-size: 21px; }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface2);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border);
  }
  .bottom-nav a, .bottom-nav button {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; color: var(--muted);
    text-decoration: none; background: none; border: 0; padding: 4px 0; position: relative; cursor: pointer;
  }
  .bottom-nav .pill { padding: 3px 16px; border-radius: 999px; font-size: 18px; line-height: 1.3; }
  .bottom-nav .on { color: var(--text); font-weight: 600; }
  .bottom-nav .on .pill { background: var(--primary-soft); }
  .bottom-nav .badge { position: absolute; top: 0; left: calc(50% + 6px); margin: 0; min-width: 18px; height: 18px; font-size: 11px; }
}

/* surfaces */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
  margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h2 { font-size: 17px; margin: 0 0 10px; }
.card h3 { font-size: 15px; margin: 0 0 8px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-bottom: 12px; }
.stat { display: block; text-decoration: none; color: inherit; }
.stat b { display: block; font-size: 28px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.hot { border-color: var(--primary); }
.stat.hot b { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.spacer { flex: 1; }
.pre { white-space: pre-wrap; word-break: break-word; }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px;
  background: var(--surface2); color: var(--muted); white-space: nowrap;
}
.chip.ok { background: var(--primary-soft); color: var(--on-soft); }
.chip.bad { background: var(--danger-soft); color: var(--danger); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--border); background: var(--surface); padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.tabs button.on { background: var(--primary-soft); color: var(--on-soft); border-color: transparent; font-weight: 600; }
hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }

/* controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; cursor: pointer; border-radius: 999px;
  padding: 9px 18px; font-weight: 600; background: var(--surface2); color: var(--text); text-decoration: none; min-height: 40px;
  transition: transform .12s ease, background-color .15s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.soft { background: var(--primary-soft); color: var(--on-soft); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.ghost { background: transparent; color: var(--primary); padding: 9px 10px; }
.btn.small { padding: 5px 12px; min-height: 32px; font-size: 13.5px; }
.btn[disabled] { opacity: .5; cursor: default; transform: none; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 999px; cursor: pointer; font-size: 18px; }
.icon-btn:hover { background: var(--surface2); }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=url], input[type=number], input[type=date], select, textarea {
  width: 100%; border: 1px solid var(--border); background: var(--bg); border-radius: 12px; padding: 10px 12px; outline: none;
  font-size: 16px;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
textarea { resize: vertical; min-height: 90px; line-height: 1.45; }
select { width: auto; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; padding: 6px 0; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex: none; }
.counter { font-size: 12.5px; color: var(--muted); }
.counter.over { color: var(--danger); font-weight: 700; }
.when-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.when-pick input[type=date] { width: auto; }

/* photos */
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { position: relative; width: 92px; height: 92px; border-radius: 12px; overflow: hidden; background: var(--surface2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 999px; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.thumb.off img { opacity: .3; }
.photos { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.photos img { max-height: 220px; border-radius: 12px; }

/* posts */
.post-text { white-space: pre-wrap; word-break: break-word; }
.meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-top: 8px; }
.reply { border-left: 3px solid var(--border); padding: 6px 0 6px 12px; margin: 8px 0; }

/* chats */
.chat-row { display: flex; gap: 12px; align-items: center; padding: 12px; border-radius: 14px; text-decoration: none; color: inherit; }
.chat-row:hover { background: var(--surface2); }
.avatar {
  width: 42px; height: 42px; border-radius: 999px; flex: none; background: var(--primary-soft); color: var(--on-soft);
  display: flex; align-items: center; justify-content: center; font-weight: 700; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.chat-row .txt { flex: 1; min-width: 0; }
.chat-row .txt div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row.unread .name { font-weight: 700; }
.talk { display: flex; flex-direction: column; gap: 6px; padding-bottom: 8px; }
.bubble {
  max-width: min(78%, 520px); padding: 8px 12px; border-radius: 18px; background: var(--theirs); border: 1px solid var(--border);
  align-self: flex-start; word-break: break-word; white-space: pre-wrap; cursor: pointer; position: relative;
}
.bubble.mine { align-self: flex-end; background: var(--mine); border-color: transparent; }
.bubble .time { font-size: 11.5px; color: var(--muted); margin-top: 2px; text-align: right; }
.bubble .btns { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.bubble .btns div { display: flex; gap: 4px; }
.bubble .btns span { flex: 1; text-align: center; font-size: 13px; padding: 4px 8px; border-radius: 10px; background: color-mix(in srgb, var(--primary) 14%, transparent); }
.reacts { font-size: 13px; margin-top: 2px; }
.composer { position: sticky; bottom: 0; background: var(--bg); padding: 8px 0; }
@media (max-width: 900px) { .composer { bottom: calc(64px + env(safe-area-inset-bottom)); } }
.composer .box { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 200px; border-radius: 22px; padding: 10px 16px; }

/* polls */
.bar { height: 10px; border-radius: 999px; background: var(--surface2); overflow: hidden; margin: 4px 0 10px; }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s ease; }

/* misc */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px 24px; }
.login img { width: 56px; height: 56px; border-radius: 16px; }
#toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
@media (max-width: 900px) { #toasts { bottom: calc(84px + env(safe-area-inset-bottom)); } }
.toast { background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; box-shadow: var(--shadow); animation: up .2s ease-out; max-width: 100%; }
.toast.bad { background: var(--danger); color: #fff; }
@keyframes up { from { opacity: 0; transform: translateY(8px); } }
.spin { width: 28px; height: 28px; border: 3px solid var(--surface3); border-top-color: var(--primary); border-radius: 999px; animation: rot .8s linear infinite; margin: 32px auto; }
@keyframes rot { to { transform: rotate(360deg); } }
dialog { border: 0; border-radius: 22px; padding: 0; background: var(--surface); color: var(--text); width: min(480px, calc(100vw - 32px)); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0,0,0,.4); }
dialog .in { padding: 20px; }
dialog h2 { margin: 0 0 12px; font-size: 19px; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 12px 8px; border-radius: 10px; cursor: pointer; }
.menu-list button:hover { background: var(--surface2); }
.code { font-family: ui-monospace, "JetBrains Mono", monospace; font-size: 12.5px; background: var(--surface2); border-radius: 10px; padding: 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
.log-line { border-bottom: 1px solid var(--border); padding: 6px 0; font-size: 13px; }
.log-line.error { color: var(--danger); }
.log-line.warn { color: var(--warn); }
details summary { cursor: pointer; font-weight: 600; padding: 4px 0; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
