:root {
  --blue: #1b5bb5; --blue2: #2f7de1; --sky: #dbe7f8; --ink: #16233a; --muted: #6b7a90; --line: #d6e0ef; --panel: #fff;
  --green: #43b02a; --orange: #f08a16; --red: #d9231d; --sat: env(safe-area-inset-top); --sab: env(safe-area-inset-bottom);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 -apple-system, "Segoe UI", Roboto, "Noto Sans Thai", Tahoma, sans-serif; color: var(--ink); background: #eef3fa; overscroll-behavior: none; }
button, input, textarea, select { font: inherit; }
.hidden { display: none !important; }
a { color: var(--blue); }

/* screens */
.screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: #eef3fa; }
.top { background: linear-gradient(#2f7de1, #1b5bb5); color: #fff; padding: calc(var(--sat) + 10px) 14px 10px; display: flex; align-items: center; gap: 10px; min-height: calc(var(--sat) + 52px); box-shadow: 0 2px 6px rgba(0,0,0,.2); z-index: 2; }
.top h1 { font-size: 18px; margin: 0; flex: 1; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { font-size: 12px; opacity: .85; font-weight: 400; display: block; }
.top button { background: none; border: none; color: #fff; font-size: 22px; padding: 4px 6px; line-height: 1; }
.body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tabs { display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--sab); }
.tabs button { flex: 1; background: none; border: none; padding: 8px 0 6px; color: var(--muted); font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
.tabs button .ic { font-size: 22px; line-height: 1; }
.tabs button.on { color: var(--blue); font-weight: 700; }
.tabs .badge { position: absolute; top: 4px; left: calc(50% + 8px); background: var(--red); color: #fff; font-size: 10px; min-width: 17px; height: 17px; border-radius: 9px; display: flex; align-items: center; justify-content: center; padding: 0 4px; font-weight: 700; }

/* lists */
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: #fff; border-bottom: 1px solid #eef2f8; }
.row:active { background: #f0f5fd; }
.row .av { width: 46px; height: 46px; border-radius: 8px; border: 1px solid var(--line); background: #e4edf8; object-fit: cover; flex: none; }
.row .av.sm { width: 36px; height: 36px; }
.row .mid { flex: 1; min-width: 0; }
.row .nm { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.sico { width: 14px; height: 14px; display: inline-block; vertical-align: -2px; flex: none; }
.row .ps { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .ps.unread { color: var(--ink); font-weight: 600; }
.row .right { text-align: right; font-size: 12px; color: var(--muted); flex: none; }
.row .cnt { display: inline-block; background: var(--blue); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; font-weight: 700; margin-top: 3px; }
.grp { padding: 8px 14px 4px; font-size: 12px; font-weight: 700; color: #1f3f73; text-transform: uppercase; letter-spacing: .4px; }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty b { display: block; font-size: 17px; color: var(--ink); margin-bottom: 6px; }

/* login */
.login { padding: calc(var(--sat) + 30px) 24px 24px; display: flex; flex-direction: column; align-items: center; background: linear-gradient(#fff, var(--sky)); }
.login .brand { font: 800 24px "Trebuchet MS", sans-serif; color: var(--blue); margin: 8px 0 2px; }
.login .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; text-align: center; }
.login form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.login label { font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: -6px; }
.field { display: flex; align-items: center; border: 1px solid #a9bfdf; border-radius: 10px; background: #fff; padding: 0 10px; }
.field input { flex: 1; min-width: 0; border: none; outline: none; padding: 12px 0; background: transparent; font-size: 16px; }
.field .suf { color: var(--muted); font-size: 14px; }
.btn { border: none; border-radius: 10px; padding: 12px 16px; font-weight: 700; font-size: 16px; background: linear-gradient(#3b86e8, #1b5bb5); color: #fff; }
.btn.ghost { background: #fff; color: var(--blue); border: 1px solid #a9bfdf; }
.btn.sm { padding: 7px 12px; font-size: 14px; border-radius: 8px; }
.btn.danger { background: #fff; color: var(--red); border: 1px solid #f0b4b0; }
.btn:disabled { opacity: .5; }
.err { color: var(--red); font-size: 13px; min-height: 18px; text-align: center; }
.login .links { margin-top: 14px; display: flex; gap: 18px; font-size: 14px; }
.login .lang { margin-top: auto; padding-top: 20px; font-size: 13px; color: var(--muted); }
.login select { border: 1px solid #a9bfdf; border-radius: 8px; padding: 4px 8px; background: #fff; }

/* signing-in orbit animation */
.msn-orbit { position: relative; margin: 0 auto; }
.msn-orbit .bd { position: absolute; left: 50%; top: 50%; width: 46%; height: 78%; margin-left: -23%; margin-top: -39%; animation: msnOrbit 2.1s linear infinite; will-change: transform; }
.msn-orbit .bd.blue { animation-delay: -1.05s; }
@keyframes msnOrbit {
  0% { transform: translateX(-42%) scale(.98); z-index: 1; } 12.5% { transform: translateX(-30%) scale(.86); z-index: 0; } 25% { transform: translateX(0) scale(.8); z-index: 0; } 37.5% { transform: translateX(30%) scale(.86); z-index: 0; }
  50% { transform: translateX(42%) scale(.98); z-index: 1; } 62.5% { transform: translateX(30%) scale(1.1); z-index: 2; } 75% { transform: translateX(0) scale(1.16); z-index: 2; } 87.5% { transform: translateX(-30%) scale(1.1); z-index: 2; } 100% { transform: translateX(-42%) scale(.98); z-index: 1; }
}

/* chat */
.chat .body { padding: 10px 12px 6px; background: #fff; }
.m { margin-bottom: 8px; }
.m .who { font-size: 12px; color: #3a5a86; }
.m .who.me { color: #6b4a1b; }
.m .txt { padding: 2px 0 2px 14px; font-size: 16px; white-space: pre-wrap; word-wrap: break-word; }
.m .time { font-size: 10px; color: var(--muted); margin-left: 4px; }
.sys { color: #666; font-style: italic; font-size: 13px; text-align: center; margin: 8px 0; }
.sys.err { color: var(--red); }
.readmark { text-align: right; color: #3a8f2a; font-size: 11px; margin: -4px 2px 8px 0; }
.readmark span { color: var(--muted); }
.day { text-align: center; color: var(--muted); font-size: 11px; margin: 10px 0 6px; }
.compose { background: #f3f6fb; border-top: 1px solid var(--line); padding: 6px 8px calc(var(--sab) + 6px); display: flex; align-items: flex-end; gap: 6px; }
.compose textarea { flex: 1; border: 1px solid #a9bfdf; border-radius: 18px; padding: 9px 12px; resize: none; max-height: 110px; font-size: 16px; outline: none; background: #fff; line-height: 1.35; }
.compose button { border: none; background: none; font-size: 24px; padding: 4px 6px; color: var(--blue); line-height: 1; }
.compose button.send { background: var(--blue); color: #fff; border-radius: 50%; width: 40px; height: 40px; font-size: 18px; }
.typing { font-size: 12px; color: #335; padding: 2px 14px; min-height: 18px; background: #fff; }
.emopick { display: none; flex-wrap: wrap; gap: 4px; padding: 8px; background: #fff; border-top: 1px solid var(--line); max-height: 180px; overflow-y: auto; }
.emopick span { font-size: 24px; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; border-radius: 8px; }
.emopick span:active { background: #eef4fc; }
.emo { font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif; }
@keyframes shake { 10%, 90% { transform: translate(-6px, 2px); } 20%, 80% { transform: translate(7px, -3px); } 30%, 50%, 70% { transform: translate(-9px, 4px); } 40%, 60% { transform: translate(9px, -4px); } }
.shaking { animation: shake .7s cubic-bezier(.36,.07,.19,.97) both; }
.grp-av { display: flex; align-items: center; justify-content: center; font-size: 24px; background: linear-gradient(#e4f4ff, #bcd8f8); width: 46px; height: 46px; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.grp-av.sm { width: 36px; height: 36px; font-size: 20px; }
.filebox { display: inline-flex; align-items: center; gap: 10px; margin: 2px 0 2px 14px; padding: 8px 12px; border: 1px solid #a9c1e4; background: linear-gradient(#fff, #edf3fb); border-radius: 10px; text-decoration: none; color: var(--ink); max-width: 100%; }
.filebox .ic { font-size: 22px; }
.filebox .fi { display: flex; flex-direction: column; min-width: 0; }
.filebox .fi b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55vw; }
.filebox .fi small { color: var(--muted); font-size: 12px; }
.filebox .dl { color: var(--blue); font-size: 18px; }
.compose #fileBtn, .compose #picBtn { font-size: 22px; padding: 4px 3px; }
.picbox { display: inline-block; margin: 2px 0 2px 14px; max-width: 100%; }
.picbox img { display: block; max-width: min(78vw, 360px); max-height: 300px; border-radius: 10px; border: 1px solid var(--line); background: #f3f6fb; }

/* voice call overlay */
.callbox { position: fixed; inset: 0; z-index: 40; background: linear-gradient(#1b2a45, #0f1f3d); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: calc(var(--sat) + 20px) 20px calc(var(--sab) + 30px); }
.callbox img { width: 120px; height: 120px; border-radius: 20px; border: 2px solid rgba(255,255,255,.5); object-fit: cover; background: #e4edf8; }
.callbox .cn { font-size: 22px; font-weight: 700; margin-top: 8px; }
.callbox .cs { font-size: 14px; opacity: .85; }
.callbox .ct { font-size: 16px; font-variant-numeric: tabular-nums; min-height: 22px; }
.callbox .cbtns { display: flex; gap: 14px; margin-top: 30px; }
.callbox .btn.cgreen { background: linear-gradient(#7ad35a, #3f9a2a); }
.callbox .btn.cred { background: linear-gradient(#f06a60, #c0271d); }
.callbox .btn.ghost { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.3); }

/* me */
.me-head { background: #fff; padding: 18px 16px; display: flex; gap: 14px; align-items: center; border-bottom: 1px solid var(--line); }
.me-head img { width: 72px; height: 72px; border-radius: 10px; border: 1px solid var(--line); object-fit: cover; background: #e4edf8; }
.me-head .n { font-size: 18px; font-weight: 700; }
.me-head .p { color: var(--muted); font-size: 13px; }
.cell { background: #fff; padding: 13px 16px; border-bottom: 1px solid #eef2f8; display: flex; align-items: center; gap: 12px; }
.cell .lbl { flex: 1; }
.cell .val { color: var(--muted); font-size: 14px; max-width: 55%; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell select { border: 1px solid #a9bfdf; border-radius: 8px; padding: 6px 8px; background: #fff; }
.sect { padding: 14px 16px 6px; font-size: 12px; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.switch { width: 46px; height: 26px; border-radius: 13px; background: #c9d2e0; position: relative; transition: background .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .2s; }
.switch.on { background: var(--green); }
.switch.on::after { left: 23px; }

/* modal / sheet */
.sheet { position: fixed; inset: 0; background: rgba(15,31,61,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.sheet .box { background: #fff; width: 100%; max-width: 520px; border-radius: 16px 16px 0 0; padding: 16px 16px calc(var(--sab) + 16px); }
.sheet h3 { margin: 0 0 10px; font-size: 17px; }
.sheet .opt { padding: 13px 4px; border-bottom: 1px solid #eef2f8; display: flex; align-items: center; gap: 10px; font-size: 16px; }
.sheet .opt.danger { color: var(--red); }
.sheet input[type=text], .sheet input[type=password] { width: 100%; border: 1px solid #a9bfdf; border-radius: 10px; padding: 11px 12px; font-size: 16px; margin: 6px 0 10px; }
.sheet .acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.toast { position: fixed; top: calc(var(--sat) + 10px); left: 12px; right: 12px; background: #fff; border: 1px solid #5f7ca8; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); padding: 10px 12px; display: flex; gap: 10px; align-items: center; z-index: 30; transform: translateY(-120%); transition: transform .3s; }
.toast.in { transform: translateY(0); }
.toast img { width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--line); object-fit: cover; }
.toast .t { flex: 1; min-width: 0; }
.toast .n { font-weight: 700; color: #1f3f73; }
.toast .m { font-size: 13px; color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.banner { background: #fff6c8; color: #6b5300; font-size: 13px; padding: 6px 14px; border-bottom: 1px solid #e3cd77; }
.install-hint { background: #fff; margin: 12px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.install-hint b { color: var(--ink); }
