/* ===== กล้าถาม — โทนฟ้าโมเดิร์น สะอาดตา ===== */
:root {
  --paper: #f4f7fb;
  --paper-2: #eaf0f7;
  --surface: #ffffff;
  --ink: #142235;
  --ink-2: #3d4b5f;
  --muted: #7a879a;
  --line: #e3e9f1;
  --line-2: #d0d9e5;
  --brand: #2f7de1;
  --brand-ink: #ffffff;
  --brand-soft: #e6f0fd;
  --accent: #2f7de1;
  --accent-soft: #e6f0fd;
  --sun: #cfe3fb;
  --danger: #d64545;
  --shadow-sm: 0 1px 2px rgba(20, 40, 80, .05), 0 2px 6px rgba(20, 40, 80, .04);
  --shadow: 0 2px 4px rgba(20, 40, 80, .04), 0 12px 32px rgba(20, 40, 80, .08);
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Anuphan", "Noto Sans Thai", system-ui, sans-serif;
  --font-display: "Mitr", "Anuphan", sans-serif;

  /* สีประจำห้อง — โทนฟ้า/น้ำเงิน/เขียวน้ำทะเล */
  --c0: #2f7de1; --c0s: #e6f0fd;
  --c1: #1aa3c8; --c1s: #e2f5fa;
  --c2: #4f63d8; --c2s: #e9ecfb;
  --c3: #149e8e; --c3s: #e0f4f1;
  --c4: #7a5cd6; --c4s: #efeafb;
  --c5: #3b5b85; --c5s: #e7edf4;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0f1622; --paper-2: #17202e; --surface: #18212f;
    --ink: #e8eef7; --ink-2: #c3cddb; --muted: #8796ab;
    --line: #253144; --line-2: #324058;
    --brand: #5aa0f2; --brand-ink: #0b1626; --brand-soft: #1c2d47;
    --accent: #5aa0f2; --accent-soft: #1c2d47; --sun: #1f3452;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3); --shadow: 0 8px 24px rgba(0,0,0,.35);
    --c0: #5aa0f2; --c0s: #1c2d47; --c1: #4cc3e3; --c1s: #173540; --c2: #8293f0; --c2s: #232a4d;
    --c3: #3fc3b2; --c3s: #163834; --c4: #a58cf0; --c4s: #2a2448; --c5: #8aa5c9; --c5s: #222e40;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] { color-scheme: dark; }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    radial-gradient(circle at 10% 0%, rgba(47, 125, 225, .07), transparent 40%),
    radial-gradient(circle at 95% 90%, rgba(26, 163, 200, .06), transparent 45%);
  background-attachment: fixed;
  min-height: 100vh;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; line-height: 1.3; margin: 0; }
