/* =========================================================
   topbar.css — แถบบน: การแจ้งเตือน / วันเวลา / ผู้ใช้
   ========================================================= */

.topbar {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--topbar-gap);
    height: var(--topbar-h);
    flex: none;
}

/* ตอนเปิดเมนู dropdown ให้แถบบนอยู่เหนือฉากหลังที่ใช้ปิดเมนู */
.topbar.menu-open {
    z-index: 60;
}

.topbar-spacer {
    flex: 1;
}

/* ปุ่ม ☰ (แสดงเฉพาะจอเล็ก) */
.topbar-menu-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: var(--pill-h);
    height: var(--pill-h);
    flex: none;
    border: 0;
    border-radius: var(--pill-radius);
    background: var(--c-sidebar);
    color: #fff;
    cursor: pointer;
}

/* ---------- ปุ่มแบบเม็ดยา (pill) ใช้ร่วมกันทั้ง 3 ส่วน ---------- */
.tb-pill {
    display: flex;
    align-items: center;
    gap: var(--pill-gap);
    height: var(--pill-h);
    padding: 0 var(--pill-pad);
    border: 0;
    border-radius: var(--pill-radius);
    background: var(--c-pill);
    box-shadow: inset 0 0 0 1px var(--c-pill-line);   /* พื้นขาวบนพื้นครีม ต้องมีขอบบาง ๆ */
    color: var(--c-ink);
    font-size: var(--pill-fs);
    white-space: nowrap;
}

button.tb-pill {
    cursor: pointer;
}

button.tb-pill:hover,
button.tb-pill[aria-expanded="true"] {
    background: var(--c-pill-hover);
}

.tb-pill .ms {
    font-size: var(--pill-icon);
    color: var(--c-brand);
}

/* ---------- การแจ้งเตือน ---------- */
.tb-alert {
    padding-left: var(--pill-gap);
    max-width: 32em;
}

.tb-alert-bell {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--bell);
    height: var(--bell);
    flex: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, .55);
}

.tb-badge {
    position: absolute;
    top: -3px;
    right: -5px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: var(--badge);
    height: var(--badge);
    padding: 0 3px;
    border: var(--badge-border) solid var(--c-pill);
    border-radius: calc(var(--badge) / 2);
    background: var(--c-err);
    color: #fff;
    font-size: var(--badge-fs);
    font-weight: 600;
    line-height: 1;
}

.tb-alert-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---------- วันเวลา ---------- */
.tb-clock {
    gap: 8px;
    font-variant-numeric: tabular-nums;
}

.tb-clock-time {
    min-width: 2.8em;
}

/* เชื่อมต่อฐานข้อมูลไม่ได้: ไอคอนแดง (วางเมาส์ดูรายละเอียด) */
.tb-clock.db-off .ms {
    color: var(--c-err);
}

/* ---------- ผู้ใช้ ---------- */
.tb-user {
    padding: 0 var(--pill-gap) 0 5.5px;
    border-radius: calc(var(--pill-h) / 2);
}

.tb-user-avatar {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--avatar);
    height: var(--avatar);
    flex: none;
    border-radius: 50%;
    background: var(--c-ink);
}

.tb-user-avatar .ms {
    color: #fff;
}

.tb-user-online {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: var(--online-dot);
    height: var(--online-dot);
    border: var(--badge-border) solid var(--c-pill);
    border-radius: 50%;
    background: var(--c-ok);
}

.tb-user-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    text-align: left;
}

.tb-user-name {
    font-size: var(--user-name-fs);
    font-weight: 600;
}

.tb-user-sub {
    font-size: var(--user-sub-fs);
    color: var(--c-ink-soft);
}

.tb-user-chevron {
    color: var(--c-ink-soft);
}

/* ---------- เมนู dropdown ---------- */
.tb-dropdown {
    position: relative;
}

.tb-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 100%;
    overflow: hidden;
    border-radius: var(--pill-radius);
    background: var(--c-surface);
    font-size: var(--menu-fs);
    box-shadow: 0 10px 30px rgba(34, 51, 71, .18), 0 1px 3px rgba(34, 51, 71, .12);
}

.tb-menu-alerts {
    width: 25em;
}

.tb-menu-head {
    padding: 11px 14px 8px;
    font-weight: 600;
    border-bottom: 1px solid var(--c-line);
}

.tb-menu-empty {
    padding: 18px 14px;
    color: var(--c-ink-soft);
}

.tb-alert-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    border-bottom: 1px solid var(--c-line);
    color: var(--c-ink);
    text-decoration: none;
}

