:root {
    --bg-primary: #000000;
    --bg-secondary: #050505;
    --bg-surface: #0d0d0d;
    --bg-surface-hover: #161616;
    --border-color: #1a1a1a;
    --text-main: #f0f0f0;
    --text-muted: #555;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: rgba(37, 99, 235, 0.12);
    --accent-glow: rgba(37, 99, 235, 0.08);
    --danger: #dc2626;
    --danger-light: rgba(220, 38, 38, 0.15);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-user-select: none;
    -moz-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    height: 100dvh;
}

body {
    background: var(--bg-primary);
    color: var(--text-main);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* ==================== MODAL ==================== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.92);
    backdrop-filter: blur(8px);
}

.modal-content {
    width: 100%;
    max-width: 360px;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 36px 28px;
    animation: modalIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(12px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 6px;
    letter-spacing: -0.3px;
}

.modal-header p {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 28px;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-body input {
    width: 100%;
    background: #080808;
    border: 1px solid var(--border-color);
    padding: 14px 16px;
    border-radius: 12px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 16px;
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s;
}

.modal-body input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Password field wrapper */
.password-wrapper {
    position: relative;
    display: flex;
}

.password-wrapper input {
    padding-right: 48px;
}

.pass-toggle {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px !important;
    margin: 0;
    width: auto;
    height: auto;
    border-radius: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.pass-toggle:hover {
    background: none !important;
    color: var(--text-main);
}

.pass-toggle:active {
    transform: translateY(-50%) !important;
}

.modal-body button {
    background: var(--accent);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-body button:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.25);
}

.modal-body button:active {
    transform: scale(0.98);
}

.config-warning {
    margin-top: 16px;
    padding: 12px;
    background: var(--danger-light);
    border: 1px solid rgba(220, 38, 38, 0.3);
    border-radius: 8px;
    font-size: 12px;
    color: #fca5a5;
}

/* ==================== CHAT LAYOUT ==================== */
.app-container {
    width: 100%;
    max-width: 500px;
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    position: relative;
}

/* ==================== HEADER ==================== */
header {
    padding: 16px 20px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    font-size: 17px;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.details h1 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.2px;
}

.details .status {
    font-size: 11px;
    color: var(--text-muted);
    transition: color 0.3s;
}

.details .status.typing {
    color: var(--accent);
}

.details .status.online {
    color: #22c55e;
}

/* Typing dots */
.typing-dots {
    display: inline-flex;
    gap: 3px;
    margin-left: 4px;
    vertical-align: middle;
}

.typing-dots span {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--accent);
    animation: typingBounce 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* Typing bubble in chat (Messenger style) */
.typing-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px !important;
    min-width: 60px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: dotPulse 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.15s; }
.typing-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes dotPulse {
    0%, 60%, 100% { transform: scale(0.6); opacity: 0.4; }
    30% { transform: scale(1); opacity: 1; }
}

.typing-bubble-wrapper {
    animation: msgIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ==================== MESSAGES ==================== */
.messages-area {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-primary);
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: #1a1a1a transparent;
}

.messages-area::-webkit-scrollbar {
    width: 3px;
}
.messages-area::-webkit-scrollbar-thumb {
    background: #1a1a1a;
    border-radius: 10px;
}

/* Message */
.message {
    max-width: 78%;
    display: flex;
    flex-direction: column;
    animation: msgIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    margin-bottom: 2px;
}

@keyframes msgIn {
    from { opacity: 0; transform: translateY(10px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.message.sent {
    align-self: flex-end;
}

.message.received {
    align-self: flex-start;
}

/* Bubble */
.bubble {
    padding: 10px 14px;
    border-radius: 20px;
    font-size: 15px;
    line-height: 1.5;
    position: relative;
    word-break: break-word;
    -webkit-user-select: text;
    -moz-user-select: text;
    user-select: text;
    transition: transform 0.15s;
}

.bubble:active {
    transform: scale(0.98);
}

.message.sent .bubble {
    background: var(--accent);
    border-bottom-right-radius: 6px;
    color: white;
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.2);
}

.message.received .bubble {
    background: #0f0f0f;
    border-bottom-left-radius: 6px;
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

/* Consecutive messages - tighter spacing */
.message.sent + .message.sent {
    margin-top: -2px;
}
.message.sent + .message.sent .bubble {
    border-top-right-radius: 6px;
}

.message.received + .message.received {
    margin-top: -2px;
}
.message.received + .message.received .bubble {
    border-top-left-radius: 6px;
}

/* Image in bubble */
.bubble img {
    max-width: 100%;
    max-height: 280px;
    border-radius: 12px;
    display: block;
    margin-bottom: 4px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.bubble img:hover {
    opacity: 0.9;
}

.bubble .msg-text {
    /* text wrapper */
}

.bubble .edited-tag {
    font-size: 10px;
    opacity: 0.5;
    margin-left: 6px;
    font-style: italic;
}

.sender-name {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 3px;
    margin-left: 12px;
    font-weight: 500;
}

.message.sent .sender-name {
    display: none;
}

.time {
    font-size: 10px;
    color: #3a3a3a;
    margin-top: 3px;
    padding: 0 12px;
}

.message.sent .time {
    align-self: flex-end;
    color: #444;
}

.message.received .time {
    align-self: flex-start;
}

/* ==================== INPUT AREA ==================== */
.input-area {
    padding: 14px 16px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    z-index: 10;
}

#messageForm {
    display: flex;
    align-items: center;
    gap: 10px;
}

#messageForm input {
    flex: 1;
    background: #080808;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 12px 20px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 15px;
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s;
}

#messageForm input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-actions {
    display: flex;
    gap: 6px;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    padding: 0;
}

.icon-btn.send-btn {
    background: var(--accent);
    color: white;
    box-shadow: 0 2px 10px rgba(37, 99, 235, 0.25);
}

.icon-btn.send-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
}

.icon-btn.img-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.icon-btn.img-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: var(--accent-glow);
}