a { color: inherit; }
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; }
code { background: var(--paper-2); padding: 1px 6px; border-radius: 6px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.center { text-align: center; }
.ic { flex: none; }

/* ---------- ปุ่ม ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line-2);
  font-weight: 500; text-decoration: none; cursor: pointer;
  transition: transform .15s, box-shadow .15s, background .15s;
}
.btn:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--paper-2); box-shadow: none; }
.btn-sm { padding: 6px 14px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .6; pointer-events: none; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px; flex: none;
  border-radius: 50%; border: 0; background: transparent; cursor: pointer; color: var(--ink-2);
}
.icon-btn:hover { background: var(--paper-2); }
.row-gap { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- แถบบน ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px clamp(16px, 3vw, 32px);
  background: color-mix(in srgb, var(--paper) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; color: var(--brand); }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 1.25rem; color: var(--ink); }
.brand-lg .brand-name { font-size: 1.5rem; }
.brand-lg .brand-mark svg { width: 36px; height: 36px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.me { display: flex; align-items: center; gap: 8px; }
.me-name { font-weight: 500; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex: none; }
.avatar-text { display: inline-grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* ---------- หน้า Login ---------- */
.login {
  min-height: 100vh; max-width: 1120px; margin: 0 auto;
  display: grid; grid-template-columns: 1.05fr 1fr; align-items: center; gap: 48px;
  padding: 40px 24px;
}
.login-copy h1 { font-size: clamp(2rem, 4.4vw, 3.2rem); margin: 28px 0 16px; letter-spacing: -.01em; }
.hl { position: relative; color: var(--brand); white-space: nowrap; }
.hl::after {
  content: ""; position: absolute; left: -2%; right: -2%; bottom: .02em; height: .32em; z-index: -1;
  background: var(--sun); opacity: .9; border-radius: 6px;
}
.lead { color: var(--ink-2); font-size: 1.1rem; max-width: 34em; margin: 0 0 28px; }
.btn-google {
  display: inline-flex; align-items: center; gap: 12px;
  padding: 14px 24px; border-radius: 999px; text-decoration: none; font-weight: 600;
  background: var(--surface); border: 1px solid var(--line-2); box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s;
}
.btn-google:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(20,40,80,.14); }
.dev-link { display: block; margin-top: 12px; font-size: .9rem; color: var(--muted); }
.login-points { list-style: none; padding: 0; margin: 36px 0 0; display: grid; gap: 10px; color: var(--ink-2); }
.login-points li { display: flex; align-items: center; gap: 10px; }
.login-points .ic { color: var(--brand); }
.alert {
  background: var(--accent-soft); color: var(--ink); border-left: 4px solid var(--accent);
  padding: 12px 16px; border-radius: 10px; margin-bottom: 20px; max-width: 34em;
}
.login-art { position: relative; padding: 20px; }
.paper-card {
  background: var(--surface); border-radius: 22px; padding: 22px; box-shadow: var(--shadow);
  border: 1px solid var(--line); display: grid; gap: 12px; max-width: 440px; margin-left: auto;
}
.pc-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .95rem; padding-bottom: 6px; border-bottom: 1px dashed var(--line-2); }
.pc-head .chip { margin-left: auto; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c1); }
.dot.c1 { background: var(--c1); }
.bubble { padding: 10px 14px; border-radius: 18px; max-width: 85%; font-size: .95rem; }
.b-me { background: var(--brand); color: var(--brand-ink); justify-self: end; border-bottom-right-radius: 6px; }
.b-them { background: var(--paper-2); border-bottom-left-radius: 6px; }
.tilt-l { transform: none; }
.tilt-r { transform: none; }
.sticky-note {
  position: absolute; left: 0; bottom: -10px; width: 180px; padding: 16px 18px;
  background: var(--brand); color: var(--brand-ink); font-family: var(--font-display); font-size: 1.05rem; line-height: 1.35;
  box-shadow: 0 12px 28px rgba(47, 125, 225, .28); border-radius: 18px;
}

/* ---------- โครงหน้าหลัก ---------- */
.shell {
  max-width: 1280px; margin: 0 auto; padding: 24px clamp(16px, 3vw, 32px) 48px;
  display: grid; grid-template-columns: 280px 1fr; gap: 28px; align-items: start;
}
.side { position: sticky; top: 76px; display: grid; gap: 12px; }
.side-action {
  display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
  padding: 14px 16px; border-radius: var(--radius); cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.side-action:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--line-2); }
.side-action strong { display: block; font-weight: 600; }
.side-action small { display: block; color: var(--muted); font-size: .82rem; }
.side-ic { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 14px; background: var(--brand-soft); color: var(--brand); flex: none; }
.side-action + .side-action .side-ic { background: var(--accent-soft); color: var(--accent); }
.side-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 10px 10px; margin-top: 6px; }
.side-title { font-size: .95rem; padding: 0 8px 8px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.side-empty { color: var(--muted); font-size: .9rem; padding: 18px 8px; margin: 0; text-align: center; }
.side-classes { list-style: none; margin: 0; padding: 0; max-height: calc(100vh - 340px); overflow: auto; }
.side-classes a { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; text-decoration: none; }
.side-classes a:hover { background: var(--paper-2); }
.sc-swatch { width: 10px; align-self: stretch; border-radius: 6px; background: var(--c); flex: none; }
.sc-text { min-width: 0; }
.sc-code { display: block; font-size: .8rem; color: var(--muted); font-weight: 600; }
.sc-code em { font-style: normal; font-weight: 500; color: var(--brand); margin-left: 4px; }
.sc-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.c0 { --c: var(--c0); --cs: var(--c0s); } .c1 { --c: var(--c1); --cs: var(--c1s); }
.c2 { --c: var(--c2); --cs: var(--c2s); } .c3 { --c: var(--c3); --cs: var(--c3s); }
.c4 { --c: var(--c4); --cs: var(--c4s); } .c5 { --c: var(--c5); --cs: var(--c5s); }

.main { min-width: 0; display: grid; gap: 24px; }
.greet h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); }
.greet p { margin: 4px 0 0; color: var(--muted); }

