/* ==========================================================================
   SKLO MESSENGER — STYLESHEET
   Core palette:   --blue #2563eb  |  --ink #1e293b  |  --white #ffffff
   Status accents: --green (ok) | --red (err / destructive)
   No other hand-coded colors below — derive everything from these via
   var() or rgba(...). Keeps the look consistent and makes a future
   re-theme a single block edit.
   ========================================================================== */

:root {
    --blue:       #2563eb;
    --blue-hover: #1d4ed8;
    --blue-light: rgba(37, 99, 235, 0.09);
    --ink:        #1e293b;
    --white:      #ffffff;

    /* Derived surface tones (tints of the 3 core colors) */
    --surface: #f1f5f9;   /* page / chat background */
    --panel:   #ffffff;   /* sidebar, header, input strip */
    --border:  #e2e8f0;   /* hairline dividers */
    --muted:   #64748b;   /* secondary text, placeholders */

    /* Semantic accents (used sparingly, only for status / destructive UI) */
    --green:       #10b981;
    --green-light: rgba(16, 185, 129, 0.10);
    --red:         #ef4444;
    --red-light:   rgba(239, 68, 68, 0.10);

    /* Auth-overlay dark glass */
    --auth-bg:      #030712;
    --glass-bg:     rgba(255, 255, 255, 0.10);
    --glass-border: rgba(255, 255, 255, 0.20);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--surface);
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    font-family: 'Inter', -apple-system, sans-serif;
    overflow: hidden;
    color: var(--ink);
}


/* ==========================================================================
   1. BACKGROUND GLOW BLOBS (visible through auth overlay)
   ========================================================================== */
.glow-blob {
    position: fixed;
    width: 400px; height: 400px;
    background: radial-gradient(circle, rgba(37, 99, 235, 0.15) 0%, transparent 70%);
    filter: blur(50px);
    z-index: 1;
    top: 20%; left: 20%;
    animation: blob-float 20s infinite alternate ease-in-out;
    pointer-events: none;
}
.blob-2 {
    background: radial-gradient(circle, rgba(16, 185, 129, 0.08) 0%, transparent 70%);
    top: 50%; left: 60%;
    animation-delay: -5s;
}
@keyframes blob-float {
    from { transform: translate(0, 0); }
    to   { transform: translate(100px, 50px); }
}


/* ==========================================================================
   2. CONNECTION STATUS INDICATOR
   ========================================================================== */
/* Connection indicator lives at the top of the Identity sidebar section,
   in place of the previous "Identity" section title. It serves as the
   section header and a live link/auth status pill at once. */
#connection-indicator {
    display: flex; align-items: center; gap: 8px;
    font-size: 10px; font-weight: 800; letter-spacing: 0.08em;
    color: var(--muted);
    margin-bottom: 14px;
    text-transform: uppercase;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; }
#connection-indicator.status-pending .status-dot {
    background: var(--muted);
    box-shadow: 0 0 6px var(--muted);
    animation: pulse-heartbeat 1.2s infinite ease-in-out;
}
#connection-indicator.status-err .status-dot {
    background: var(--red);
    box-shadow: 0 0 8px var(--red);
    animation: pulse-heartbeat 1.2s infinite ease-in-out;
}
#connection-indicator.status-ok .status-dot {
    background: var(--green);
    box-shadow: 0 0 8px var(--green);
}
@keyframes pulse-heartbeat {
    0%, 100% { transform: scale(1); opacity: 1; }
    30%       { transform: scale(1.4); opacity: 0.8; }
}


/* ==========================================================================
   3. AUTH OVERLAY (dark glassmorphism)
   ========================================================================== */
#auth-overlay {
    position: fixed; inset: 0;
    background: var(--auth-bg);
    z-index: 9999;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
}
.auth-box {
    position: relative;
    width: 380px; padding: 45px;
    z-index: 10; overflow: hidden;
    background: var(--glass-bg);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    border-radius: 32px;
    border: 1px solid var(--glass-border);
    box-shadow:
        inset 1px 1px 0 rgba(255, 255, 255, 0.10),
        0 25px 50px -12px rgba(0, 0, 0, 0.70);
}
.auth-box::after {
    content: "";
    position: absolute; top: -50%; left: -150%;
    width: 150%; height: 200%;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.10), transparent);
    transform: rotate(35deg);
    animation: single-shine 1.5s 0s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    pointer-events: none;
}
@keyframes single-shine {
    from { left: -150%; }
    to   { left: 150%; }
}

