:root {
    --tg-bg: #0e1621;
    --tg-panel: #17212b;
    --tg-border: #101921;
    --tg-text: #f5f5f5;
    --tg-muted: #7f91a4;
    --tg-primary: #5288c1;
    --tg-primary-hover: #4878a8;
    --tg-msg-sent: #2b5278;
    --tg-msg-received: #182533;
    --tg-divider: rgba(255, 255, 255, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Roboto', 'Segoe UI', Tahoma, Helvetica, sans-serif;
}

body.telegram-dark {
    background-color: var(--tg-bg);
    color: var(--tg-text);
    height: 100vh;
    display: flex;
    overflow: hidden;
    font-size: 15px;
    /* Telegram uses slightly smaller default font */
}

/* Auth Pages (Keeping similar but adapted colors) */
.auth-container {
    background: var(--tg-panel);
    border: 1px solid var(--tg-border);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 360px;
    margin: auto;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

/* Auth Layout structure */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--tg-muted);
}

.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    color: #fff;
}

.btn:hover {
    background: var(--tg-primary-hover);
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 13px;
    color: var(--tg-muted);
}

.auth-switch a {
    color: var(--tg-primary);
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* Toast Notification */
#toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--tg-panel);
    border: 1px solid var(--tg-border);
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    transition: transform 0.3s ease;
    z-index: 3000;
}

#toast.show {
    transform: translateX(-50%) translateY(0);
}

/* Chat Layout structure */
.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* SIDEBAR */
.sidebar {
    width: 30vw;
    min-width: 300px;
    max-width: 420px;
    background: var(--tg-panel);
    border-right: 1px solid var(--tg-border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 15px;
}

.menu-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    color: var(--tg-muted);
}

.menu-icon:hover {
    background: rgba(255, 255, 255, 0.05);
}

.menu-icon svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

.search-bar {
    flex: 1;
    background: #242f3d;
    border-radius: 20px;
    display: flex;
    align-items: center;
    padding: 0 15px;
    height: 40px;
    border: 1px solid transparent;
}

.search-bar:focus-within {
    border-color: var(--tg-primary);
    background: var(--tg-bg);
}

.search-icon {
    width: 18px;
    height: 18px;
    fill: var(--tg-muted);
    margin-right: 10px;
}

.search-bar input {
    background: none;
    border: none;
    color: white;
    outline: none;
    font-size: 14px;
    width: 100%;
}

/* STORIES CAROUSEL */
.stories-container {
    display: flex;
    gap: 12px;
    padding: 10px 15px;
    overflow-x: auto;
    border-bottom: 1px solid var(--tg-border);
}

.stories-container::-webkit-scrollbar {
    display: none;
}

.story {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    min-width: 60px;
}

.story-avatar-wrapper {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    padding: 2px;
    background: linear-gradient(45deg, #38A1F3, #8B5CF6);
    /* Unread story gradient */
}

.story.read .story-avatar-wrapper {
    background: var(--tg-muted);
    /* Read story */
}

.story.add-story .story-avatar-wrapper {
    background: none;
    border: 1px dashed var(--tg-primary);
}

.story-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background-color: var(--tg-panel);
    border: 2px solid var(--tg-panel);
    object-fit: cover;
}

.story-avatar.add-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    color: var(--tg-primary);
    background: none;
    border: none;
}

.story-name {
    font-size: 11px;
    color: var(--tg-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 60px;
    text-align: center;
}


/* CHAT LIST */
.chat-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
}

.chat-list::-webkit-scrollbar {
    width: 6px;
}

.chat-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.chat-item {
    padding: 10px 15px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: background 0.1s;
}

.chat-item:hover {
    background: #202b36;
}

.chat-item.active {
    background: var(--tg-primary);
}

.avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.chat-item-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 12px;
    color: var(--tg-muted);
}

.chat-item.active .chat-item-time,
.chat-item.active .chat-item-msg {
    color: rgba(255, 255, 255, 0.8);
}

.chat-item-msg {
    font-size: 14px;
    color: var(--tg-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* MAIN CHAT AREA */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--tg-bg);
    /* Fallback */
}

/* Background pattern (like telegram) */
.telegram-bg::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('data:image/svg+xml,%3Csvg opacity="0.04" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"%3E%3Cpath d="M10 10h80v80h-80z" fill="white"/%3E%3C/svg%3E');
    /* Placeholder for pattern */
    background-size: 300px;
    z-index: 0;
    pointer-events: none;
}