.icon-btn:active {
    transform: scale(0.9);
}

#imageInput {
    display: none;
}

/* Mic button */
.icon-btn.mic-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.icon-btn.mic-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}

.icon-btn.mic-btn.recording {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
    animation: recordPulse 1s infinite;
}

@keyframes recordPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}

/* Recording bar */
.recording-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--danger-light);
    border-left: 3px solid var(--danger);
    margin: 0 16px;
    border-radius: 0 8px 8px 0;
    font-size: 13px;
    color: var(--danger);
    animation: fadeIn 0.2s ease;
}

.recording-bar .rec-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    animation: recBlink 1s infinite;
}

@keyframes recBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

.recording-bar .rec-timer {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}

.recording-bar .rec-cancel {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
}

/* Custom voice player */
.voice-player {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 180px;
}

.voice-player audio {
    display: none;
}

.vp-play {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s;
}

.message.received .vp-play {
    background: rgba(255,255,255,0.08);
    color: var(--text-main);
}

.vp-play:hover {
    background: rgba(255,255,255,0.25);
}

.vp-play:active {
    transform: scale(0.92);
}

.vp-track {
    flex: 1;
    height: 4px;
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
    cursor: pointer;
    position: relative;
    min-width: 80px;
}

.message.received .vp-track {
    background: rgba(255,255,255,0.08);
}

.vp-progress {
    height: 100%;
    background: white;
    border-radius: 2px;
    width: 0%;
    transition: width 0.1s linear;
    position: relative;
}

.vp-progress::after {
    content: '';
    position: absolute;
    right: -5px;
    top: -3px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: white;
}

.message.received .vp-progress {
    background: var(--accent);
}

.message.received .vp-progress::after {
    background: var(--accent);
}

.vp-time {
    font-size: 11px;
    opacity: 0.7;
    min-width: 30px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Sending indicator bubble */
.sending-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    opacity: 0.7;
    padding: 12px 16px !important;
}