/* Cascade entrance animations */
@keyframes fade-in-up {
    0%   { opacity: 0; transform: translateY(15px); }
    100% { opacity: 1; transform: translateY(0); }
}
/* Cascade entrance animation — scoped to the auth-box so it does not leak
   onto .btn-primary buttons created elsewhere (e.g. the recovery modal,
   where dynamically adding `btn-primary` was hiding the Continue button
   under an `opacity: 0` + 4.7-second delay). */
.auth-box .auth-subtitle,
.auth-box .auth-input,
.auth-box .btn-primary {
    opacity: 0;
    animation: fade-in-up 0.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.auth-box .auth-subtitle             { animation-delay: 2.1s; }
.auth-box .auth-input:nth-of-type(1) { animation-delay: 2.25s; }
.auth-box .auth-input:nth-of-type(2) { animation-delay: 2.4s; }
.auth-box .btn-primary               { animation-delay: 2.55s; }

.auth-subtitle {
    color: rgba(255, 255, 255, 0.60);
    font-size: 13px; margin-bottom: 25px;
    text-align: center; font-weight: 500;
}
.auth-input {
    width: 100%; padding: 15px; margin-bottom: 12px;
    background: rgba(0, 0, 0, 0.40);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: #fff; outline: none;
    position: relative; z-index: 5;
    transition: border-color 0.2s, background 0.2s;
}
.auth-input::placeholder { color: rgba(255, 255, 255, 0.40); }
.auth-input:focus {
    border-color: var(--blue);
    background: rgba(0, 0, 0, 0.60);
}
.btn-primary {
    width: 100%; padding: 15px;
    background: var(--blue); color: #fff;
    border: none; border-radius: 12px;
    font-weight: 700; cursor: pointer;
    position: relative; z-index: 5;
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
}
.btn-primary:hover {
    background: var(--blue-hover);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}


/* ==========================================================================
   4. SVG LOGO ANIMATION
   ========================================================================== */
.logo-container {
    width: 100%; display: flex;
    justify-content: center; align-items: center;
    margin-bottom: 35px;
}
.sklo-svg-logo {
    width: 100%; max-width: 240px; height: auto;
    display: block; overflow: visible;
}
.draw-path {
    stroke: #ffffff; stroke-width: 2; fill: none;
    stroke-dasharray: 3000; stroke-dashoffset: 3000;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.40));
    animation: draw-sklo 2s 0s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes draw-sklo {
    0%   { stroke-dashoffset: 3000; fill: rgba(255, 255, 255, 0); }
    75%  { stroke-dashoffset: 0;    fill: rgba(255, 255, 255, 0); }
    100% { stroke-dashoffset: 0;    fill: rgba(255, 255, 255, 1); }
}


/* ==========================================================================
   5. MAIN MESSENGER — LAYOUT
   ========================================================================== */
#main-wrapper {
    display: flex; width: 100%;
    height: 100vh; height: 100dvh;
    position: relative; z-index: 5;
}

.sidebar {
    width: 300px;
    background: var(--panel);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
}

.chat-area {
    flex: 1; display: flex; flex-direction: column;
    background: var(--surface);
}