.chat-header {
    height: 60px;
    background: var(--tg-panel);
    display: flex;
    align-items: center;
    padding: 0 20px;
    border-bottom: 1px solid var(--tg-border);
    z-index: 10;
    justify-content: space-between;
}

.header-avatar {
    width: 40px;
    height: 40px;
    margin-right: 12px;
}

.chat-info {
    display: flex;
    align-items: center;
    flex: 1;
    cursor: pointer;
}

.chat-title-status h3 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 2px;
}

.status-text {
    font-size: 13px;
    color: var(--tg-primary);
    /* Online status color usually */
}

.chat-actions {
    display: flex;
    gap: 15px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--tg-muted);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.05);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
}

/* MESSAGES */
.messages-container {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1;
}

.empty-state {
    margin: auto;
    background: rgba(0, 0, 0, 0.3);
    padding: 6px 14px;
    border-radius: 14px;
    font-size: 14px;
    color: #fff;
}

.message {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 12px;
    line-height: 1.4;
    word-wrap: break-word;
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.message.sent {
    align-self: flex-end;
    background: var(--tg-msg-sent);
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: var(--tg-msg-received);
    border-bottom-left-radius: 4px;
}

.msg-file {
    max-width: 300px;
    border-radius: 8px;
    margin-bottom: 5px;
}

.msg-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    align-self: flex-end;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 4px;
    margin-right: -4px;
}

.msg-meta .ticks {
    width: 16px;
    height: 16px;
    fill: #5eb5f7;
    /* Telegram read tick color */
}

.msg-meta .ticks.unread {
    fill: rgba(255, 255, 255, 0.6);
}

/* INPUT AREA */
.chat-input-area {
    background: var(--tg-panel);
    padding: 10px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 10;
}

.chat-input {
    flex: 1;
    background: var(--tg-bg);
    border: none;
    padding: 12px 20px;
    border-radius: 20px;
    color: white;
    font-size: 15px;
    outline: none;
}

.chat-input::placeholder {
    color: var(--tg-muted);
}

.send-btn-telegram {
    color: var(--tg-primary);
}

.send-btn-telegram:hover {
    color: var(--tg-primary-hover);
    background: rgba(82, 136, 193, 0.1);
}


/* DRAWERS AND MODALS */
.drawer-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
}

.main-menu-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    background: var(--tg-panel);
    z-index: 2001;
    transition: transform 0.3s ease;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.4);
}

.main-menu-drawer.hidden {
    transform: translateX(-100%);
}

.drawer-header {
    padding: 24px 24px 16px 24px;
    background: #242f3d;
    border-bottom: 1px solid var(--tg-border);
}

.drawer-header h3 {
    margin-bottom: 4px;
}

.drawer-list {
    list-style: none;
    padding: 10px 0;
}

.drawer-list li {
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    cursor: pointer;
    font-weight: 500;
    color: var(--tg-text);
}

.drawer-list li:hover {
    background: rgba(255, 255, 255, 0.05);
}

.drawer-list li svg {
    width: 24px;
    height: 24px;
    fill: var(--tg-muted);
}

.mobile-only {
    display: none;
}

.hidden {
    display: none !important;
}

/* Auth specific fixes */
#login-form-container input,
#register-form-container input,
#reset-form-container input {
    background: #242f3d;
    border: 1px solid var(--tg-border);
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--tg-text);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

#login-form-container input:focus,
#register-form-container input:focus,
#reset-form-container input:focus {
    border-color: var(--tg-primary);
}

#login-form-container .btn,
#register-form-container .btn,
#reset-form-container .btn {
    background: var(--tg-primary);
}

.auth-container h2 {
    text-align: center;
    margin-bottom: 24px;
    font-weight: 500;
}

/* MOBILE FIX */
@media(max-width: 768px) {
    .app-container {
        position: relative;
    }

    .sidebar {
        position: absolute;
        width: 100%;
        max-width: 100%;
        z-index: 100;
        transition: transform 0.3s;
    }

    .sidebar.hide-on-mobile {
        transform: translateX(-100%);
    }

    .chat-area {
        width: 100%;
    }

    .mobile-only {
        display: flex;
        margin-right: 15px;
        color: var(--tg-muted);
    }

    .chat-header {
        padding-left: 10px;
    }

    .chat-info {
        min-width: 0;
    }
}