/* ===========================================================================
 * mes789-system / assets/css/topbar.css
 * แถบบน 2 แถว + เมนูซ่อน — โหลดหลังสุด ทับค่าของ shell-nav.css โดยตั้งใจ
 * =========================================================================== */

:root { --tb-row1: 54px; --tb-row2: 46px; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 300;
    background: rgba(10, 8, 8, .94);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(212, 175, 55, .14);
}

/* ปิดแถบเก่าที่ shell-nav.css สร้างไว้ กันซ้อนกันสองแถบ */
.shell-topbar { display: none !important; }

/* ===========================================================================
   แถวที่ 1
   =========================================================================== */
.topbar-row1 {
    height: var(--tb-row1);
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tb-logo { flex-shrink: 0; display: flex; align-items: center; }
.tb-logo img {
    height: 30px;
    width: auto;
    display: block;
    filter: drop-shadow(0 0 6px rgba(212, 175, 55, .3));
}

/* ---- ช่องค้นหา ---- */
.tb-search {
    flex: 1;
    max-width: 340px;
    position: relative;
    display: flex;
    align-items: center;
}
.tb-search .ico-svg {
    position: absolute;
    left: 12px;
    color: var(--text-mute, #6f6360);
    pointer-events: none;
}
.tb-search input {
    width: 100%;
    background: rgba(255, 255, 255, .045);
    border: 1px solid rgba(212, 175, 55, .16);
    border-radius: 999px;
    padding: .46rem .9rem .46rem 36px;
    color: var(--text, #ece5e0);
    font-family: inherit;
    font-size: .88rem;
}
.tb-search input::placeholder { color: var(--text-mute, #6f6360); }
.tb-search input:focus {
    outline: none;
    border-color: rgba(212, 175, 55, .45);
    background: rgba(255, 255, 255, .07);
}

/* ---- ปุ่มฝั่งขวา ---- */
.tb-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.tb-btn {
    position: relative;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, .045);
    border: 1px solid rgba(212, 175, 55, .16);
    color: var(--gold-soft, #f0d98a);
    cursor: pointer;
    padding: 0;
    text-decoration: none;
    transition: border-color .16s ease, background .16s ease;
}
.tb-btn:hover,
.tb-btn[aria-expanded="true"] {
    border-color: rgba(212, 175, 55, .55);
    background: rgba(212, 175, 55, .1);
    color: var(--gold, #d4af37);
}

.tb-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    background: var(--red, #b3202a);
    color: #fff;
    font-size: .62rem;
    font-weight: 700;
    line-height: 17px;
    text-align: center;
    border-radius: 999px;
    border: 2px solid #0a0808;
}

.tb-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    border: 1.5px solid rgba(212, 175, 55, .5);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface-2, #221a1a);
    color: var(--gold, #d4af37);
    font-weight: 700;
    text-decoration: none;
}
.tb-avatar img { width: 100%; height: 100%; object-fit: cover; }

.tb-link {
    color: var(--gold-soft, #f0d98a);
    text-decoration: none;
    font-size: .88rem;
    padding: .4rem .7rem;
    white-space: nowrap;
}
.tb-cta {
    background: linear-gradient(160deg, #e8c46a, #c9a132);
    color: #241a08;
    font-weight: 700;
    font-size: .88rem;
    padding: .45rem 1rem;
    border-radius: 999px;
    text-decoration: none;
    white-space: nowrap;
}

/* ===========================================================================
   แถวที่ 2 — 6 หมวดหลัก
   =========================================================================== */
.topbar-row2 {
    height: var(--tb-row2);
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 12px;
    display: flex;
    align-items: stretch;
    gap: 2px;
    border-top: 1px solid rgba(255, 255, 255, .045);
}

.tb-nav {
    flex: 1;
    max-width: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    position: relative;
    color: var(--text-dim, #a1938c);
    text-decoration: none;
    border-radius: 8px;
    transition: color .16s ease, background .16s ease;
}
.tb-nav:hover { color: var(--gold-soft, #f0d98a); background: rgba(255, 255, 255, .035); }

.tb-nav.active { color: var(--gold, #d4af37); }
/* ขีดทองใต้หมวดที่กำลังดูอยู่ */
.tb-nav.active::after {
    content: '';
    position: absolute;
    left: 18%;
    right: 18%;
    bottom: 0;
    height: 2.5px;
    border-radius: 3px 3px 0 0;
    background: linear-gradient(90deg, transparent, var(--gold, #d4af37) 25%, var(--gold, #d4af37) 75%, transparent);
}

.tb-nav-label { font-size: .82rem; white-space: nowrap; }

/* จอแคบกว่า 980px — เหลือแต่ไอคอน ตัดข้อความทิ้ง */
@media (max-width: 980px) {
    .tb-nav-label { display: none; }
    .tb-nav { max-width: none; }
}
@media (max-width: 640px) {
    .topbar-row1 { padding: 0 8px; gap: 7px; }
    .tb-logo img { height: 26px; }
    .tb-search { max-width: none; }
    .tb-btn { width: 34px; height: 34px; }
    .tb-avatar { width: 32px; height: 32px; }
    .topbar-row2 { padding: 0 4px; }
}
/* จอเล็กมาก — [24 ต.ค. 2569 · เจ้าของเลือกแบบ ก] เดิมซ่อนช่องค้นหาที่จอ ≤420px (เจ้าของเจอ "ค้นหาหาย ใช้ไม่ได้" บนโทรศัพท์)
   ถอดกฎซ่อนออกแล้ว — ช่องค้นหา (flex:1) หดตามที่เหลือเอง · เทส test-topbar-search-mobile.sh: 320–1024px ไม่ล้นจอ ไม่ทับปุ่ม */

/* เนื้อหาไม่ต้องเว้นที่ให้แถบเก่าอีก */
.shell-grid { padding-top: 16px; }
.shell-left, .shell-right {
    top: calc(var(--tb-row1) + var(--tb-row2) + 16px);
}

/* ===========================================================================
   เมนูซ่อน (กดตารางสี่เหลี่ยม)
   =========================================================================== */
.tb-apps {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: rgba(0, 0, 0, .55);
    display: flex;
    justify-content: flex-end;
    align-items: flex-start;
    padding: calc(var(--tb-row1) + 6px) 12px 12px;
}
.tb-apps[hidden] { display: none; }

.tb-apps-inner {
    width: 100%;
    max-width: 340px;
    background: #161112;
    border: 1px solid rgba(212, 175, 55, .2);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .7);
    padding: 12px;
    max-height: calc(100vh - var(--tb-row1) - 24px);
    overflow-y: auto;
    animation: tbDrop .18s ease-out;
}
@keyframes tbDrop {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .tb-apps-inner { animation: none; }
}

.tb-apps-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: .95rem;
    font-weight: 700;
    color: var(--gold-soft, #f0d98a);
}
.tb-apps-close {
    background: none;
    border: 0;
    color: var(--text-mute, #6f6360);
    cursor: pointer;
    padding: 4px;
    line-height: 0;
}
.tb-apps-close:hover { color: var(--text, #ece5e0); }

.tb-apps-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}
.tb-app {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 14px 8px;
    border-radius: 11px;
    background: rgba(255, 255, 255, .035);
    border: 1px solid rgba(255, 255, 255, .05);
    color: var(--text-dim, #a1938c);
    text-decoration: none;
    font-size: .8rem;
    text-align: center;
}
.tb-app:hover {
    border-color: rgba(212, 175, 55, .4);
    color: var(--gold-soft, #f0d98a);
}
.tb-app-ico { color: var(--gold, #d4af37); line-height: 0; }

.tb-apps-sep { height: 1px; background: rgba(255, 255, 255, .06); margin: 12px 2px; }

.tb-app-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: .62rem .6rem;
    border-radius: 9px;
    color: var(--text-dim, #a1938c);
    text-decoration: none;
    font-size: .88rem;
}
.tb-app-row:hover { background: rgba(255, 255, 255, .045); color: var(--text, #ece5e0); }
.tb-app-row .ico-svg { color: var(--gold-dim, #8a7128); flex-shrink: 0; }
.tb-app-row:hover .ico-svg { color: var(--gold, #d4af37); }
.tb-app-row.danger { color: rgba(224, 67, 77, .82); }
.tb-app-row.danger .ico-svg { color: rgba(224, 67, 77, .7); }
.tb-app-row.danger:hover { background: rgba(179, 32, 42, .1); color: var(--red-soft, #e0434d); }

/* โฟกัสคีย์บอร์ดต้องเห็นชัด */
.tb-btn:focus-visible, .tb-nav:focus-visible, .tb-app:focus-visible,
.tb-app-row:focus-visible, .tb-avatar:focus-visible, .tb-logo:focus-visible {
    outline: 2px solid var(--gold, #d4af37);
    outline-offset: 2px;
}

/* ===========================================================================
   เมนูตอนลากคลุมลิงก์ (link-menu.js)
   =========================================================================== */
.sel-link-menu {
    position: absolute;
    z-index: 500;
    background: #161112;
    border: 1px solid rgba(212, 175, 55, .35);
    border-radius: 11px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .7);
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    min-width: 190px;
    max-width: 280px;
}
.sel-link-host {
    font-size: .78rem;
    color: var(--gold-soft, #f0d98a);
    font-weight: 600;
    word-break: break-all;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.sel-link-menu button {
    background: none;
    border: 1px solid rgba(212, 175, 55, .3);
    border-radius: 7px;
    color: var(--gold-soft, #f0d98a);
    padding: .42rem .8rem;
    font-size: .84rem;
    font-family: inherit;
    cursor: pointer;
    text-align: center;
}
.sel-link-menu button:hover {
    border-color: var(--gold, #d4af37);
    background: rgba(212, 175, 55, .1);
}
.sel-link-warn {
    font-size: .7rem;
    color: var(--text-mute, #6f6360);
    line-height: 1.5;
    text-align: center;
}

/* ลิงก์ตายในเนื้อหาโพสต์ — ให้เห็นว่าเป็นลิงก์ แต่กดไม่ได้
   เส้นใต้ประ + เมาส์เป็นลูกศรธรรมดา บอกเป็นนัยว่า "ไม่ใช่ปุ่ม" */
.post-body .dead-link {
    color: var(--text-dim, #a1938c);
    text-decoration: underline dotted;
    text-underline-offset: 3px;
    cursor: text;
    word-break: break-all;
}
