/* ── design tokens ────────────────────────────────────────────────────────── */
:root {
    --bg-body:     #0d0d1a;
    --bg-card:     #13132b;
    --bg-card-alt: #1a1a35;
    --bg-input:    #111126;
    --bg-msg-own:  #2d1f6e;
    --bg-msg-peer: #1c1c3c;
    --bg-sys:      transparent;

    --accent:      #7c3aed;
    --accent-h:    #6d28d9;
    --accent-lite: #a78bfa;

    --text-pri:  #e2e8f0;
    --text-sec:  #94a3b8;
    --text-acc:  #a78bfa;

    --border:    #252546;
    --success:   #10b981;
    --error:     #ef4444;

    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 20px;
}

/* ── reset / base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-body);
    color: var(--text-pri);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--accent-lite); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── utility ──────────────────────────────────────────────────────────────── */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

/* ── buttons ──────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 22px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.btn--primary {
    background: var(--accent);
    color: #fff;
}
.btn--primary:hover { background: var(--accent-h); }
.btn--primary:active { transform: scale(0.97); }

.btn--outline {
    background: transparent;
    color: var(--accent-lite);
    border: 1px solid var(--accent);
}
.btn--outline:hover { background: rgba(124,58,237,.15); }

.btn--ghost {
    background: transparent;
    color: var(--text-sec);
    padding: 8px 12px;
}
.btn--ghost:hover { color: var(--text-pri); }

.btn--icon {
    background: transparent;
    color: var(--text-sec);
    padding: 8px;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
}
.btn--icon:hover { color: var(--text-pri); background: rgba(255,255,255,.07); }

/* ── ═══════════════════  HOME PAGE  ═══════════════════ ──────────────── */
.landing {
    min-height: 100vh;
    min-height: 100svh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 16px;
    gap: 40px;
    overflow-y: auto;
}

/* hero */
.hero { text-align: center; }

.hero__logo {
    font-size: 2.8rem;
    font-weight: 800;
    letter-spacing: -1px;
    background: linear-gradient(135deg, var(--accent-lite) 0%, #38bdf8 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.hero__tagline {
    margin-top: 10px;
    color: var(--text-sec);
    font-size: 1.05rem;
}

/* cards */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 680px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 32px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.card:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.card__icon { font-size: 2rem; line-height: 1; }
.card__title { font-size: 1.15rem; font-weight: 700; }
.card__desc { color: var(--text-sec); font-size: 0.9rem; flex: 1; }

/* join input */
.join-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-pri);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}
.input:focus { border-color: var(--accent); }
.input::placeholder { color: var(--text-sec); }

/* error banner */
.error-banner {
    background: rgba(239,68,68,.12);
    border: 1px solid var(--error);
    color: var(--error);
    border-radius: var(--radius-sm);
    padding: 12px 18px;
    font-size: 14px;
    max-width: 680px;
    width: 100%;
    text-align: center;
}

/* footer note */
.landing__note {
    color: var(--text-sec);
    font-size: 0.8rem;
    text-align: center;
}

/* ── ═══════════════════  SESSION PAGE  ═══════════════════ ──────────────── */

/* Prevent body-level scroll on the session page (e.g. from virtual keyboard or browser chrome). */
.session-body {
    overflow: hidden;
    height: 100%;
}

.session-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100svh; /* stable small-viewport height: accounts for browser chrome on mobile */
    height: 100dvh; /* dynamic viewport height – adapts when mobile keyboard opens */
    overflow: hidden;
}

/* top bar */
.topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.topbar__brand {
    font-weight: 800;
    font-size: 1.1rem;
    background: linear-gradient(135deg, var(--accent-lite), #38bdf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

.topbar__session-id {
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-sec);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar__peers {
    margin-left: auto;
    font-size: 0.8rem;
    color: var(--text-acc);
    white-space: nowrap;
}

/* share bar */
.sharebar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-card-alt);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sharebar__label {
    font-size: 0.78rem;
    color: var(--text-sec);
    white-space: nowrap;
}

.sharebar__input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 0.78rem;
    color: var(--text-sec);
    font-family: monospace;
    outline: none;
    min-width: 0;
}

.sharebar__copy {
    flex-shrink: 0;
    padding: 6px 14px;
    font-size: 0.78rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s;
}
.sharebar__copy:hover { background: var(--accent-h); }

/* chat area */
#chat-area {
    flex: 1;
    min-height: 0; /* critical: allows flex child to shrink below content size */
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

