/* ทล.บ. Sec1 — iOS-style UI */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f2f2f7;
  --label: #000000;
  --label-2: rgba(60, 60, 67, .6);
  --label-3: rgba(60, 60, 67, .3);
  --separator: rgba(60, 60, 67, .29);
  --fill: rgba(120, 120, 128, .12);
  --fill-2: rgba(120, 120, 128, .2);
  --blue: #007aff;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;
  --indigo: #5856d6;
  --bar-bg: rgba(249, 249, 249, .82);
  --shadow: 0 1px 2px rgba(0, 0, 0, .04);
  --radius: 12px;
  --gutter: 16px;
  --tabbar-h: 50px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Sukhumvit Set", "Noto Sans Thai", "IBM Plex Sans Thai", "Leelawadee UI", system-ui, sans-serif;
  --seg-active: #ffffff;
  color-scheme: light;
}

/* ธีมมืด: ตามเครื่อง (อัตโนมัติ) เว้นแต่ผู้ใช้เลือก "สว่าง" หรือบังคับ "มืด" ใน <html data-theme> */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, .6);
    --label-3: rgba(235, 235, 245, .3);
    --separator: rgba(84, 84, 88, .6);
    --fill: rgba(118, 118, 128, .24);
    --fill-2: rgba(118, 118, 128, .32);
    --blue: #0a84ff;
    --green: #30d158;
    --red: #ff453a;
    --orange: #ff9f0a;
    --indigo: #5e5ce6;
    --bar-bg: rgba(22, 22, 24, .78);
    --shadow: none;
    --seg-active: #636366;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000;
  --card: #1c1c1e;
  --card-2: #2c2c2e;
  --label: #ffffff;
  --label-2: rgba(235, 235, 245, .6);
  --label-3: rgba(235, 235, 245, .3);
  --separator: rgba(84, 84, 88, .6);
  --fill: rgba(118, 118, 128, .24);
  --fill-2: rgba(118, 118, 128, .32);
  --blue: #0a84ff;
  --green: #30d158;
  --red: #ff453a;
  --orange: #ff9f0a;
  --indigo: #5e5ce6;
  --bar-bg: rgba(22, 22, 24, .78);
  --shadow: none;
  --seg-active: #636366;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: 17px/1.4 var(--font);
  letter-spacing: -.01em;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}
a { color: var(--blue); text-decoration: none; }
button { font: inherit; color: inherit; }
.ic { width: 22px; height: 22px; flex: none; }

/* ---------- navbar ---------- */
.navbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: transparent;
  transition: background .2s, box-shadow .2s;
}
.navbar.scrolled, .navbar-solid {
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 .5px 0 var(--separator);
}
.navbar-inner {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: 44px; padding: 0 8px; max-width: 720px; margin: 0 auto;
}
.nav-title {
  font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; transition: opacity .2s;
}
.navbar.scrolled .nav-title, .navbar-solid .nav-title { opacity: 1; }
.nav-right { justify-self: end; display: flex; gap: 4px; }
.nav-back, .nav-action {
  display: inline-flex; align-items: center; gap: 2px; min-height: 44px; padding: 0 8px; font-size: 17px;
}
.nav-back .ic { width: 24px; height: 24px; margin-left: -6px; stroke-width: 2.4; }
.nav-action .ic { width: 26px; height: 26px; }
.nav-text { font-weight: 600; }

.page {
  max-width: 720px; margin: 0 auto;
  padding: 0 var(--gutter) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 96px);
}
.large-title { font-size: 34px; font-weight: 700; letter-spacing: .01em; margin: 2px 0 10px; line-height: 1.2; }
.navbar-solid + .page { padding-top: 12px; }
.greeting { margin: -4px 0 16px; color: var(--label-2); font-size: 15px; }
.greeting span { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 99px; background: var(--fill); font-size: 13px; }

/* ---------- inset grouped list ---------- */
.list {
  list-style: none; margin: 0 0 24px; padding: 0;
  background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.list-header {
  margin: 0 var(--gutter) 6px; font-size: 13px; color: var(--label-2); text-transform: uppercase; letter-spacing: .02em;
}
.list-header-row { display: flex; justify-content: space-between; align-items: baseline; text-transform: none; font-size: 20px; font-weight: 700; color: var(--label); margin: 8px 0 8px; }
.list-header-row a { font-size: 15px; font-weight: 400; }
.list-footer { margin: -16px var(--gutter) 24px; font-size: 13px; color: var(--label-2); }
[data-panel] .list-footer { margin: 0 var(--gutter) 8px; }
.row {
  position: relative; display: flex; align-items: center; gap: 12px;
  min-height: 44px; padding: 10px var(--gutter);
}
.row + .row::before {
  content: ""; position: absolute; top: 0; right: 0; left: var(--gutter);
  border-top: .5px solid var(--separator);
}
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.row-sub { font-size: 14px; color: var(--label-2); margin-top: 2px; }
.row-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; color: inherit; }
.row-link > .ic { width: 16px; height: 16px; color: var(--label-3); stroke-width: 2.6; }

