:root {
  --bg: #f3f5f4;
  --card: #ffffff;
  --text: #17201d;
  --muted: #66736e;
  --line: #dde3e0;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --ok: #1f6f5c;
  --chat-bg: #e7ece9;
  --bubble-in: #ffffff;
  --bubble-out: #d6eee4;
  --bubble-out-text: #10231c;
  --quote: #1f6f5c;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101413;
    --card: #1a201e;
    --text: #e8eeeb;
    --muted: #93a19b;
    --line: #2c3532;
    --accent: #4fb89c;
    --accent-text: #0c1a16;
    --danger: #ff8a80;
    --ok: #4fb89c;
    --chat-bg: #0c100f;
    --bubble-in: #1f2624;
    --bubble-out: #1f4a3e;
    --bubble-out-text: #e8f5ef;
    --quote: #6fd3b6;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; color: inherit; }

/* ---------- screens ---------- */
.screen {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  background: var(--bg);
}
.screen.padded, .scroll.padded { padding-left: 16px; padding-right: 16px; }
#auth { overflow-y: auto; padding-bottom: 32px; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.scroll.padded { padding-top: 12px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.narrow { max-width: 560px; margin: 0 auto; }

.bar {
  display: flex; align-items: center; gap: 4px;
  min-height: 56px; padding: 4px 8px;
  background: var(--card); border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.bar-title { flex: 1; margin: 0 8px; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 44px; height: 44px; flex-shrink: 0;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 50%; background: transparent; color: var(--text);
}
.icon-btn:active { background: var(--line); }
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn.small { width: 36px; height: 36px; }
.icon-btn.small svg { width: 20px; height: 20px; }
.bar-who {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  border: 0; background: transparent; padding: 4px; text-align: left; border-radius: 10px;
}
.who-text { display: flex; flex-direction: column; min-width: 0; }
.who-text b, .who-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-text small { color: var(--muted); font-size: 13px; }

/* ---------- auth & cards ---------- */
.brand { text-align: center; margin: 32px 0 20px; }
.brand img { border-radius: 16px; }
.brand h1 { margin: 8px 0 0; font-size: 26px; }
.tabs { display: flex; gap: 4px; background: var(--line); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tab { flex: 1; border: 0; background: transparent; padding: 10px; border-radius: 9px; }
.tab.active { background: var(--card); font-weight: 600; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 12px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
select { width: auto; margin: 0; padding: 8px 10px; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.primary { width: 100%; padding: 13px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.primary:disabled { opacity: .6; }
.ghost { border: 1px solid var(--line); background: transparent; border-radius: 10px; padding: 10px 14px; }
.ghost.wide { width: 100%; padding: 13px; }
.ghost.danger, .danger-text { color: var(--danger); }
.small { padding: 6px 10px; font-size: 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
.small.ok { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.small.bad { color: var(--danger); }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
h2 { font-size: 18px; margin: 0; }
.hello { font-size: 18px; margin: 0 0 4px; }
.muted, .hint { color: var(--muted); margin: 4px 0 0; font-size: 14px; }
.msg { min-height: 1.2em; margin: 10px 0 0; font-size: 14px; }
.msg.error { color: var(--danger); }
.msg.success { color: var(--ok); }
summary { font-weight: 600; cursor: pointer; }
details form { margin-top: 12px; }
.list { list-style: none; padding: 0; margin: 0; }
.list li { padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .who { font-weight: 600; overflow-wrap: anywhere; }
.list .meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.list .actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.empty { color: var(--muted); padding: 8px 0; }

/* ---------- avatars ---------- */
.avatar {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: 50%;
  display: inline-grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 16px;
  background: var(--av, #1f6f5c);
}
.avatar.big { width: 52px; height: 52px; font-size: 20px; }

/* ---------- chat list ---------- */
.chat-list { list-style: none; margin: 0; padding: 0 0 calc(16px + env(safe-area-inset-bottom)); }
.chat-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 10px 16px; border: 0; background: transparent; text-align: left;
}
.chat-item:active { background: var(--line); }
.chat-main { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.chat-top, .chat-bottom { display: flex; align-items: center; gap: 8px; }
.chat-name { flex: 1; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-time { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.chat-last { flex: 1; color: var(--muted); font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge {
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: var(--accent); color: var(--accent-text);
  font-size: 13px; font-weight: 600; display: inline-grid; place-items: center; flex-shrink: 0;
}
.empty-state { text-align: center; color: var(--muted); padding: 48px 24px; max-width: 360px; margin: 0 auto; }

/* ---------- messages ---------- */
.messages { background: var(--chat-bg); padding: 8px 10px 12px; }
.load-more { text-align: center; color: var(--muted); font-size: 13px; padding: 8px; }
.day { text-align: center; margin: 12px 0 6px; }
.day span { background: rgba(0,0,0,.18); color: #fff; font-size: 13px; padding: 3px 10px; border-radius: 10px; }
.sys { text-align: center; margin: 6px 0; }
.sys span { color: var(--muted); font-size: 13px; background: var(--card); padding: 3px 10px; border-radius: 10px; display: inline-block; max-width: 90%; }
.m { display: flex; margin: 2px 0; }
.m.out { justify-content: flex-end; }
.m.gap { margin-top: 8px; }
.bubble { cursor: pointer; user-select: text; -webkit-user-select: text;
  max-width: min(80%, 520px);
  padding: 6px 10px 6px; border-radius: 14px;
  background: var(--bubble-in); color: var(--text);
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
  border: 0; text-align: left; font: inherit;
  overflow-wrap: anywhere; white-space: pre-wrap;
}
.m.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); }
.m.flash .bubble { outline: 2px solid var(--accent); }
.author { display: block; font-size: 13px; font-weight: 600; color: var(--av, var(--quote)); margin-bottom: 1px; white-space: nowrap; }
.quote {
  display: block; border-left: 3px solid var(--quote); padding: 2px 8px; margin: 2px 0 4px;
  background: rgba(127,127,127,.12); border-radius: 4px; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.quote b { display: block; color: var(--quote); font-size: 13px; }
.meta-line { float: right; margin: 6px 0 -4px 10px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.m.out .meta-line { color: color-mix(in srgb, var(--bubble-out-text) 60%, transparent); }
.deleted { color: var(--muted); font-style: italic; }
.bubble a { color: inherit; text-decoration: underline; }

/* ---------- composer ---------- */
.compose-wrap { background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); flex-shrink: 0; }
.compose-bar { display: flex; align-items: center; gap: 8px; padding: 6px 8px 0 14px; }
.compose-bar-text { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 8px; font-size: 14px; }
.compose-bar-text b { display: block; color: var(--accent); font-size: 13px; }
.compose-bar-text span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px; }
.composer textarea {
  margin: 0; resize: none; max-height: 140px; min-height: 44px;
  border-radius: 22px; padding: 11px 16px; line-height: 1.35;
}
.send-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 0; flex-shrink: 0;
  background: var(--accent); color: var(--accent-text); display: grid; place-items: center;
}
.send-btn svg { width: 22px; height: 22px; }

/* ---------- action sheet ---------- */
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet-panel {
  width: 100%; max-width: 480px; background: var(--card);
  border-radius: 16px 16px 0 0; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
.sheet-preview { padding: 8px 12px 10px; color: var(--muted); font-size: 14px; border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-panel button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 14px 12px; border-radius: 10px; font-size: 17px; }
.sheet-panel button:active { background: var(--line); }
.sheet-panel button.danger { color: var(--danger); }

/* ---------- pickers & group info ---------- */
.pick { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 4px; border: 0; background: transparent; text-align: left; border-bottom: 1px solid var(--line); }
.pick .name { flex: 1; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick input[type=checkbox] { width: 22px; height: 22px; margin: 0; flex-shrink: 0; accent-color: var(--accent); }
.pick .role { color: var(--muted); font-size: 13px; }
.pick.special .avatar { background: var(--accent); }
.switch { display: flex; align-items: center; gap: 12px; color: var(--text); font-size: 16px; margin: 0; }
.switch input { width: 22px; height: 22px; margin: 0; flex-shrink: 0; accent-color: var(--accent); }
.section-title { color: var(--muted); font-size: 14px; margin: 16px 4px 4px; }
.sticky-bottom { position: sticky; bottom: 0; padding: 12px 0 4px; background: var(--bg); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 20px; font-size: 14px; z-index: 20;
  max-width: calc(100% - 32px);
}

/* ---------- notifications ---------- */
.banner {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 12px 4px; padding: 10px 6px 10px 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.banner-text { flex: 1; min-width: 0; font-size: 14px; }
.banner-text b { display: block; }
.banner-text span { color: var(--muted); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-row .ghost { flex: 1; }
.help { margin-top: 12px; }
.help summary { font-weight: 500; color: var(--accent); }
.help ol { padding-left: 20px; margin: 10px 0; }
.help li { margin: 6px 0; }
.mute-icon { width: 16px; height: 16px; color: var(--muted); flex-shrink: 0; }
.badge.muted { background: var(--muted); color: var(--card); }