/* scrollbar */
#chat-area::-webkit-scrollbar { width: 6px; }
#chat-area::-webkit-scrollbar-track { background: transparent; }
#chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* messages */
.msg {
    display: flex;
    flex-direction: column;
    max-width: 72%;
}
.msg--own { align-self: flex-end; align-items: flex-end; }
.msg--peer { align-self: flex-start; align-items: flex-start; }

.msg__bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 0.93rem;
    line-height: 1.5;
    word-break: break-word;
}
.msg--own  .msg__bubble { background: var(--bg-msg-own);  border-bottom-right-radius: var(--radius-sm); }
.msg--peer .msg__bubble { background: var(--bg-msg-peer); border-bottom-left-radius: var(--radius-sm); }

.msg__meta {
    font-size: 0.72rem;
    color: var(--text-sec);
    margin-top: 3px;
    padding: 0 4px;
}

/* system messages */
.sys-msg {
    align-self: center;
    font-size: 0.78rem;
    color: var(--text-sec);
    background: rgba(255,255,255,.04);
    border-radius: 100px;
    padding: 4px 14px;
    text-align: center;
}

/* fatal error */
.fatal-error {
    align-self: center;
    background: rgba(239,68,68,.12);
    border: 1px solid var(--error);
    color: var(--error);
    border-radius: var(--radius-md);
    padding: 20px 28px;
    margin: auto;
    text-align: center;
    font-size: 0.95rem;
    max-width: 480px;
}

/* file cards */
.file-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    min-width: 220px;
}

.file-card__icon { font-size: 1.6rem; line-height: 1; flex-shrink: 0; }

.file-card__info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.file-card__name {
    font-size: 0.88rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-card__size { font-size: 0.78rem; color: var(--text-sec); }

.file-card__dl {
    flex-shrink: 0;
    padding: 6px 14px;
    background: var(--accent);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s;
}
.file-card__dl:hover { background: var(--accent-h); text-decoration: none; }

/* file upload progress bar (shown while sending) */
.file-card__progress-wrap {
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}

.file-card__progress-bar {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    width: 0%;
    transition: width 0.15s ease;
}

/* file offer accept/decline buttons */
.file-card__actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    align-items: center;
}

.file-card__accept {
    padding: 6px 14px;
    background: var(--success);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: filter 0.15s;
}
.file-card__accept:hover { filter: brightness(1.1); }

.file-card__decline {
    padding: 6px 14px;
    background: transparent;
    color: var(--text-sec);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.file-card__decline:hover { border-color: var(--error); color: var(--error); }

/* cancel button for in-progress transfers and pending offers */
.file-card__cancel {
    flex-shrink: 0;
    background: transparent;
    color: var(--text-sec);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 9px;
    font-size: 0.78rem;
    line-height: 1;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.file-card__cancel:hover { border-color: var(--error); color: var(--error); }

/* ads grid – home page (4 banners in 2-column grid) */
.ads-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    width: 100%;
    max-width: 680px;
}

.ads-grid__unit {
    min-height: 90px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

/* input bar */
.inputbar {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 16px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#msg-input {
    flex: 1;
    resize: none;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--text-pri);
    font-size: 0.93rem;
    font-family: inherit;
    outline: none;
    min-height: 42px;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.5;
    transition: border-color 0.15s;
    field-sizing: content; /* modern auto-resize (Chrome 123+) */
}
#msg-input:focus { border-color: var(--accent); }
#msg-input::placeholder { color: var(--text-sec); }

#send-btn {
    flex-shrink: 0;
    padding: 10px 20px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    line-height: 1.5;
}
#send-btn:hover { background: var(--accent-h); }

#attach-btn {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-sec);
    font-size: 1.2rem;
    padding: 8px 12px;
    cursor: pointer;
    line-height: 1;
    transition: color 0.15s, border-color 0.15s;
}
#attach-btn:hover { color: var(--text-pri); border-color: var(--accent); }

/* ── QR code modal ────────────────────────────────────────────────────────── */
.qr-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.qr-modal[hidden] { display: none; }

.qr-modal__box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 28px 24px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
}

.qr-modal__hint {
    font-size: 0.85rem;
    color: var(--text-sec);
    text-align: center;
}

.qr-modal__canvas {
    border-radius: var(--radius-sm);
    display: block;
}

.qr-modal__close {
    padding: 7px 20px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-sec);
    font-size: 0.82rem;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s;
}
.qr-modal__close:hover { border-color: var(--accent); color: var(--text-pri); }

/* ── responsive tweaks ────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .msg { max-width: 88%; }
    .topbar__session-id { display: none; }
    .sharebar { padding: 6px 10px; gap: 6px; }
    .sharebar__label { display: none; }
    .inputbar { padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)); gap: 6px; }
}