.sidebar-section {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}
.contact-list-wrapper {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.section-title {
    font-size: 10px; text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 14px;
    font-weight: 800; letter-spacing: 0.08em;
}

.profile-info {
    display: flex; align-items: center;
    margin-bottom: 14px;
}
.profile-text { display: flex; flex-direction: column; overflow: hidden; }
.alias-text   { font-size: 15px; font-weight: 700; color: var(--ink); }
.id-meta      { font-size: 10px; color: var(--muted); font-family: monospace; }
.profile-actions { display: flex; gap: 8px; }


/* ==========================================================================
   6. CHAT HEADER
   ========================================================================== */
.header {
    padding: 16px 28px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    background: var(--panel);
}
.chat-title    { font-weight: 700; font-size: 16px; color: var(--ink); }
.safety-number { font-size: 10px; color: var(--muted); font-family: monospace; margin-top: 3px; }


/* ==========================================================================
   7. MESSAGES
   ========================================================================== */
.messages {
    flex: 1; padding: 28px 32px;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 12px;
}

.message-box {
    padding: 12px 16px;
    border-radius: 18px 18px 18px 4px;
    background: var(--panel);
    border: 1px solid var(--border);
    max-width: 70%; align-self: flex-start;
    line-height: 1.55; font-size: 14.5px;
    color: var(--ink);
}
.message-box.self {
    background: var(--blue); color: #fff;
    border-color: transparent;
    align-self: flex-end;
    border-radius: 18px 18px 4px 18px;
}
.message-box small {
    display: block;
    color: var(--blue); font-weight: 700;
    margin-bottom: 4px;
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.05em;
}
.message-box.self small { color: rgba(255, 255, 255, 0.75); }


/* ==========================================================================
   8. INPUT AREA
   ========================================================================== */
.input-area {
    padding: 16px 28px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    display: flex; gap: 10px; align-items: center;
}
.input-area input[type="text"] {
    flex: 1; padding: 13px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 30px;
    color: var(--ink); outline: none;
    font-size: 14px;
    transition: border-color 0.2s;
}
.input-area input[type="text"]:focus { border-color: var(--blue); }
.input-area input[type="text"]::placeholder { color: var(--muted); }

#send-btn {
    width: 48px; height: 48px; flex-shrink: 0;
    border-radius: 50%;
    background: var(--blue); color: #fff;
    border: none; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s, transform 0.15s;
}
#send-btn:hover:not(:disabled) {
    background: var(--blue-hover);
    transform: scale(1.05);
}
#send-btn:disabled {
    background: var(--border);
    color: var(--muted);
    cursor: not-allowed;
}

#file-attach-btn {
    width: 42px; height: 42px; flex-shrink: 0;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
#file-attach-btn:hover:not(:disabled) {
    background: var(--surface);
    color: var(--ink);
}
#file-attach-btn:disabled { opacity: 0.35; cursor: not-allowed; }


/* ==========================================================================
   9. FILE TRANSFER BUBBLES
   ========================================================================== */
.message-box.file-transfer .file-name {
    margin: 4px 0 8px; font-weight: 600; font-size: 13.5px;
}
.message-box.file-transfer .file-size {
    font-weight: 400; font-size: 11px;
    opacity: 0.55; margin-left: 6px;
}
.file-progress-wrap {
    height: 4px;
    background: var(--border);
    border-radius: 2px; overflow: hidden; margin-bottom: 6px;
}
.message-box.self .file-progress-wrap { background: rgba(255, 255, 255, 0.25); }
.file-progress-bar {
    height: 100%; width: 0%;
    background: var(--blue);
    border-radius: 2px;
    transition: width 0.25s ease;
}
.message-box.self .file-progress-bar { background: rgba(255, 255, 255, 0.85); }
.file-status { font-size: 11px; opacity: 0.65; }

.file-download-btn {
    display: inline-block; margin-top: 4px;
    padding: 6px 14px;
    background: var(--blue-light);
    border: 1px solid rgba(37, 99, 235, 0.20);
    border-radius: 20px;
    color: var(--blue);
    text-decoration: none;
    font-size: 12px; font-weight: 700;
    transition: background 0.15s;
}
.file-download-btn:hover { background: rgba(37, 99, 235, 0.15); }
.message-box.self .file-download-btn {
    background: rgba(255, 255, 255, 0.20);
    border-color: rgba(255, 255, 255, 0.30);
    color: #fff;
}
.message-box.self .file-download-btn:hover { background: rgba(255, 255, 255, 0.32); }


/* ==========================================================================
   10. SIDEBAR CONTROLS & CONTACTS
   ========================================================================== */
.hidden { display: none !important; }
.w100   { width: 100%; }
.mb8    { margin-bottom: 8px; }

.clean-input {
    width: 100%; padding: 11px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px; color: var(--ink);
    margin-bottom: 10px; outline: none;
    font-size: 13px;
    transition: border-color 0.2s;
}
.clean-input:focus { border-color: var(--blue); }
.clean-input::placeholder { color: var(--muted); }

.btn-secondary {
    flex: 1; padding: 9px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--ink);
    border-radius: 8px; cursor: pointer;
    font-size: 12px; font-weight: 600;
    transition: background 0.15s;
}
.btn-secondary:hover { background: var(--surface); }

