:root {
    --chat-ink: var(--color-forest-ink);
    --chat-muted: var(--color-muted);
    --chat-bronze: var(--color-bronze);
    --chat-bronze-dark: var(--color-bronze-dark);
    --chat-cream: var(--color-cream);
    --chat-line: var(--color-line);
    --chat-green: var(--color-success);
    --chat-danger: var(--color-danger);
}

.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;
}

.livechat-page .page-section {
    max-width: 680px;
    padding-top: 105px;
}

.livechat-app {
    overflow: hidden;
    max-width: 620px;
    margin: 0 auto;
    border: 1px solid rgba(73, 38, 0, 0.24);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 18px 50px rgba(51, 32, 12, 0.18);
}

.livechat-app__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 20px 24px;
    color: #fff;
    background: linear-gradient(120deg, var(--chat-bronze-dark), var(--chat-bronze));
}

.livechat-eyebrow {
    margin: 0 0 4px;
    color: inherit;
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.livechat-app__header h1,
.teacher-livechat-controls h1,
.teacher-chat-card h2 {
    margin: 0;
    line-height: 1.15;
}

.livechat-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    flex: 0 0 auto;
    font-size: 0.82rem;
    font-weight: 700;
}

.livechat-status__dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: #e5b84f;
    box-shadow: 0 0 0 4px rgba(229, 184, 79, 0.18);
}

.livechat-status.is-online .livechat-status__dot {
    background: #7be39a;
    box-shadow: 0 0 0 4px rgba(123, 227, 154, 0.18);
}

.livechat-status.is-offline .livechat-status__dot {
    background: #ef7777;
    box-shadow: 0 0 0 4px rgba(239, 119, 119, 0.18);
}

.livechat-student-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
}

.livechat-conversation {
    display: flex;
    min-width: 0;
    min-height: min(650px, calc(100vh - 170px));
    flex-direction: column;
}

.livechat-messages {
    display: flex;
    flex: 1 1 auto;
    min-height: 0;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 18px;
    scroll-behavior: smooth;
}

.livechat-message {
    position: relative;
    width: fit-content;
    max-width: min(82%, 680px);
    padding: 10px 13px;
    border: 1px solid rgba(55, 120, 74, 0.16);
    border-radius: 6px 16px 16px 16px;
    background: #f1f7f1;
    color: #213326;
    overflow-wrap: anywhere;
}

.livechat-message__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 9px;
    margin-bottom: 3px;
}

.livechat-message__name {
    color: var(--chat-ink);
    font-size: 0.85rem;
    font-weight: 800;
}

.livechat-message__time {
    flex-shrink: 0;
    white-space: nowrap;
    color: var(--chat-muted);
    font-size: 0.7rem;
}

.livechat-message__body {
    margin: 0;
    font-size: 1rem;
    line-height: 1.42;
    white-space: pre-wrap;
}

.livechat-message__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.livechat-message__delete {
    position: static;
    flex-shrink: 0;
    width: 28px;
    min-width: 28px;
    height: 28px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: #8c2a2a;
    background: transparent;
    cursor: pointer;
    font-size: 1.15rem;
}

.livechat-message__delete:hover,
.livechat-message__delete:focus-visible {
    background: #f5dede;
}

.livechat-separator {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    margin: 7px 0;
    color: #775a42;
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    text-align: center;
    text-transform: uppercase;
}

.livechat-separator::before,
.livechat-separator::after {
    content: "";
    flex: 1 1 auto;
    height: 1px;
    background: rgba(119, 90, 66, 0.28);
}

.livechat-empty {
    margin: auto;
    padding: 24px;
    color: var(--chat-muted);
    text-align: center;
}

.livechat-history-note {
    margin: 0 auto 6px;
    color: var(--chat-muted);
    font-size: 0.78rem;
    text-align: center;
}

.livechat-compose {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 10px 12px;
    padding: 14px 16px 10px;
    border-top: 1px solid var(--chat-line);
    background: #fffdf8;
}

.livechat-field {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 5px;
    color: var(--chat-ink);
    font-size: 0.78rem;
    font-weight: 800;
}

