/* ═══════════════════════════════════════════
   P2P Messenger — Premium Dark Theme v2.0
   ═══════════════════════════════════════════ */

/* --- Imports --- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* --- Design Tokens --- */
:root {
    /* Backgrounds */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #1c2128;
    --bg-elevated: #21262d;
    --bg-surface: rgba(255, 255, 255, 0.04);

    /* Accent — Blue-Indigo Gradient */
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-glow: rgba(59, 130, 246, 0.25);
    --accent-gradient: linear-gradient(135deg, #3b82f6, #8b5cf6);
    --accent-gradient-hover: linear-gradient(135deg, #2563eb, #7c3aed);

    /* Text */
    --text: #e6edf3;
    --text-secondary: #8b949e;
    --text-dim: #484f58;

    /* Semantic */
    --success: #3fb950;
    --danger: #f85149;
    --warning: #d29922;

    /* Effects */
    --glass: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.06);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);

    /* Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 50%;

    /* Transitions */
    --ease: cubic-bezier(0.4, 0, 0.2, 1);
    --ease-bounce: cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

body {
    font-family: 'Inter', 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Scrollbars --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* --- Toast Notifications --- */
#toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-120px);
    background: var(--bg-elevated);
    color: var(--text);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 500;
    z-index: 3000;
    box-shadow: var(--shadow-lg), inset 0 0 0 1px var(--glass-border);
    transition: 0.5s var(--ease-bounce);
    display: flex;
    align-items: center;
    gap: 10px;
    pointer-events: none;
    opacity: 0;
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
}

#toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ═══════════════════════════════════
   Layout
   ═══════════════════════════════════ */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
    background: var(--bg-primary);
}

/* ═══════════════════════════════════
   Sidebar
   ═══════════════════════════════════ */
.sidebar {
    width: 320px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    position: relative;
    z-index: 10;
}

/* --- Profile Header --- */
.profile-header {
    padding: 20px;
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.08) 0%, transparent 100%);
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    position: relative;
}

.profile-info h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 3px;
    letter-spacing: -0.01em;
}

.profile-info small {
    font-size: 11px;
    color: var(--accent);
    opacity: 0.9;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: opacity 0.2s var(--ease);
}

.profile-info small:hover {
    opacity: 1;
}

.id-status-dot {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent-glow);
    animation: pulse-dot 2s infinite var(--ease);
}

@keyframes pulse-dot {

    0%,
    100% {
        opacity: 1;
        box-shadow: 0 0 8px var(--accent-glow);
    }

    50% {
        opacity: 0.6;
        box-shadow: 0 0 16px var(--accent-glow);
    }
}

/* --- Settings Button --- */
.btn-settings {
    margin-left: auto;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.25s var(--ease);
    font-size: 18px;
    padding: 6px;
    border-radius: var(--radius-sm);
}

.btn-settings:hover {
    opacity: 1;
    background: var(--bg-surface);
    transform: rotate(30deg);
}

/* --- Search Bar --- */
.search-container {
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    align-items: center;
}

.search-container input {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: all 0.3s var(--ease);
}

.search-container input::placeholder {
    color: var(--text-dim);
}

.search-container input:focus {
    background: var(--bg-tertiary);
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* --- Contact List --- */
.contact-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* JS-generated contact items */
.contact-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-bottom: 2px;
    transition: all 0.2s var(--ease);
    position: relative;
    border: 1px solid transparent;
}

.contact-item:hover {
    background: var(--bg-surface);
    border-color: var(--glass-border);
}

.contact-item.active {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.2);
}

.contact-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 24px;
    background: var(--accent-gradient);
    border-radius: 0 3px 3px 0;
}

.contact-item .contact-info {
    flex: 1;
    min-width: 0;
}

.contact-item .contact-info .name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}

