/* แท็บแจ้งเตือน — แนวนอน สีฟ้า ชิดขอบขวา */

body.fos-widget-enabled #floating-order-sidebar-root {
    display: block;
}

#floating-order-sidebar-root {
    display: none;
    position: fixed;
    right: 0;
    /* ชิดขอบขวา · ห่างจากขอบล่าง ~52px (+ safe-area) */
    bottom: calc(env(safe-area-inset-bottom, 0px) + 52px);
    z-index: 240;
    pointer-events: none;
    max-width: 100vw;
}

.fos-root {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    pointer-events: auto;
    font-family: 'Noto Sans Thai', 'Sarabun', 'Thonburi', system-ui, sans-serif;
}

/* —— แท็บแจ้งเตือน (pill แนวนอน ชิดขอบขวา) —— */
.fos-notify-tab {
    position: relative;
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
    outline: none;
}

.fos-notify-tab:focus-visible .fos-notify-tab__pill {
    outline: 2px solid #7dd3fc;
    outline-offset: 3px;
}

.fos-notify-tab__pill {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.45rem 0.35rem 0.45rem 0.55rem;
    border-radius: 9999px 0 0 9999px;
    background: linear-gradient(
        90deg,
        var(--fos-blue-start, #22d3ee) 0%,
        var(--fos-blue-end, #2563eb) 100%
    );
    border: 1px solid rgba(125, 211, 252, 0.35);
    border-right: none;
    box-shadow:
        -6px 4px 24px var(--fos-blue-glow, rgba(56, 189, 248, 0.4)),
        0 8px 28px rgba(0, 0, 0, 0.35),
        inset 0 1px 0 rgba(255, 255, 255, 0.22);
    transition: box-shadow 0.25s ease, filter 0.25s ease, padding 0.25s ease;
    overflow: hidden;
}

.fos-notify-tab--collapsed .fos-notify-tab__pill {
    padding-right: 0.15rem;
}

.fos-notify-tab--collapsed .fos-notify-tab__body {
    opacity: 0;
    max-width: 0;
    overflow: hidden;
}

.fos-notify-tab--expanded .fos-notify-tab__body {
    opacity: 1;
    max-width: 5rem;
}

.fos-notify-tab:hover .fos-notify-tab__pill,
.fos-notify-tab[aria-expanded='true'] .fos-notify-tab__pill {
    filter: brightness(1.06);
    box-shadow:
        -8px 6px 32px rgba(56, 189, 248, 0.55),
        0 10px 32px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

.fos-notify-tab__icon-wrap {
    position: relative;
    flex-shrink: 0;
    width: 2.35rem;
    height: 2.35rem;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.28) 0%, rgba(255, 255, 255, 0.08) 100%);
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.fos-notify-tab__icon {
    color: #ffffff;
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.25));
}

.fos-notify-tab__body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
    transition: opacity 0.25s ease, max-width 0.3s ease;
    white-space: nowrap;
}

.fos-notify-tab__vlabel {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: #ffffff;
    line-height: 1.1;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.fos-notify-tab__count {
    font-size: 0.58rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.9);
    background: rgba(0, 0, 0, 0.18);
    padding: 0.12rem 0.28rem;
    border-radius: 9999px;
}

.fos-notify-tab--has-new .fos-notify-tab__pill {
    filter: brightness(1.05);
}

.fos-notify-tab__badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 1.1rem;
    height: 1.1rem;
    padding: 0 0.25rem;
    border-radius: 9999px;
    font-size: 0.58rem;
    font-weight: 800;
    color: #ffffff;
    background: linear-gradient(180deg, #f87171 0%, #dc2626 100%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 10px rgba(248, 113, 113, 0.65);
    border: 2px solid #ffffff;
    z-index: 2;
}

.fos-notify-tab__live-dot {
    position: absolute;
    top: 1px;
    right: 1px;
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 9999px;
    background: #4ade80;
    border: 2px solid #ffffff;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.8);
}

.fos-notify-tab__pulse {
    position: absolute;
    inset: -3px 0 -3px -4px;
    border-radius: 9999px 0 0 9999px;
    border: 1px solid rgba(125, 211, 252, 0.65);
    border-right: none;
    opacity: 0.55;
    animation: fos-pulse-ring 1.6s ease-out infinite;
    pointer-events: none;
}

@keyframes fos-pulse-ring {
    0% {
        transform: scale(0.97);
        opacity: 0.7;
    }
    70% {
        transform: scale(1.04);
        opacity: 0;
    }
    100% {
        transform: scale(1.04);
        opacity: 0;
    }
}

/* —— Popover เลื่อนขึ้นจากแท็บ (ชิดขวา) —— */
.fos-popover {
    position: absolute;
    bottom: calc(100% + 0.55rem);
    right: 0;
    width: min(360px, calc(100vw - 1rem));
    max-height: min(58vh, 480px);
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #0f172a 0%, #0b1220 100%);
    border: 1px solid rgba(56, 189, 248, 0.22);
    border-radius: 1rem 0.85rem 0.85rem 1rem;
    box-shadow:
        -8px -8px 40px rgba(0, 0, 0, 0.55),
        0 0 28px rgba(56, 189, 248, 0.1);
    overflow: hidden;
}

.fos-popover__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.85rem 0.9rem 0.65rem;
    border-bottom: 1px solid rgba(56, 189, 248, 0.12);
    background: linear-gradient(180deg, rgba(56, 189, 248, 0.08) 0%, transparent 100%);
}