.livechat-field input,
.livechat-field textarea,
.teacher-separator-form input {
    box-sizing: border-box;
    width: 100%;
    margin: 0;
    padding: 10px 11px;
    border: 1px solid rgba(73, 38, 0, 0.25);
    border-radius: 9px;
    background: #fff;
    color: #1e2b20;
    font: inherit;
    font-weight: 400;
}

.livechat-field textarea {
    min-height: 66px;
    resize: vertical;
}

.livechat-field input:focus,
.livechat-field textarea:focus,
.teacher-separator-form input:focus {
    border-color: var(--chat-green);
    outline: 3px solid rgba(55, 120, 74, 0.16);
}

.livechat-compose__footer {
    display: flex;
    grid-column: 1 / -1;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.livechat-emojis {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.livechat-emoji {
    width: 38px;
    height: 34px;
    margin: 0;
    padding: 0;
    border: 1px solid var(--chat-line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    font-size: 1.15rem;
}

.livechat-emoji:hover,
.livechat-emoji:focus-visible {
    background: var(--chat-cream);
    transform: translateY(-1px);
}

.livechat-send {
    width: auto;
    min-width: 118px;
    margin: 0;
}

.livechat-form-message {
    min-height: 1em;
    grid-column: 1 / -1;
    margin: 0;
    color: var(--chat-danger);
    font-size: 0.8rem;
}

.boring-control {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--chat-line);
    background: linear-gradient(180deg, #fbf5e9, #f4ead8);
}

.boring-slider {
    position: relative;
    z-index: 1;
    display: block;
    width: 100%;
    margin: 0;
    accent-color: var(--chat-bronze);
    cursor: pointer;
}

.boring-slider-wrap {
    position: relative;
    padding: 8px 0;
}

.boring-average-marker {
    position: absolute;
    z-index: 2;
    top: 50%;
    width: 5px;
    height: 24px;
    border: 1px solid #fff;
    border-radius: 999px;
    background: var(--chat-green);
    box-shadow: 0 1px 4px rgba(23, 59, 33, 0.5);
    pointer-events: none;
    transform: translate(-50%, -50%);
}

.boring-average-marker[hidden] {
    display: none;
}

.boring-scale {
    display: flex;
    justify-content: space-between;
    margin-top: -12px;
    font-size: 1.3rem;
}

.boring-track {
    overflow: hidden;
    height: 10px;
    margin: 9px 0 7px;
    border-radius: 999px;
    background: #dfd8ca;
}

.boring-track span {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #4e985e 0%, #e0a538 55%, #b13d35 100%);
    transition: width 300ms ease;
}


.teacher-chat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
    max-width: 980px;
    margin: 24px auto 0;
}

.teacher-chat-card {
    padding: 22px;
    border: 1px solid var(--chat-line);
    border-radius: 14px;
    color: var(--chat-ink);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 10px 24px rgba(45, 28, 12, 0.12);
}

.teacher-chat-card__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.teacher-chat-card__actions .button {
    width: auto;
    margin: 0;
    padding: 9px 14px;
}

.teacher-bulk-management {
    max-width: 936px;
    margin: 22px auto 0;
    padding: 22px;
    border: 1px solid var(--chat-line);
    border-radius: 14px;
    color: var(--chat-ink);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 10px 24px rgba(45, 28, 12, 0.12);
}

.teacher-bulk-management h2 {
    margin: 0 0 18px;
}

.teacher-bulk-separator label {
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
}

.teacher-bulk-separator > div,
.teacher-bulk-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
}

.teacher-bulk-separator input {
    min-width: min(360px, 100%);
    flex: 1 1 260px;
    padding: 10px 12px;
    border: 1px solid var(--chat-line);
    border-radius: 8px;
    font: inherit;
}

.teacher-bulk-actions {
    margin-top: 14px;
}

.teacher-bulk-management .button {
    width: auto;
    margin: 0;
}

.teacher-livechat-page {
    min-height: 100vh;
    background: #e9e0d1;
}

.teacher-livechat-shell {
    display: grid;
    grid-template-columns: minmax(420px, 720px) 410px;
    justify-content: center;
    gap: 24px;
    box-sizing: border-box;
    min-height: 100vh;
    padding: 24px;
}

.teacher-livechat-controls {
    align-self: start;
    padding: 26px;
    border: 1px solid var(--chat-line);
    border-radius: 16px;
    color: var(--chat-ink);
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 12px 34px rgba(45, 28, 12, 0.14);
}

.teacher-livechat-controls__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 30px;
}