.btn-primary-outline {
    padding: 11px;
    background: transparent;
    border: 1px solid var(--blue);
    color: var(--blue);
    border-radius: 8px; cursor: pointer;
    font-size: 13px; font-weight: 700;
    transition: background 0.15s, color 0.15s;
}
.btn-primary-outline:hover { background: var(--blue); color: #fff; }

.contact-item {
    padding: 12px 0;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: padding-left 0.15s;
}
.contact-item:last-child { border-bottom: none; }
.contact-item:hover { padding-left: 6px; }
.contact-item strong { display: block; font-size: 14px; margin-bottom: 3px; color: var(--ink); }
.contact-item small  { display: block; color: var(--muted); font-size: 10px; font-family: monospace; }


/* ==========================================================================
   11. DELIVERY STATUS
   ========================================================================== */
.delivery-status {
    display: block;
    text-align: right;
    font-size: 10px;
    margin-top: 5px;
    color: rgba(255, 255, 255, 0.50);
    letter-spacing: 0.5px;
    transition: color 0.2s;
}
.delivery-status.delivered {
    color: rgba(255, 255, 255, 0.90);
}
.msg-time {
    display: block;
    text-align: right;
    font-size: 10px;
    margin-top: 5px;
    color: var(--muted);
}


/* ==========================================================================
   12. GLOBAL FEED & BADGES
   ========================================================================== */

/* Back button in header */
#btn-back-feed {
    display: flex; align-items: center; gap: 5px;
    padding: 7px 13px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--ink);
    font-size: 12px; font-weight: 600;
    cursor: pointer; flex-shrink: 0;
    transition: background 0.15s;
}
#btn-back-feed:hover { background: var(--surface); }

/* Contact row with badge + actions */
.contact-header {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 3px;
}
.contact-header strong { font-size: 14px; color: var(--ink); margin-bottom: 0; }

.contact-actions {
    display: flex; align-items: center; gap: 2px;
    flex-shrink: 0;
}

.contact-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 18px; height: 18px;
    padding: 0 5px;
    background: var(--red); color: var(--white);
    font-size: 10px; font-weight: 700;
    border-radius: 9px;
    line-height: 1;
    flex-shrink: 0;
    margin-right: 2px;
}

.contact-action-btn {
    width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    border: none; background: transparent;
    border-radius: 6px;
    color: var(--muted); font-size: 22px;
    cursor: pointer; padding: 0; flex-shrink: 0;
    opacity: 0;
    transition: background 0.12s, color 0.12s, opacity 0.15s;
}
.contact-item:hover .contact-action-btn { opacity: 1; }
.contact-action-btn:hover { background: var(--surface); color: var(--ink); }
.contact-action-delete:hover { background: var(--red-light); color: var(--red); }

/* Floating new-message pill */
.chat-area { position: relative; }

#new-msg-float {
    position: absolute;
    bottom: 80px; left: 50%;
    transform: translateX(-50%);
    padding: 8px 18px;
    background: var(--blue); color: #fff;
    border: none; border-radius: 20px;
    font-size: 12px; font-weight: 600;
    cursor: pointer; white-space: nowrap;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
    z-index: 50;
    transition: background 0.15s, transform 0.15s;
}
#new-msg-float:hover {
    background: var(--blue-hover);
    transform: translateX(-50%) translateY(-2px);
}

/* Clickable messages in global feed */
.feed-clickable { cursor: pointer; }
.feed-clickable:hover { opacity: 0.80; }

/* Link-style button in auth box (recover, etc.) */
.btn-link {
    width: 100%; margin-top: 14px;
    padding: 10px 0;
    background: transparent; border: none;
    color: rgba(255, 255, 255, 0.55);
    font-size: 12px; font-weight: 500;
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.15s;
    z-index: 5; position: relative;
}
.btn-link:hover { color: rgba(255, 255, 255, 0.95); }

/* Panic slider — scorched-earth wipe on slide + 3s hold */
.sidebar-footer {
    padding: 14px 20px 18px;
    border-top: 1px solid var(--border);
    margin-top: auto;
}
.panic-slider {
    position: relative;
    width: 100%;
    height: 38px;
    background: var(--surface);
    border: 1px solid rgba(16, 185, 129, 0.30);
    border-radius: 19px;
    overflow: hidden;
    user-select: none;
    touch-action: none;
}
.panic-fill {
    position: absolute;
    inset: 0;
    width: 0;
    background: rgba(16, 185, 129, 0.55);
    pointer-events: none;
}
.panic-label {
    position: absolute;
    inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px; font-weight: 800;
    color: var(--green);
    text-transform: uppercase;
    letter-spacing: 0.10em;
    pointer-events: none;
}
.panic-thumb {
    position: absolute;
    left: 2px; top: 2px;
    width: 32px; height: 32px;
    background: var(--green);
    border-radius: 50%;
    cursor: grab;
    touch-action: none;
    box-shadow: 0 2px 8px rgba(16, 185, 129, 0.45);
}
.panic-thumb:active { cursor: grabbing; }
.panic-slider.armed {
    border-color: rgba(16, 185, 129, 0.95);
}
.panic-slider.armed .panic-label {
    color: var(--white);
    position: relative; z-index: 1;
}

