/* ─── TOKENS ─────────────────────────────────────────────────────────── */
:root {
    --bg:         #09090b;
    --surface:    #0f1014;
    --surface-2:  #141519;
    --surface-3:  #1a1d24;
    --border:     #1f2229;
    --border-2:   #272b34;
    --text:       #e8eaf0;
    --text-2:     #8b919e;
    --text-3:     #555d6b;
    --accent:     #22d3a5;
    --accent-dim: rgba(34,211,165,0.12);
    --accent-glow:rgba(34,211,165,0.06);
    --danger:     #f43f5e;
    --danger-dim: rgba(244,63,94,0.12);
    --mono:       'Geist Mono', 'Fira Code', monospace;
    --sans:       'Geist', 'Inter', sans-serif;
    --radius:     10px;
    --sidebar-w:  220px;
    --mobile-nav: 64px;
}

/* ─── RESET ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }

body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ─── SETUP VIEW ─────────────────────────────────────────────────────── */
#setup-view {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background:
        radial-gradient(ellipse 60% 50% at 50% -10%, rgba(34,211,165,0.07) 0%, transparent 70%),
        var(--bg);
}

.setup-inner {
    width: 100%;
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    animation: fadeUp 0.5s ease both;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
}
.brand-icon {
    width: 28px;
    height: 28px;
    background: var(--accent-dim);
    border: 1px solid rgba(34,211,165,0.25);
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    flex-shrink: 0;
}
.brand-name {
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.04em;
    color: var(--text-2);
}

.setup-hero h1 {
    font-size: clamp(1.6rem, 4vw, 2rem);
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.03em;
}
.setup-sub {
    margin-top: 0.6rem;
    color: var(--text-2);
    font-size: 13px;
    line-height: 1.6;
}

.setup-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-radius: 99px;
    font-size: 11px;
    font-family: var(--mono);
    color: var(--text-2);
}
.pill svg { color: var(--accent); flex-shrink: 0; }

.setup-form { display: flex; flex-direction: column; gap: 1rem; }
.input-group { display: flex; flex-direction: column; gap: 6px; }
.input-group label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-3);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.input-wrap { position: relative; }
.input-wrap input { padding-right: 60px; }
.input-suffix {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-family: var(--mono);
    font-size: 12px;
    color: var(--text-3);
    pointer-events: none;
}
.input-hint { font-size: 11px; color: var(--text-3); line-height: 1.5; }

input, textarea {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    color: var(--text);
    padding: 10px 14px;
    border-radius: var(--radius);
    font-family: var(--mono);
    font-size: 16px;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}
input::placeholder { color: var(--text-3); }
input:focus {
    border-color: rgba(34,211,165,0.4);
    box-shadow: 0 0 0 3px rgba(34,211,165,0.07);
}

.primary-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    padding: 11px 16px;
    background: var(--accent);
    color: #031a13;
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    letter-spacing: -0.01em;
}
.primary-btn:hover { background: #1ec99d; transform: translateY(-1px); box-shadow: 0 4px 20px rgba(34,211,165,0.2); }
.primary-btn:active { transform: none; box-shadow: none; }
.primary-btn.compact {
    width: auto;
    flex-shrink: 0;
    padding: 9px 14px;
    font-size: 13px;
    justify-content: center;
}
.btn-text { flex: 1; text-align: left; }
.btn-icon { display: flex; align-items: center; opacity: 0.7; }

#setup-status {
    font-size: 12px;
    font-family: var(--mono);
    color: var(--text-2);
    min-height: 18px;
}

/* ─── CHAT VIEW ROOT ─────────────────────────────────────────────────── */
#chat-view {
    display: flex;
    flex-direction: row;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

/* ─── SIDEBAR ────────────────────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.identity-card {
    margin: 12px;
    padding: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    flex-shrink: 0;
}
.identity-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--text-3);
    margin-bottom: 4px;
}
.identity-value {
    font-family: var(--mono);
    font-size: 13px;
    color: var(--text);
    word-break: break-all;
    font-weight: 500;
    line-height: 1.4;
}
.session-timer {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 8px;
    font-size: 11px;
    font-family: var(--mono);
    color: var(--text-3);
}
.session-timer svg { color: var(--accent); opacity: 0.7; flex-shrink: 0; }

.sidebar-nav {
    flex: 1;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    padding: 8px 10px;
    background: none;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-2);
    font-family: var(--sans);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.12s;
    text-align: left;
    flex-shrink: 0;
}
.nav-item svg { flex-shrink: 0; }
.nav-label { flex: 1; }
.nav-item:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.nav-item.active { background: var(--surface-3); color: var(--text); border-color: var(--border-2); }

.nav-badge {
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    font-family: var(--mono);
    min-width: 18px;
    height: 18px;
    border-radius: 99px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.burn-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--text-3);
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.12s;
}
.burn-btn:hover { background: var(--danger-dim); border-color: rgba(244,63,94,0.2); color: var(--danger); }

/* ─── MAIN PANEL ─────────────────────────────────────────────────────── */
#main-panel {
    flex: 1;
    min-width: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
    position: relative;
}

