/* ========================================
   Telegram Simulator - Styles
   Cybernetic Immortality Exhibit
   ======================================== */

:root {
    /* Telegram Colors */
    --bg-primary: #17212b;
    --bg-secondary: #0e1621;
    --bg-header: #17212b;
    --bg-input: #242f3d;
    --bg-message-out: #2b5278;
    --bg-message-in: #182533;
    --text-primary: #ffffff;
    --text-secondary: #6c7883;
    --text-link: #6ab2f2;
    --accent: #5288c1;
    --accent-light: #64b5ef;
    --border-color: #0e1621;
    --typing-indicator: #6ab2f2;
    --unread-badge: #3390ec;
    --online-indicator: #4dcd5e;

    /* Layout */
    --max-width: 420px;
    --header-height: 56px;
    --input-height: 56px;
    --tabs-height: 44px;

    /* Typography */
    --font-family: 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-family);
    background: #000;
    color: var(--text-primary);
    display: flex;
    justify-content: center;
    align-items: center;
}

#app {
    /* Responsive width: 100% up to the point where width equals height (square) */
    /* Then caps at 100vh to maintain maximum square aspect */
    width: min(100%, 100vh);
    max-width: 100vh;
    /* Never wider than viewport height (square limit) */
    height: 100vh;
    max-height: 100%;
    background: var(--bg-secondary);
    position: relative;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
}

/* For very narrow screens, allow full width */
@media (max-width: 480px) {
    #app {
        width: 100%;
        max-width: 100%;
    }
}

/* ========================================
   Screens & Transitions
   ======================================== */

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    visibility: hidden;
}

.screen.active {
    transform: translateX(0);
    visibility: visible;
}

.screen.slide-left {
    transform: translateX(-30%);
}

/* ========================================
   Header
   ======================================== */

.header {
    height: var(--header-height);
    min-height: var(--header-height);
    background: var(--bg-header);
    display: flex;
    align-items: center;
    padding: 0 8px;
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
}

.header-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.header-title {
    font-size: 20px;
    font-weight: 500;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

.icon-btn:active {
    background: rgba(255, 255, 255, 0.12);
}

/* Chat Header */
.chat-header .header-center {
    justify-content: flex-start;
    margin-left: 4px;
}

.chat-info {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.chat-details {
    display: flex;
    flex-direction: column;
}

.chat-name {
    font-size: 16px;
    font-weight: 500;
    line-height: 1.3;
}

.chat-status {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.3;
}

.chat-status.typing {
    color: var(--typing-indicator);
}

/* ========================================
   Tabs
   ======================================== */

.tabs {
    height: var(--tabs-height);
    min-height: var(--tabs-height);
    background: var(--bg-header);
    display: flex;
    padding: 0 12px;
    gap: 4px;
    border-bottom: 1px solid var(--border-color);
}

.tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 20px;
    transition: background 0.2s, color 0.2s;
}

.tab:hover {
    background: rgba(255, 255, 255, 0.08);
}

.tab.active {
    background: var(--accent);
    color: var(--text-primary);
}

/* ========================================
   User List
   ======================================== */

.user-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.user-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    gap: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.user-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.user-item:active {
    background: rgba(255, 255, 255, 0.08);
}

.user-avatar-wrapper {
    position: relative;
    flex-shrink: 0;
}

.user-avatar {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    object-fit: cover;
}

.unread-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 20px;
    height: 20px;
    background: var(--unread-badge);
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    transform: scale(0);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.unread-badge.show {
    transform: scale(1);
}

.user-content {
    flex: 1;
    min-width: 0;
    border-bottom: 1px solid var(--border-color);
    padding: 10px 0;
}

.user-item:last-child .user-content {
    border-bottom: none;
}

.user-top-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    margin-bottom: 4px;
}

.user-name {
    font-size: 16px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-time {
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
    margin-left: 8px;
}

.user-last-message {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

/* ========================================
   Messages
   ======================================== */

.messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 8px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--bg-secondary);
}

.message {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    animation: messageAppear 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

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

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

.message.outgoing {
    background: var(--bg-message-out);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.incoming {
    background: var(--bg-message-in);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    margin-left: 8px;
    float: right;
    margin-top: 4px;
}

.message.outgoing .message-time {
    color: rgba(255, 255, 255, 0.6);
}

/* Typing Indicator Bubble */
.typing-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg-message-in);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

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

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

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

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

@keyframes typingDot {

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

    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* ========================================
   Input Area
   ======================================== */

.input-area {
    min-height: var(--input-height);
    background: var(--bg-header);
    display: flex;
    align-items: flex-end;
    padding: 8px;
    gap: 4px;
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: var(--bg-input);
    border-radius: 20px;
    padding: 8px 4px 8px 16px;
}

.message-input {
    flex: 1;
    min-height: 24px;
    max-height: 120px;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    line-height: 1.4;
    outline: none;
    resize: none;
    overflow-y: auto;
}

.message-input::placeholder {
    color: var(--text-secondary);
}

.send-btn {
    color: var(--accent-light);
}

.send-btn:hover {
    color: var(--text-primary);
}

/* Typing animation in input */
.message-input.typing-animation {
    animation: inputCursor 0.5s step-end infinite;
}

@keyframes inputCursor {

    0%,
    100% {
        border-right: 2px solid var(--text-primary);
    }

    50% {
        border-right: 2px solid transparent;
    }
}

/* ========================================
   Scrollbar
   ======================================== */

::-webkit-scrollbar {
    width: 6px;
}

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

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

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

/* ========================================
   Utility Classes
   ======================================== */

.hidden {
    display: none !important;
}

/* Date separator */
.date-separator {
    text-align: center;
    padding: 8px 16px;
    margin: 8px 0;
}

.date-separator span {
    background: rgba(0, 0, 0, 0.3);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

/* ========================================
   Click Cursor Animation
   ======================================== */

.click-cursor {
    position: fixed;
    width: 50px;
    height: 50px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transform: translate(-50%, -50%);
    transition: opacity 0.2s ease;
}

.click-cursor.visible {
    opacity: 1;
}

.click-cursor svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(2px 2px 4px rgba(0, 0, 0, 0.5));
}

.click-cursor.clicking {
    animation: clickPulse 0.3s ease-out;
}

@keyframes clickPulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
    }

    50% {
        transform: translate(-50%, -50%) scale(0.85);
    }

    100% {
        transform: translate(-50%, -50%) scale(1);
    }
}

/* Click ripple effect */
.click-ripple {
    position: fixed;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(100, 181, 239, 0.4);
    pointer-events: none;
    z-index: 999;
    transform: translate(-50%, -50%) scale(0);
    animation: rippleExpand 0.5s ease-out forwards;
}

@keyframes rippleExpand {
    0% {
        transform: translate(-50%, -50%) scale(0);
        opacity: 1;
    }

    100% {
        transform: translate(-50%, -50%) scale(2);
        opacity: 0;
    }
}

/* Highlight selected user */
.user-item.selected {
    background: rgba(100, 181, 239, 0.15);
}