/* css/portal.css — ระบบเรียกดูข้อมูล (index.php = กรอบเมนู + iframe, home.php = หน้าแรกใน iframe) */

:root {
    --bg: #f4f6f3;
    --surface: #ffffff;
    --line: #dfe6dd;
    --ink: #1c2420;
    --ink-2: #4a5550;
    --ink-3: #66716b;
    --green: #2e7d32;
    --green-ink: #1b5e20;
    --green-soft: #e8f3e9;
    --focus: #1d4ed8;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--ink);
    font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Leelawadee", Tahoma, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}
a { color: var(--green-ink); }
a:focus, button:focus, iframe:focus { outline: 3px solid var(--focus); outline-offset: 2px; }

.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: 2000; padding: 10px 16px;
    background: #0f172a; color: #fff; font-weight: 700; border-radius: 0 0 8px 8px; text-decoration: none;
}
.skip-link:focus { top: 0; }
.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ================= index.php ================= */
html:has(body.portal), body.portal { height: 100%; }
body.portal { display: flex; flex-direction: column; overflow: hidden; height: 100vh; }

.p-header {
    flex: none; display: flex; align-items: center; gap: 14px; padding: 10px 20px;
    background: linear-gradient(135deg, #ffffff 0%, #f1f8ef 100%);
    border-bottom: 3px solid var(--green);
}
.p-header img { width: 56px; height: auto; }
.p-header h1 { margin: 0; font-size: 22px; line-height: 1.25; color: var(--green-ink); }
.p-sub { margin: 2px 0 0; font-size: 14px; color: var(--ink-2); }

.topbar, .backdrop, .close-btn { display: none; }

.wrap { flex: 1; min-height: 0; display: flex; }
.side {
    width: 320px; flex: none; overflow-y: auto; padding: 12px 12px 16px;
    background: var(--surface); border-right: 1px solid var(--line);
}
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 8px; }
.side-head h2 { margin: 0; font-size: 17px; }
.side ul { list-style: none; margin: 0; padding: 0; }
.menu-home { margin-bottom: 4px !important; }
.grp { padding: 10px 0 6px; border-top: 1px solid var(--line); }
.grp-title {
    display: flex; align-items: center; gap: 8px; margin: 0 0 4px; padding: 0 6px;
    font-size: 13px; font-weight: 700; letter-spacing: .02em; color: var(--green-ink);
}
.side a {
    display: flex; gap: 8px; align-items: flex-start; padding: 7px 10px 7px 12px; margin: 1px 0;
    color: var(--ink); text-decoration: none; border-radius: 8px; border-left: 3px solid transparent;
    font-size: 15px; line-height: 1.45;
}
.side a:hover { background: #f1f5f0; }
.side a.active { background: var(--green-soft); border-left-color: var(--green); font-weight: 700; color: var(--green-ink); }
.side .note { color: var(--green-ink); }
.side .ext, .home .ext { color: var(--ink-3); }
.side-footer { display: none; margin-top: 12px; padding: 10px 6px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.side-footer p { margin: 3px 0; }

.main { flex: 1; min-width: 0; background: var(--bg); }
.main iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }

.p-footer { flex: none; padding: 6px 20px; font-size: 13px; color: var(--ink-2); background: var(--surface); border-top: 1px solid var(--line); }
.p-footer p { margin: 0; }

/* ----- จอเล็ก: เมนูเป็นลิ้นชัก ----- */
@media (max-width: 800px) {
    body.portal { height: 100vh; height: 100dvh; }
    .p-header { padding: 6px 10px; gap: 8px; }
    .p-header img { width: 36px; }
    .p-header h1 { font-size: 16px; }
    .p-sub { display: none; }

    .topbar { flex: none; display: flex; align-items: center; gap: 10px; padding: 6px 8px; background: var(--surface); border-bottom: 1px solid var(--line); }
    .menu-btn {
        font: inherit; font-weight: 700; min-height: 44px; padding: 0 16px; border: 0; border-radius: 8px;
        background: var(--green); color: #fff; cursor: pointer;
    }
    #current { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; color: var(--ink-2); }

    .side {
        position: fixed; top: 0; left: 0; bottom: 0; width: 86%; max-width: 360px; z-index: 1000;
        border-right: 0; box-shadow: 2px 0 16px rgba(0, 0, 0, .3);
        transform: translateX(-105%); visibility: hidden;          /* ปิดอยู่ = กด Tab เข้าไม่ได้ */
        transition: transform .25s ease, visibility 0s linear .25s;
        -webkit-overflow-scrolling: touch; padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
    body.open .side { transform: none; visibility: visible; transition: transform .25s ease; }
    .close-btn {
        display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; font: inherit;
        border: 1px solid #7d8a82; border-radius: 8px; background: #fff; color: var(--ink); cursor: pointer;
    }
    .side a { padding: 11px 10px 11px 12px; }      /* พื้นที่แตะใหญ่ขึ้น */
    .backdrop {
        display: block; position: fixed; top: 0; left: 0; right: 0; bottom: 0; z-index: 999;
        background: rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .25s ease;
    }
    body.open .backdrop { opacity: 1; pointer-events: auto; }
    .p-footer { display: none; }
    .side-footer { display: block; }
}
@media (prefers-reduced-motion: reduce) {
    .side, .backdrop { transition: none !important; }
}

/* ================= home.php (ใน iframe) ================= */
body.home { background: var(--bg); }
.home-wrap { max-width: 1100px; margin: 0 auto; padding: 24px 20px 32px; }
.home h1 { margin: 0; font-size: 24px; color: var(--green-ink); }
.home-lead { margin: 6px 0 18px; color: var(--ink-2); }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.home-card {
    padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
    border-top: 4px solid var(--green);
}
.home-card h2 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 17px; color: var(--green-ink); }
.home-card h2 .ico { width: 24px; height: 24px; }
.home-card ul { margin: 0; padding: 0 0 0 4px; list-style: none; }
.home-card li { padding: 5px 0; border-bottom: 1px dashed var(--line); }
.home-card li:last-child { border-bottom: 0; }
.home-card a { color: var(--ink); text-decoration: none; font-size: 15px; }
.home-card a:hover { color: var(--green-ink); text-decoration: underline; }
.home-card .note { color: var(--green-ink); }
@media (max-width: 640px) {
    .home-wrap { padding: 16px 12px 24px; }
    .home h1 { font-size: 20px; }
    .home-grid { grid-template-columns: 1fr; }
}
@media (forced-colors: active) {
    .side a.active { outline: 2px solid Highlight; }
}
