@font-face {
  font-family: "Prompt";
  src: url("/assets/fonts/Prompt-Regular-thai.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: "Prompt";
  src: url("/assets/fonts/Prompt-Regular-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Prompt";
  src: url("/assets/fonts/Prompt-SemiBold-thai.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC;
}
@font-face {
  font-family: "Prompt";
  src: url("/assets/fonts/Prompt-SemiBold-latin.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
    U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #eef7f5; --card: #fff; --ink: #27304f; --muted: #7b8499; --line: #dcebe8;
  --brand: #1aa7a2; --brand-dark: #138b88; --brand-soft: #dff7f1; --brand-ink: #fff;
  --accent: #ffad5c; --accent-dark: #f2953f; --danger: #b42318;
  --shadow: 0 14px 38px rgba(38, 91, 91, .10);
  --ok-bg: #def7ee; --ok: #14775c; --info-bg: #e4f5f7; --info: #187379;
  --warn-bg: #fff1df; --warn: #9a5b18; --bad-bg: #fde8e7; --bad: #9b1c14;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body { margin: 0; background:
    radial-gradient(circle at 4% 10%, rgba(99, 226, 196, .30), transparent 24rem),
    radial-gradient(circle at 96% 5%, rgba(255, 186, 112, .18), transparent 19rem),
    linear-gradient(145deg, #edf9f6 0%, #edf3f4 48%, #f8f3eb 100%);
  background-attachment: fixed; color: var(--ink); min-height: 100vh;
  font: 15px/1.5 "Prompt", -apple-system, BlinkMacSystemFont, "Sukhumvit Set", Thonburi,
    "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  overflow-wrap: anywhere; }
.wrap { width: 100%; max-width: 1180px; margin: 0 auto;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right)); }
a { color: var(--brand); }
h1 { font-size: 1.55rem; letter-spacing: -.015em; margin: 26px 0 16px; }
h2 { font-size: 1.1rem; margin: 26px 0 10px; }
button, input, select, textarea { font-family: inherit; }
small, .small { font-size: .85em; }
.muted { color: var(--muted); }
.big { font-size: 1.6rem; font-weight: 700; margin: 4px 0; }

.top { background: linear-gradient(135deg, #159d9d 0%, #38c4b1 72%, #70dac0 100%);
  color: var(--brand-ink); box-shadow: 0 10px 30px rgba(25, 125, 121, .16); }
.bar { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; justify-content: space-between; padding-block: 12px; }
.brand { color: inherit; text-decoration: none; font-weight: 800; font-size: 1.15rem; letter-spacing: .01em; }
.brand small { display: block; font-weight: 400; opacity: .8; }
.logo { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 12px;
  background: rgba(255,255,255,.22); box-shadow: inset 0 0 0 1px rgba(255,255,255,.16); }
.who { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: .9rem; }
.who a, .who .link { color: inherit; opacity: .9; }
.tabs { display: flex; gap: 5px; overflow-x: auto; overscroll-behavior-x: contain;
  scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.tabs a { color: var(--brand-ink); text-decoration: none; padding: 9px 14px; border-radius: 12px 12px 0 0;
  white-space: nowrap; opacity: .88; transition: background .15s, opacity .15s; }
.tabs a:hover { background: rgba(255,255,255,.12); opacity: 1; }
.tabs a.on { background: rgba(255,255,255,.96); color: var(--brand-dark); opacity: 1; font-weight: 700; }
.navicon { display: none; }

.card { background: rgba(255,255,255,.94); border: 1px solid rgba(255,255,255,.9); border-radius: 22px;
  padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow); backdrop-filter: blur(8px); }
.card h2 { margin-top: 0; }
.narrow { max-width: 480px; margin-inline: auto; }
details.card > summary { cursor: pointer; font-weight: 600; color: var(--brand); }
details[open].card > summary { margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; }
.span3 { grid-column: 1 / -1; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { position: relative; overflow: hidden; background: rgba(255,255,255,.94); border: 1px solid rgba(255,255,255,.9);
  border-radius: 20px; padding: 16px 18px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s; }
.stat::after { content: ""; position: absolute; width: 58px; height: 58px; right: -20px; top: -22px;
  border-radius: 50%; background: linear-gradient(135deg, rgba(39,190,171,.20), rgba(255,173,92,.16)); }
.stat:hover { transform: translateY(-2px); box-shadow: 0 18px 42px rgba(38, 91, 91, .14); }
.stat b { display: block; font-size: 1.85rem; color: var(--brand-dark); }
.stat span { color: var(--muted); font-size: .9rem; }

label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 12px; }
input, select, textarea { display: block; width: 100%; min-width: 0; max-width: 100%; margin-top: 5px; padding: 9px 12px; font: inherit; color: var(--ink);
  border: 1px solid #d4e3e1; border-radius: 12px; background: #fbfefd; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26,167,162,.15); }
input.num { width: 110px; }
input.date-th { width: 150px; }
input.period-th { width: 120px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row input, .row select { width: auto; margin: 0; }
.row label { margin: 0; display: flex; gap: 8px; align-items: center; }
.stack { display: grid; gap: 6px; min-width: 200px; }
.stack input, .stack select { margin: 0; }
form.inline { display: inline; }

.btn { display: inline-block; padding: 8px 17px; border-radius: 12px; border: 1px solid #d4e3e1; background: #fff;
  color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform .15s, border-color .15s, box-shadow .15s, background .15s; }
.btn:hover { border-color: var(--brand); transform: translateY(-1px); box-shadow: 0 7px 18px rgba(37,117,113,.12); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #ffbc72); border-color: var(--accent);
  color: #fff; box-shadow: 0 8px 20px rgba(242,149,63,.22); }
.btn.primary:hover { background: linear-gradient(135deg, var(--accent-dark), var(--accent)); border-color: var(--accent-dark); }
.btn.danger { color: var(--danger); border-color: #e7b4b0; }
.btn.sm { padding: 4px 10px; font-size: .88rem; }
.btn.full { width: 100%; padding-block: 10px; }
.link { background: none; border: 0; padding: 0; font: inherit; text-decoration: underline; cursor: pointer; }
.actions { white-space: nowrap; }

.tbl { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch;
  background: rgba(255,255,255,.96); border: 1px solid rgba(255,255,255,.9); border-radius: 20px;
  margin-bottom: 18px; box-shadow: var(--shadow); }
table { width: max-content; min-width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .85rem; color: var(--brand-dark); font-weight: 700; background: #eefaf7; white-space: nowrap; }
tbody tr:hover td, table > tr:hover td { background: #fbfefd; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
tr.off td { opacity: .5; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .82rem; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.muted { background: #eef0f3; color: var(--muted); }

.flash { padding: 11px 15px; border-radius: 14px; margin: 14px 0; box-shadow: 0 8px 22px rgba(38,91,91,.08); }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.bad { background: var(--bad-bg); color: var(--bad); }
code.pw { font-size: 1.1rem; background: #fff; padding: 2px 8px; border-radius: 6px; user-select: all; }

.foot { color: var(--muted); font-size: .85rem; padding-block: 30px; }

/* ---------- อาคาร / ห้อง (รุ่น 2) ---------- */
.bgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.bcard { display: block; background: rgba(255,255,255,.96); border: 1px solid rgba(255,255,255,.9); border-radius: 22px;
  overflow: hidden; text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
  transition: box-shadow .15s, transform .15s; }
.bcard:hover { box-shadow: 0 20px 44px rgba(38,91,91,.16); transform: translateY(-3px); }
.bimg { position: relative; aspect-ratio: 16 / 9; background: linear-gradient(145deg, #b8eee0, #e1f6ef 58%, #ffe4c2); }
.bimg img { width: 100%; height: 100%; object-fit: cover; display: block; }
.noimg { display: grid; place-items: center; height: 100%; font-size: 2.8rem; color: rgba(19,139,136,.52); }
.kind { position: absolute; top: 10px; left: 10px; background: rgba(255,255,255,.92); color: var(--ink);
  font-size: .78rem; padding: 2px 10px; border-radius: 99px; }
.bbody { padding: 12px 14px 14px; }
.bbody b { font-size: 1.05rem; }
.bmeta { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 6px; font-size: .86rem; color: var(--muted); }
.bmeta .ok { color: var(--ok); } .bmeta .warn { color: var(--warn); }

.bhead { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.bhead img { width: min(320px, 100%); aspect-ratio: 16 / 9; object-fit: cover; border-radius: 10px; }
.bhead p { margin: 0 0 6px; }

.rgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.rtile { display: flex; flex-direction: column; gap: 2px; padding: 11px 13px; border-radius: 16px; border: 1px solid var(--line);
  background: rgba(255,255,255,.94); color: var(--ink); text-decoration: none; border-left-width: 5px; min-height: 78px;
  box-shadow: 0 7px 20px rgba(38,91,91,.07); }
a.rtile:hover { box-shadow: 0 12px 26px rgba(38,91,91,.13); transform: translateY(-1px); }
.rtile b { font-size: 1.05rem; }
.rtile .occ { font-size: .82rem; color: var(--muted); margin-top: auto; }
.rtile .names { font-size: .76rem; color: var(--muted); line-height: 1.3; overflow: hidden; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.rtile.vacant  { border-left-color: #30b98e; }
.rtile.partial { border-left-color: #27aaa7; }
.rtile.full    { border-left-color: #8b95a5; background: #fafbfc; }
.rtile.closed  { border-left-color: var(--accent); background: var(--warn-bg); }
.legend .badge { margin-right: 2px; }

.resident { border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 12px; }
.resident p { margin: 0 0 6px; }
.resident details form { margin-top: 10px; }
details > summary { cursor: pointer; }
.grid2.tight { gap: 0 14px; }
label.check { display: flex; gap: 8px; align-items: center; }
label.check input { width: auto; margin: 0; }
p.r { text-align: right; margin: 8px 0 0; }
.offscreen { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- Responsive: tablet / mobile ---------- */
@media (max-width: 760px) {
  body { padding-bottom: calc(82px + env(safe-area-inset-bottom));
    background: radial-gradient(circle at 0 0, rgba(62,207,181,.16), transparent 18rem), #f2f6f5; }
  .wrap { padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right)); }
  h1 { font-size: 1.65rem; line-height: 1.2; font-weight: 750; letter-spacing: -.035em; margin-block: 20px 14px; }
  h2 { margin-top: 20px; }

  .top { position: sticky; z-index: 40; top: 0; color: var(--ink);
    background: rgba(247,251,250,.84); border-bottom: .5px solid rgba(60,60,67,.14);
    box-shadow: none; backdrop-filter: saturate(180%) blur(24px); -webkit-backdrop-filter: saturate(180%) blur(24px); }
  .bar { align-items: flex-start; gap: 10px; padding-block: 10px; }
  .brand { min-width: 0; color: var(--ink); font-weight: 750; letter-spacing: -.015em; }
  .brand small { white-space: normal; }
  .logo { color: #fff; background: linear-gradient(145deg, #1aa7a2, #61d5bd); border-radius: 10px;
    box-shadow: 0 5px 14px rgba(26,167,162,.22); }
  .who { width: 100%; justify-content: space-between; gap: 8px 12px; padding-top: 8px;
    border-top: .5px solid rgba(60,60,67,.14); }
  .who span { flex: 1 1 100%; }
  .who a, .who .link { color: var(--brand-dark); opacity: 1; font-weight: 600; text-decoration: none; }
  .tabs { position: fixed; z-index: 50; left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right)); bottom: max(8px, env(safe-area-inset-bottom));
    width: auto; max-width: 620px; margin-inline: auto; padding: 7px 8px; gap: 2px;
    background: rgba(250,252,252,.88); border: .5px solid rgba(60,60,67,.16); border-radius: 24px;
    box-shadow: 0 12px 36px rgba(31,58,63,.20); backdrop-filter: saturate(180%) blur(24px);
    -webkit-backdrop-filter: saturate(180%) blur(24px); scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { display: flex; flex: 0 0 72px; min-width: 72px; min-height: 58px; padding: 5px 4px;
    flex-direction: column; align-items: center; justify-content: center; gap: 2px; border-radius: 16px;
    color: var(--muted); font-size: .68rem; line-height: 1.15; text-align: center; opacity: 1;
    scroll-snap-align: center; }
  .tabs a:hover { background: var(--brand-soft); }
  .tabs a.on { background: rgba(26,167,162,.10); color: var(--brand-dark); }
  .navicon { display: grid; width: 29px; height: 29px; place-items: center; border-radius: 11px;
    font-size: 1.05rem; line-height: 1; color: var(--brand-dark); }
  .tabs a.on .navicon { color: #fff; background: linear-gradient(135deg, var(--accent), #ffc179);
    box-shadow: 0 6px 14px rgba(242,149,63,.25); transform: translateY(-1px); }

  .card { padding: 16px; border: 0; border-radius: 20px; box-shadow: 0 5px 20px rgba(39,76,82,.07); }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 14px; border: 0; border-radius: 18px; box-shadow: 0 5px 18px rgba(39,76,82,.07); }
  .stat b { font-size: 1.45rem; }

  .row { align-items: stretch; }
  .row > label, .row > .stack { flex: 1 1 100%; min-width: 0; }
  .row input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
  .row select, .row textarea { width: 100%; }
  input, select, textarea { min-height: 44px; font-size: 16px; border-color: transparent;
    border-radius: 12px; background: #f2f4f4; }
  .btn { min-height: 44px; padding: 10px 14px; border-radius: 12px; text-align: center; }
  .btn.sm { min-height: 40px; padding: 8px 10px; }
  .actions { white-space: normal; }

  .tbl { margin-inline: -12px; border-radius: 0; border-inline: 0; box-shadow: none; }
  th, td { padding: 9px 10px; }
  .bgrid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); gap: 12px; }
  .rgrid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
  .bhead { gap: 12px; }
  .bhead > div { min-width: 0; }
  .foot { padding-block: 22px; }
}

@media (max-width: 420px) {
  .stats { grid-template-columns: minmax(0, 1fr); }
  .bgrid { grid-template-columns: minmax(0, 1fr); }
  .rgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row > .btn, .row > form.inline, .row > form.inline .btn { width: 100%; }
  .flash { padding: 9px 11px; }
}

@media (min-width: 1600px) {
  .wrap { max-width: 1380px; }
  .bgrid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