.class-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.class-card {
  display: flex; flex-direction: column; text-decoration: none; overflow: hidden;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); transition: transform .18s, box-shadow .18s;
}
.class-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.cc-band {
  position: relative; padding: 16px 18px 18px; color: #fff; background: var(--c);
  background-image: radial-gradient(circle at 110% -20%, rgba(255,255,255,.28) 0 38%, transparent 39%),
                    radial-gradient(circle at 85% 130%, rgba(255,255,255,.14) 0 30%, transparent 31%);
}
.cc-code { display: block; font-size: .85rem; opacity: .9; font-weight: 600; letter-spacing: .02em; }
.cc-name { display: block; font-family: var(--font-display); font-size: 1.25rem; line-height: 1.3; }
.cc-body { padding: 12px 18px 4px; display: grid; }
.cc-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .92rem; }
.cc-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 18px 14px; color: var(--ink-2); font-size: .88rem; margin-top: auto; }
.cc-foot span { display: inline-flex; align-items: center; gap: 6px; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; padding: 1px 10px; font-weight: 600; font-size: .8rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 18px 8px; box-shadow: var(--shadow-sm); }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 0 4px 12px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 1.15rem; }

.thread-list { list-style: none; margin: 0; padding: 6px 0; }
.thread-list li + li { border-top: 1px dashed var(--line); }
.thread-item { display: flex; align-items: center; gap: 12px; padding: 12px 8px; text-decoration: none; border-radius: 12px; }
.thread-item:hover { background: var(--paper); }
.thread-item.is-resolved { opacity: .72; }
.thread-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; }
.thread-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.thread-top { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; font-size: .9rem; }
.thread-no { color: var(--muted); font-variant-numeric: tabular-nums; }
.thread-preview { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
.thread-time { color: var(--muted); font-size: .82rem; white-space: nowrap; flex: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 10px 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 500; white-space: nowrap; }
.chip-anon { background: var(--paper-2); color: var(--ink-2); }
.chip-open { background: var(--brand-soft); color: var(--brand); }
.chip-done { background: var(--brand); color: var(--brand-ink); }

.empty-mini { display: grid; justify-items: center; gap: 6px; padding: 36px 12px; color: var(--muted); text-align: center; }
.empty-mini p { margin: 0; }
.empty-big { text-align: center; padding: 48px 20px; background: var(--surface); border: 2px dashed var(--line-2); border-radius: 24px; }
.empty-big h2 { margin: 14px 0 6px; }
.empty-big p { color: var(--muted); margin: 0 auto 22px; max-width: 30em; }
.empty-illo { display: inline-grid; place-items: center; width: 84px; height: 84px; border-radius: 28px; background: var(--brand-soft); color: var(--brand); }

/* ---------- หน้าห้องเรียน ---------- */
.page { max-width: 960px; margin: 0 auto; padding: 20px clamp(16px, 3vw, 32px) 56px; display: grid; gap: 20px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); text-decoration: none; font-size: .95rem; justify-self: start; }
.back:hover { color: var(--ink); }
.class-hero {
  display: flex; gap: 16px; align-items: stretch; flex-wrap: wrap;
  background: var(--c); color: #fff; border-radius: 24px; padding: 24px 26px; box-shadow: var(--shadow);
  background-image: radial-gradient(circle at 100% 0, rgba(255,255,255,.22) 0 22%, transparent 23%),
                    radial-gradient(circle at 92% 120%, rgba(255,255,255,.12) 0 26%, transparent 27%);
}
.class-hero-main { flex: 1 1 320px; min-width: 0; }
.class-hero-code { font-weight: 600; opacity: .9; letter-spacing: .03em; }
.class-hero-name { font-size: clamp(1.6rem, 3.4vw, 2.2rem); margin: 2px 0 14px; }
.class-hero-meta { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0; }
.class-hero-meta dt { font-size: .8rem; opacity: .8; }
.class-hero-meta dd { margin: 0; font-weight: 500; }
.class-hero-side { display: flex; }
.hero-action {
  display: grid; justify-items: center; align-content: center; gap: 2px; min-width: 150px; padding: 14px 18px;
  background: rgba(255,255,255,.95); color: var(--ink); border: 0; border-radius: 18px; cursor: pointer;
  box-shadow: 0 6px 16px rgba(0,0,0,.12); transition: transform .15s;
}
.hero-action .ic { color: var(--c); }
.hero-action:hover { transform: translateY(-2px); }
.hero-action small { color: var(--muted); }
.class-desc { margin: 0; color: var(--ink-2); background: var(--surface); border-left: 4px solid var(--c, var(--brand)); padding: 12px 16px; border-radius: 10px; }

