/*
 * TechCraft CZ/SK - the chat
 *
 * Three surfaces and the same palette as everything else: the bubble beside
 * the bell and the panel it opens, the rooms docked in the bottom right
 * corner, and the window which opens a new one.
 *
 * Organisation
 *   1. The bubble in the header      5. The dialog and its people picker
 *   2. The panel of rooms            6. The administration, and small screens
 *   3. The dock and its windows      7. The chat read from the administration
 *   4. The messages inside a window
 *
 * The bubble and the panel are deliberately the bell and its panel wearing
 * another icon: two round things side by side in a header which behave
 * differently are two things somebody has to learn twice.
 */

/* ------------------------------------------------ 1. The bubble in the header */

.chat-bubble {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: none;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.chat-bubble:hover {
    background: var(--panel-hover);
    border-color: var(--accent);
    color: var(--accent);
}

.chat-bubble[aria-expanded="true"] {
    border-color: var(--accent);
    color: var(--accent);
}

.chat-bubble__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 0.25rem;
    background: var(--accent);
    border: 2px solid var(--bg-alt);
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 14px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.chat-bubble__badge.is-empty {
    display: none;
}

/* --------------------------------------------------- 2. The panel of rooms */

/*
 * The rows reach the edges, the way the rows of the bell do.
 *
 * Both class names on purpose. This file is imported at the top of the main
 * stylesheet, so a rule of the same weight further down it - and
 * `.user-menu__panel`, which pads every dropdown, is one - would otherwise
 * win and leave a gap around every row.
 */
.user-menu__panel.chat-panel {
    width: min(24rem, calc(100vw - 1.5rem));
    padding: 0;
    gap: 0;
    overflow: hidden;
}

.chat-panel__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--border);
}

.chat-panel__head strong {
    color: var(--text-strong);
    font-size: 0.9rem;
}

.chat-panel__list {
    max-height: min(26rem, 60vh);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.chat-panel__empty {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0;
    padding: 1.5rem 1rem;
    color: var(--text-dim);
    font-size: 0.85rem;
}

.chat-panel__empty .icon {
    color: var(--border-strong);
}

.chat-panel__foot {
    padding: 0.6rem 0.9rem;
    background: var(--panel-alt);
    border-top: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 0.74rem;
}

/*
 * One room in the list. The whole row is the button - a target the size of a
 * line of text beside a preview which is not one is a row somebody misses.
 */
.chat-room {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.chat-room:last-child {
    border-bottom: 0;
}

.chat-room:hover {
    background: var(--panel-hover);
}

.chat-room__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    flex: none;
    margin-top: 0.1rem;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
}

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

.chat-room__title {
    color: var(--text-strong);
    font-size: 0.84rem;
    font-weight: 600;
    line-height: 1.35;
}

/* One line and no more: a preview which wraps is the message itself. */
.chat-room__said,
.chat-room__meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-dim);
    font-size: 0.76rem;
}

/*
 * The face of whoever spoke last stands in front of the line. The words trail
 * off at the edge of the panel rather than pushing the face out of it, which
 * is why they are their own element and the ellipsis is on them.
 */
.chat-room__preview {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
}

.chat-room__meta {
    font-size: 0.7rem;
    opacity: 0.85;
}

/* A room with something in it is bolder rather than a different colour. */
.chat-room.is-unread .chat-room__title,
.chat-room.is-unread .chat-room__said {
    color: var(--text-strong);
    font-weight: 600;
}

.chat-room.is-unread .chat-room__icon {
    border-color: var(--accent);
    color: var(--accent);
}