.contact-item .contact-info .last-msg {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

/* Legacy .contact class (HTML-defined) */
.contact {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    margin-bottom: 2px;
    transition: all 0.2s var(--ease);
    border: 1px solid transparent;
}

.contact:hover {
    background: var(--bg-surface);
    border-color: var(--glass-border);
}

.contact.active {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.2);
}

.contact-details {
    flex: 1;
    min-width: 0;
}

.contact-details div {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-details span {
    font-size: 12px;
    color: var(--text-secondary);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

/* --- Avatar --- */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    position: relative;
}

/* --- Status Dot --- */
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: var(--radius-full);
    background: var(--text-dim);
    border: 2px solid var(--bg-secondary);
    transition: background 0.3s var(--ease);
}

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px rgba(63, 185, 80, 0.4);
    animation: pulse-online 2s infinite var(--ease);
}

@keyframes pulse-online {

    0%,
    100% {
        box-shadow: 0 0 8px rgba(63, 185, 80, 0.4);
    }

    50% {
        box-shadow: 0 0 16px rgba(63, 185, 80, 0.6);
    }
}

/* --- Sidebar Bottom --- */
.sidebar>div:last-child .btn-main {
    background: var(--accent-gradient);
    border: none;
    font-weight: 600;
    letter-spacing: 0.01em;
    box-shadow: 0 4px 16px var(--accent-glow);
    transition: all 0.3s var(--ease);
}

.sidebar>div:last-child .btn-main:hover {
    box-shadow: 0 6px 24px var(--accent-glow);
    transform: translateY(-1px);
}

/* ═══════════════════════════════════
   Chat Area
   ═══════════════════════════════════ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    overflow: hidden;
    position: relative;
}

/* --- Chat Header --- */
.chat-header {
    height: 56px;
    padding: 0 20px;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    flex-shrink: 0;
}

.chat-header h3 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.chat-header span,
.chat-header-info span {
    font-size: 12px;
    color: var(--text-secondary);
}

.chat-header-info {
    display: flex;
    flex-direction: column;
}

/* --- Messages Container --- */
.chat-main {
    flex: 1;
    display: flex;
    overflow: hidden;
    background: var(--bg-primary);
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* --- Message Bubbles (JS-generated) --- */
.message {
    max-width: 70%;
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    animation: msg-in 0.3s var(--ease-bounce);
    word-break: break-word;
}

@keyframes msg-in {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.them {
    align-self: flex-start;
    background: var(--bg-elevated);
    border: 1px solid var(--glass-border);
    border-bottom-left-radius: 4px;
    color: var(--text);
}

.message.me {
    align-self: flex-end;
    background: var(--accent-gradient);
    border-bottom-right-radius: 4px;
    color: #fff;
    box-shadow: 0 2px 12px var(--accent-glow);
}

.message .text {
    white-space: pre-wrap;
}

.message .time {
    font-size: 10px;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

/* Legacy msg-group classes (from old template) */
.msg-group {
    display: flex;
    gap: 14px;
    max-width: 90%;
}

.msg-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}

.msg-content {
    flex: 1;
}

.msg-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}

.msg-nick {
    font-weight: 600;
    font-size: 15px;
}

.msg-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.msg-text {
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.msg-group.me .msg-text {
    opacity: 0.95;
}

.sys-msg {
    text-align: center;
    font-size: 13px;
    color: var(--text-dim);
    padding: 8px 16px;
    margin: auto;
}

/* --- Input Bar --- */
.input-bar {
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    flex-shrink: 0;
}

.input-bar input {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid transparent;
    border-radius: var(--radius-xl);
    padding: 12px 18px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: all 0.3s var(--ease);
}

.input-bar input::placeholder {
    color: var(--text-dim);
}

.input-bar input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: var(--bg-tertiary);
}

.btn-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: var(--radius-full);
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    cursor: pointer;
    font-size: 16px;
    flex-shrink: 0;
    transition: all 0.25s var(--ease);
    box-shadow: 0 2px 12px var(--accent-glow);
    position: static;
}

