/* -------------------------------------------------------------------------
   Self-contained styles. System font stack, no external downloads.
   Tweak the palette in :root to restyle the whole app.
   ------------------------------------------------------------------------- */
:root {
    --bg:           #0b141a;   /* app background */
    --panel:        #111b21;   /* header / input bar */
    --mine:         #005c4b;   /* my bubbles (right) */
    --theirs:       #202c33;   /* her bubbles (left) */
    --text:         #e9edef;
    --text-dim:     #8696a0;   /* timestamps, receipts */
    --accent:       #00a884;
    --radius:       12px;
}

* { box-sizing: border-box; }

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    /* Lock to viewport so only the message list scrolls. */
    height: 100dvh;
    overflow: hidden;
}

.hidden { display: none !important; }

/* ---- Identity ("Who are you?") screen ---------------------------------- */
.identity {
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.identity-card {
    text-align: center;
    max-width: 360px;
    width: 100%;
}

.identity-card h1 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 24px;
}

.identity-choices {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.identity-btn {
    padding: 16px;
    font-size: 1.1rem;
    color: var(--text);
    background: var(--theirs);
    border: 1px solid #2a3942;
    border-radius: var(--radius);
    cursor: pointer;
}
.identity-btn:hover { background: #2a3942; }

/* ---- Chat layout ------------------------------------------------------- */
.chat {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    max-width: 800px;
    margin: 0 auto;
}

.chat-header {
    flex: 0 0 auto;
    background: var(--panel);
    padding: 14px 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* Respect notches on mobile. */
    padding-top: max(14px, env(safe-area-inset-top));
}

.switch-user {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.8rem;
    cursor: pointer;
}

/* ---- Messages list ----------------------------------------------------- */
.messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bubble {
    max-width: 75%;
    padding: 8px 10px 6px;
    border-radius: var(--radius);
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;     /* keep newlines the sender typed */
    position: relative;
}

/* Her messages: left-aligned. */
.bubble.theirs {
    align-self: flex-start;
    background: var(--theirs);
    border-top-left-radius: 4px;
}

/* My messages: right-aligned. */
.bubble.mine {
    align-self: flex-end;
    background: var(--mine);
    border-top-right-radius: 4px;
}

.meta {
    display: block;
    margin-top: 2px;
    font-size: 0.68rem;
    color: var(--text-dim);
    text-align: right;
}

/* Read receipt tick under my own messages. */
.receipt { margin-left: 4px; }
.receipt.read { color: #53bdeb; }   /* blue double-check when read */

/* ---- Attachments ------------------------------------------------------- */
.att { margin-bottom: 4px; }

/* Sender's inline image preview. */
.att-img {
    display: block;
    max-width: 100%;
    max-height: 320px;
    border-radius: 8px;
    cursor: pointer;
}

/* Recipient's download card (before download). */
.att-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px;
    min-width: 180px;
    background: rgba(0, 0, 0, 0.18);
    border-radius: 8px;
}
.att-label { font-weight: 600; }
.att-hint { font-size: 0.72rem; color: var(--text-dim); }
.att-download {
    align-self: flex-start;
    padding: 6px 14px;
    border: none;
    border-radius: 14px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}
.att-download:disabled { opacity: 0.6; cursor: default; }

/* Once the image is gone from the server. */
.att-gone {
    font-size: 0.8rem;
    color: var(--text-dim);
    font-style: italic;
}

/* ---- Composer (sticky input bar) -------------------------------------- */
.composer {
    flex: 0 0 auto;
    display: flex;
    gap: 8px;
    padding: 10px;
    background: var(--panel);
    /* Respect home indicator on mobile. */
    padding-bottom: max(10px, env(safe-area-inset-bottom));
}

/* Attach (📎) button, mirrors the send button's footprint. */
.attach {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-dim);
    font-size: 1.25rem;
    cursor: pointer;
}
.attach:active { transform: scale(0.95); }

/* Pending-image preview strip, sits just above the input bar. */
.pending {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--panel);
    border-top: 1px solid #2a3942;
}
.pending-thumb {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 6px;
}
.pending-name {
    flex: 1 1 auto;
    font-size: 0.85rem;
    color: var(--text-dim);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pending-cancel {
    flex: 0 0 auto;
    border: none;
    background: transparent;
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
}

.input {
    flex: 1 1 auto;
    resize: none;
    max-height: 120px;
    padding: 10px 14px;
    color: var(--text);
    background: var(--theirs);
    border: none;
    border-radius: 20px;
    font: inherit;
    outline: none;
}

.send {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
}
.send:active { transform: scale(0.95); }
