:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, .08);
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --danger: #ff3b30;
  --green: #34c759;
  --bubble: #e9e9eb;
  --hl: rgba(255, 204, 0, .45);
  --nav: rgba(245, 245, 247, .72);
  --shadow: 0 2px 12px rgba(0, 0, 0, .04);
  --radius: 18px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --text: #f5f5f7;
    --muted: #98989d;
    --line: rgba(255, 255, 255, .1);
    --accent: #2997ff;
    --accent-hover: #47a6ff;
    --bubble: #26252a;
    --hl: rgba(255, 214, 10, .35);
    --nav: rgba(22, 22, 23, .72);
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.47 -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "PingFang SC",
        "Hiragino Sans GB", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.err { color: var(--danger); min-height: 1.4em; font-size: 14px; margin: 10px 0 0; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 980px; padding: 8px 18px; cursor: pointer;
  background: var(--surface-2); font-size: 14px; font-weight: 500;
  transition: background .2s, opacity .2s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-block { width: 100%; padding: 12px; font-size: 16px; }
.btn-small { padding: 5px 14px; font-size: 13px; }
.btn-danger-text { background: transparent; color: var(--danger); }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 8px; border-radius: 50%; color: var(--muted); }
.icon-btn svg { width: 20px; height: 20px; fill: currentColor; display: block; }
.icon-btn.danger:hover { color: var(--danger); background: var(--surface-2); }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-icon { width: 76px; height: 76px; border-radius: 18px; }
.login h1 { font-size: 34px; font-weight: 700; letter-spacing: -.02em; margin: 16px 0 4px; }
.login form { margin-top: 28px; }
.login input {
  width: 100%; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); margin-bottom: 12px; font-size: 16px; outline: none;
}
.login input:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(0, 113, 227, .15); }

/* ---------- nav ---------- */
.nav {
  position: sticky; top: 0; z-index: 20;
  background: var(--nav);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}
.nav-inner {
  max-width: 1200px; margin: 0 auto; height: 52px; padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 16px; min-width: 0; }
.brand img { width: 26px; height: 26px; border-radius: 7px; }
.nav-link { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 14px; padding: 6px 0; }
.seg { display: flex; background: var(--surface-2); border-radius: 9px; padding: 2px; }
.seg button {
  border: 0; background: transparent; padding: 5px 18px; border-radius: 7px; font-size: 13px;
  font-weight: 500; cursor: pointer; color: var(--muted); transition: all .2s;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .12); }

.large-title { font-size: 34px; font-weight: 700; letter-spacing: -.025em; margin: 0; }

/* ---------- inbox ---------- */
.inbox {
  max-width: 1200px; margin: 0 auto; display: grid; grid-template-columns: 380px 1fr;
  height: calc(100vh - 53px - env(safe-area-inset-top)); height: calc(100dvh - 53px - env(safe-area-inset-top));
}
.pane-list { border-right: 1px solid var(--line); overflow-y: auto; overscroll-behavior: contain; }
.list-head { padding: 24px 16px 8px; position: sticky; top: 0; background: var(--bg); z-index: 2; }
.stats { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.chip {
  font-size: 12px; padding: 3px 10px; border-radius: 980px; background: var(--surface);
  color: var(--muted); display: inline-flex; align-items: center; gap: 5px; box-shadow: var(--shadow);
}
.chip b { color: var(--text); font-weight: 600; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--green); }
.dot.off { background: var(--danger); }
.search { position: relative; }
.search svg { position: absolute; left: 10px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); fill: var(--muted); }
.search input {
  width: 100%; border: 0; outline: none; background: var(--surface-2); border-radius: 10px;
  padding: 9px 12px 9px 32px; font-size: 15px;
}
.search input::-webkit-search-cancel-button { cursor: pointer; }