.fos-popover__eyebrow {
    margin: 0;
    font-size: 0.62rem;
    letter-spacing: 0.08em;
    color: rgba(186, 230, 253, 0.6);
}

.fos-popover__title {
    margin: 0.15rem 0 0;
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.fos-popover__unread-pill {
    font-size: 0.58rem;
    font-weight: 700;
    padding: 0.12rem 0.45rem;
    border-radius: 9999px;
    background: rgba(56, 189, 248, 0.15);
    border: 1px solid rgba(125, 211, 252, 0.35);
    color: #bae6fd;
}

.fos-popover__close {
    border: 1px solid rgba(56, 189, 248, 0.22);
    background: rgba(56, 189, 248, 0.06);
    color: rgba(186, 230, 253, 0.85);
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.fos-popover__close:hover {
    background: rgba(56, 189, 248, 0.14);
    color: #7dd3fc;
}

.fos-popover__empty {
    margin: 0;
    padding: 1.25rem 0.9rem;
    text-align: center;
    font-size: 0.78rem;
    color: rgba(255, 255, 255, 0.45);
}

.fos-popover__list {
    list-style: none;
    margin: 0;
    padding: 0 0.35rem 0.35rem;
    overflow-y: visible;
    flex: 0 0 auto;
    min-height: 0;
}

.fos-popover__sections {
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    padding-top: 0.2rem;
}

.fos-popover__section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.4rem;
    padding: 0.35rem 0.65rem 0.25rem;
    position: sticky;
    top: 0;
    z-index: 1;
    background: linear-gradient(180deg, #0f172a 85%, transparent);
}

.fos-popover__section-title {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: rgba(186, 230, 253, 0.75);
    text-transform: uppercase;
}

.fos-popover__section-badge {
    font-size: 0.58rem;
    font-weight: 800;
    min-width: 1rem;
    height: 1rem;
    padding: 0 0.3rem;
    border-radius: 9999px;
    background: rgba(248, 113, 113, 0.2);
    border: 1px solid rgba(248, 113, 113, 0.45);
    color: #fecaca;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.fos-popover__row {
    width: 100%;
    text-align: left;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(15, 23, 42, 0.72);
    border-radius: 0.75rem;
    padding: 0.5rem 0.55rem;
    margin-bottom: 0.3rem;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.92);
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.fos-popover__row--unread {
    border-color: rgba(56, 189, 248, 0.35);
    background: rgba(56, 189, 248, 0.06);
}

.fos-popover__row--beam-suspicious {
    border-color: rgba(245, 158, 11, 0.42) !important;
    background: rgba(245, 158, 11, 0.08) !important;
}

.fos-popover__row--beam-suspicious .fos-popover__line1-main {
    color: #fcd34d;
}

.fos-popover__row:hover {
    background: rgba(56, 189, 248, 0.1);
    border-color: rgba(125, 211, 252, 0.3);
    transform: translateX(-2px);
}

.fos-popover__type-icon {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    border-radius: 0.5rem;
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.2);
}

.fos-popover__slip-thumb {
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    object-fit: cover;
    border-radius: 0.4rem;
    border: 1px solid rgba(56, 189, 248, 0.35);
    background: rgba(0, 0, 0, 0.3);
}

.fos-popover__text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
}

.fos-popover__line1 {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.45rem;
    font-size: 0.74rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
    line-height: 1.35;
}

.fos-popover__line1-main {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fos-popover__time {
    flex-shrink: 0;
    font-size: 0.6rem;
    font-weight: 500;
    color: rgba(125, 211, 252, 0.75);
    white-space: nowrap;
    line-height: 1.35;
}

.fos-popover__line2 {
    font-size: 0.66rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.fos-popover__unread-dot {
    width: 0.38rem;
    height: 0.38rem;
    border-radius: 9999px;
    background: #38bdf8;
    box-shadow: 0 0 8px rgba(56, 189, 248, 0.85);
    flex-shrink: 0;
}

.fos-popover__footer {
    padding: 0.55rem 0.65rem 0.75rem;
    border-top: 1px solid rgba(56, 189, 248, 0.12);
}

.fos-popover__view-all {
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.65rem;
    border: 1px solid rgba(56, 189, 248, 0.4);
    background: rgba(56, 189, 248, 0.08);
    color: #7dd3fc;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 0 16px rgba(56, 189, 248, 0.12);
    transition: transform 0.2s ease, filter 0.2s ease, background 0.2s ease;
}

.fos-popover__view-all:hover {
    transform: translateY(-1px);
    background: rgba(56, 189, 248, 0.14);
    filter: brightness(1.06);
}

.fos-loading,
.fos-error {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    right: 0;
    font-size: 0.7rem;
    color: rgba(186, 230, 253, 0.8);
    padding: 0.35rem 0.55rem;
    background: #0b1220;
    border-radius: 0.5rem;
    border: 1px solid rgba(56, 189, 248, 0.2);
    white-space: nowrap;
}

.fos-error {
    color: #fca5a5;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body.fos-widget-enabled:has(#bulkActionButtons:not(.hidden)) #floating-order-sidebar-root {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 98px);
}

@media (max-width: 640px) {
    #floating-order-sidebar-root {
        right: 0;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 44px);
    }

    .fos-popover {
        width: min(92vw, 360px);
    }

    .fos-notify-tab__title {
        font-size: 0.76rem;
    }

    .fos-notify-tab__eyebrow {
        font-size: 0.54rem;
    }
}