/* ---------- task rows ---------- */
.task { padding-left: 12px; align-items: flex-start; }
.task + .task::before { left: 56px; }
.toggle-form { margin: 0; }
.check {
  display: grid; place-items: center; width: 44px; height: 44px; margin: -6px 0 -6px -4px;
  border: 0; background: none; padding: 0; cursor: pointer;
}
.check .ic {
  width: 26px; height: 26px; padding: 4px; border-radius: 50%;
  border: 2px solid var(--label-3); color: transparent; stroke-width: 3;
  transition: background .18s, border-color .18s, color .18s, transform .18s;
}
.check:active .ic { transform: scale(.88); }
.is-done .check .ic { background: var(--green); border-color: var(--green); color: #fff; }
.is-done .row-title { color: var(--label-2); text-decoration: line-through; text-decoration-color: var(--label-3); }
.task .row-link { align-self: stretch; }
.due-over { color: var(--red); font-weight: 500; }
.due-soon { color: var(--orange); font-weight: 500; }
.is-done .due-over, .is-done .due-soon { color: inherit; font-weight: inherit; }

.mini-progress { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.mini-progress .bar { flex: 1; max-width: 160px; }
.mini-progress .count { font-size: 12px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.bar { height: 4px; border-radius: 99px; background: var(--fill-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: inherit; background: var(--green); transition: width .35s ease; }
.bar-lg { height: 8px; }

/* ---------- cards ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 560px) { .summary { grid-template-columns: repeat(4, 1fr); } }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: var(--radius);
  background: var(--card); color: var(--label); box-shadow: var(--shadow);
  --accent: var(--blue);
}
.stat-orange { --accent: var(--orange); }
.stat-red { --accent: var(--red); }
.stat-green { --accent: var(--green); }
.stat-num { font-size: 28px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-label { font-size: 13px; color: var(--label-2); }
.stat:active { opacity: .7; }

.progress-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 15px; color: var(--label-2); }
.progress-head span { display: inline-flex; align-items: center; gap: 6px; }
.progress-head .ic { width: 18px; height: 18px; }
.progress-head strong { color: var(--label); font-weight: 600; }

.task-hero .chip { display: inline-block; padding: 3px 10px; border-radius: 99px; background: color-mix(in srgb, var(--indigo) 14%, transparent); color: var(--indigo); font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.task-title { font-size: 24px; font-weight: 700; margin: 0 0 8px; line-height: 1.25; overflow-wrap: anywhere; }
.task-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 15px; color: var(--label-2); margin-bottom: 12px; }
.task-meta span { display: inline-flex; align-items: center; gap: 4px; }
.task-meta .ic { width: 17px; height: 17px; }
.task-detail { font-size: 16px; line-height: 1.55; padding: 12px 0; border-top: .5px solid var(--separator); overflow-wrap: anywhere; }
.task-by { font-size: 13px; color: var(--label-2); margin-bottom: 14px; }

/* ---------- people ---------- */
.avatar {
  display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 50%;
  background: linear-gradient(180deg, #a1a1aa, #8e8e93); color: #fff; font-weight: 600; font-size: 16px;
}
.avatar-green { background: linear-gradient(180deg, #5ad97a, var(--green)); }
.avatar-lg { width: 64px; height: 64px; font-size: 28px; background: linear-gradient(180deg, #5ac8fa, var(--blue)); }
.people .row + .row::before { left: 64px; }
.is-me .row-title::after { content: "คุณ"; margin-left: 6px; padding: 0 6px; border-radius: 6px; font-size: 12px; background: var(--fill); color: var(--label-2); vertical-align: 2px; }

.profile-card { display: flex; align-items: center; gap: 14px; }
.profile-name { font-size: 20px; font-weight: 600; }
.badge { display: inline-block; margin-top: 6px; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--fill); color: var(--label-2); }
.badge-admin { background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange); }
.badge-moderator { background: color-mix(in srgb, var(--indigo) 16%, transparent); color: var(--indigo); }

/* ---------- segmented ---------- */
.segmented {
  display: flex; padding: 2px; margin: 0 0 16px; border-radius: 9px; background: var(--fill);
}
.segmented > * {
  flex: 1; text-align: center; padding: 6px 8px; border: 0; border-radius: 7px; background: none;
  font-size: 14px; font-weight: 500; color: var(--label); cursor: pointer; transition: background .2s;
}
.segmented > .active { background: var(--seg-active); box-shadow: 0 3px 8px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); font-weight: 600; }

/* ---------- forms ---------- */
.form { margin: 0 0 24px; }
.field { padding-top: 0; padding-bottom: 0; }
.field input, .field textarea {
  flex: 1; width: 100%; min-height: 44px; border: 0; outline: 0; background: none; color: var(--label);
  font: inherit; padding: 11px 0;
}
.field textarea { resize: vertical; line-height: 1.45; }
.field input::placeholder, .field textarea::placeholder { color: var(--label-3); }
.field-inline label { flex: none; width: 92px; }
.field-inline input { text-align: right; }
.field-inline input[type="datetime-local"] { min-width: 0; }
input::-webkit-date-and-time-value { text-align: right; }

.btn {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 50px;
  padding: 0 20px; border: 0; border-radius: var(--radius); font-size: 17px; font-weight: 600; cursor: pointer;
  transition: opacity .15s, transform .15s;
}
.btn:active { opacity: .75; transform: scale(.985); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-tinted { background: color-mix(in srgb, var(--blue) 15%, transparent); color: var(--blue); }
.btn-destructive { background: var(--card); color: var(--red); font-weight: 400; box-shadow: var(--shadow); }
.empty .btn { display: inline-flex; width: auto; min-height: 40px; margin-top: 8px; font-size: 15px; }

.btn-toggle { background: var(--blue); color: #fff; }
.btn-toggle.is-done { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.btn-toggle .when-done, .btn-toggle.is-done .when-todo { display: none; }
.btn-toggle.is-done .when-done { display: inline; }

.alert {
  margin: 0 0 16px; padding: 12px 14px; border-radius: var(--radius); font-size: 15px;
  background: color-mix(in srgb, var(--red) 12%, var(--card)); color: var(--red);
}
.alert-warn { background: color-mix(in srgb, var(--orange) 14%, var(--card)); color: var(--label); }
.alert-warn ul { margin: 6px 0; padding-left: 20px; }

/* ---------- empty ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 32px 16px 40px; color: var(--label-2); }
.empty-icon {
  display: grid; place-items: center; width: 64px; height: 64px; margin-bottom: 14px; border-radius: 50%;
  --tone: var(--label-2);
  color: var(--tone); background: color-mix(in srgb, var(--tone) 14%, transparent);
}
.empty-icon .ic { width: 30px; height: 30px; stroke-width: 1.8; }
.tone-blue { --tone: var(--blue); }
.tone-green { --tone: var(--green); }
.tone-orange { --tone: var(--orange); }
.tone-indigo { --tone: var(--indigo); }
.empty-title { margin: 0; font-size: 17px; font-weight: 600; color: var(--label); }
.empty-sub { margin: 4px 0 0; font-size: 15px; max-width: 300px; }
.empty .btn { margin-top: 16px; }
.btn .ic { width: 20px; height: 20px; margin-right: 6px; stroke-width: 2.4; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 54px); z-index: 50;
  transform: translateX(-50%); max-width: calc(100% - 32px);
  padding: 10px 18px; border-radius: 99px; font-size: 15px; font-weight: 500;
  background: var(--bar-bg); color: var(--label);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .15);
  animation: toast-in .35s cubic-bezier(.2, .9, .3, 1.2), toast-out .4s ease 3s forwards;
}
.toast-err { color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -12px) scale(.96); } }
@keyframes toast-out { to { opacity: 0; transform: translate(-50%, -12px); visibility: hidden; } }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 0 max(0px, calc((100vw - 720px) / 2)) env(safe-area-inset-bottom);
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 -.5px 0 var(--separator);
}
.tabbar a {
  flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: #8e8e93; font-size: 10px; font-weight: 500;
}
.tabbar a .ic { width: 26px; height: 26px; stroke-width: 1.8; }
.tabbar a.active { color: var(--blue); }
.tabbar a { position: relative; }
.tab-badge {
  position: absolute; top: 3px; left: calc(50% + 6px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  box-shadow: 0 0 0 2px var(--bar-bg);
}
.tabbar a.active .ic { fill: color-mix(in srgb, var(--blue) 18%, transparent); stroke-width: 2.1; }

/* ---------- FAB + action sheet ---------- */
.fab {
  position: fixed; z-index: 25;
  right: max(var(--gutter), calc((100vw - 720px) / 2 + var(--gutter)));
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  display: grid; place-items: center; width: 56px; height: 56px; border: 0; border-radius: 50%;
  background: var(--blue); color: #fff; cursor: pointer;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--blue) 45%, transparent);
  transition: transform .15s;
}
.fab:active { transform: scale(.92); }
.fab .ic { width: 28px; height: 28px; stroke-width: 2.4; }

.sheet-backdrop {
  position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, .35); opacity: 0; transition: opacity .25s;
}
.sheet-backdrop.open { opacity: 1; }
.sheet-backdrop[hidden] { display: none; }
.sheet {
  width: 100%; max-width: 480px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .32s cubic-bezier(.2, .9, .3, 1);
}
.open .sheet { transform: none; }
.sheet-group, .sheet-cancel {
  border-radius: 14px; overflow: hidden; background: var(--bar-bg);
  -webkit-backdrop-filter: blur(30px); backdrop-filter: blur(30px);
}
.sheet-title { padding: 12px 16px; text-align: center; font-size: 13px; color: var(--label-2); }
.sheet-item {
  display: flex; align-items: center; justify-content: center; gap: 10px; min-height: 57px; padding: 0 16px;
  font-size: 19px; color: var(--blue); border-top: .5px solid var(--separator);
}
.sheet-item .ic { width: 22px; height: 22px; }
.sheet-item.disabled { color: var(--label-3); }
.sheet-item small { font-size: 12px; padding: 1px 6px; border-radius: 6px; background: var(--fill); color: var(--label-2); }
.sheet-cancel { display: block; width: 100%; min-height: 57px; margin-top: 8px; border: 0; font-size: 19px; font-weight: 600; color: var(--blue); cursor: pointer; }

/* ---------- auth ---------- */
.auth .page { padding-bottom: calc(env(safe-area-inset-bottom) + 32px); }
.auth-wrap { max-width: 420px; margin: 0 auto; padding-top: calc(env(safe-area-inset-top) + 8vh); }
.brand { text-align: center; margin-bottom: 28px; }
.app-icon { width: 84px; height: 84px; border-radius: 19px; box-shadow: 0 8px 24px rgba(0, 0, 0, .14); }
.brand h1 { font-size: 28px; font-weight: 700; margin: 14px 0 4px; }
.brand p { margin: 0; color: var(--label-2); font-size: 15px; }
.auth-switch { text-align: center; font-size: 15px; color: var(--label-2); }
.foot-note { text-align: center; font-size: 13px; color: var(--label-3); }

/* ---------- shared bits (phase 2) ---------- */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.tone-red { --tone: var(--red); }
.btn-sm { width: auto; min-height: 38px; padding: 0 14px; font-size: 15px; border-radius: 10px; }
.btn-add { margin: -14px 0 24px; min-height: 44px; font-size: 16px; }
.link-btn { border: 0; background: none; padding: 6px 0; color: var(--blue); font-size: 15px; cursor: pointer; }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: 50%; background: none; color: var(--label-3); cursor: pointer; }
.icon-btn .ic { width: 18px; height: 18px; }
.avatar-sm { width: 30px; height: 30px; font-size: 13px; }

/* iOS switch */
.switch {
  appearance: none; -webkit-appearance: none; flex: none; position: relative; width: 51px; height: 31px; margin: 0;
  border-radius: 99px; background: var(--fill-2); cursor: pointer; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16); transition: transform .2s;
}
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }
label.row-main .row-sub { display: block; }

/* ---------- feed / posts ---------- */
.composer { display: flex; align-items: center; gap: 10px; padding: 12px; }
.composer-input {
  flex: 1; min-width: 0; padding: 9px 14px; border-radius: 99px; background: var(--fill);
  color: var(--label-3); font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.composer-btn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: var(--blue); }
.composer-btn:active { background: var(--fill); }

.post { padding: 14px 16px 6px; }
.post.is-pinned { box-shadow: inset 3px 0 0 var(--orange), var(--shadow); }
.post-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.post-head .row-sub { margin: 0; color: var(--label-2); font-size: 13px; }
.post-author { font-weight: 600; font-size: 15px; line-height: 1.3; }
.post-author .badge { margin: 0 0 0 4px; vertical-align: 1px; }
.pin-tag { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; color: var(--orange); }
.pin-tag .ic { width: 14px; height: 14px; }
.post-body { font-size: 16px; line-height: 1.55; margin-bottom: 10px; overflow-wrap: anywhere; }
.post-body.clamp { display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }

.media-grid { display: grid; gap: 3px; margin: 0 -16px 10px; overflow: hidden; }
.media-grid.n2 { grid-template-columns: 1fr 1fr; }
.media-grid.n3 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
.media-grid.n3 .media:first-child { grid-row: span 2; }
.media-grid.n4 { grid-template-columns: 1fr 1fr; }
.media { position: relative; display: block; background: var(--fill); aspect-ratio: 4 / 3; overflow: hidden; }
.media-grid.n1 .media { aspect-ratio: auto; max-height: 460px; }
.media-grid.n3 .media:first-child { aspect-ratio: auto; }
.media img { display: block; width: 100%; height: 100%; object-fit: cover; }
.media-grid.n1 .media img { height: auto; max-height: 460px; object-fit: contain; background: var(--fill); }
.media-more { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0, 0, 0, .45); color: #fff; font-size: 24px; font-weight: 600; }

.file-list { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--fill); color: var(--label); }
.file-row > .ic { width: 20px; height: 20px; color: var(--blue); }
.file-ext {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 8px;
  color: var(--tone, var(--label-2)); background: color-mix(in srgb, var(--tone, var(--label-2)) 16%, transparent);
  font-size: 10px; font-weight: 700; letter-spacing: .02em;
}
.file-name { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.post-actions { display: flex; align-items: center; gap: 4px; margin: 0 -8px; padding-top: 2px; border-top: .5px solid var(--separator); }
.post-actions form { margin: 0; }
.act {
  display: inline-flex; align-items: center; gap: 5px; min-height: 40px; padding: 0 8px; border: 0; background: none;
  color: var(--label-2); font-size: 14px; cursor: pointer;
}
.act .ic { width: 21px; height: 21px; }
.act.is-liked { color: var(--red); }
.act.is-liked .ic { fill: currentColor; }
.act.is-liked .ic { animation: pop .3s ease; }
@keyframes pop { 50% { transform: scale(1.25); } }
.act-end { margin-left: auto; color: var(--blue); }
.feed-end { margin: 8px 0 24px; text-align: center; }

.post-manage { display: flex; gap: 8px; justify-content: flex-end; margin: -6px 0 20px; }
.post-manage form { margin: 0; }
.post-manage .btn .ic { width: 17px; height: 17px; }

/* ---------- poll ---------- */
.poll { margin: 0 0 12px; padding: 12px; border-radius: 12px; background: var(--fill); }
.poll-q { display: flex; gap: 8px; align-items: flex-start; font-weight: 600; font-size: 16px; margin-bottom: 10px; overflow-wrap: anywhere; }
.poll-q .ic { width: 20px; height: 20px; color: var(--indigo); margin-top: 2px; }
.poll-result {
  position: relative; display: flex; align-items: center; gap: 8px; min-height: 40px; margin-bottom: 6px;
  padding: 0 12px; border-radius: 10px; background: var(--card); overflow: hidden; font-size: 15px;
}
.poll-fill { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--indigo) 16%, transparent); transition: width .4s ease; }
.is-mine .poll-fill { background: color-mix(in srgb, var(--blue) 22%, transparent); }
.poll-label { position: relative; flex: 1; display: flex; align-items: center; gap: 6px; overflow-wrap: anywhere; }
.poll-label .ic { width: 16px; height: 16px; color: var(--blue); stroke-width: 3; }
.poll-pct { position: relative; font-weight: 600; font-variant-numeric: tabular-nums; }
.poll-option {
  display: flex; align-items: center; gap: 10px; min-height: 44px; margin-bottom: 6px; padding: 0 12px;
  border-radius: 10px; background: var(--card); font-size: 15px; cursor: pointer;
}
.poll-option input { position: absolute; opacity: 0; pointer-events: none; }
.poll-mark { display: grid; place-items: center; flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--label-3); color: transparent; }
.poll-option input[type="checkbox"] + .poll-mark { border-radius: 6px; }
.poll-mark .ic { width: 14px; height: 14px; stroke-width: 3.2; }
.poll-option input:checked + .poll-mark { background: var(--blue); border-color: var(--blue); color: #fff; }
.poll-option input:focus-visible + .poll-mark { outline: 2px solid var(--blue); outline-offset: 2px; }
.poll-buttons { display: flex; align-items: center; gap: 14px; margin-top: 4px; }
.poll-meta { margin-top: 6px; font-size: 13px; color: var(--label-2); }

/* ---------- composer page ---------- */
.composer-full { padding: 14px 16px; }
.composer-full textarea {
  width: 100%; border: 0; outline: 0; resize: vertical; background: none; color: var(--label);
  font: inherit; font-size: 17px; line-height: 1.5; padding: 0;
}
.composer-full textarea::placeholder { color: var(--label-3); }
.composer-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; padding-top: 10px; border-top: .5px solid var(--separator); }
.tool-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 99px;
  background: color-mix(in srgb, var(--blue) 12%, transparent); color: var(--blue); font-size: 15px; font-weight: 500; cursor: pointer;
}
.tool-btn .ic { width: 19px; height: 19px; }
.tool-hint { font-size: 13px; color: var(--label-2); }
.tool-hint.over { color: var(--red); font-weight: 600; }
.file-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; margin-top: 10px; }
.file-preview:empty { display: none; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--fill); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-file { display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px; padding: 4px; text-align: center; font-size: 11px; color: var(--label-2); }
.thumb-file strong { font-size: 12px; color: var(--label); }
.thumb-file span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-progress { margin: 0 0 12px; }
.upload-progress .bar { height: 6px; margin-bottom: 6px; }
.upload-progress .bar > span { background: var(--blue); width: 0; }
.btn .ic { flex: none; }