.ask-card {
  display: flex; align-items: center; gap: 18px; width: 100%; text-align: left; cursor: pointer;
  padding: 22px 24px; border-radius: 22px; border: 2px dashed var(--line-2); background: var(--surface);
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.ask-card:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: var(--shadow); }
.ask-card strong { display: block; font-family: var(--font-display); font-weight: 500; font-size: 1.3rem; }
.ask-card small { display: block; color: var(--muted); font-size: .95rem; }
.ask-ic { display: grid; place-items: center; width: 60px; height: 60px; border-radius: 20px; background: var(--brand-soft); color: var(--brand); flex: none; }
.ask-plus { margin-left: auto; display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--brand); color: var(--brand-ink); flex: none; }

/* ---------- ป๊อปอัพ (พื้นหลังเบลอ) ---------- */
.dlg {
  border: 0; padding: 0; background: transparent; color: var(--ink);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: visible;
}
.dlg-sm { width: min(420px, calc(100vw - 32px)); }
.dlg-wide { width: min(760px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(15, 25, 45, .25); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.dlg[open] { animation: pop .22s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(.97); } }
.dlg-card {
  background: var(--surface); border-radius: 24px; padding: 22px 24px; box-shadow: 0 24px 60px rgba(15, 30, 60, .2);
  display: grid; gap: 14px; max-height: calc(100vh - 32px); overflow: auto;
}
.dlg-card.solo { max-width: 420px; margin: 0 auto; box-shadow: var(--shadow); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; margin: -4px -8px 0 0; }
.dlg-head h2 { font-size: 1.35rem; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 4px; }
.center-wrap { min-height: 80vh; display: grid; place-items: center; padding: 24px 16px; }

.form-grid { display: grid; grid-template-columns: 1fr 1.6fr; gap: 12px; }
.field { display: grid; gap: 6px; }
.field > span { font-weight: 500; font-size: .92rem; color: var(--ink-2); }
input:not([type=file]):not([type=hidden]), textarea {
  width: 100%; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--paper);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, textarea:focus { outline: none; border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent); }
textarea { resize: vertical; }
.repeat { display: grid; gap: 8px; }
.repeat-row { display: flex; gap: 6px; align-items: center; }
.repeat-row.is-new { animation: slidein .2s ease-out; }
.repeat-row.is-new input { border-style: dashed; }
@keyframes slidein { from { opacity: 0; transform: translateY(-6px); } }
.add-row {
  justify-self: start; display: inline-flex; align-items: center; gap: 6px; margin-top: 2px;
  background: none; border: 0; padding: 4px 6px; border-radius: 8px; color: var(--brand); font-weight: 500; cursor: pointer;
}
.add-row:hover { background: var(--brand-soft); }
.form-error { margin: 0; color: var(--danger); font-size: .92rem; }
.code-input { text-align: center; font-size: 1.8rem !important; letter-spacing: .35em; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; padding: 14px !important; }