/* On the dark auth overlay we need lighter surface + readable label */
.auth-panic {
    margin-top: 22px;
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(16, 185, 129, 0.45);
}
.auth-panic .panic-label { color: var(--green); opacity: 0.85; }

/* Recovery modal — forced backup before first use */
#recovery-modal {
    position: fixed; inset: 0;
    z-index: 10000;
    background: var(--auth-bg);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
}
.recovery-box {
    width: 420px;
    max-width: calc(100% - 32px);
    padding: 38px 32px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 28px;
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.70);
}
.recovery-title {
    margin: 0 0 18px;
    font-size: 19px; font-weight: 700;
    color: #fff;
    text-align: center;
}
.recovery-text {
    margin: 0 0 12px;
    font-size: 13.5px; line-height: 1.55;
    color: rgba(255, 255, 255, 0.85);
}
.recovery-warn { color: var(--red); }
.recovery-list {
    margin: 0 0 18px; padding-left: 22px;
    font-size: 13px; line-height: 1.7;
    color: rgba(255, 255, 255, 0.78);
}
.recovery-btn { width: 100%; margin-bottom: 10px; }
.recovery-btn:last-child { margin-bottom: 0; }
.recovery-btn:disabled,
.recovery-btn:disabled:hover {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    background: transparent;
    color: var(--blue);
}


/* App footer — single bottom-left line that combines the build version
   and the integrity fingerprint. Always visible (including over the auth
   overlay) so the user can check both before unlocking. */
#app-footer {
    position: fixed;
    bottom: 10px; left: 12px;
    z-index: 10001;
    display: flex; align-items: center; gap: 8px;
    font-family: 'Inter', monospace;
    font-size: 9px; font-weight: 600;
    letter-spacing: 0.08em;
    color: rgba(148, 163, 184, 0.55);
    user-select: none;
}
.app-footer-sep { opacity: 0.55; }
#app-fingerprint {
    cursor: pointer;
    transition: color 0.15s;
}
#app-fingerprint:hover { color: rgba(148, 163, 184, 0.95); }


/* ==========================================================================
   13. RESPONSIVE / MOBILE (≤ 768px)
   ========================================================================== */
#sidebar-toggle { display: none; }
#sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.40);
    z-index: 199;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

@media (max-width: 768px) {
    /* iOS Safari zooms the page when a text input under 16px font-size
       receives focus and does not always restore the zoom cleanly when the
       input is hidden (e.g. after unlock). Lock every text input on small
       screens to ≥16px to prevent the auto-zoom from ever firing. */
    .auth-input,
    .clean-input,
    .input-area input[type="text"] {
        font-size: 16px;
    }

    .auth-box {
        width: calc(100% - 32px);
        padding: 30px 22px;
        border-radius: 24px;
    }
    .sidebar {
        position: fixed; left: -100%; top: 0;
        height: 100%; width: 280px; z-index: 200;
        transition: left 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
    }
    .sidebar.open { left: 0; }
    #sidebar-overlay.visible { display: block; }
    #sidebar-toggle {
        display: flex; align-items: center; justify-content: center;
        flex-shrink: 0; width: 36px; height: 36px;
        background: none;
        border: 1px solid var(--border);
        border-radius: 8px;
        color: var(--ink);
        cursor: pointer; margin-right: 10px;
    }
    .header {
        padding: 12px 14px;
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
    }
    .messages { padding: 14px 12px; }
    .message-box { max-width: 82%; font-size: 14px; }
    .input-area {
        padding: 10px 12px;
        padding-bottom: calc(18px + env(safe-area-inset-bottom, 0px));
        gap: 8px;
    }
    .input-area input[type="text"] { padding: 11px 16px; font-size: 16px; }
    #send-btn { width: 44px; height: 44px; }
    #connection-indicator {
        font-size: 9px;
        gap: 7px;
    }
}