.btn-send:hover {
    transform: scale(1.08);
    box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-send:active {
    transform: scale(0.95);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* --- Fingerprint Badge --- */
.fingerprint {
    font-size: 11px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    border: 1px solid var(--glass-border);
    transition: all 0.2s var(--ease);
}

.fingerprint:hover {
    background: var(--bg-elevated);
    border-color: var(--accent);
    color: var(--accent);
}

/* ═══════════════════════════════════
   Empty State
   ═══════════════════════════════════ */
.empty-state {
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.empty-state .chat-header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.empty-state h2 {
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 8px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 14px;
    max-width: 320px;
    line-height: 1.5;
}

.empty-state .btn-main {
    margin-top: 24px !important;
    background: var(--bg-elevated) !important;
    border: 1px solid var(--glass-border) !important;
    width: auto !important;
    padding: 10px 20px !important;
    font-size: 13px !important;
    border-radius: var(--radius-md) !important;
    transition: all 0.25s var(--ease) !important;
}

.empty-state .btn-main:hover {
    border-color: var(--accent) !important;
    background: rgba(59, 130, 246, 0.1) !important;
    color: var(--accent) !important;
}

/* ═══════════════════════════════════
   Overlays & Modals
   ═══════════════════════════════════ */
.overlay,
.lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(12px);
    animation: overlay-in 0.3s var(--ease);
}

.lock-screen {
    flex-direction: column;
    gap: 15px;
}

@keyframes overlay-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    background: var(--bg-secondary);
    width: 90%;
    max-width: 440px;
    max-height: 85vh;
    border-radius: var(--radius-xl);
    padding: 28px;
    box-shadow: var(--shadow-lg), inset 0 0 0 1px var(--glass-border);
    border: 1px solid var(--border);
    overflow-y: auto;
    padding-bottom: 40px;
    animation: modal-in 0.35s var(--ease-bounce);
    position: relative;
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.modal h2 {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.modal p {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.5;
}

/* --- Form Inputs --- */
.big-input {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    margin-bottom: 12px;
    color: var(--text);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    outline: none;
    font-family: inherit;
    font-size: 14px;
    transition: all 0.3s var(--ease);
}

.big-input::placeholder {
    color: var(--text-dim);
}

.big-input:focus {
    border-color: var(--accent);
    background: var(--bg-tertiary);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* --- Buttons --- */
.btn-main {
    width: 100%;
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    font-family: inherit;
    transition: all 0.25s var(--ease);
    letter-spacing: 0.01em;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.btn-main:hover {
    box-shadow: 0 4px 16px var(--accent-glow);
    transform: translateY(-1px);
}

.btn-main:active {
    transform: translateY(0) scale(0.98);
}

/* --- Color Picker --- */
.color-picker {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    padding: 8px;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.color-dot {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.25s var(--ease);
}

.color-dot:hover {
    transform: scale(1.15);
}

.color-dot.active {
    border-color: #fff;
    box-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
    transform: scale(1.1);
}

/* --- Members Sidebar --- */
.members-sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    padding: 16px;
    overflow-y: auto;
}

.members-sidebar h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

/* --- Back Button --- */
.btn-back {
    display: none;
    cursor: pointer;
    font-size: 18px;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all 0.2s var(--ease);
}

.btn-back:hover {
    background: var(--bg-surface);
}

/* ═══════════════════════════════════
   Mobile Responsive
   ═══════════════════════════════════ */
@media screen and (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 100;
    }

    .chat-area {
        display: none;
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
    }

    .btn-back {
        display: flex;
    }

    .members-sidebar {
        width: 100%;
    }

    .message {
        max-width: 85%;
    }
}

/* ═══════════════════════════════════
   Utility Animations
   ═══════════════════════════════════ */
@keyframes fade-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(16px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-6px);
    }
}

/* Selection */
::selection {
    background: rgba(59, 130, 246, 0.3);
    color: var(--text);
}