/* Replace global star selector with targeted box-sizing to preserve layout
   and paddings while avoiding the `*` rule. This restores right/bottom
   padding that depended on border-box sizing. */
html, body, .container, .left, .right, .chat-messages, .chat-form,
input, textarea, button, .user-menu, .modal {
    box-sizing: border-box;
}

:root {
    --chat-font-size: 14px;
}

@font-face {
    font-family: 'Merchant Copy';
    src: url('Merchant Copy.ttf') format('truetype');
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 15px;
}

h1 {
    margin: 0;
    font-size: 3em;
    text-align: left;
    color: #333;
    flex-shrink: 0;
    font-family: 'Merchant Copy', sans-serif;
}

.container {
    display: flex;
    gap: 15px;
    flex: 1;
    min-height: 0;
}

.left {
    flex: 0 0 70%;
    background-color: lightgrey;
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.left iframe {
    width: 100%;
    height: 100%;
    border: none;
}

.divider {
    width: 10px;
    background-color: transparent;
    cursor: col-resize;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.divider::after {
    content: '';
    width: 2px;
    height: 100%;
    background-color: #999;
}

.right {
    flex: 0 0 30%;
    background-color: rgb(255, 255, 255);
    min-width: 0;
    padding: 15px;
}

    .right iframe {
        width: 100%;
        height: 100%;
        border: none;
    }

/* Chat styles */
.right .chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 10px;
    font-family: 'Merchant Copy', sans-serif;
    color: #222;
}

.chat-status {
    font-size: 0.9em;
    color: #444;
    padding: 6px 8px;
    border-radius: 4px;
    background: rgba(0,0,0,0.03);
}

.chat-debug {
    display: none; /* debug UI removed from view; kept hidden */
}

/* user/logout area (replaces debug box) */
.chat-user-area {
    font-size: 0.9em;
    color: #222;
    padding: 6px 8px;
    border-radius: 4px;
    background: rgba(0,0,0,0.02);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    position: relative;
}

/* Dropdown menu inside the user area */
.user-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 220px;
    background: white;
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 6px 18px rgba(0,0,0,0.08);
    padding: 8px;
    border-radius: 6px;
    display: none;
    z-index: 20;
}
.user-menu .menu-row { margin: 6px 0; }
.chat-user-area.open .user-menu { display: block; }
.chat-user-area #chatMenuToggle { background: transparent; border: none; cursor: pointer; font-size: 1.05em; margin-left: auto; }

/* Ensure the font control inside the menu looks compact */
.user-menu .chat-font-control { display: flex; gap: 8px; align-items: center; }
.user-menu input[type="range"] { width: 120px; }

/* show/hide name input when logged in/out controlled by JS (fallback styles) */
.user-menu #chatName { width: 100%; padding: 6px; border: 1px solid #ddd; border-radius: 4px; }