/* ---------- comments ---------- */
.comments .row { align-items: flex-start; }
.comment .avatar { margin-top: 2px; }
.comments .row + .row::before { left: 58px; }
.comment-head { display: flex; align-items: baseline; gap: 8px; font-size: 15px; }
.comment-head .row-sub { margin: 0; font-size: 12px; }
.comment-body { font-size: 15px; line-height: 1.5; margin-top: 2px; overflow-wrap: anywhere; }
.comments-empty { margin: 0 var(--gutter) 16px; }
.comment-form {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 10;
  display: flex; align-items: flex-end; gap: 8px; padding: 8px; border-radius: 22px;
  background: var(--bar-bg); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: 0 2px 12px rgba(0, 0, 0, .08), 0 0 0 .5px var(--separator);
}
.comment-form textarea {
  flex: 1; min-height: 36px; max-height: 140px; padding: 7px 12px; border: 0; outline: 0; border-radius: 18px;
  background: var(--card); color: var(--label); font: inherit; font-size: 16px; resize: none;
}
.send-btn { display: grid; place-items: center; flex: none; width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--blue); color: #fff; cursor: pointer; }
.send-btn .ic { width: 18px; height: 18px; }

/* ---------- bell + notifications (phase 3) ---------- */
.bell { position: relative; }
.bell-badge {
  position: absolute; top: 6px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  box-shadow: 0 0 0 2px var(--bg);
}
.nav-form { margin: 0; }
.nav-right .nav-text { white-space: nowrap; }
.nav-form button { border: 0; background: none; color: var(--blue); cursor: pointer; }
.notif-icon {
  display: grid; place-items: center; flex: none; width: 36px; height: 36px; border-radius: 50%;
  color: var(--tone, var(--label-2)); background: color-mix(in srgb, var(--tone, var(--label-2)) 15%, transparent);
}
.notif-icon .ic { width: 19px; height: 19px; }
.notif .row-link { align-items: flex-start; }
.notif .row-title { font-size: 15px; font-weight: 500; }
.notif.is-unread .row-title { font-weight: 700; }
.notif.is-unread .notif-time::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 50%; background: var(--blue); vertical-align: 1px; }
.notif .row-sub { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.notif-time { margin-top: 3px; font-size: 12px; color: var(--label-3); }
.notif + .notif::before { left: 64px; }
.push-card { display: flex; align-items: center; gap: 12px; }
.push-card .row-title { font-weight: 600; }

/* ---------- events ---------- */
.date-badge {
  display: flex; flex-direction: column; align-items: center; justify-content: center; flex: none;
  width: 48px; height: 52px; border-radius: 10px; background: var(--card); overflow: hidden;
  box-shadow: 0 0 0 .5px var(--separator), var(--shadow);
}
.db-month { width: 100%; padding: 2px 0; background: var(--red); color: #fff; font-size: 11px; font-weight: 700; text-align: center; }
.db-day { flex: 1; display: grid; place-items: center; font-size: 22px; font-weight: 700; line-height: 1; }
.event-row .row-link { gap: 12px; }
.event-row + .event-row::before { left: 76px; }
.rsvp-chip { display: inline-block; margin-left: 4px; padding: 0 7px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--fill); }
.rsvp-going { color: var(--green); background: color-mix(in srgb, var(--green) 15%, transparent); }
.rsvp-maybe { color: var(--orange); background: color-mix(in srgb, var(--orange) 15%, transparent); }
.rsvp-no { color: var(--label-2); }
.rsvp-live { color: var(--red); background: color-mix(in srgb, var(--red) 13%, transparent); }

.event-top { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 4px; }
.event-hero .task-meta { margin-bottom: 4px; }
.rsvp { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 4px 0 10px; }
.rsvp-btn {
  display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 44px; border: 0; border-radius: 12px;
  background: var(--fill); color: var(--label); font-size: 16px; font-weight: 600; cursor: pointer;
}
.rsvp-btn .ic { width: 17px; height: 17px; stroke-width: 3; }
.rsvp-btn.active.rsvp-going { background: var(--green); color: #fff; }
.rsvp-btn.active.rsvp-maybe { background: var(--orange); color: #fff; }
.rsvp-btn.active.rsvp-no { background: var(--label-2); color: var(--card); }
.btn-cal { min-height: 44px; font-size: 16px; }
.btn-cal .ic { width: 19px; height: 19px; margin-right: 6px; }
.segmented > button { font-size: 13px; padding: 6px 4px; }

.next-event { display: flex; align-items: center; gap: 12px; color: var(--label); }
.next-event > .ic { width: 16px; height: 16px; color: var(--label-3); stroke-width: 2.6; }
.next-label { font-size: 12px; font-weight: 700; color: var(--red); text-transform: uppercase; letter-spacing: .02em; }

/* ---------- Cloudflare Turnstile ---------- */
.turnstile { display: flex; justify-content: center; min-height: 65px; margin: -8px 0 16px; }
.turnstile .cf-turnstile { width: 100%; }

/* ---------- Thai date field ---------- */
.dt { position: relative; flex: 1; display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-height: 44px; }
.dt-text { color: var(--blue); font-variant-numeric: tabular-nums; pointer-events: none; }
.dt-text.is-empty { color: var(--label-3); }
.dt input[type="datetime-local"] {
  position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; opacity: 0; cursor: pointer;
}
.dt input[type="datetime-local"]::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: auto; height: auto; cursor: pointer; }
.dt-clear {
  position: relative; z-index: 1; display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0;
  border-radius: 50%; background: var(--fill-2); color: var(--label-2); font-size: 16px; line-height: 1; cursor: pointer;
}

/* ---------- home tabs (งานของห้อง / ฟีดของห้อง) ---------- */
.home-tabs {
  position: sticky; top: calc(44px + env(safe-area-inset-top)); z-index: 15;
  display: flex; margin: 0 calc(var(--gutter) * -1) 16px; padding: 0 var(--gutter);
  background: var(--bar-bg); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
  box-shadow: 0 .5px 0 var(--separator);
}
.home-tabs a {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: 46px;
  color: var(--label-2); font-size: 15px; font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -.5px;
  transition: color .15s, border-color .15s;
}
.home-tabs a .ic { width: 20px; height: 20px; }
.home-tabs a.active { color: var(--blue); border-bottom-color: var(--blue); }
.home-tabs a:active { background: var(--fill); }
.tab-count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--red); color: #fff;
  font-size: 12px; font-weight: 700; line-height: 20px; text-align: center;
}

