:root {
  --bg: #f2f2f7; --card: #ffffff; --text: #000000; --muted: #6e6e73; --line: #d8d8dc; --key: #e5e5ea; --key-on: #c7c7cc;
  --blue: #007aff; --green: #34c759; --red: #ff3b30; --in-bubble: #e9e9eb; --in-text: #000; --out-bubble: #007aff; --out-text: #fff;
  --tab: rgba(249, 249, 249, .94); --sheet: rgba(0, 0, 0, .35);
  --top: env(safe-area-inset-top, 0px); --bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #000; --card: #1c1c1e; --text: #fff; --muted: #98989f; --line: #38383a; --key: #333335; --key-on: #5a5a5e;
    --blue: #0a84ff; --green: #30d158; --red: #ff453a; --in-bubble: #26252a; --in-text: #fff; --out-bubble: #0a84ff; --tab: rgba(22, 22, 24, .94); --sheet: rgba(0, 0, 0, .6); }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 17px/1.3 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }
svg.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.boot { display: grid; place-items: center; height: 100dvh; color: var(--muted); }
[hidden] { display: none !important; }

/* layout */
.app { display: flex; flex-direction: column; height: 100dvh; max-width: 560px; margin: 0 auto; }
.screen { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-top: var(--top); }
.head { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px 4px; min-height: 44px; }
.head h1 { font-size: 32px; font-weight: 700; margin: 4px 0 6px; letter-spacing: .2px; }
.head .act { color: var(--blue); padding: 8px; margin: -8px; display: flex; }
.tabs { display: flex; border-top: .5px solid var(--line); background: var(--tab); padding-bottom: var(--bottom); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 5px; font-size: 11px; color: var(--muted); position: relative; }
.tabs button.on { color: var(--blue); }
.tabs .badge { position: absolute; top: 2px; left: calc(50% + 6px); background: var(--red); color: #fff; border-radius: 10px; min-width: 18px; height: 18px;
  font-size: 12px; line-height: 18px; padding: 0 5px; font-weight: 600; }

/* login */
.login { display: flex; flex-direction: column; justify-content: center; min-height: 100dvh; padding: calc(var(--top) + 24px) 24px calc(var(--bottom) + 24px); max-width: 400px; margin: 0 auto; }
.login img { width: 84px; height: 84px; border-radius: 20px; align-self: center; margin-bottom: 14px; }
.login h1 { text-align: center; font-size: 28px; margin: 0 0 4px; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 24px; font-size: 15px; }
.field { display: block; background: var(--card); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
.field input { display: block; width: 100%; border: 0; background: transparent; padding: 14px 16px; outline: none; font-size: 17px; }
.field input + input { border-top: .5px solid var(--line); }
.btn { display: block; width: 100%; background: var(--blue); color: #fff; border-radius: 12px; padding: 14px; font-weight: 600; text-align: center; }
.btn[disabled] { opacity: .5; }
.err { color: var(--red); text-align: center; min-height: 22px; font-size: 15px; margin: 6px 0; }

/* keypad */
.kp { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-height: 100%; padding: 8px 0 18px; }
.kp-num { font-size: 36px; font-weight: 400; min-height: 52px; letter-spacing: 1px; text-align: center; padding: 0 20px; word-break: break-all; }
.kp-name { color: var(--muted); min-height: 22px; font-size: 15px; margin-bottom: 14px; }
.kp-grid { display: grid; grid-template-columns: repeat(3, 78px); gap: 14px 26px; }
.key { width: 78px; height: 78px; border-radius: 50%; background: var(--key); display: flex; flex-direction: column; align-items: center; justify-content: center;
  user-select: none; -webkit-user-select: none; transition: background .12s; }
.key:active, .key.on { background: var(--key-on); }
.key b { font-size: 34px; font-weight: 400; line-height: 1; }
.key small { font-size: 10px; font-weight: 700; letter-spacing: 2px; color: var(--text); min-height: 12px; margin-top: 2px; }
.kp-row { display: grid; grid-template-columns: repeat(3, 78px); gap: 26px; margin-top: 16px; align-items: center; justify-items: center; }
.callbtn { width: 78px; height: 78px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; }
.callbtn svg.i { width: 34px; height: 34px; fill: #fff; stroke: none; }
.callbtn[disabled] { opacity: .45; }
.del { color: var(--muted); padding: 14px; }
.del svg.i { width: 30px; height: 30px; }

/* lists */
.list { margin: 0; padding: 0; list-style: none; }
.row { display: flex; align-items: center; gap: 12px; padding: 0 0 0 16px; min-height: 64px; width: 100%; text-align: left; }
.row > .body { flex: 1; min-width: 0; padding: 10px 16px 10px 0; border-bottom: .5px solid var(--line); display: flex; align-items: center; gap: 8px; align-self: stretch; }
.row:last-child > .body { border-bottom: 0; }
.row .main { flex: 1; min-width: 0; }
.row .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t2 { color: var(--muted); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t2.two { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row .when { color: var(--muted); font-size: 15px; align-self: flex-start; padding-top: 2px; white-space: nowrap; }
.row .bad { color: var(--red); }
.row .side { color: var(--blue); padding: 10px; margin: -10px -6px -10px 0; display: flex; }
.av { width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(#a5abb8, #858994); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 17px; flex: none; }
.av svg.i { width: 24px; height: 24px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--blue); flex: none; margin-left: -10px; margin-right: -2px; }
.row.unread .t1 { font-weight: 700; }
.row.unread .t2 { color: var(--text); }
.empty { color: var(--muted); text-align: center; padding: 48px 32px; }
.card { background: var(--card); border-radius: 12px; margin: 6px 16px 16px; overflow: hidden; }
.note { color: var(--muted); font-size: 13px; padding: 0 32px 24px; text-align: center; }

/* thread */
.thread { display: flex; flex-direction: column; height: 100dvh; max-width: 560px; margin: 0 auto; }
.thead { display: grid; grid-template-columns: 80px 1fr 80px; align-items: center; padding: calc(var(--top) + 6px) 8px 8px; border-bottom: .5px solid var(--line); background: var(--tab);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); }
.thead .back { color: var(--blue); display: flex; align-items: center; font-size: 17px; justify-self: start; padding: 6px 4px; }
.thead .who { text-align: center; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 2px 0; }
.thead .who .av { width: 40px; height: 40px; font-size: 15px; }
.thead .who span { font-size: 12px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thead .call { color: var(--blue); justify-self: end; padding: 8px; display: flex; }
.to { display: flex; align-items: center; gap: 8px; padding: calc(var(--top) + 10px) 16px 10px; border-bottom: .5px solid var(--line); background: var(--tab); }
.to .back { color: var(--blue); }
.to label { color: var(--muted); }
.to input { flex: 1; border: 0; background: transparent; outline: none; font-size: 17px; padding: 6px 0; }
.msgs { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px 6px; display: flex; flex-direction: column; gap: 2px; }
.stamp { text-align: center; color: var(--muted); font-size: 12px; margin: 12px 0 6px; }
.b { max-width: 76%; padding: 8px 13px; border-radius: 19px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; font-size: 17px; line-height: 1.28; }
.b.in { align-self: flex-start; background: var(--in-bubble); color: var(--in-text); }
.b.out { align-self: flex-end; background: var(--out-bubble); color: var(--out-text); }
.b.out.other { background: #5e5ce6; }
.b.gap { margin-top: 8px; }
.b.failed { background: #8e8e93; }
.b a { color: inherit; }
.b img { display: block; max-width: 100%; border-radius: 12px; margin: 2px 0; }
.st { align-self: flex-end; font-size: 11px; color: var(--muted); margin: 2px 6px 4px; }
.st.bad { color: var(--red); }
.who-note { align-self: flex-end; font-size: 11px; color: var(--muted); margin: 6px 6px 0; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 10px calc(var(--bottom) + 8px); border-top: .5px solid var(--line); background: var(--tab); }
.composer textarea { flex: 1; resize: none; border: 1px solid var(--line); background: var(--card); border-radius: 19px; padding: 8px 14px; max-height: 140px; min-height: 38px;
  outline: none; font-size: 17px; line-height: 1.3; }
.send { width: 34px; height: 34px; border-radius: 50%; background: var(--blue); color: #fff; display: grid; place-items: center; margin-bottom: 2px; flex: none; }
.send[disabled] { opacity: .35; }
.send svg.i { width: 20px; height: 20px; stroke-width: 2.6; }
.noreply { text-align: center; color: var(--muted); font-size: 13px; padding: 12px 16px calc(var(--bottom) + 12px); border-top: .5px solid var(--line); }

/* call screen */
.callui { position: fixed; inset: 0; z-index: 50; background: linear-gradient(#3a4150, #1b1e26); color: #fff; display: flex; flex-direction: column; align-items: center;
  padding: calc(var(--top) + 64px) 24px calc(var(--bottom) + 40px); }
.callui .nm { font-size: 32px; font-weight: 500; text-align: center; word-break: break-word; }
.callui .stt { font-size: 17px; opacity: .8; margin-top: 8px; min-height: 22px; font-variant-numeric: tabular-nums; }
.callui .tones { font-size: 26px; letter-spacing: 2px; min-height: 34px; margin-top: 14px; }
.callui .ctrls { margin-top: auto; display: grid; grid-template-columns: repeat(3, 78px); gap: 18px 26px; justify-items: center; }
.callui .ctl { width: 72px; height: 72px; border-radius: 50%; background: rgba(255, 255, 255, .18); display: grid; place-items: center; color: #fff; }
.callui .ctl.on { background: #fff; color: #1b1e26; }
.callui .lbl { font-size: 12px; text-align: center; margin-top: 6px; opacity: .9; }
.callui .ctlwrap { display: flex; flex-direction: column; align-items: center; }
.callui .end { width: 78px; height: 78px; border-radius: 50%; background: var(--red); display: grid; place-items: center; margin-top: 30px; }
.callui .end svg.i { width: 34px; height: 34px; fill: #fff; stroke: none; transform: rotate(135deg); }
.callui .kp-grid .key { background: rgba(255, 255, 255, .18); color: #fff; }
.callui .kp-grid .key small { color: #fff; }
.callui .kp-grid .key:active { background: rgba(255, 255, 255, .4); }
.callui .hidepad { margin-top: 18px; font-size: 17px; opacity: .9; }

/* sheet + toast */
.sheet-bg { position: fixed; inset: 0; background: var(--sheet); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; padding: 0 8px calc(var(--bottom) + 8px); }
.sheet .grp { background: var(--card); border-radius: 14px; overflow: hidden; margin-bottom: 8px; }
.sheet .grp > * { display: block; width: 100%; padding: 16px; text-align: center; color: var(--blue); font-size: 19px; border-bottom: .5px solid var(--line); }
.sheet .grp > *:last-child { border-bottom: 0; }
.sheet .grp .info { color: var(--muted); font-size: 13px; padding: 12px 16px; }
.sheet .grp .danger { color: var(--red); }
.sheet .grp .cancel { font-weight: 600; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottom) + 76px); z-index: 60; background: rgba(30, 30, 32, .92); color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 15px; max-width: min(92vw, 480px); text-align: center; }
.toast.bad { background: rgba(200, 30, 30, .95); }
.spin { color: var(--muted); text-align: center; padding: 24px; font-size: 15px; }
