/* ── Event chat on the public event page (info.js EVENT CHAT) ──────────────────────────────────────────────────────
   Closed: a pill at the bottom. Open on wide screens (992 px and up): a rail on the right, and the page narrows to make
   room (body.chat-docked), so it never covers the live scores. Open on phones and tablets: a sheet from the bottom at
   half height (taller while typing, with a one-line score strip on top). */
:root { --chat-rail-w: 340px; }

/* The "Chat" button in the LIVE NOW header */
.live-chat-btn {
    display: inline-flex; flex-shrink: 0; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 999px; background: rgba(255, 255, 255, 0.1); color: #FFFFFF;
    font-family: var(--ag-font-body); font-size: 14px; font-weight: 700; letter-spacing: 0; text-transform: none; white-space: nowrap; cursor: pointer;
}
.live-viewers + .live-chat-btn { margin-left: 4px; }
.live-viewers[style*="none"] + .live-chat-btn { margin-left: auto; }
.live-chat-btn:hover { background: rgba(255, 255, 255, 0.18); }
.live-chat-btn:focus-visible { outline: 2px solid var(--ag-sky); outline-offset: 2px; }
.live-chat-btn[aria-expanded="true"] { border-color: #FFFFFF; background: #FFFFFF; color: var(--ag-deep); }
.live-chat-n:empty { display: none; }
.live-chat-n {
    display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px;
    border-radius: 999px; background: var(--ag-live); color: #FFFFFF; font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums;
}

/* The pill (closed chat) */
.chat-pill {
    position: fixed; right: max(20px, env(safe-area-inset-right, 0px)); bottom: max(20px, env(safe-area-inset-bottom, 0px)); z-index: 9000;
    display: flex; align-items: center; gap: 8px; height: 48px; max-width: 320px; padding: 0 16px;
    border: 0; border-radius: 999px; background: var(--ag-deep); color: #FFFFFF; font: inherit; font-size: 15px; font-weight: 700;
    box-shadow: 0 12px 30px rgba(6, 47, 56, 0.3); cursor: pointer; transition: background-color 0.15s, opacity 0.15s;
}
.chat-pill:hover { background: var(--ag-deeper); }
.chat-pill:focus-visible { outline: 3px solid var(--ag-sky); outline-offset: 3px; }
.chat-pill > i { flex-shrink: 0; font-size: 18px; color: var(--ag-sky); }
.chat-pill-last { display: none; min-width: 0; overflow: hidden; font-weight: 500; text-align: left; white-space: nowrap; text-overflow: ellipsis; color: #DCEFF3; }
.chat-pill-last b { font-weight: 700; color: #FFFFFF; }
.chat-badge:empty { display: none; }
.chat-badge {
    display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 7px;
    border-radius: 999px; background: var(--ag-live); font-size: 12px; font-weight: 800; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.chat-pill[aria-expanded="true"], body.is-typing .chat-pill { opacity: 0; pointer-events: none; }

/* The panel */
.chat-panel { position: fixed; z-index: 9001; display: flex; flex-direction: column; overflow: hidden; background: #FFFFFF; color: var(--ag-text); font-size: 15px; }
.chat-panel[hidden] { display: none; }
.chat-grab, .chat-strip { display: none; }
.chat-head { display: flex; flex-shrink: 0; align-items: center; gap: 10px; min-height: 56px; padding: 6px 8px 6px 18px; border-bottom: 1px solid var(--ag-line); }
.chat-title { margin: 0; font-family: var(--ag-font-display); font-size: 17px; font-weight: 600; line-height: 1.2; color: var(--ag-ink); }
.chat-title:focus { outline: none; }
.chat-viewers { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ag-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.chat-here-dot { width: 7px; height: 7px; border-radius: 50%; background: #22B573; }
.chat-icon-btn {
    display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center; width: 44px; height: 44px; margin-left: auto;
    border: 0; border-radius: 12px; background: none; color: var(--ag-muted); font-size: 18px; cursor: pointer;
}
.chat-icon-btn:hover { background: var(--ag-tint); color: var(--ag-ink); }
.chat-icon-btn:focus-visible, .chat-msgs:focus-visible { outline: 2px solid var(--ag-cyan); outline-offset: -2px; }

/* Messages */
.chat-msgs { position: relative; display: flex; flex: 1; flex-direction: column; min-height: 0; padding: 4px 16px 10px; overflow-y: auto; overscroll-behavior: contain; }
.chat-msgs > :first-child { margin-top: auto; }
.chat-empty { margin: auto 0; padding: 24px 8px; font-size: 14px; line-height: 1.45; text-align: center; color: var(--ag-muted); }
.chat-day, .chat-unread-line { display: flex; flex-shrink: 0; align-items: center; gap: 10px; margin: 14px 0 2px; font-size: 11px; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ag-muted); }
.chat-day::before, .chat-day::after, .chat-unread-line::before, .chat-unread-line::after { content: ""; flex: 1; height: 1px; background: var(--ag-line); }
.chat-unread-line { color: #B4232A; }
.chat-unread-line::before, .chat-unread-line::after { background: rgba(217, 48, 54, 0.35); }
.chat-group { display: flex; flex-shrink: 0; flex-direction: column; align-items: flex-start; gap: 3px; margin-top: 10px; }
.chat-who { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; font-size: 13px; font-weight: 800; line-height: 1.3; color: var(--ag-ink); }
.chat-who .verified { font-size: 12px; color: var(--ag-cyan-ink); }
.chat-role { padding: 1px 6px; border-radius: 5px; background: var(--ag-deep); color: #FFFFFF; font-size: 10px; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.chat-time { font-size: 12px; font-weight: 500; color: #5F7A81; font-variant-numeric: tabular-nums; }
.chat-line { position: relative; display: flex; align-items: flex-start; gap: 2px; max-width: 100%; }
.chat-text { min-width: 0; font-size: 15px; line-height: 1.4; overflow-wrap: anywhere; }
.chat-group.mine { align-items: flex-end; }
.chat-group.mine .chat-line { max-width: 85%; }
.chat-group.mine .chat-text { padding: 6px 12px; border-radius: 16px 16px 4px 16px; background: var(--ag-tint-2); }
.chat-group.mine .chat-line:not(:last-child) .chat-text { border-bottom-right-radius: 16px; }
.chat-line.is-sending .chat-text { opacity: 0.6; }
.chat-system { flex-shrink: 0; margin: 10px 0 0; font-size: 13px; text-align: center; color: var(--ag-muted); }

/* Organizer tools on each message */
.chat-mod {
    flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 24px;
    border: 0; border-radius: 6px; background: none; color: var(--ag-muted); font-size: 16px; cursor: pointer; opacity: 0;
}
.chat-line:hover .chat-mod, .chat-mod:focus-visible, .chat-mod[aria-expanded="true"] { opacity: 1; }
@media (hover: none) { .chat-mod { opacity: 0.8; } }
.chat-mod:hover, .chat-mod[aria-expanded="true"] { background: var(--ag-tint); color: var(--ag-ink); }
.chat-mod:focus-visible { outline: 2px solid var(--ag-cyan); }
.chat-menu {
    position: absolute; top: 26px; left: 0; z-index: 2; display: flex; flex-direction: column; min-width: 210px; padding: 6px;
    border: 1px solid var(--ag-line); border-radius: 12px; background: #FFFFFF; box-shadow: 0 12px 30px rgba(6, 47, 56, 0.18);
}
.chat-menu button { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 10px; border: 0; border-radius: 8px; background: none; font: inherit; font-size: 14px; font-weight: 600; text-align: left; white-space: nowrap; color: var(--ag-text); cursor: pointer; }
.chat-menu button:hover, .chat-menu button:focus-visible { background: var(--ag-tint); outline: none; }
.chat-menu .danger { color: #B4232A; }
.chat-group.mine .chat-menu { left: auto; right: 0; }

/* "New messages" chip when the reader has scrolled up */
.chat-jump {
    position: absolute; left: 50%; bottom: 84px; z-index: 1; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 16px;
    border: 0; border-radius: 999px; background: var(--ag-deep); color: #FFFFFF; font: inherit; font-size: 13px; font-weight: 700; white-space: nowrap;
    box-shadow: 0 8px 20px rgba(6, 47, 56, 0.3); transform: translateX(-50%); cursor: pointer;
}
.chat-jump[hidden] { display: none; }
.chat-jump:focus-visible { outline: 3px solid var(--ag-sky); outline-offset: 2px; }
.chat-note { flex-shrink: 0; margin: 0; padding: 8px 16px; border-top: 1px solid #F4D4D6; background: #FFF4F4; font-size: 13px; line-height: 1.4; color: #9F1D23; }
.chat-note[hidden] { display: none; }

/* Nickname and message fields */
.chat-nick-bar, .chat-input-row { flex-shrink: 0; margin: 0; padding: 10px 12px; border-top: 1px solid var(--ag-line); background: #FFFFFF; }
.chat-nick-bar[hidden], .chat-input-row[hidden] { display: none; }
.chat-nick-label { display: block; margin: 0 6px 6px; font-size: 13px; font-weight: 700; color: var(--ag-ink); }
.chat-field-row { display: flex; align-items: center; gap: 8px; }
.chat-field {
    flex: 1; min-width: 0; height: 44px; padding: 0 16px; border: 1.5px solid transparent; border-radius: 999px;
    background: var(--ag-tint); color: var(--ag-text); font: inherit; font-size: 16px;
}
.chat-field::placeholder { color: #5F7A81; }
.chat-field:focus { outline: none; border-color: var(--ag-cyan); background: #FFFFFF; box-shadow: 0 0 0 3px var(--ag-tint-2); }
.chat-field[aria-invalid="true"] { border-color: var(--ag-live); }
.chat-send, .chat-join {
    flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; height: 44px; border: 0; border-radius: 999px;
    background: var(--ag-deep); color: #FFFFFF; font: inherit; font-size: 15px; font-weight: 700; white-space: nowrap; cursor: pointer;
}
.chat-send { width: 44px; font-size: 16px; }
.chat-join { padding: 0 20px; }
.chat-send:hover, .chat-join:hover { background: var(--ag-deeper); }
.chat-send:disabled { background: #B5C7CC; cursor: default; }
.chat-send:focus-visible, .chat-join:focus-visible { outline: 3px solid var(--ag-sky); outline-offset: 2px; }

/* Wide screens: a rail beside the page */
@media (min-width: 992px) {
    .chat-panel { top: 0; right: 0; bottom: 0; width: var(--chat-rail-w); border-left: 1px solid var(--ag-line); box-shadow: -8px 0 30px rgba(6, 47, 56, 0.06); }
    .chat-input-row, .chat-nick-bar { padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)); }
    body.chat-docked { padding-right: var(--chat-rail-w); }
    body.chat-docked #signalr-status-badge { left: calc(50% - var(--chat-rail-w) / 2); }
}
@media (min-width: 992px) and (prefers-reduced-motion: no-preference) {
    .chat-panel { animation: chat-rail-in 0.2s ease-out; }
    @keyframes chat-rail-in { from { transform: translateX(24px); opacity: 0; } }
}

/* Phones and tablets: the pill spans the bottom with the latest line, and opens a sheet */
@media (max-width: 991.98px) {
    .chat-pill {
        left: max(12px, env(safe-area-inset-left, 0px)); right: max(12px, env(safe-area-inset-right, 0px)); bottom: max(12px, env(safe-area-inset-bottom, 0px));
        max-width: none; height: 52px; padding: 0 10px 0 18px;
    }
    .chat-pill-last { display: block; flex: 1; }
    .chat-pill-label { flex: 1; text-align: left; }
    .chat-pill:has(.chat-pill-last:not(:empty)) .chat-pill-label { display: none; }
    body:has(#chatFab) main { padding-bottom: 76px; }
    .chat-panel {
        left: 0; right: 0; bottom: var(--chat-kb, 0px); height: min(var(--chat-sheet-h, 55dvh), calc(100dvh - 24px));
        border-radius: 20px 20px 0 0; box-shadow: 0 -12px 36px rgba(6, 47, 56, 0.22);
    }
    .chat-panel.is-full { height: var(--chat-full-h, calc(100dvh - 48px)); }
    .chat-input-row, .chat-nick-bar { padding-bottom: max(10px, env(safe-area-inset-bottom, 0px)); }
    .chat-panel.has-keyboard .chat-input-row, .chat-panel.has-keyboard .chat-nick-bar { padding-bottom: 10px; }
    .chat-grab { display: flex; flex-shrink: 0; justify-content: center; padding: 8px 0 0; touch-action: none; cursor: grab; }
    .chat-grab span { width: 40px; height: 5px; border-radius: 5px; background: #C9D9DD; }
    .chat-head { min-height: 48px; padding-top: 0; padding-bottom: 0; touch-action: none; }
    body.chat-sheet-open #signalr-status-badge { opacity: 0; }
    /* The connection notice sits above the pill instead of on it */
    body:has(#chatFab) #signalr-status-badge { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
    /* Typing: a strip above the sheet keeps the live heat in sight */
    .chat-strip.show {
        position: fixed; left: 0; right: 0; top: var(--chat-strip-top, 0px); z-index: 9002; display: flex; align-items: center; gap: 10px; height: 40px;
        padding: 0 max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); background: var(--ag-deep); color: #FFFFFF;
        font-size: 13px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums;
    }
    .chat-strip .st-dot { width: 7px; height: 7px; flex-shrink: 0; border-radius: 50%; background: #FF6B6B; }
    .chat-strip .st-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
    .chat-strip .st-clock { flex-shrink: 0; }
    .chat-strip .st-lead { flex-shrink: 1; min-width: 0; margin-left: auto; overflow: hidden; text-overflow: ellipsis; color: var(--ag-sky); }
}
@media (max-width: 991.98px) and (prefers-reduced-motion: no-preference) {
    .chat-panel { animation: chat-sheet-in 0.22s ease-out; }
    @keyframes chat-sheet-in { from { transform: translateY(40px); opacity: 0; } }
    .chat-panel.is-dragging { animation: none; }
}
@media (max-width: 374.98px) {
    .live-chat-btn { width: 36px; height: 32px; padding: 0; justify-content: center; position: relative; }
    .live-chat-label { display: none; }
    .live-chat-n { position: absolute; top: -6px; right: -6px; }
}
/* Small phones: "LIVE NOW", the watcher count and the Chat button stay on one line */
.live-chat-btn > i { font-size: 15px; color: var(--ag-sky); }
.live-chat-btn[aria-expanded="true"] > i { color: var(--ag-deep); }
.live-banner-title { flex-wrap: nowrap; white-space: nowrap; }
@media (max-width: 419.98px) {
    .lv-word { display: none; }
}