.sending-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==================== CONTEXT MENU ==================== */
.context-menu {
    position: fixed;
    z-index: 500;
    background: #0e0e0e;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 6px 0;
    min-width: 150px;
    box-shadow: 0 12px 40px rgba(0,0,0,0.6);
    animation: ctxIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes ctxIn {
    from { opacity: 0; transform: scale(0.92); }
    to { opacity: 1; transform: scale(1); }
}

.context-menu-item {
    padding: 11px 18px;
    font-size: 14px;
    color: var(--text-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s;
}

.context-menu-item:first-child {
    border-radius: 8px 8px 0 0;
}

.context-menu-item:last-child {
    border-radius: 0 0 8px 8px;
}

.context-menu-item:hover {
    background: var(--bg-surface-hover);
}

.context-menu-item.danger {
    color: var(--danger);
}

/* ==================== EDIT BAR ==================== */
.edit-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--accent-light);
    border-left: 3px solid var(--accent);
    margin: 0 16px;
    border-radius: 0 8px 8px 0;
    font-size: 13px;
    color: var(--accent);
}

.edit-bar span {
    flex: 1;
}

.edit-bar .cancel-edit {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 8px;
    transition: color 0.2s;
}

.edit-bar .cancel-edit:hover {
    color: var(--text-main);
}

/* ==================== LIGHTBOX ==================== */
.lightbox-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 2000;
    background: rgba(0,0,0,0.97);
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    animation: lbIn 0.25s ease;
    cursor: pointer;
}

@keyframes lbIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.lightbox-overlay img {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
    object-fit: contain;
    box-shadow: 0 0 60px rgba(0,0,0,0.5);
}

/* Date divider */
.date-divider {
    text-align: center;
    padding: 14px 0;
    font-size: 11px;
    color: var(--text-muted);
}

/* ==================== RESPONSIVE ==================== */

/* Tablets & Desktop */
@media (min-width: 520px) {
    body {
        background: #000;
    }

    .app-container {
        max-width: 500px;
        height: 92dvh;
        height: 92vh;
        border-radius: 18px;
        border: 1px solid var(--border-color);
        overflow: hidden;
        box-shadow: 0 0 80px rgba(0,0,0,0.5);
    }

    header {
        border-radius: 18px 18px 0 0;
    }

    .input-area {
        border-radius: 0 0 18px 18px;
    }

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

/* Mobile */
@media (max-width: 519px) {
    .app-container {
        max-width: 100%;
        height: 100%;
        height: 100dvh;
    }

    header {
        padding: 12px 14px;
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .avatar {
        width: 38px;
        height: 38px;
        font-size: 15px;
    }

    .details h1 {
        font-size: 14px;
    }

    .messages-area {
        padding: 12px;
    }

    .input-area {
        padding: 10px 10px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    #messageForm {
        gap: 6px;
    }

    #messageForm input[type="text"] {
        font-size: 16px;
        padding: 10px 14px;
    }

    .icon-btn {
        width: 40px;
        height: 40px;
    }

    .icon-btn svg {
        width: 18px;
        height: 18px;
    }

    .message {
        max-width: 85%;
    }

    .bubble {
        padding: 9px 12px;
        font-size: 14px;
        border-radius: 18px;
    }

    .voice-player {
        min-width: 150px;
    }

    .modal-content {
        padding: 28px 22px;
        margin: 0 12px;
    }

    .modal-header h2 {
        font-size: 20px;
    }
}

/* Landscape phone */
@media (max-height: 500px) and (orientation: landscape) {
    header { padding: 8px 16px; }
    .avatar { width: 32px; height: 32px; font-size: 14px; }
    .details h1 { font-size: 14px; }
    .messages-area { padding: 8px 12px; gap: 2px; }
    .input-area { padding: 8px 12px; }
    .icon-btn { width: 38px; height: 38px; }
    .bubble { padding: 7px 12px; font-size: 14px; }
}