/* Panels use absolute positioning to fill main-panel */
.panel {
    position: absolute;
    inset: 0;
    /* JS sets display:flex to show, display:none to hide */
    display: none;
    flex-direction: column;
    overflow: hidden;
}

/* Chat sub-views — fill the chat panel, toggled by JS */
.chat-subview {
    display: none;          /* JS overrides to flex */
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: absolute;
    inset: 0;
}

.panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-height: 57px;
}
.panel-title {
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
    margin: 0;
}
.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    min-height: 0;
}

.new-chat-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    background: var(--accent);
    border: 1px solid var(--accent);
    border-radius: 8px;
    color: #031a13;
    font-family: var(--sans);
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s;
    flex-shrink: 0;
    letter-spacing: -0.01em;
}
.new-chat-btn:hover { background: #1ec99d; border-color: #1ec99d; transform: translateY(-1px); box-shadow: 0 3px 12px rgba(34,211,165,0.25); }
.new-chat-btn:active { transform: none; box-shadow: none; }

/* ─── CONTACT LIST ───────────────────────────────────────────────────── */
.contact-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.contact-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.12s;
}
.contact-item:hover { background: var(--surface-2); border-color: var(--border-2); }
.contact-name {
    font-family: var(--mono);
    font-size: 13.5px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.unread-dot {
    background: var(--danger);
    color: white;
    font-size: 10px;
    font-weight: 700;
    font-family: var(--mono);
    min-width: 20px;
    height: 20px;
    border-radius: 99px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    padding: 0 5px;
    flex-shrink: 0;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 48px 16px;
    text-align: center;
    color: var(--text-3);
    font-size: 13px;
    line-height: 1.6;
}
.empty-state svg { opacity: 0.35; }

.request-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 4px;
}
.request-item > span { font-size: 13px; color: var(--text-2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.request-item strong { font-family: var(--mono); color: var(--text); font-weight: 500; }
.accept-btn {
    padding: 6px 12px;
    background: var(--accent-dim);
    border: 1px solid rgba(34,211,165,0.25);
    border-radius: 7px;
    color: var(--accent);
    font-family: var(--sans);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.12s;
    flex-shrink: 0;
}
.accept-btn:hover { background: var(--accent); color: #031a13; }

/* ─── CHAT PANEL INTERNALS ───────────────────────────────────────────── */
/* The chat panel itself is position:absolute filling main-panel.
   Its children (handshake-init-view / active-chat-view) must also fill it. */
#chat-panel {
    /* panel styles already handle this */
}

/* chat-subview class handles handshake-init-view and active-chat-view */

.handshake-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 16px;
}
.handshake-card {
    width: 100%;
    max-width: 380px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}
.handshake-icon {
    width: 52px;
    height: 52px;
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
}
.handshake-desc { font-size: 13px; color: var(--text-2); line-height: 1.6; max-width: 280px; }
.handshake-input-row { display: flex; gap: 8px; width: 100%; }
.handshake-input-row input { font-size: 16px; }

/* Active chat */
.chat-header { gap: 0; }
.chat-peer { display: flex; align-items: center; gap: 11px; }
.peer-avatar {
    width: 34px;
    height: 34px;
    border-radius: 99px;
    background: linear-gradient(135deg, var(--surface-3), var(--surface-2));
    border: 1px solid var(--border-2);
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}
.peer-avatar::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(34,211,165,0.15), transparent);
}
.peer-status { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text-3); font-family: var(--mono); margin-top: 1px; }
.status-dot {
    width: 6px; height: 6px; border-radius: 99px;
    background: var(--accent); box-shadow: 0 0 6px var(--accent);
    flex-shrink: 0; animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.4; }
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
    min-height: 0;
}
.messages-container::-webkit-scrollbar { width: 4px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 99px; }

.msg {
    max-width: 72%;
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.6;
    word-break: break-word;
    animation: msgIn 0.15s ease both;
}
@keyframes msgIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
.msg.mine { align-self: flex-end; background: var(--accent-dim); border: 1px solid rgba(34,211,165,0.15); color: var(--text); border-bottom-right-radius: 4px; }
.msg.theirs { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border-2); color: var(--text); border-bottom-left-radius: 4px; }
.msg-sender {
    display: block;
    font-size: 10px;
    font-family: var(--mono);
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    margin-bottom: 3px;
    opacity: 0.5;
}