/* ---------- theme picker ---------- */
.theme-row { gap: 12px; }
.theme-row .row-main { flex: 0 1 auto; }
.theme-picker { flex: 1; max-width: 230px; margin: 0 0 0 auto; }
.theme-picker > a { padding: 6px 4px; font-size: 13px; white-space: nowrap; }

/* ---------- tickets (phase 4) ---------- */
.intro { margin: -4px 0 14px; font-size: 15px; color: var(--label-2); }
.segmented + .segmented { margin-top: -6px; }
.ticket-row .row-link { align-items: flex-start; gap: 12px; }
.ticket-row .notif-icon { font-weight: 600; font-size: 15px; }
.ticket-row + .ticket-row::before { left: 64px; }
.ticket-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ticket-top .row-title { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-top .notif-time { flex: none; margin: 0; }
.ticket-row.is-unread .ticket-top .row-title::before { content: ""; display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 50%; background: var(--blue); vertical-align: 2px; }
.ticket-preview { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.ticket-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.ticket-head .ticket-chips { margin: 0 0 8px; }
.status-chip { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--fill); color: var(--label-2); }
.status-open { color: var(--blue); background: color-mix(in srgb, var(--blue) 14%, transparent); }
.status-in_progress { color: var(--orange); background: color-mix(in srgb, var(--orange) 15%, transparent); }
.status-closed { color: var(--green); background: color-mix(in srgb, var(--green) 15%, transparent); }
.status-private { color: var(--red); background: color-mix(in srgb, var(--red) 12%, transparent); }

.status-picker, .role-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 4px 0 0; }
.role-picker { margin-bottom: 24px; }
.status-btn {
  min-height: 40px; padding: 0 4px; border: 0; border-radius: 10px; background: var(--fill);
  color: var(--label); font-size: 13px; font-weight: 600; white-space: nowrap; cursor: pointer;
}
.status-btn.active { background: var(--blue); color: #fff; }
.status-btn.status-in_progress.active { background: var(--orange); }
.status-btn.status-closed.active { background: var(--green); }
.ticket-head .btn-sm .ic { width: 18px; height: 18px; margin-right: 6px; }

.chat { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.chat-system { align-self: center; padding: 2px 10px; border-radius: 99px; background: var(--fill); font-size: 12px; color: var(--label-2); text-align: center; }
.bubble-row { display: flex; align-items: flex-end; gap: 8px; max-width: 85%; }
.bubble-row.mine { align-self: flex-end; flex-direction: row-reverse; }
.bubble-wrap { min-width: 0; }
.bubble-name { font-size: 12px; color: var(--label-2); margin: 0 0 2px 12px; }
.bubble {
  padding: 8px 13px; border-radius: 18px; background: var(--card); font-size: 16px; line-height: 1.45;
  overflow-wrap: anywhere; box-shadow: var(--shadow);
}
.bubble-staff { background: color-mix(in srgb, var(--indigo) 14%, var(--card)); }
.mine .bubble { background: var(--blue); color: #fff; border-bottom-right-radius: 6px; }
.bubble-row:not(.mine) .bubble { border-bottom-left-radius: 6px; }
.mine .bubble a { color: #fff; text-decoration: underline; }
.bubble-time { margin: 2px 12px 0; font-size: 11px; color: var(--label-3); }
.mine .bubble-time { text-align: right; }
.avatar-staff { background: linear-gradient(180deg, #8e8cf0, var(--indigo)); }

.radio-row { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.radio-row input { position: absolute; opacity: 0; pointer-events: none; }
.radio-row span:first-of-type { flex: 1; }
.radio-check { color: transparent; }
.radio-check .ic { width: 20px; height: 20px; stroke-width: 2.6; }
.radio-row input:checked ~ .radio-check { color: var(--blue); }
.radio-row input:focus-visible ~ span:first-of-type { text-decoration: underline; }

/* ---------- admin ---------- */
.admin-stats .stat-num small { font-size: 15px; color: var(--label-2); font-weight: 600; }
.stat-small { font-size: 20px; padding-top: 6px; }
.inline-form { margin: 0; }
.switch-btn {
  position: relative; flex: none; width: 51px; height: 31px; border: 0; border-radius: 99px; padding: 0;
  background: var(--fill-2); cursor: pointer; transition: background .2s;
}
.switch-btn span {
  position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .15), 0 1px 1px rgba(0, 0, 0, .16); transition: transform .2s;
}
.switch-btn.on { background: var(--green); }
.switch-btn.on span { transform: translateX(20px); }
.admin-search { display: flex; gap: 8px; margin: 0 0 10px; }
.admin-search input, .admin-search select, .inline-select {
  min-height: 40px; padding: 0 12px; border: 0; border-radius: 10px; background: var(--card); color: var(--label);
  font: inherit; font-size: 16px; box-shadow: var(--shadow);
}
.admin-search input { flex: 1; min-width: 0; }
.admin-search select { flex: none; max-width: 45%; }
.inline-select { margin-left: auto; box-shadow: none; background: var(--fill); }
.chip-filter { display: flex; gap: 6px; overflow-x: auto; margin: 0 0 12px; padding-bottom: 2px; scrollbar-width: none; }
.chip-filter a { flex: none; padding: 6px 12px; border-radius: 99px; background: var(--card); color: var(--label); font-size: 14px; box-shadow: var(--shadow); }
.chip-filter a.active { background: var(--blue); color: #fff; }
.badge-off { background: color-mix(in srgb, var(--red) 13%, transparent); color: var(--red); }
.people .badge { margin: 0 0 0 4px; vertical-align: 1px; }
.admin-actions { display: grid; gap: 8px; margin-bottom: 24px; }
.admin-actions form { margin: 0; }
.log-title { font-size: 15px; }
.log-empty { margin: 0 var(--gutter) 24px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