.mode-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.mode-card {
  display: grid; justify-items: start; align-content: start; gap: 6px; padding: 20px; border-radius: 20px; text-decoration: none;
  background: var(--paper); border: 2px solid var(--line); transition: transform .15s, border-color .15s, box-shadow .15s;
}
.mode-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.mode-card strong { font-family: var(--font-display); font-weight: 500; font-size: 1.25rem; }
.mode-card span:last-child { color: var(--ink-2); font-size: .95rem; }
.mode-ic { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 18px; margin-bottom: 4px; }
.mode-anon .mode-ic { background: var(--ink); color: var(--paper); }
.mode-anon:hover { border-color: var(--ink); }
.mode-open .mode-ic { background: var(--brand-soft); color: var(--brand); }
.mode-open:hover { border-color: var(--brand); }

.invite { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; }
.invite-qr { display: grid; justify-items: center; gap: 12px; padding: 18px; background: var(--paper); border-radius: 20px; border: 1px solid var(--line); }
#qr { background: #fff; padding: 14px; border-radius: 16px; box-shadow: var(--shadow-sm); }
#qr img, #qr canvas { display: block; width: 200px; height: 200px; }
.invite-link { width: 100%; }
.invite-link input { font-size: .85rem; text-align: center; color: var(--ink-2); }
.invite-side { display: grid; gap: 16px; align-content: start; }
.label { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; font-size: .92rem; color: var(--ink-2); }
.invite-code { display: grid; justify-items: center; gap: 6px; padding: 16px; border-radius: 20px; background: var(--brand-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--brand) 25%, transparent); }
.invite-code .label, .invite-code .muted { color: var(--ink-2); }
#invite-code { color: var(--brand); }
.invite-code .btn-ghost { color: var(--brand); }
.invite-code .btn-ghost:hover { background: var(--surface); }
#invite-code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 2rem; font-weight: 700; letter-spacing: .25em; padding-left: .25em; }
.invite-mail { display: grid; gap: 8px; }
.invite-mail .btn { justify-self: end; }

