/* css/dorm.css — หน้าข้อมูลหอพัก (ฝังใน iframe ได้) ; โครงเดียวกับ css/brand.css ของ Bangkok Brand */

:root {
    --bg: #f4f6f3;
    --surface: #ffffff;
    --line: #e2e8e0;
    --ink: #1c2420;
    --ink-2: #4a5550;
    --ink-3: #66716b;
    --focus: #1d4ed8;
    --radius: 14px;
    --hero-1: #123f24; --hero-2: #17552f; --accent: #f2c14e;
    --primary: #2e7d32; --primary-ink: #1b5e20; --primary-soft: #e8f3e9;
    /* สีข้อมูล 2 กลุ่ม (ผ่านการตรวจตาบอดสี): ได้รับ / ไม่ได้รับใบอนุญาต */
    --s-r: #2a78d6; --s-n: #eb6834;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Leelawadee", Tahoma, sans-serif;
    font-size: 16px;
    line-height: 1.55;
}
a { color: var(--primary-ink); }
a:focus, button:focus, input:focus, select:focus, [tabindex]:focus { outline: 3px solid var(--focus); outline-offset: 2px; }
.bp { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* ---------- การเข้าถึง ---------- */
.sr-only {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
    position: absolute; left: 8px; top: -60px; z-index: 100; padding: 10px 16px;
    background: #0f172a; color: #fff; font-weight: 700; border-radius: 0 0 8px 8px; text-decoration: none;
}
.skip-link:focus { top: 0; }
.muted { color: var(--ink-3); }

/* ---------- หัวหน้า ---------- */
.bp-hero {
    position: relative;
    overflow: hidden;
    padding: 26px 28px 24px;
    border-radius: var(--radius);
    color: #fff;
    background: linear-gradient(120deg, var(--hero-1) 0%, var(--hero-2) 100%);
}
.bp-hero::after {               /* ลายวงกลมตกแต่ง */
    content: ""; position: absolute; right: -60px; top: -80px; width: 280px; height: 280px; border-radius: 50%;
    border: 36px solid rgba(255, 255, 255, .06);
}
.bp-eyebrow {
    margin: 0 0 4px; font-size: 14px; font-weight: 600; letter-spacing: .02em; color: var(--accent);
}
.bp-hero h1 { margin: 0; font-size: 30px; line-height: 1.2; }
.bp-lead { margin: 8px 0 0; max-width: 680px; color: rgba(255, 255, 255, .88); }

/* ---------- ค้นหา ---------- */
.bp-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    margin-top: 14px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.fld { flex: 1 1 160px; min-width: 0; }
.fld-search { flex: 2 1 260px; }
.fld label { display: block; margin-bottom: 4px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.fld input, .fld select {
    width: 100%; height: 42px; padding: 0 12px; font: inherit; font-size: 15px; color: var(--ink);
    background: #fff; border: 1px solid #7d8a82; border-radius: 10px;
}
.fld.fld-actions { flex: 0 0 auto; display: flex; gap: 8px; }
.btn {
    display: inline-flex; align-items: center; justify-content: center; height: 42px; padding: 0 18px;
    font: inherit; font-weight: 700; border-radius: 10px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; border: 1px solid var(--primary); }
.btn-primary:hover { background: var(--primary-ink); }
.btn-ghost { background: #fff; color: var(--ink-2); border: 1px solid #7d8a82; }
.btn-ghost:hover { background: #f1f4f1; }

/* ---------- ภาพรวม ---------- */
.bp-overview { margin-top: 14px; }
.stats { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat {
    padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    display: flex; flex-direction: column;
}
.stat-v { font-size: 28px; font-weight: 800; line-height: 1.1; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-l { margin-top: 4px; font-size: 14px; color: var(--ink-2); }
.stat-main { background: var(--primary-soft); border-color: transparent; }
.stat-main .stat-v { color: var(--primary-ink); }

.panels { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.panels-one { grid-template-columns: 1fr; }
.panel { padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel h3 { margin: 0; font-size: 16px; }
.panel-hint { margin: 2px 0 10px; font-size: 13px; color: var(--ink-3); }

/* แท่งแนวนอน: สีเดียว ค่าเขียนกำกับทุกแท่ง (ไม่ต้องมีคำอธิบายสี) */
.bars { list-style: none; margin: 0; padding: 0; }
.bar-row {
    display: grid; grid-template-columns: minmax(110px, 32%) 1fr 64px; align-items: center; gap: 10px;
    padding: 6px 8px; margin: 0 -8px; border-radius: 8px; color: var(--ink); text-decoration: none;
}
a.bar-row:hover { background: #f3f6f3; }
.bar-row.is-on { background: var(--primary-soft); box-shadow: inset 0 0 0 2px var(--primary); }
.bar-label { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { position: relative; height: 12px; background: #edf1ec; border-radius: 0 6px 6px 0; overflow: hidden; }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; min-width: 2px; max-width: 100%; background: var(--primary); border-radius: 0 4px 4px 0; }
.bar-row.is-rest { border-top: 1px dashed var(--line); border-radius: 0; margin-top: 4px; padding-top: 8px; }
.bar-note { font-size: 13px; color: var(--ink-3); }
.bar-val { text-align: right; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }

/* ---------- ตาราง ---------- */
.bp-results { margin-top: 14px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.bp-results:focus { outline: none; }
.res-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.res-head h2 { margin: 0; font-size: 20px; }
.res-count { margin: 2px 0 0; color: var(--ink-2); }

.seg { display: inline-flex; padding: 3px; background: #eef2ee; border-radius: 10px; }
.seg a { padding: 6px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--ink-2); text-decoration: none; }
.seg a.on { background: #fff; color: var(--primary-ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }

.chips { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex; gap: 4px; align-items: center; padding: 4px 12px; border-radius: 999px; font-size: 14px;
    background: var(--primary-soft); color: var(--primary-ink); text-decoration: none; border: 1px solid transparent;
}
.chip:hover { border-color: var(--primary); }

.cards { list-style: none; margin: 16px 0 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.card article {
    height: 100%; padding: 14px 16px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
    border-top: 4px solid var(--primary);
}
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.type-chip { font-size: 13px; color: var(--ink-2); background: #f1f4f1; padding: 2px 10px; border-radius: 999px; }
.card h3 { margin: 10px 0 8px; font-size: 17px; line-height: 1.35; word-break: break-word; }
.card-meta { margin: 0; display: grid; gap: 4px; font-size: 14px; }
.card-meta div { display: grid; grid-template-columns: 96px 1fr; gap: 6px; }
.card-meta dt { color: var(--ink-3); }
.card-meta dd { margin: 0; color: var(--ink); word-break: break-word; }
.tel-link { color: var(--primary-ink); font-weight: 600; white-space: nowrap; }

.table-wrap { margin-top: 16px; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl thead th { background: var(--primary); color: #fff; font-weight: 700; white-space: nowrap; }
.tbl tbody th { font-weight: 600; }
.tbl tbody tr:nth-child(even) { background: #f8faf8; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; width: 64px; }
.tbl .nowrap { white-space: nowrap; }

.empty { margin-top: 16px; padding: 28px; text-align: center; border: 2px dashed var(--line); border-radius: 12px; color: var(--ink-2); }
.empty p { margin: 4px 0; }

.pager { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 18px; }
.pager a, .pager span {
    min-width: 40px; height: 40px; padding: 0 12px; display: inline-flex; align-items: center; justify-content: center;
    border-radius: 10px; font-weight: 600; text-decoration: none;
}
.pager a { border: 1px solid #7d8a82; color: var(--ink-2); background: #fff; }
.pager a:hover { border-color: var(--primary); color: var(--primary-ink); }
.pager .cur { background: var(--primary); color: #fff; }
.pager .gap { color: var(--ink-3); }

.bp-foot { margin: 14px 0 4px; text-align: center; font-size: 13px; color: var(--ink-3); }


/* ---------- หอพัก ---------- */
.bp-meta { margin: 10px 0 0; font-size: 14px; color: var(--accent); font-weight: 600; }
.hero-admin {
    position: absolute; right: 20px; top: 20px; z-index: 1; padding: 6px 14px; border-radius: 999px;
    background: rgba(255, 255, 255, .14); color: #fff; font-size: 14px; font-weight: 600; text-decoration: none;
    border: 1px solid rgba(255, 255, 255, .45);
}
.hero-admin:hover { background: rgba(255, 255, 255, .24); }

.dot { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 8px; vertical-align: middle; }
.dot-r { background: var(--s-r); }
.dot-n { background: var(--s-n); }
.stat-v .dot { width: 14px; height: 14px; position: relative; top: -3px; }

.panel h2 { margin: 0; font-size: 16px; }
.panel h3 { margin: 18px 0 6px; font-size: 15px; }
.legend { list-style: none; margin: 8px 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; color: var(--ink-2); }

/* แท่งซ้อน: ช่องว่าง 2px ระหว่างสองสี, ปลายแท่งมน */
.sb-track { display: flex; gap: 2px; height: 14px; background: #fff; box-shadow: inset 0 0 0 1px #d5ddd7; border-radius: 0 6px 6px 0; overflow: hidden; }   /* พื้นขาว: สีส้มต้องตัดกับพื้นอย่างน้อย 3:1 */
.seg { display: block; height: 100%; min-width: 2px; }
.seg-r { background: var(--s-r); }
.seg-n { background: var(--s-n); }
.sb-track .seg:last-child { border-radius: 0 4px 4px 0; }

.share .sb-track { height: 26px; border-radius: 6px; }
.share .sb-track .seg:first-child { border-radius: 4px 0 0 4px; }
.share-labels { display: flex; justify-content: space-between; margin-top: 6px; font-size: 14px; color: var(--ink-2); }
.share-labels b { color: var(--ink); }

.sbars { list-style: none; margin: 0; padding: 0; }
.sb-row { display: grid; grid-template-columns: minmax(96px, 30%) 1fr 56px; gap: 10px; align-items: center; padding: 5px 0; }
.sb-name { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-val { text-align: right; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.more { margin-top: 6px; }
.more summary {
    cursor: pointer; padding: 8px 0; font-weight: 600; color: var(--primary-ink);
}
.more summary:focus { outline: 3px solid var(--focus); outline-offset: 2px; }

/* เครื่องมือเหนือตาราง */
.tools { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.tools .fld { min-width: 220px; }
#tbl-title:focus { outline: none; }

/* ตาราง 2 ชั้น */
.tbl thead th { text-align: center; vertical-align: bottom; }
.tbl thead th.grp-r { background: #1c5cab; }
.tbl thead th.grp-n { background: #a8431b; }
.tbl thead th button {
    font: inherit; font-weight: 700; color: inherit; background: none; border: 0; padding: 0; cursor: pointer;
    display: inline-flex; align-items: center; gap: 4px; text-align: inherit;
}
.tbl thead th button::after { content: "\2195"; opacity: .55; font-size: 12px; }
.tbl thead th[aria-sort="ascending"] button::after { content: "\25B2"; opacity: 1; }
.tbl thead th[aria-sort="descending"] button::after { content: "\25BC"; opacity: 1; }
.tbl thead th button:focus { outline: 3px solid #fff; outline-offset: 2px; }
.tbl td.sub-total { background: rgba(46, 125, 50, .05); font-weight: 600; }
.tbl td.grand { font-weight: 800; }
.tbl tbody th { white-space: nowrap; }
.tbl tfoot th, .tbl tfoot td { background: var(--primary-soft); font-weight: 800; border-top: 2px solid var(--primary); }
.tbl tfoot th { text-align: left; }

/* ---------- จอแคบ ---------- */
@media (max-width: 900px) {
    .panels { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .bp { padding: 10px; }
    .bp-hero { padding: 20px; }
    .bp-hero h1 { font-size: 24px; }
    .hero-admin { position: static; display: inline-block; margin-top: 12px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stat-v { font-size: 24px; }
    .tools, .tools .fld { width: 100%; }
    .tools .btn { width: 100%; }
    .bp-results { padding: 14px; }
}
@media (forced-colors: active) {
    .seg-r { background: CanvasText; }
    .seg-n { background: GrayText; }
    .sb-track { border: 1px solid CanvasText; }
}
@media print {
    .tools, .skip-link, .hero-admin { display: none; }
    .bp-hero { color: #000; background: none; border: 1px solid #000; }
    .bp-lead, .bp-eyebrow, .bp-meta { color: #000; }
    .more:not([open]) > *:not(summary) { display: block; }
}
.bp-hero + section .stats, .bp-hero + .note { margin-top: 14px; }

/* ---------- ตาราง 3 ชั้น (สถานะ → ประเภท/ลักษณะ → รายการ) ---------- */
.tbl thead th.sub-grp { font-weight: 600; }
.tbl thead th[id^="h-r-"] { background: #174f93; }   /* ชั้นกลางฝั่งจดทะเบียน */
.tbl thead th[id^="h-n-"] { background: #8f3815; }   /* ชั้นกลางฝั่งไม่จดทะเบียน */
.tbl thead tr:nth-child(2) th.sub-grp { border-left: 1px solid rgba(255, 255, 255, .35); }
.tbl thead th.kind { background: #3d6b40; }
.tbl td.kind { background: rgba(42, 120, 214, .045); }
.tbl td .z { color: var(--ink-3); }   /* ศูนย์ให้จางลง แต่ยังอ่านได้ (คอนทราสต์ 5:1) */
.tbl tbody tr.zero th { color: var(--ink-3); font-weight: 500; }
.stat-v small { font-size: 16px; font-weight: 600; color: var(--ink-3); }
.nodorm { margin: 4px 0 0; font-size: 14px; line-height: 1.9; color: var(--ink-2); }

/* =========================================================
   กราฟ (รุ่นปรับปรุง): การ์ด 3 ใบ + รายเขตเต็มความกว้าง 2 คอลัมน์
   แท่งไม่มีกรอบ ตัวเลขอยู่ที่ปลายแท่ง ช่องว่าง 2px ระหว่างสองสี
   ========================================================= */
.charts { margin-top: 14px; }
.charts-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin: 4px 2px 10px; }
.charts-head h2 { margin: 0; font-size: 18px; }
.charts-head .legend { margin: 0; }

.cards3 { display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 12px; }
.cards3.cards2 { grid-template-columns: 1fr 1fr; }
.ccard { padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ccard h3 { margin: 0 0 12px; font-size: 15px; color: var(--ink); }
.ccard h3 .muted { font-weight: normal; font-size: 13px; }
.ccard-wide { margin-top: 12px; }
.ccard-note { margin: 10px 0 0; font-size: 13px; color: var(--ink-3); }

/* สัดส่วน */
.share-top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.sv { display: flex; flex-direction: column; }
.sv b { font-size: 28px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.sv span { font-size: 13px; color: var(--ink-2); }
.sv-right { text-align: right; }
.c-r { color: #1d5fb0; }
.c-n { color: #b4471b; }
.share-bar { display: flex; gap: 3px; height: 22px; }
.share-bar .seg { height: 100%; }
.share-bar .seg-r { border-radius: 6px 0 0 6px; }
.share-bar .seg-n { border-radius: 0 6px 6px 0; }
.share-bar .seg:only-child { border-radius: 6px; }

/* แท่งรายการ */
.sbars { list-style: none; margin: 0; padding: 0; }
.sb-row {
    display: grid; grid-template-columns: minmax(84px, 34%) 1fr; gap: 10px; align-items: center;
    padding: 5px 6px; margin: 0 -6px; border-radius: 6px;
}
.sb-row:hover { background: #f3f6f3; }
.sb-name { font-size: 14px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-bar { display: flex; align-items: center; gap: 2px; min-width: 0; height: 16px; }
.sb-bar .seg { display: block; height: 100%; min-width: 3px; }
.sb-bar .seg:first-child { border-radius: 3px 0 0 3px; }
.sb-bar .seg:nth-last-child(2) { border-radius: 0 4px 4px 0; }       /* ส่วนสุดท้ายก่อนตัวเลข: ปลายมน */
.sb-bar .seg:first-child:nth-last-child(2) { border-radius: 3px 4px 4px 3px; }
.sb-bar .sb-val { margin-left: 8px; font-size: 14px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* รายเขต 2 คอลัมน์ (เรียงลงก่อนแล้วไปคอลัมน์ขวา) */
.sbars-2col { display: grid; grid-auto-flow: column; grid-template-columns: 1fr 1fr; column-gap: 32px; }
.sbars-2col .sb-row { grid-template-columns: 120px 1fr; }

/* ยกเลิกสไตล์แท่งรุ่นเก่า */
.sb-track { display: none; }
.panels { display: none; }

@media (max-width: 1000px) {
    .cards3, .cards3.cards2 { grid-template-columns: 1fr 1fr; }
    .cards3 > .ccard:first-child { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
    .cards3, .cards3.cards2 { grid-template-columns: 1fr; }
    .sbars-2col { grid-auto-flow: row; grid-template-columns: 1fr; grid-template-rows: none !important; }
    .sbars-2col .sb-row { grid-template-columns: 96px 1fr; }
    .sv b { font-size: 24px; }
}
@media (forced-colors: active) {
    .sb-bar .seg, .share-bar .seg { border: 1px solid CanvasText; }
}