/* small inline login button next to name input */
.user-menu .login-btn { padding: 6px 8px; border-radius: 4px; border: 1px solid #ccc; background: #f4f4f4; cursor: pointer; }

/* Admin login modal */
.modal { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; background: rgba(0,0,0,0.35); z-index: 60; }
.modal.open { display: flex; }
.modal .modal-content { background: white; padding: 16px; border-radius: 8px; width: 320px; box-shadow: 0 10px 30px rgba(0,0,0,0.2); position: relative; }
.modal .modal-row { margin: 8px 0; display:flex; flex-direction:column; }
.modal .modal-actions { display:flex; gap:8px; justify-content:flex-end; margin-top:8px; }
.modal .modal-close { position:absolute; right:8px; top:8px; background:transparent; border:none; font-size:1rem; cursor:pointer; }
.modal .modal-error { color: #b03030; margin-top:8px; min-height:1.1em; }

/* Hidden list (public UI) - darker background for readability */
.hidden-list .hidden-row { background: rgba(0,0,0,0.6); color: #fff; padding: 8px; border-radius: 6px; margin-bottom: 8px; }
.hidden-list .hidden-row .hid-id { font-size: 0.85rem; color: #cbd5e1; margin-top:6px }
.hidden-list .hidden-row .hid-actions { margin-top:6px }

/* Admin badge */
.admin-badge {
    background: #b03030;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: 700;
    letter-spacing: 0.6px;
}

/* error overlay inside chat messages */
.chat-messages { position: relative; }
.chat-error {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 1rem;
    pointer-events: none;
    opacity: 0;
    transition: opacity 180ms ease;
    z-index: 5;
    color: rgba(200,30,30,0.98);
    font-weight: 700;
    font-size: 1.25rem;
    background: linear-gradient(rgba(255,255,255,0.03), rgba(255,255,255,0.03));
}
.chat-error.visible {
    opacity: 1;
    pointer-events: auto;
}
.chat-error small { display: block; font-weight: 400; font-size: 0.8rem; color: rgba(100,100,100,0.9); margin-top: 0.4rem; }

.chat-messages {
    flex: 1 1 auto;
    overflow-y: auto;
    background: #fffdf6; /* receipt-ish off-white */
    padding: 8px;
    border-radius: 6px;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.03);
}

.chat-message {
    margin-bottom: 4px;
    line-height: 1.08;
    /* Use grid so we can place name (left) and meta/time (right) on the
       top row, and the message body on a second row aligned left */
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "name meta"
        "body body";
    gap: 4px 8px;
    align-items: start;
    text-align: left;
    width: 100%;
    align-self: stretch;
}

/* Message layout now uses grid (see .chat-message above) */

/* vertical spacing handled by grid gap */

/* extra small spacing after the timestamp for clarity */
.chat-message .meta { margin-bottom: 2px; }

.chat-message .body {
    max-width: 100%;
    word-break: break-word;
    grid-area: body;
    justify-self: start;
}

.chat-message .name {
    grid-area: name;
    font-weight: 700;
    margin: 0; /* reset top/bottom margins — spacing controlled by the grid gap */
    font-size: calc(var(--chat-font-size) * 0.95);
    color: #222;
    justify-self: start;
}

.chat-message .body {
    font-size: var(--chat-font-size);
    grid-area: body;
    justify-self: start;
}

.chat-message .meta {
    grid-area: meta;
    font-size: 0.85em;
    color: #666;
    margin-bottom: 0;
    justify-self: end;
    align-self: center;
}

/* Receipt themed tweaks */
.receipt-time {
    font-style: italic;
    color: #333;
    font-size: 0.95em;
    user-select: none;
}

.receipt-line {
    font-family: monospace;
    font-size: 0.72rem;
    color: #9aa0a6;
    user-select: none;
    margin: 1px 0 2px 0;
    letter-spacing: 1px;
    text-align: center;
}

.chat-message .body { /* keep the same font as the surrounding chat */ }

/* small divider between time and user */
.receipt-divider {
    font-family: monospace;
    font-size: 0.8rem;
    color: #b0b4b7;
    user-select: none;
    text-align: center;
    align-self: stretch; /* span the message width */
    margin: 4px 0 2px 0;
    letter-spacing: 1px;
}

/* long splitter between messages */
.message-split {
    /* Receipt-style dashed splitter: use a pseudo-element to draw
       repeating dashes so it remains a single visual line and scales
       with the container width without wrapping into text rows. */
    display: block;
    width: 100%;
    height: 18px; /* vertical space for the splitter */
    margin: 8px 0;
    align-self: stretch;
    position: relative;
}

.message-split::after {
    content: "";
    position: absolute;
    left: 6px;
    right: 6px;
    top: 50%;
    height: 1px;
    transform: translateY(-50%);
    /* 6px dash, 6px gap repeated across the width */
    background-image: repeating-linear-gradient(90deg, #d0d4d7 0 6px, rgba(0,0,0,0) 6px 12px);
    background-repeat: repeat-x;
    background-size: 12px 1px;
    pointer-events: none;
}

.chat-form {
    display: flex;
    gap: 8px;
}

.chat-form input[type="text"] {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

#chatName {
    width: 24%;
    min-width: 70px;
}

/* When the name input lives in the user area, make it a reasonable inline size */
.chat-user-area #chatName {
    width: auto;
    min-width: 120px;
    max-width: 220px;
    padding: 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: white;
}

#chatInput {
    flex: 1;
}

/* Prevent children from overflowing the right padding and allow inputs to shrink */
.right > * {
    box-sizing: border-box;
    max-width: 100%;
}

#chatInput {
    min-width: 0;
}

.chat-messages {
    padding-right: 15px;
}

.chat-form button {
    padding: 8px 12px;
    border: none;
    background: #4a90e2;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
}

/* Registration bar styles */
.chat-reg {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
}
.chat-reg .reg-name {
    flex: 1 1 auto;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
}
.chat-reg .reg-btn,
.chat-reg .reg-logout {
    padding: 8px 10px;
    border: none;
    background: #2d8659;
    color: #fff;
    border-radius: 4px;
    cursor: pointer;
}
.chat-reg .reg-logout {
    background: #c0392b;
}
.chat-reg .reg-status {
    font-size: 0.9em;
    color: #333;
    margin-left: 6px;
}

.chat-font-control {
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.95em;
}
.chat-font-control input[type="range"] {
    width: 120px;
}

/* Responsive: stack the chat column under the stream on narrow screens */
@media (max-width: 768px) {
    body {
        padding: 10px;
        gap: 10px;
    }
    .container {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    /* hide the divider used for desktop resizing */
    .divider { display: none; }

    .left, .right {
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
    }

    /* keep the stream visible with a reasonable height on phones */
    .left { align-items: stretch; }
    .left iframe { width: 100%; height: 320px; }

    /* chat column spans full width and gets modest padding */
    .right { padding: 12px; }
    .right iframe { height: auto; }

    /* make chat content height automatic and limit message area height */
    .right .chat { height: auto; }
    .chat-messages { max-height: 40vh; overflow-y: auto; padding-right: 8px; }

     /* Allow the page to scroll on small screens so controls (send button)
         can be reached — override the desktop `overflow: hidden` behavior. */
     html, body { overflow: auto; height: auto; }

    /* ensure form stretches full width on small screens */
    .chat-form { flex-direction: column; align-items: stretch; }
    .chat-form input[type="text"], #chatInput { width: 100%; }
    .chat-form button { width: 100%; }
}

/* Admin/mod controls: place controls on their own row and right-align buttons */
.chat-message .mod-controls {
    grid-column: 1 / -1; /* span full width of the message grid */
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}
.chat-message .mod-controls button {
    padding: 6px 8px;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,0.08);
    background: #f4f4f4;
    cursor: pointer;
}