.senders { list-style: none; margin: 0; padding: 4px 8px 24px; }
.sender {
  display: flex; gap: 12px; padding: 11px 10px; border-radius: 12px; cursor: pointer; align-items: center;
  transition: background .15s;
}
.sender:hover { background: var(--surface-2); }
.sender.active { background: var(--accent); color: #fff; }
.sender.active .muted, .sender.active .s-time, .sender.active .s-preview { color: rgba(255, 255, 255, .85); }
.sender.active .code-tag { background: rgba(255, 255, 255, .22); color: #fff; }
.avatar {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 16px;
  background: linear-gradient(180deg, #a5a5aa, #86868b);
}
.s-body { flex: 1; min-width: 0; }
.s-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.s-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s-num { font-weight: 400; font-size: 12px; margin-left: 4px; }
.s-time { font-size: 12px; color: var(--muted); flex: 0 0 auto; }
.s-preview {
  font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; word-break: break-all;
}
.badge {
  background: var(--accent); color: #fff; border-radius: 980px; font-size: 11px; font-weight: 600;
  min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center; margin-left: 6px;
}
.sender.active .badge { background: #fff; color: var(--accent); }
.code-tag {
  font: 600 12px ui-monospace, "SF Mono", Menlo, monospace; background: rgba(0, 113, 227, .1); color: var(--accent);
  padding: 1px 6px; border-radius: 6px; margin-right: 4px;
}
mark { background: var(--hl); color: inherit; border-radius: 3px; padding: 0 1px; }

.empty { text-align: center; padding: 60px 24px; }
.empty-icon { font-size: 44px; margin-bottom: 8px; }

/* thread */
.pane-thread { display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }
.thread-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line);
  background: var(--nav); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.thread-title { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.thread-title .avatar { width: 36px; height: 36px; font-size: 14px; }
.thread-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; border: 0; background: none; color: var(--accent); cursor: pointer; align-items: center; gap: 4px; padding: 4px 6px 4px 0; font-size: 16px; }
.back svg { width: 11px; height: 18px; }
.thread { flex: 1; overflow-y: auto; padding: 16px 16px 40px; overscroll-behavior: contain; }
.thread-placeholder { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; background: var(--bg); }

.day { text-align: center; font-size: 12px; color: var(--muted); margin: 18px 0 8px; font-weight: 500; }
.msg { display: flex; flex-direction: column; align-items: flex-start; margin: 6px 0; }
.bubble {
  max-width: min(560px, 86%); background: var(--bubble); padding: 9px 14px; border-radius: 20px;
  border-bottom-left-radius: 6px; white-space: pre-wrap; word-break: break-word; font-size: 15px;
  user-select: text;
}
.msg-meta { font-size: 11px; color: var(--muted); margin: 4px 6px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.msg-meta button { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 11px; padding: 0; }
.msg-meta .del { color: var(--muted); }
.msg-meta .del:hover { color: var(--danger); }
.push-ok { color: var(--green); }
.push-err { color: var(--danger); cursor: help; }
.code-btn {
  margin-top: 6px; border: 0; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); box-shadow: var(--shadow); border-radius: 12px; padding: 7px 12px;
  font: 600 18px ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .08em; color: var(--text);
}
.code-btn span { font: 500 12px -apple-system, "PingFang SC", sans-serif; letter-spacing: 0; color: var(--accent); }
.load-more { display: block; margin: 8px auto 16px; }

/* ---------- settings ---------- */
.settings { max-width: 720px; margin: 0 auto; padding: 24px 16px calc(60px + env(safe-area-inset-bottom)); }
.settings .large-title { margin-bottom: 12px; }
.group-title { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--muted); margin: 28px 16px 8px; letter-spacing: .02em; }
.group { background: var(--surface); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); margin: 0 0 8px; }
.group-foot { font-size: 13px; color: var(--muted); margin: 6px 16px 0; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 16px;
  min-height: 46px; position: relative;
}
.row + .row::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--line); }
.row > label:first-child { flex: 0 0 auto; }
.row.col { flex-direction: column; align-items: stretch; gap: 6px; }
.row input:not([type=checkbox]), .row select {
  flex: 1; min-width: 0; text-align: right; border: 0; outline: none; background: transparent; color: var(--muted);
  padding: 4px 0;
}
.row select { direction: rtl; cursor: pointer; appearance: none; -webkit-appearance: none; }
.row select option { direction: ltr; }
.row input:focus { color: var(--text); }
.row textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 8px 10px;
  outline: none; resize: vertical; font-size: 14px;
}
.row textarea:focus { border-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 0; }
.copyline { display: flex; gap: 10px; align-items: center; }
.copyline code {
  flex: 1; min-width: 0; font: 13px ui-monospace, "SF Mono", Menlo, monospace; background: var(--bg);
  padding: 7px 10px; border-radius: 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.copyline code.wrap { white-space: normal; word-break: break-all; }
.save-bar {
  position: sticky; bottom: 0; padding: 14px 0 calc(14px + env(safe-area-inset-bottom)); text-align: center; z-index: 5;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}
.save-bar .btn { padding: 11px 40px; font-size: 15px; }
.banner { background: rgba(255, 149, 0, .14); color: var(--text); border-radius: 12px; padding: 12px 16px; font-size: 14px; }

.device { display: flex; align-items: center; gap: 12px; }
.device-icon { font-size: 26px; }
.device-info { flex: 1; min-width: 0; }
.device-name { font-weight: 600; }

/* iOS switch */
.switch { position: relative; width: 51px; height: 31px; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--surface-2); border-radius: 31px; transition: background .25s; cursor: pointer; }
@media (prefers-color-scheme: light) { .switch span { background: #e9e9ea; } }
.switch span::after {
  content: ""; position: absolute; width: 27px; height: 27px; left: 2px; top: 2px; background: #fff; border-radius: 50%;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16); transition: transform .25s;
}
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(20px); }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(32px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: rgba(29, 29, 31, .92); color: #fff; padding: 10px 18px; border-radius: 980px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .3s; z-index: 100; max-width: calc(100% - 32px); text-align: center;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  .brand span { display: none; }
  .inbox { grid-template-columns: 1fr; height: auto; min-height: calc(100dvh - 53px); }
  .pane-list { border-right: 0; overflow: visible; }
  .list-head { position: static; padding-top: 16px; }
  .pane-thread {
    position: fixed; inset: 0; z-index: 30; transform: translateX(100%); transition: transform .32s cubic-bezier(.4, 0, .2, 1);
    padding-top: env(safe-area-inset-top);
  }
  body.thread-open .pane-thread { transform: none; }
  body.thread-open { overflow: hidden; }
  .back { display: inline-flex; }
  .thread-placeholder { display: none; }
  .thread { padding-bottom: calc(40px + env(safe-area-inset-bottom)); }
  .bubble { max-width: 92%; }
  .row > label:first-child { max-width: 45%; }
}