.teacher-livechat-controls__top .button {
    width: auto;
    margin: 0;
}

.teacher-livechat-controls__top .page-heading__back {
    position: static;
    align-self: center;
}

.teacher-separator-form {
    margin-top: 30px;
    padding-top: 22px;
    border-top: 1px solid var(--chat-line);
}

.teacher-separator-form label {
    display: block;
    margin-bottom: 8px;
    font-weight: 800;
}

.teacher-separator-form > div {
    display: flex;
    align-items: stretch;
    gap: 8px;
}

.teacher-separator-form .button {
    width: auto;
    margin: 0;
    white-space: nowrap;
}

.teacher-control-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.teacher-control-group .button {
    width: auto;
    margin: 0;
}

.teacher-action-status {
    min-height: 1.3em;
    margin: 14px 0 0;
    color: var(--chat-muted);
}

.livechat-projection {
    display: flex;
    overflow: hidden;
    flex-direction: column;
    width: 410px;
    max-width: 100%;
    height: calc(100vh - 48px);
    min-height: 650px;
    border: 1px solid rgba(73, 38, 0, 0.25);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 16px 44px rgba(45, 28, 12, 0.18);
}

.projection-qr {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 14px 17px;
    border-bottom: 1px solid var(--chat-line);
    background: var(--chat-cream);
}

.projection-qr img {
    width: 132px;
    height: 132px;
    flex: 0 0 auto;
    border: 6px solid #fff;
    border-radius: 8px;
    image-rendering: pixelated;
    box-shadow: 0 3px 10px rgba(45, 28, 12, 0.12);
}

.projection-qr__link {
    min-width: 0;
}

.projection-qr__link a {
    display: block;
    color: var(--chat-green);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.projection-boring {
    padding: 12px 17px;
    border-bottom: 1px solid var(--chat-line);
    background: #fffdf7;
}

.projection-boring[hidden] {
    display: none;
}

.projection-boring__scale {
    display: flex;
    justify-content: space-between;
    margin-bottom: -4px;
    font-size: 1.35rem;
}

.projection-boring__scale span {
    opacity: 0.38;
    filter: grayscale(0.75);
    transform: scale(0.92);
    transition: opacity 200ms ease, filter 200ms ease, transform 200ms ease;
}

.projection-boring__scale span.is-active {
    opacity: 1;
    filter: none;
    transform: scale(1.18);
}

.projection-chat-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 17px 8px;
    color: var(--chat-ink);
}

.projection-chat-title h2 {
    margin: 0;
    font-size: 1.05rem;
}

.projection-chat-title .livechat-status {
    color: var(--chat-muted);
}

.projection-chat-title__tools,
.projection-message-size {
    display: flex;
    align-items: center;
}

.projection-chat-title__tools {
    gap: 11px;
}

.projection-message-size {
    overflow: hidden;
    border: 1px solid rgba(73, 38, 0, 0.24);
    border-radius: 8px;
    background: var(--chat-cream);
}

.projection-message-size button {
    width: 32px;
    height: 30px;
    margin: 0;
    padding: 0;
    border: 0;
    color: var(--chat-bronze-dark);
    background: transparent;
    cursor: pointer;
    font-size: 1.25rem;
    font-weight: 800;
    line-height: 1;
}

.projection-message-size button + button {
    border-left: 1px solid rgba(73, 38, 0, 0.2);
}

.projection-message-size button:hover,
.projection-message-size button:focus-visible {
    background: rgba(154, 96, 56, 0.13);
}

.projection-message-size button:disabled {
    opacity: 0.35;
    cursor: default;
}

.livechat-messages--projection {
    padding: 8px 13px 15px;
}

.livechat-messages--projection .livechat-message {
    max-width: 90%;
    padding: 8px 10px;
}

.livechat-messages--projection .livechat-message__body {
    font-size: calc(0.92rem * var(--projection-message-scale, 1));
}

.teacher-livechat-page--presentation {
    overflow: hidden;
    background: #2b2219;
}

.teacher-livechat-page--presentation .teacher-livechat-shell {
    display: flex;
    justify-content: center;
    padding: 0;
}

.teacher-livechat-page--presentation .livechat-projection {
    width: min(430px, 100vw);
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    border-width: 0 1px;
    border-radius: 0;
}

