/* ระบบดีไซน์ร่วม — iOS / Liquid Glass ตาม Apple HIG (docs/2026-11-10-multichannel-ios-design.md)
   content layer = พื้น grouped · Liquid Glass เฉพาะ bar/control ที่ลอยเหนือ content */
:root {
  --tint: #007aff; --tint-press: #0062cc; --green: #34c759; --red: #ff3b30; --orange: #ff9500;
  --bg: #f2f2f7; --bg-elev: #ffffff; --fill: rgba(120,120,128,.12); --fill-2: rgba(120,120,128,.16); --fill-3: rgba(120,120,128,.2);
  --label: #000; --label-2: rgba(60,60,67,.6); --label-3: rgba(60,60,67,.3); --sep: rgba(60,60,67,.2);
  --bubble-in: #e9e9eb; --bubble-in-text: #000; --bubble-out: var(--tint); --bubble-out-text: #fff;
  --glass-bg: rgba(255,255,255,.62); --glass-border: rgba(255,255,255,.55); --glass-hi: rgba(255,255,255,.75); --glass-shadow: 0 10px 30px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --blob-a: #cfe3ff; --blob-b: #ffe1ec; --blob-c: #d9f6e7;
  --radius-bar: 22px; --radius-pill: 999px; --radius-bubble: 18px; --radius-card: 16px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Noto Sans Thai", "Sukhumvit Set", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --tint: #0a84ff; --tint-press: #409cff; --green: #30d158; --red: #ff453a; --orange: #ff9f0a;
    --bg: #000; --bg-elev: #1c1c1e; --fill: rgba(120,120,128,.24); --fill-2: rgba(120,120,128,.32); --fill-3: rgba(120,120,128,.36);
    --label: #fff; --label-2: rgba(235,235,245,.6); --label-3: rgba(235,235,245,.3); --sep: rgba(84,84,88,.65);
    --bubble-in: #262629; --bubble-in-text: #fff;
    --glass-bg: rgba(28,28,30,.6); --glass-border: rgba(255,255,255,.14); --glass-hi: rgba(255,255,255,.18); --glass-shadow: 0 10px 30px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
    --blob-a: #10243f; --blob-b: #3a1a2b; --blob-c: #12302a;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; font: 17px/1.35 var(--font); color: var(--label); background: var(--bg); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--tint); text-decoration: none; }

/* Dynamic Type */
.t-large { font-size: 34px; font-weight: 700; letter-spacing: .37px; line-height: 41px; }
.t-title3 { font-size: 20px; font-weight: 600; line-height: 25px; }
.t-headline { font-size: 17px; font-weight: 600; line-height: 22px; }
.t-body { font-size: 17px; line-height: 22px; }
.t-callout { font-size: 16px; line-height: 21px; }
.t-sub { font-size: 15px; line-height: 20px; }
.t-foot { font-size: 13px; line-height: 18px; }
.t-cap { font-size: 12px; line-height: 16px; }
.t-cap2 { font-size: 11px; line-height: 13px; }
.c2 { color: var(--label-2); } .c3 { color: var(--label-3); } .mono { font-family: var(--mono); }

/* พื้นหลัง content layer: gradient นุ่ม ๆ ให้ glass มีอะไรให้หักเห */
.backdrop { position: fixed; inset: 0; z-index: -1; background: var(--bg); overflow: hidden; }
.backdrop i { position: absolute; border-radius: 50%; filter: blur(80px); opacity: .9; }
.backdrop i:nth-child(1) { width: 60vmax; height: 60vmax; background: var(--blob-a); top: -25vmax; left: -15vmax; }
.backdrop i:nth-child(2) { width: 50vmax; height: 50vmax; background: var(--blob-b); bottom: -20vmax; right: -10vmax; }
.backdrop i:nth-child(3) { width: 40vmax; height: 40vmax; background: var(--blob-c); bottom: 10vmax; left: 30vmax; }

/* Liquid Glass (regular) */
.glass {
  background: var(--glass-bg);
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 var(--glass-hi), var(--glass-shadow);
}
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .glass { background: var(--bg-elev); }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
  .glass { background: var(--bg-elev); -webkit-backdrop-filter: none; backdrop-filter: none; border-color: var(--sep); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* bars (ลอย) */
.bar { position: sticky; z-index: 5; margin: 8px 8px 0; padding: 6px 8px; border-radius: var(--radius-bar); display: flex; align-items: center; gap: 6px; min-height: 52px; }
.bar.top { top: 8px; }
.bar.bottom { position: sticky; bottom: calc(8px + var(--safe-b)); margin: 0 8px 8px; }
.bar .grow { flex: 1; min-width: 0; }
.bar .title { padding-left: 10px; font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { width: 40px; height: 40px; border-radius: 999px; display: inline-flex; align-items: center; justify-content: center; color: var(--tint); transition: background .15s, transform .1s; }
.icon-btn:hover { background: var(--fill); } .icon-btn:active { transform: scale(.94); background: var(--fill-2); }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.prominent { background: var(--tint); color: #fff; width: 36px; height: 36px; } .icon-btn.prominent:active { background: var(--tint-press); }
.icon-btn.prominent:disabled { opacity: .4; cursor: default; transform: none; }
.icon-btn.neutral { color: var(--label); }

/* large title → ย่อเมื่อเลื่อน */
.large-title { padding: 10px 20px 6px; }
.large-title h1 { margin: 0; }

/* search / segmented */
.search { display: flex; align-items: center; gap: 8px; margin: 10px 16px 0; padding: 0 12px; height: 38px; border-radius: 12px; background: var(--fill); color: var(--label-2); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; outline: none; color: var(--label); }
.search svg { width: 16px; height: 16px; flex: none; }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; margin: 10px 16px 0; padding: 2px; border-radius: 10px; background: var(--fill); }
.segmented button { height: 30px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--label); transition: background .15s, box-shadow .15s; }
.segmented button.on { background: var(--bg-elev); box-shadow: 0 1px 3px rgba(0,0,0,.12); font-weight: 600; }

/* list */
.list { overflow: auto; flex: 1; padding: 8px 8px calc(16px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.row { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border-radius: 14px; cursor: pointer; transition: background .12s; }
.row:hover { background: var(--fill); } .row.on { background: var(--fill-2); }
.row .meta { flex: 1; min-width: 0; }
.row .l1 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.row .l1 b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .l2 { display: flex; justify-content: space-between; gap: 8px; align-items: center; color: var(--label-2); font-size: 15px; }
.row .l2 span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--fill-2); object-fit: cover; flex: none; display: inline-flex; align-items: center; justify-content: center; color: var(--label-2); font-weight: 600; position: relative; }
.avatar.sm { width: 36px; height: 36px; }
.avatar .ch { position: absolute; right: -2px; bottom: -2px; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--bg); display: flex; align-items: center; justify-content: center; }
.avatar .ch.line { background: #06c755; } .avatar .ch.web { background: var(--tint); } .avatar .ch.telegram { background: #2aabee; }
.avatar .ch svg { width: 10px; height: 10px; color: #fff; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--tint); color: #fff; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 8px; border-radius: 10px; background: var(--fill); font-size: 11px; font-weight: 600; color: var(--label-2); }
.empty { margin: auto; color: var(--label-3); text-align: center; padding: 40px 20px; }

/* thread */
.thread { flex: 1; overflow: auto; padding: 8px 14px 4px; display: flex; flex-direction: column; gap: 2px; -webkit-overflow-scrolling: touch; }
.day { align-self: center; margin: 14px 0 6px; font-size: 12px; font-weight: 600; color: var(--label-2); }
.msg { max-width: min(78%, 560px); padding: 8px 13px; border-radius: var(--radius-bubble); white-space: pre-wrap; word-break: break-word; font-size: 17px; line-height: 22px; position: relative; }
.msg.in { align-self: flex-start; background: var(--bubble-in); color: var(--bubble-in-text); border-bottom-left-radius: 6px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-text); border-bottom-right-radius: 6px; }
.msg.in + .msg.in, .msg.out + .msg.out { margin-top: 1px; }
.msg.img { padding: 0; overflow: hidden; background: var(--fill); }
.msg.img img { display: block; max-width: 280px; max-height: 300px; cursor: zoom-in; }
.msg.sticker { background: none !important; padding: 0; }
.msg.sticker img { width: 128px; height: 128px; object-fit: contain; display: block; }
.msg.card { padding: 0; background: var(--bg-elev); color: var(--label); border: 1px solid var(--sep); min-width: 240px; }
.msg.card .head { padding: 12px 14px; font-weight: 600; color: #fff; background: var(--tint); border-radius: var(--radius-bubble) var(--radius-bubble) 0 0; }
.msg.card .body { padding: 10px 14px; font-size: 15px; }
.msg.card a { display: block; padding: 10px 14px; border-top: 1px solid var(--sep); font-weight: 600; text-align: center; }
.msg.failed { background: var(--red); }
.meta-line { align-self: flex-end; display: flex; gap: 6px; align-items: center; padding: 2px 6px 6px; font-size: 11px; color: var(--label-3); }
.meta-line.in { align-self: flex-start; }
.meta-line .retry { color: var(--tint); font-weight: 600; }
.sysnote { align-self: center; font-size: 12px; color: var(--label-3); padding: 2px 0 8px; }

/* composer */
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 6px; }
.composer textarea { flex: 1; min-width: 0; resize: none; max-height: 120px; height: 36px; padding: 7px 14px; border: 1px solid var(--sep); border-radius: 18px; background: var(--fill); outline: none; line-height: 22px; }
.composer textarea:focus { border-color: var(--tint); background: var(--bg-elev); }

/* sheets (modal) */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.25); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: min(100%, 560px); max-height: 80vh; overflow: auto; border-radius: 24px 24px 0 0; padding: 8px 16px calc(16px + var(--safe-b)); }
.sheet .grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label-3); margin: 4px auto 12px; }
.sheet h2 { margin: 8px 0 10px; font-size: 20px; font-weight: 600; }
.sheet .group { background: var(--bg-elev); border-radius: 14px; overflow: hidden; margin-bottom: 14px; }
.sheet .cell { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 16px; border-bottom: 1px solid var(--sep); color: var(--label); width: 100%; text-align: left; }
.sheet .cell:last-child { border-bottom: 0; }
.sheet .cell.action { color: var(--tint); font-weight: 500; } .sheet .cell.danger { color: var(--red); }
.sheet .cell:disabled { color: var(--label-3); cursor: default; }
.sheet .cell input { flex: 1; min-width: 0; border: 0; background: none; outline: none; text-align: right; color: var(--label-2); }
.sheet .cell input:focus { color: var(--label); }
.grid-st { display: grid; grid-template-columns: repeat(auto-fill, 72px); gap: 6px; justify-content: center; max-height: 280px; overflow: auto; padding: 6px 0; }
.grid-st img { width: 72px; height: 72px; object-fit: contain; border-radius: 12px; cursor: pointer; } .grid-st img:active { background: var(--fill); }
.tabs { display: flex; gap: 6px; overflow: auto; padding: 2px 0 8px; }
.tabs button { flex: none; height: 30px; padding: 0 12px; border-radius: 15px; background: var(--fill); font-size: 13px; font-weight: 500; }
.tabs button.on { background: var(--tint); color: #fff; }
.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%); z-index: 30; padding: 10px 16px; border-radius: 14px; font-size: 14px; max-width: min(90vw, 520px); white-space: pre-wrap; }
.toast.err { color: var(--red); }

/* login */
.login { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login form { width: 320px; border-radius: 28px; padding: 28px 22px 22px; display: flex; flex-direction: column; gap: 10px; }
.login .mark { width: 64px; height: 64px; border-radius: 18px; background: var(--tint); margin: 0 auto 6px; display: flex; align-items: center; justify-content: center; color: #fff; }
.login .mark svg { width: 34px; height: 34px; }
.login input { height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--sep); background: var(--fill); outline: none; }
.login input:focus { border-color: var(--tint); background: var(--bg-elev); }
.btn-primary { height: 46px; border-radius: 14px; background: var(--tint); color: #fff; font-weight: 600; font-size: 17px; }
.btn-primary:active { background: var(--tint-press); } .btn-primary:disabled { opacity: .5; }
.field-err { min-height: 18px; color: var(--red); font-size: 13px; text-align: center; }