/* ---------- แชท ---------- */
.page-chat { overflow: hidden; }
.chat-page { max-width: 880px; margin: 0 auto; padding: 14px clamp(12px, 3vw, 24px) 16px; height: calc(100dvh - 59px); display: flex; flex-direction: column; gap: 10px; }
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); overflow: hidden; }
.chat-head { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--line); border-top: 6px solid var(--c); }
.chat-head-top { display: flex; gap: 10px; align-items: baseline; }
.chat-code { font-weight: 600; color: var(--c); }
.chat-no { color: var(--muted); font-variant-numeric: tabular-nums; }
.chat-title { font-family: var(--font-display); font-size: 1.2rem; line-height: 1.3; }
.chat-sub { font-size: .88rem; }
.chat-head-side { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chat-head-side .chip { font-size: .85rem; padding: 4px 12px 4px 10px; }
.chat-scroll { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.chat-note { align-self: center; display: inline-flex; align-items: center; gap: 8px; text-align: center; font-size: .88rem; color: var(--ink-2); background: var(--paper); border: 1px dashed var(--line-2); padding: 8px 14px; border-radius: 14px; max-width: 520px; }
.chat-empty { margin: auto; text-align: center; display: grid; justify-items: center; gap: 6px; padding: 24px; }
.chat-empty p { margin: 8px 0 0; font-family: var(--font-display); font-size: 1.15rem; }
.msgs { display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; font-size: .78rem; color: var(--muted); background: var(--paper); padding: 2px 12px; border-radius: 999px; margin: 10px 0 6px; }
.msg { display: flex; flex-direction: column; max-width: min(78%, 560px); align-self: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg-label { font-size: .78rem; color: var(--muted); margin: 8px 12px 2px; display: inline-flex; align-items: center; gap: 4px; }
.msg.cont .msg-label { display: none; }
.msg-bubble { padding: 10px 14px; border-radius: 20px; background: var(--paper-2); white-space: pre-wrap; overflow-wrap: anywhere; border-bottom-left-radius: 6px; }
.msg.mine .msg-bubble { background: var(--brand); color: var(--brand-ink); border-bottom-left-radius: 20px; border-bottom-right-radius: 6px; }
.msg.side-teacher:not(.mine) .msg-bubble { background: var(--cs, var(--brand-soft)); }
.msg-time { font-size: .72rem; color: var(--muted); margin: 2px 10px 0; }
.msg-img { display: block; max-width: 280px; max-height: 320px; border-radius: 16px; border: 1px solid var(--line); margin-top: 4px; cursor: zoom-in; object-fit: cover; }
.msg-file { display: inline-flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 16px; background: var(--paper); border: 1px solid var(--line); text-decoration: none; margin-top: 4px; max-width: 100%; }
.msg-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-file small { color: var(--muted); }
.msg.pending { opacity: .55; }

.composer { border-top: 1px solid var(--line); padding: 10px 12px 12px; background: var(--surface); }
.composer-row { display: flex; align-items: flex-end; gap: 6px; background: var(--paper); border: 1px solid var(--line-2); border-radius: 26px; padding: 5px 5px 5px 6px; transition: border-color .15s, box-shadow .15s; }
.composer-row:focus-within { border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 15%, transparent); }
.composer textarea { flex: 1; border: 0 !important; background: transparent !important; box-shadow: none !important; resize: none; padding: 8px 4px !important; max-height: 160px; line-height: 1.5; }
.attach-btn { cursor: pointer; }
.send-btn { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer; background: var(--brand); color: var(--brand-ink); flex: none; transition: transform .15s, opacity .15s; }
.send-btn:hover { transform: scale(1.06); }
.send-btn[disabled] { opacity: .5; transform: none; }
.attach-preview { display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 8px; background: var(--paper); border-radius: 14px; border: 1px dashed var(--line-2); }
.attach-preview img { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; }
.attach-preview .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .92rem; }

/* ---------- แจ้งเตือน / เว็บแอป ---------- */
.notif { position: relative; }
.bell { position: relative; color: var(--ink-2); }
.bell[aria-expanded="true"] { background: var(--brand-soft); color: var(--brand); }
.bell-badge {
  position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700;
  display: grid; place-items: center; line-height: 1; border: 2px solid var(--paper);
}
.notif-panel {
  position: absolute; right: -8px; top: calc(100% + 10px); width: min(380px, calc(100vw - 24px)); z-index: 30;
  background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 18px 48px rgba(15, 30, 60, .18);
  overflow: hidden; animation: pop .18s ease-out;
}
.np-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.np-link { background: none; border: 0; color: var(--brand); font-weight: 500; cursor: pointer; padding: 2px 6px; border-radius: 6px; font-size: .9rem; }
.np-link:hover { background: var(--brand-soft); }
.np-list { list-style: none; margin: 0; padding: 6px; max-height: min(60vh, 440px); overflow-y: auto; }
.np-item { display: flex; gap: 10px; padding: 10px; border-radius: 12px; text-decoration: none; align-items: flex-start; }
.np-item:hover { background: var(--paper); }
.np-item .thread-dot { margin-top: 7px; opacity: .35; }
.np-item.unread { background: color-mix(in srgb, var(--brand-soft) 55%, transparent); }
.np-item.unread .thread-dot { opacity: 1; }
.np-text { display: grid; gap: 1px; min-width: 0; }
.np-text strong { font-size: .9rem; font-weight: 600; }
.np-body { color: var(--ink-2); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.np-text time { color: var(--muted); font-size: .78rem; }
.np-empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.np-empty small { font-size: .82rem; }

.push-cta { display: flex; align-items: center; gap: 14px; }
.push-cta[hidden] { display: none !important; }
.pc-ic { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 14px; background: var(--brand); color: var(--brand-ink); flex: none; }
.pc-text { flex: 1; min-width: 0; display: grid; gap: 2px; }
.pc-text strong { font-weight: 600; }
.pc-text small { color: var(--ink-2); font-size: .88rem; }
.pc-act { display: flex; gap: 8px; flex-wrap: wrap; flex: none; }
.pc-act:empty { display: none; }
.push-banner { padding: 16px 18px; border-radius: var(--radius); background: var(--brand-soft); border: 1px solid color-mix(in srgb, var(--brand) 22%, transparent); }
.np-cta { margin: 10px 10px 4px; padding: 12px; border-radius: 14px; background: var(--brand-soft); flex-wrap: wrap; gap: 10px; }
.np-cta .pc-ic { width: 36px; height: 36px; border-radius: 12px; }
.np-cta .pc-act { width: 100%; }

.class-hero-side { flex-direction: column; gap: 10px; align-items: stretch; }
.notify-toggle {
  display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none;
  padding: 8px 12px; border-radius: 14px; background: rgba(255, 255, 255, .18); color: #fff; font-weight: 500; font-size: .92rem;
}
.notify-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; width: 38px; height: 22px; border-radius: 999px; background: rgba(255, 255, 255, .35); transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.notify-toggle input:checked + .switch { background: rgba(255, 255, 255, .95); }
.notify-toggle input:checked + .switch::after { transform: translateX(16px); background: var(--c); }
.notify-toggle input:focus-visible + .switch { outline: 2px solid #fff; outline-offset: 2px; }

/* โหมดแอป (เปิดจากไอคอนบนหน้าจอโฮม) */
@media (display-mode: standalone) {
  .topbar { padding-top: max(10px, env(safe-area-inset-top)); }
  .install-btn { display: none !important; }
}

/* lightbox */
.lightbox { border: 0; padding: 0; background: transparent; max-width: 96vw; max-height: 96vh; }
.lightbox::backdrop { background: rgba(10,10,10,.75); backdrop-filter: blur(4px); }
.lightbox img { display: block; max-width: 96vw; max-height: 92vh; border-radius: 12px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); opacity: 0; z-index: 100;
  background: var(--ink); color: var(--paper); padding: 10px 20px; border-radius: 999px; box-shadow: var(--shadow);
  transition: opacity .2s, transform .2s; pointer-events: none; font-weight: 500; max-width: calc(100vw - 32px); text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- มือถือ ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; grid-template-columns: 1fr 1fr; }
  .side-box { grid-column: 1 / -1; display: none; }
  .login { grid-template-columns: 1fr; gap: 24px; padding-top: 32px; }
  .login-art { order: -1; display: none; }
}
@media (max-width: 640px) {
  .me-name { display: none; }
  .me { display: none; }
  .install-btn { padding: 6px 10px; }
  .notif-panel { position: fixed; left: 12px; right: 12px; top: 62px; width: auto; }
  .push-cta { flex-wrap: wrap; }
  .push-banner .pc-act { width: 100%; }
  .side { grid-template-columns: 1fr; }
  .form-grid, .mode-grid, .invite { grid-template-columns: 1fr; }
  .class-hero { padding: 20px; }
  .hero-action { width: 100%; grid-auto-flow: column; justify-content: center; gap: 8px; }
  .class-hero-side { width: 100%; }
  .ask-card { padding: 18px; gap: 14px; }
  .ask-ic { width: 48px; height: 48px; }
  .thread-item { flex-wrap: wrap; }
  .thread-time { width: 100%; padding-left: 22px; }
  .msg { max-width: 88%; }
  .msg-img { max-width: 220px; }
  .chat-page { padding: 8px 8px 8px; }
  .chat { border-radius: 18px; }
  .chat-head { padding: 12px 14px; }
  .chat-scroll { padding: 14px 12px; }
  .dlg-card { padding: 18px; }
}