@media (max-width: 960px) {
    .teacher-livechat-shell {
        grid-template-columns: 1fr;
    }

    .livechat-projection {
        justify-self: center;
    }
}

@media (max-width: 700px) {
    .teacher-chat-grid {
        grid-template-columns: 1fr;
    }

    .livechat-page .page-section {
        padding: 88px 10px 24px;
    }

    .livechat-app {
        border-radius: 12px;
    }

    .livechat-app__header {
        align-items: flex-start;
        padding: 15px 16px;
    }

    .livechat-app__header h1 {
        font-size: 1.35rem;
    }

    .livechat-conversation {
        min-height: calc(100vh - 175px);
    }

    .livechat-messages {
        padding: 12px;
    }

    .livechat-message {
        max-width: 90%;
    }

    .livechat-compose {
        grid-template-columns: 1fr;
        padding: 11px;
    }

    .livechat-field--message {
        grid-row: 1;
    }

    .livechat-field--nickname {
        grid-row: 2;
    }

    .livechat-compose__footer {
        grid-row: 3;
    }

    .livechat-form-message {
        grid-row: 4;
    }

    .livechat-emoji {
        width: 34px;
    }

    .boring-control {
        padding: 20px 16px;
    }

    .teacher-livechat-shell {
        padding: 10px;
    }

    .teacher-livechat-controls {
        padding: 18px;
    }

    .teacher-livechat-controls__top,
    .teacher-separator-form > div,
    .teacher-bulk-separator > div,
    .teacher-bulk-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .teacher-livechat-controls__top .button,
    .teacher-separator-form .button,
    .teacher-control-group .button,
    .teacher-bulk-management .button {
        width: 100%;
    }

    .teacher-livechat-controls__top .page-heading__back {
        width: auto;
        min-width: 48px;
        align-self: flex-start;
    }

    .teacher-bulk-separator input {
        min-width: 0;
        flex-basis: auto;
    }

    .livechat-projection {
        width: 100%;
    }
}

@media (max-width: 400px) {
    .projection-qr img {
        width: 112px;
        height: 112px;
    }

}


/* Teacher messages and quoted replies are shared by all chat views. */
.livechat-message--teacher {
    align-self: flex-end;
    border-color: #c99800;
    border-inline-start: 4px solid #805500;
    border-radius: 16px 6px 16px 16px;
    background: #ffdc00;
    color: #382900;
}

.livechat-message__badge {
    padding: 2px 7px;
    border-radius: 5px;
    background: #365f91;
    color: #fff;
    font-size: 0.75rem;
}

.livechat-message__quote {
    margin: 7px 0 9px;
    padding: 6px 9px;
    border-inline-start: 3px solid #7d98bc;
    border-radius: 3px;
    background: #fff9;
    color: #3b526e;
    font-size: calc(0.8rem * var(--projection-message-scale, 1));
}

.livechat-message__quote p {
    margin: 3px 0 0;
    white-space: pre-wrap;
}

.livechat-message__reply {
    display: inline-flex;
    align-items: center;
    width: auto;
    margin: 0;
    padding: 5px 9px;
    border: 1px solid currentColor;
    border-radius: 6px;
    color: #365f91;
    background: #fff;
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
}

.livechat-message__reply:hover,
.livechat-message__reply:focus-visible {
    background: #dce8f8;
}

.livechat-messages--projection .teacher-message-form {
    display: grid;
    gap: 12px;
    margin-top: 24px;
}

.teacher-message-form .livechat-compose__footer {
    justify-content: flex-end;
    flex-wrap: wrap;
}

.teacher-message-form .button {
    width: auto;
    margin: 0;
}

.teacher-message-form small {
    color: var(--chat-muted);
}

.teacher-message-form .teacher-action-status {
    margin: 0;
}

.teacher-reply-preview {
    padding: 12px;
    border-inline-start: 3px solid #365f91;
    border-radius: 6px;
    background: #edf3fc;
    color: #203b5c;
    overflow-wrap: anywhere;
}

.teacher-reply-preview p {
    max-height: 7em;
    overflow-y: auto;
    margin: 8px 0;
    white-space: pre-wrap;
}

.teacher-livechat-page .teacher-action-status:empty {
    display: none;
}