.chat-room__badge {
    min-width: 18px;
    height: 18px;
    padding: 0 0.28rem;
    flex: none;
    align-self: center;
    background: var(--accent);
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.62rem;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* -------------------------------------------- 3. The dock and its windows */

/*
 * The corner the open rooms live in. It sits above the button which scrolls
 * back to the top, and it never covers the whole screen: a chat which hides
 * the page it was opened from is a chat which has to be closed to be used.
 */
.chat-dock {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 60;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
    max-width: calc(100vw - 2rem);
    pointer-events: none;
}

.chat-dock > * {
    pointer-events: auto;
}

/* The strip which switches between the rooms which are open. */
.chat-dock__tabs {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.35rem;
    max-width: 100%;
}

.chat-tab {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    max-width: 12rem;
    padding: 0.35rem 0.6rem;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-soft);
    color: var(--text);
    font: inherit;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.chat-tab > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-tab:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.chat-tab.is-active {
    background: var(--panel-hover);
    border-color: var(--accent);
    color: var(--text-strong);
}

.chat-tab__badge {
    min-width: 16px;
    padding: 0 0.25rem;
    background: var(--accent);
    border-radius: var(--radius);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.chat-window {
    display: flex;
    flex-direction: column;
    width: min(22rem, calc(100vw - 2rem));
    height: min(26rem, 60vh);
    background: var(--panel);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.chat-window__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.7rem;
    background: var(--panel-alt);
    border-bottom: 1px solid var(--border);
}

.chat-window__title {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
    color: var(--text-strong);
    font-size: 0.85rem;
    font-weight: 600;
}

.chat-window__title > span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-window__actions {
    display: inline-flex;
    align-items: center;
    gap: 0.15rem;
    flex: none;
}

.chat-window__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: transparent;
    border: 0;
    border-radius: var(--radius);
    color: var(--text-dim);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.chat-window__action:hover {
    background: var(--panel-hover);
    color: var(--accent);
}

/* ------------------------------------ 4. The messages inside a window */

.chat-window__log {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    flex: 1;
    margin: 0;
    padding: 0.75rem;
    list-style: none;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/*
 * A room with three lines in it fills from the bottom, the way every chat
 * does: the newest message sits where the next one will appear, just above
 * the box it is typed into.
 *
 * A spacer rather than `justify-content: flex-end`, which clips the top of
 * the list the moment it overflows and cannot be scrolled back to.
 */
.chat-window__log::before {
    content: "";
    margin-top: auto;
}

.chat-window__older {
    display: flex;
    justify-content: center;
}

.chat-window__older button {
    padding: 0.2rem 0.6rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-dim);
    font: inherit;
    font-size: 0.72rem;
    cursor: pointer;
}

.chat-window__older button:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.chat-window__empty {
    padding: 1.5rem 0.5rem;
    color: var(--text-dim);
    font-size: 0.8rem;
    text-align: center;
}

/*
 * One message. Whose it is decides which edge it hangs off and what tint the
 * bubble has - the two together, because colour alone is not something every
 * reader can see and a side alone is not something a narrow window keeps.
 */
.chat-line {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    align-items: flex-start;
    max-width: 85%;
}

.chat-line--mine {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-line__who {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-dim);
    font-size: 0.68rem;
}

/*
 * The faces of a conversation. Barely rounded: these are the smallest
 * pictures on the portal and the corner it is given everywhere else eats a
 * third of a sixteen pixel head.
 */
.chat-line__who .avatar,
.chat-room__preview .avatar {
    width: 16px;
    height: 16px;
    flex: none;
    border-radius: 2px;
    image-rendering: pixelated;
}

.chat-line__who strong {
    color: var(--text-strong);
    font-weight: 600;
}

.chat-line__when {
    opacity: 0.8;
}

/* Said inside the game rather than here, which is worth one badge. */
.chat-line__origin {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    padding: 0 0.3rem;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    font-size: 0.62rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chat-line__bubble {
    padding: 0.45rem 0.7rem;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-line--mine .chat-line__bubble {
    background: rgba(227, 79, 14, 0.1);
    border-color: rgba(227, 79, 14, 0.32);
    color: var(--text-strong);
}

/* What happened to the room, between what was said in it. */
.chat-note {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    padding: 0.15rem 0;
    color: var(--text-dim);
    font-size: 0.7rem;
    text-align: center;
}

.chat-note__icon {
    display: inline-flex;
    color: var(--border-strong);
}

.chat-window__compose {
    display: flex;
    align-items: flex-end;
    gap: 0.4rem;
    padding: 0.5rem;
    background: var(--panel-alt);
    border-top: 1px solid var(--border);
}

/*
 * Where the box stood while the reader is muted: the same strip, so the
 * window keeps its shape, carrying the sentence instead of the box.
 */
.chat-window__muted {
    margin: 0;
    padding: 0.65rem 0.75rem;
    color: var(--warn);
    font-size: 0.78rem;
    line-height: 1.45;
    background: var(--panel-alt);
    border-top: 1px solid var(--border);
}

.chat-window__muted[hidden],
.chat-window__compose[hidden] {
    display: none;
}

.chat-window__compose textarea {
    flex: 1;
    min-height: 2.2rem;
    max-height: 6rem;
    padding: 0.45rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-strong);
    font: inherit;
    font-size: 0.85rem;
    line-height: 1.4;
    resize: none;
}

.chat-window__compose textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.chat-window__send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex: none;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    color: #fff;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.chat-window__send:hover {
    background: var(--accent-dark);
}

/* ------------------------------- 5. The dialog and its people picker */

/*
 * The dialog names itself with a symbol beside the words, the way the window
 * which asks about a punishment does.
 *
 * Nothing here sets a width. The box is centred by the browser and the form
 * inside it fills it; an inner box narrower than the dialog around it is
 * what used to push the whole form against one edge.
 */
/*
 * The list the picker opens hangs out of the dialog, over the page behind it.
 *
 * A `<dialog>` scrolls its own content by default, which turns a panel
 * hanging below a field into a panel cut off at the edge of the box. The form
 * is short enough that nothing here needs to scroll, so the box simply lets
 * the list out.
 */
.chat-dialog {
    overflow: visible;
}

.chat-dialog__title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-dialog__title .icon {
    color: var(--accent);
}

/* ------------------------- 6. The administration, and small screens */

/* The one room above the list of people, on every screen of the section. */
.chat-global {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.chat-global__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex: none;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--accent);
}

.chat-global__main {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.chat-global__main strong {
    color: var(--text-strong);
}

.chat-people {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.chat-people__title {
    margin: 1.1rem 0 0;
    color: var(--text-dim);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.chat-person {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.2rem 0.55rem 0.2rem 0.2rem;
    background: var(--panel-alt);
    border: 1px solid var(--border);
    /* The one radius the portal draws everything with, pills included. */
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.78rem;
}

.chat-person:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.chat-person .avatar {
    border-radius: var(--radius);
}

/* Somebody who was taken out of the room, greyed rather than hidden. */
.chat-person.is-past {
    opacity: 0.6;
    border-style: dashed;
}

/*
 * A transcript is the page rather than a panel on it, so it is not given the
 * height a ticket gives its conversation - it is paged instead. Both class
 * names again, for the same reason the panel needs them.
 */
/*
 * The transcript of a room scrolls inside itself, like every other long list
 * on the portal.
 *
 * It used to be the one exception - given no ceiling at all - which meant one
 * talkative room pushed the pages either side of it off the bottom of the
 * screen. There is nothing about it which wants an exception: it is a list
 * too long to read at once, which is what `.chat` already says. Marked to
 * open at its end, it opens on the last thing said rather than the first.
 */

@media screen and (max-width: 620px) {
    /*
     * On a telephone the window is the screen minus the tabs above it. A
     * chat squeezed into a corner of a 360 pixel display is a chat nobody
     * can type into.
     */
    .chat-dock {
        right: 0.5rem;
        left: 0.5rem;
        bottom: 0.5rem;
        align-items: stretch;
        max-width: none;
    }

    .chat-dock__tabs {
        justify-content: flex-start;
    }

    .chat-window {
        width: 100%;
        height: min(70vh, 30rem);
    }

    .chat-line {
        max-width: 92%;
    }
}

/* ------------------------------- 7. The chat read from the administration */

/*
 * The search stands above everything it narrows. It is a form rather than a
 * row of controls, because the switch beside the box changes what the box
 * means and the two have to travel together.
 */
/*
 * Both class names, again: this file is imported at the top of the main
 * stylesheet, so the rules for a toolbar and for a search box further down it
 * would otherwise decide where these two sit.
 */
.toolbar.chat-search {
    align-items: center;
    justify-content: flex-start;
    gap: 1.25rem;
}

.chat-search .search-box.search-box {
    flex: 0 1 22rem;
    max-width: 22rem;
}

/* The switch stands beside the box because it says what the box means. */
.chat-search__inside {
    flex: 0 1 auto;
    max-width: 24rem;
    margin: 0;
}

/*
 * One table, grouped. The account is a row spanning every column and the
 * conversations of that account are ordinary rows underneath it, so a room
 * of one person and a room of another line up under the same headings.
 */
/*
 * A person carries no line above them.
 *
 * Their row spans the indent as well, so a line along its top ran straight
 * across the strip the conversations above are set in from - which is the one
 * place nothing should be drawn. What separates one person from the next is
 * the edge closing the block above them and the shade their own row wears,
 * both of which stop where they should.
 */
.chat-table .chat-table__person > td {
    background: var(--panel-alt);
    /*
     * And none below them either. Their row spans the indent, so the line
     * every other row of the table draws underneath itself ran across the
     * strip the conversations are set in from - which from the strip reads as
     * a lid on top of it. The shade of the bar and its rounded end already
     * say where a person stops and their conversations start.
     *
     * Named through the table on purpose: the rule which puts a line under
     * every cell is `table.data td`, and a selector of one class does not
     * reach it however far down the sheet it stands.
     */
    border-bottom: 0;
}

/*
 * A corner can only be rounded on a table which draws its lines cell by cell.
 * Collapsed, the browser hands every edge to the table and drops the radius
 * with it - so this one is asked to keep them, at no spacing, which draws the
 * same lines in the same places. Nothing here puts a border on both sides of
 * a join, so there is none to double.
 */
table.data.chat-table {
    border-collapse: separate;
    border-spacing: 0;
}

/*
 * A person is a bar of their own, so the end of it is rounded like everything
 * else the portal draws. Only the left: the right runs off to the actions and
 * on to the edge of the table.
 */
.chat-table__person > td:first-child {
    border-top-left-radius: var(--radius);
    border-bottom-left-radius: var(--radius);
}

.chat-table__person .user-cell {
    display: inline-flex;
    vertical-align: middle;
}

/*
 * A conversation is set in from the edge, and the indent is a column of its
 * own rather than padding inside the first cell.
 *
 * Padding moved the words and left the row where it was, which read as a row
 * that happens to start late. This leaves the row itself standing further in,
 * with the page showing through beside it: no line above it, none below it
 * and none down either side, so there is nothing there to read as a cell -
 * including while the row underneath the pointer is lit.
 */
.chat-table .chat-table__gap {
    /*
     * `min-width` rather than `width`: a table lays its columns out on what
     * fits, and a width on a cell is a suggestion it is free to shrink. This
     * one was asked for thirty-six pixels and given twenty-four, which is why
     * the indent kept reading as no indent at all.
     *
     * The measurement is where the nickname above starts, so a conversation
     * begins under the name of whoever is in it rather than under their face.
     */
    width: 3.2rem;
    min-width: 3.2rem;
    padding: 0;
}

/*
 * Only the rows are set in. The heading above them keeps its strip unbroken
 * across the whole table, or the corner it starts in is a notch.
 */
.chat-table td.chat-table__gap {
    border: 0;
    background: var(--bg);
}

/*
 * The edge the conversations begin at.
 *
 * Setting the rows in moved where their lines start and left them with no
 * side of their own, so the block had no edge to be read against - it simply
 * began late. This gives it one, and because the lines above and below stop
 * at the same place, the three of them close a corner: a block standing
 * inside the table rather than a column of empty cells beside it.
 */
.chat-table__room > td:nth-child(2),
.chat-table__none > td:nth-child(2) {
    border-left: 1px solid var(--border);
}

/*
 * Nothing closes the block along the bottom. The row of whoever comes next is
 * a bar of its own, in its own shade and with its own rounded end - a line
 * above it as well would be the same thing said twice.
 */
.chat-table__group tr:last-child > td {
    border-bottom: 0;
}


/* Who is in a room, so a room of two is told from a room of twenty. */
.chat-table__people {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
}

.chat-table__people .avatar {
    width: 18px;
    height: 18px;
    border-radius: var(--radius);
}

.chat-table__people .cell-sub {
    margin-left: 0.25rem;
}

/* An account in no conversation says so where its rooms would have been. */
.quiet-line {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--text-dim);
    font-size: 0.82rem;
}

.quiet-line .icon {
    color: var(--border-strong);
}

/*
 * The people and their conversations have no side of their own.
 *
 * A conversation stands in from the edge and carries its own left line. With
 * the panel drawing one too, the space between the two of them closed into a
 * narrow column - the very thing the indent is there to avoid. So the panel
 * keeps its fill and gives up its outline: what marks the block is where the
 * conversations begin, and there is only ever one line saying it.
 */
.panel.chat-people {
    border-left-color: transparent;
    border-bottom-color: transparent;
}

/*
 * The line the panel would have drawn along its bottom, drawn by the last row
 * instead - and by every cell of it except the one holding the indent, which
 * is the page showing through and has nothing to be closed off by.
 */
.chat-table tbody:last-of-type tr:last-child > td:not(.chat-table__gap) {
    border-bottom: 1px solid var(--border);
}

/* The one room everybody is in stands apart from the people underneath it. */
.panel.chat-global {
    margin-bottom: 1.5rem;
}

@media screen and (max-width: 720px) {
    /* Stacked into cards, an indent is a hanging edge rather than a level. */
    /* Stacked into cards there are no columns left to set a row in from. */
    .chat-table .chat-table__gap {
        display: none;
    }

    .chat-search__inside {
        max-width: none;
    }
}