.compose-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    flex-shrink: 0;
}
.compose-area input { flex: 1; background: var(--surface-2); padding: 10px 14px; font-size: 16px; border-radius: 10px; }
.send-btn {
    width: 38px; height: 38px; flex-shrink: 0;
    background: var(--accent); border: none; border-radius: 10px;
    color: #031a13; display: flex; align-items: center; justify-content: center;
    cursor: pointer; transition: all 0.12s;
}
.send-btn:hover { background: #1ec99d; transform: scale(1.04); }
.send-btn:active { transform: scale(0.97); }

/* ─── TOAST ──────────────────────────────────────────────────────────── */
.toast-success {
    position: fixed;
    bottom: 20px; right: 20px;
    background: var(--surface-2);
    border: 1px solid rgba(34,211,165,0.25);
    color: var(--accent);
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    font-family: var(--mono);
    font-weight: 500;
    z-index: 999;
    animation: toastIn 0.2s ease both, toastOut 0.2s ease 2.8s both;
    box-shadow: 0 4px 24px rgba(0,0,0,0.3);
    pointer-events: none;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }

/* ─── MOBILE ─────────────────────────────────────────────────────────── */
/* Hidden on desktop, shown on mobile */
.mobile-only { display: none; }

@media (max-width: 640px) {
    html, body { height: 100%; overflow: hidden; }

    #setup-view {
        height: 100svh;
        align-items: flex-start;
        padding: 3rem 1.25rem 2rem;
        overflow-y: auto;
    }

    /* Stack: content above, nav below */
    #chat-view {
        flex-direction: column;
        height: 100svh;
    }

    #main-panel {
        order: 1;
        flex: 1;
        min-height: 0;
        position: relative;
    }

    /* ── BOTTOM NAV BAR ──
       Keep flex-direction: ROW so nav-items and burn sit side by side.
       Use padding-bottom for safe area so it doesn't squash children. */
    #sidebar {
        order: 2;
        width: 100%;
        min-width: unset;
        flex-direction: row;           /* MUST be row */
        align-items: stretch;
        flex-shrink: 0;
        height: var(--mobile-nav);
        border-right: none;
        border-top: 1px solid var(--border);
        background: var(--surface);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* Hide desktop sidebar chrome */
    .sidebar-header,
    .identity-card { display: none; }

    /* Show mobile-only items (ID tab) */
    .mobile-only { display: flex; }

    /* Nav row fills all space left of burn button */
    .sidebar-nav {
        flex: 1;
        flex-direction: row;
        align-items: stretch;
        padding: 0;
        gap: 0;
        overflow: hidden;
    }

    /* Each tab button */
    .nav-item {
        flex: 1;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 4px;
        padding: 12px;
        height: 100%;
        border-radius: 0;
        border: none;
        border-top: 2px solid transparent;
        font-size: 11px;
        color: var(--text-2);
    }
    .nav-item:hover { background: transparent; color: var(--text); }
    .nav-item.active {
        background: transparent;
        color: var(--accent);
        border-top-color: var(--accent);
    }
    .nav-item.active svg { color: var(--accent); }
    .nav-label { font-size: 11px; line-height: 1; }

    /* Burn button — right side of the bar */
    .sidebar-footer {
        display: flex;
        align-items: center;
        flex-shrink: 0;
        padding: 0;
        border-top: none;
        border-left: 1px solid var(--border);
    }
    .burn-btn {
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 4px;
        padding: 0 14px;
        font-size: 11px;
        width: auto;
        height: 100%;
        border-radius: 0;
    }
    .burn-label { font-size: 11px; }

    /* ── IDENTITY PANEL (mobile) ── */
    .mobile-identity-card {
        background: var(--surface-2);
        border: 1px solid var(--border-2);
        border-radius: 14px;
        padding: 20px;
        display: flex;
        flex-direction: column;
        gap: 16px;
        margin: 20px;
    }
    .mobile-identity-row {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }
    .mobile-identity-row label {
        font-size: 11px;
        font-weight: 600;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: var(--text-3);
    }
    .mobile-identity-row .val {
        font-family: var(--mono);
        font-size: 15px;
        color: var(--text);
        font-weight: 500;
        word-break: break-all;
    }
    .mobile-identity-row .val.timer-val { color: var(--accent); }
    .mobile-burn-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        margin: 0 20px;
        padding: 12px 16px;
        background: var(--danger-dim);
        border: 1px solid rgba(244,63,94,0.25);
        border-radius: var(--radius);
        color: var(--danger);
        font-family: var(--sans);
        font-size: 14px;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.12s;
        width: calc(100% - 40px);
    }
    .mobile-burn-btn:hover { background: rgba(244,63,94,0.2); }

    /* Messages */
    .messages-container { flex: 1; min-height: 0; }
    .msg { max-width: 88%; }

    /* Handshake */
    .handshake-input-row { flex-direction: column; }
    .primary-btn.compact { width: 100%; }

    .toast-success { bottom: calc(var(--mobile-nav) + 12px); right: 12px; }
}