.tb-alert-row:hover {
    background: var(--c-surface-2);
    color: var(--c-ink);
}

.tb-alert-ico {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.3em;
    height: 2.3em;
    flex: none;
    border-radius: 6px;
}

.tb-alert-ico .ms {
    font-size: 1.35em;
}

.sev-info     { background: var(--c-surface-2); color: var(--c-ink-soft); }
.sev-warning  { background: var(--c-warn-bg);   color: var(--c-warn-fg); }
.sev-critical { background: var(--c-err-bg);    color: var(--c-err-fg); }

.tb-alert-body {
    display: flex;
    flex-direction: column;
    line-height: 1.3;
}

.tb-alert-title {
    font-weight: 600;
}

.tb-alert-time {
    font-size: .88em;
    color: var(--c-ink-soft);
}

.tb-menu-foot {
    display: block;
    padding: 9px 14px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
}

.tb-menu-foot:hover {
    background: var(--c-surface-2);
}

.tb-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 14px;
    border: 0;
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.tb-menu-item:hover {
    background: var(--c-surface-2);
}

.tb-menu-item .ms {
    font-size: 1.35em;
    color: var(--c-ink-soft);
}

/* ฉากหลังโปร่งใสสำหรับคลิกปิดเมนู */
.tb-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
}

/* ---------- จอเล็ก ---------- */
@media (max-width: 1100px) {
    .topbar {
        gap: 8px;
    }

    .topbar-menu-btn {
        display: flex;
    }

    .tb-clock-date {
        display: none; /* เหลือแค่เวลา */
    }
}

@media (max-width: 700px) {
    .tb-alert-text,
    .tb-user-text,
    .tb-user-chevron,
    .tb-clock > .ms {
        display: none;
    }

    .tb-alert {
        padding: 0 8px;
    }

    .tb-user {
        padding: 0 4px;
    }

    .tb-menu-alerts {
        position: fixed;
        top: 64px;
        left: 8px;
        right: 8px;
        width: auto;
    }
}

/* ---------- แถบ Alarm (กระดิ่ง + ปุ่มปิดเสียง) ---------- */
.tb-alarm {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

a.tb-pill {
    color: var(--c-ink);
    text-decoration: none;
    cursor: pointer;
}

a.tb-pill:hover {
    background: var(--c-pill-hover);
}

.tb-alert-lines {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.15;
}

.tb-alert-count {
    font-size: .78em;
    font-weight: 700;
}

/* มี Alarm ค้าง Ack: กระพริบแดงเข้ม / ตัวขาว แบบติดดับ ทุก 1 วินาที */
@keyframes tbAlarmBlink {
    0%, 45% {
        background: #dc2626;
        color: #fff;
        box-shadow: 0 0 0 3px rgba(220, 38, 38, .35), 0 0 14px rgba(220, 38, 38, .55);
    }
    55%, 100% {
        background: var(--c-pill);
        color: var(--c-ink);
        box-shadow: none;
    }
}

.tb-alert.al-blink {
    animation: tbAlarmBlink 1s steps(1, end) infinite;
}

.tb-alert.al-blink:hover {
    animation-play-state: paused;
    background: #dc2626;
    color: #fff;
}

/* ยังเล่นเสียงไม่ได้ (โหลดหน้าใหม่ขณะ login ค้าง ยังไม่มีใครคลิก) · หายเองเมื่อคลิกที่ใดก็ได้ */
.tb-sound-lock {
    gap: 6px;
    border: 0;
    background: var(--c-orange-bg);
    box-shadow: inset 0 0 0 1px var(--c-orange);
    color: var(--c-orange-fg);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.tb-sound-lock .ms { font-size: var(--pill-icon); }

@media (max-width: 700px) {
    .tb-sound-text { display: none; }
}

.tb-mute {
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--pill-h);
    height: var(--pill-h);
    flex: none;
    border: 0;
    border-radius: 50%;
    background: var(--c-pill);
    box-shadow: inset 0 0 0 1px var(--c-pill-line);
    color: #b8392c;
    cursor: pointer;
}

.tb-mute:hover { background: var(--c-pill-hover); }
.tb-mute.muted { color: var(--c-ink-soft); }
.tb-mute .ms { font-size: var(--pill-icon); }
.tb-mute:focus-visible, a.tb-pill:focus-visible { outline: 3px solid #2563eb; outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    .tb-alert.al-blink { animation: none; background: #dc2626; color: #fff; }
}

/* เมนูย่อยชื่อยาว (กำหนดค่า Alarm & Event) */
.nav-sub-long {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
