/* WAP-Chat 2.0 — Telegram Desktop Theme */
@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@400;500;600;700&display=swap');

:root {
    --bg: #17212b;
    --bg-darker: #0e1621;
    --bg-panel: #17212b;
    --bg-message: #182533;
    --bg-message-own: #2b5278;
    --bg-input: #242f3d;
    --bg-hover: #202b36;
    --bg-selected: #2b5278;
    --border: #0e1621;
    --border-light: #1c2a3a;
    --text: #f5f5f5;
    --text-secondary: #6c7883;
    --text-muted: #546778;
    --accent: #5eb5f7;
    --accent-hover: #4aa3e0;
    --accent-bg: #2b5278;
    --green: #4fae4e;
    --danger: #e53935;
    --warning: #f5a623;
    --online: #4fae4e;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-bubble: 18px;
    --font: 'Rubik', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 14px; overflow-x: hidden; width: 100%; height: 100%; }
body {
    font-family: var(--font); background: var(--bg); color: var(--text);
    min-height: 100vh; min-height: 100dvh;
    overflow: hidden; overflow-x: hidden;
    width: 100%; max-width: 100vw; height: 100%;
    -webkit-text-size-adjust: 100%;
    -webkit-overflow-scrolling: touch;
    /* iOS safe area */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}
a { color: var(--accent); text-decoration: none; transition: color .15s; }
a:hover { color: var(--accent-hover); }
::selection { background: var(--accent-bg); color: #fff; }

/* ═══ LAYOUT ═══ */
.app-wrapper { display: flex; height: 100vh; overflow: hidden; }

/* ── SIDEBAR ── */
.sidebar {
    width: 260px; height: 100vh; background: var(--bg-darker);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; z-index: 100; flex-shrink: 0;
}
.sidebar-logo {
    padding: 12px 16px; display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
}
.sidebar-logo h2 { font-size: 15px; font-weight: 600; color: var(--text); letter-spacing: -0.3px; }
.sidebar-logo small { color: var(--text-muted); font-size: 10px; font-weight: 400; }

.sidebar-nav { flex: 1; padding: 6px 8px; overflow-y: auto; }
.sidebar-nav::-webkit-scrollbar { width: 5px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }

.sidebar-nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; margin-bottom: 2px;
    color: var(--text); font-size: 13.5px; font-weight: 400;
    border-radius: var(--radius-sm); transition: all .12s ease;
}
.sidebar-nav a:hover { background: var(--bg-hover); }
.sidebar-nav a.active { background: var(--accent-bg); color: #fff; }
.sidebar-nav a.push-on { color: var(--green); font-size: 12px; }
.sidebar-nav a.push-off { color: var(--text-muted); font-size: 12px; }
.sidebar-nav a.push-on:hover, .sidebar-nav a.push-off:hover { background: var(--bg-hover); }
.sidebar-nav .badge-count {
    margin-left: auto; background: var(--accent); color: #fff;
    font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 12px; min-width: 20px; text-align: center;
}

.sidebar-user {
    padding: 12px 16px; border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px;
}
.sidebar-user .avatar-sm { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.sidebar-user .nickname { font-size: 13px; font-weight: 500; }
.sidebar-user .role-tag { font-size: 11px; }

.main-content { flex: 1; margin-left: 260px; padding: 0; overflow-y: auto; height: 100vh; }

/* ═══ CARDS ═══ */
.card {
    background: var(--bg-panel); border: 1px solid var(--border-light);
    border-radius: var(--radius); padding: 24px; margin-bottom: 16px;
}
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-header h2 { font-size: 17px; font-weight: 600; }
.card-header h3 { font-size: 15px; font-weight: 600; }

/* ═══ BUTTONS ═══ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 20px; border-radius: var(--radius-sm); font-size: 13.5px;
    font-weight: 500; font-family: var(--font); border: none;
    cursor: pointer; transition: all .15s ease; text-decoration: none; line-height: 1.3;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-secondary { background: var(--bg-input); color: var(--text); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c62828; }
.btn-success { background: var(--green); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-xs { padding: 4px 10px; font-size: 11px; border-radius: 6px; }

/* ═══ FORMS ═══ */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-secondary); font-weight: 500; }
.form-control {
    width: 100%; padding: 10px 14px; background: var(--bg-input);
    border: 2px solid transparent; border-radius: var(--radius-sm);
    color: var(--text); font-size: 16px; font-family: var(--font); transition: border-color .2s;
    -webkit-appearance: none; appearance: none;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { appearance: auto; }

/* ═══ TABLES ═══ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border-light); font-size: 13px; }
th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }
tr:hover td { background: var(--bg-hover); }

/* ═══ ALERTS ═══ */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin: 16px 20px; font-size: 13.5px; }
.alert-success { background: rgba(79,174,78,.15); border: 1px solid rgba(79,174,78,.3); color: #8be28a; }
.alert-error { background: rgba(229,57,53,.15); border: 1px solid rgba(229,57,53,.3); color: #ff8a80; }
.alert-warning { background: rgba(245,166,35,.15); border: 1px solid rgba(245,166,35,.3); color: #ffd180; }

/* ═══ CHAT — Telegram-style bubbles ═══ */
.chat-container { display: flex; gap: 0; height: 100vh; }
.chat-messages-area { flex: 1; display: flex; flex-direction: column; background: var(--bg); }

.chat-room-header {
    padding: 10px 16px; background: var(--bg-darker); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px; flex-shrink: 0;
}
.chat-room-back {
    color: var(--text-secondary); font-size: 20px; text-decoration: none; line-height: 1;
}

.chat-messages {
    flex: 1; overflow-y: auto; padding: 12px 20px;
    display: flex; flex-direction: column; gap: 2px;
    background:
        radial-gradient(circle at 20% 80%, rgba(43,82,120,.12) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(94,181,247,.06) 0%, transparent 50%),
        var(--bg);
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 3px; }

.chat-input-area {
    padding: 10px 12px; background: var(--bg-darker);
    display: flex; gap: 8px; align-items: flex-end; border-top: 1px solid var(--border);
}
.chat-input-area textarea {
    flex: 1; resize: none; max-height: 140px; min-height: 40px;
    padding: 10px 16px; background: var(--bg-input); border: none;
    border-radius: 20px; color: var(--text); font-size: 16px; font-family: var(--font); line-height: 1.4;
    -webkit-appearance: none; appearance: none;
}
.chat-input-area textarea:focus { outline: none; }
.chat-input-area textarea::placeholder { color: var(--text-muted); }
.chat-input-area .btn-primary {
    width: 40px; height: 40px; border-radius: 50%; padding: 0;
    display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0;
}

/* ── Bubbles ── */
.message {
    display: flex; gap: 8px; padding: 3px 0; max-width: 70%;
    animation: msgIn .2s ease;
}
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.message .msg-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex-shrink: 0; margin-top: 2px; cursor: pointer; }
.message .msg-content {
    background: var(--bg-message); border-radius: 0 var(--radius-bubble) var(--radius-bubble) var(--radius-bubble);
    padding: 7px 12px 6px; min-width: 0; position: relative; box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.message .msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.message .msg-nick { font-weight: 600; font-size: 13px; cursor: pointer; }
.message .msg-nick:hover { text-decoration: underline; }
.message .msg-role { font-size: 10px; padding: 1px 6px; border-radius: 4px; color: #fff; font-weight: 500; }
.message .msg-time { font-size: 10px; color: var(--text-muted); margin-left: auto; white-space: nowrap; }
.message .msg-body { font-size: 14px; line-height: 1.45; word-wrap: break-word; }
.message .msg-edited { font-size: 10px; color: var(--text-muted); font-style: italic; }
.message .msg-actions {
    display: none; gap: 4px; position: absolute; top: -6px; right: 8px;
    background: var(--bg-darker); border-radius: 6px; padding: 2px 4px; box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.message:hover .msg-actions { display: flex; }

/* Own messages */
.message.own { flex-direction: row-reverse; margin-left: auto; }
.message.own .msg-content {
    background: var(--bg-message-own);
    border-radius: var(--radius-bubble) 0 var(--radius-bubble) var(--radius-bubble);
}
.message.own .msg-nick { display: none; }
.message.own .msg-role { display: none; }
.message.own .msg-header { justify-content: flex-end; }

/* ── Right panel ── */
.chat-users-panel {
    width: 240px; background: var(--bg-darker); border-left: 1px solid var(--border);
    padding: 0; overflow-y: auto; flex-shrink: 0;
}
.chat-users-panel h4 {
    font-size: 11px; color: var(--text-muted); text-transform: uppercase;
    padding: 14px 16px 6px; letter-spacing: 0.5px;
}
.online-user {
    display: flex; align-items: center; gap: 10px; padding: 8px 16px;
    font-size: 13px; cursor: pointer; transition: background .1s; color: var(--text);
}
.online-user:hover { background: var(--bg-hover); color: var(--text); }
.online-user .avatar-xs { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.online-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--online); flex-shrink: 0; box-shadow: 0 0 0 2px var(--bg-darker); }

/* ═══ ROOM LIST ═══ */
.room-card {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px; background: transparent; border: none;
    border-bottom: 1px solid var(--border-light); cursor: pointer;
    transition: background .1s; border-radius: 0; margin: 0;
}
.room-card:hover { background: var(--bg-hover); border-color: var(--border-light); }
.room-card .room-info { flex: 1; min-width: 0; }
.room-card .room-name { font-weight: 500; font-size: 14px; }
.room-card .room-desc {
    font-size: 13px; color: var(--text-secondary); margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-card .room-meta { text-align: right; font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.room-type-badge {
    font-size: 9px; padding: 2px 7px; border-radius: 4px;
    background: var(--accent-bg); color: var(--accent); text-transform: uppercase; font-weight: 600;
}

/* ═══ PROFILE ═══ */
.profile-header { display: flex; gap: 24px; align-items: flex-start; margin-bottom: 24px; }
.profile-avatar {
    width: 110px; height: 110px; border-radius: 50%; object-fit: cover;
    border: 3px solid var(--accent-bg); box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.profile-info { flex: 1; }
.profile-info h1 { font-size: 22px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.profile-info .role-badge { font-size: 11px; padding: 3px 10px; border-radius: 6px; color: #fff; font-weight: 500; }
.profile-info .custom-status { color: var(--text-secondary); font-style: italic; margin-top: 4px; font-size: 13px; }
.profile-stats { display: flex; gap: 20px; margin-top: 14px; }
.profile-stats .stat { text-align: center; background: var(--bg-input); padding: 12px 18px; border-radius: var(--radius-sm); }
.profile-stats .stat-value { font-size: 20px; font-weight: 700; color: var(--accent); }
.profile-stats .stat-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 2px; }

/* ═══ DIALOGS ═══ */
.dialog-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 20px; border-bottom: 1px solid var(--border-light);
    cursor: pointer; transition: background .1s;
}
.dialog-item:hover { background: var(--bg-hover); }
.dialog-item .avatar-md { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.dialog-item .dialog-info { flex: 1; min-width: 0; }
.dialog-item .dialog-nick { font-weight: 500; font-size: 14px; }
.dialog-item .dialog-last-msg { font-size: 13px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog-item .dialog-time { font-size: 11px; color: var(--text-muted); }
.dialog-item .unread-badge { background: var(--accent); color: #fff; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 12px; min-width: 20px; text-align: center; }

/* ═══ LIKE ═══ */
.like-btn {
    cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
    font-size: 14px; padding: 6px 14px; border-radius: 20px;
    border: 1px solid var(--border-light); background: transparent;
    color: var(--text-secondary); transition: all .15s; font-family: var(--font);
}
.like-btn:hover { border-color: #e53935; color: #e53935; }
.like-btn.liked { border-color: #e53935; color: #e53935; background: rgba(229,57,53,.1); }

/* ═══ PAGINATION ═══ */
.pagination { display: flex; gap: 4px; margin-top: 20px; justify-content: center; }
.pagination a, .pagination span { padding: 6px 12px; border-radius: var(--radius-sm); font-size: 13px; background: var(--bg-input); color: var(--text-secondary); }
.pagination a:hover { background: var(--bg-hover); color: var(--text); }
.pagination .active { background: var(--accent); color: #fff; }

/* ═══ UTILITIES ═══ */
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-danger { color: var(--danger); }
.text-success { color: var(--green); }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.hidden { display: none; }
.avatar-placeholder { display: flex; align-items: center; justify-content: center; background: var(--accent-bg); color: #fff; font-weight: 600; border-radius: 50%; }
.page-padded { padding: 24px 30px; }

/* ═══ SEARCH USERS ═══ */
.search-user-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 20px; border-bottom: 1px solid var(--border-light);
    color: var(--text); transition: background .1s; cursor: pointer; text-decoration: none;
}
.search-user-item:hover { background: var(--bg-hover); color: var(--text); }
.search-user-avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.search-user-info { flex: 1; min-width: 0; }
.search-user-nick { display: flex; align-items: center; gap: 6px; font-weight: 500; font-size: 14px; }
.search-user-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }
::-webkit-scrollbar-track { background: transparent; }

/* ═══ MOBILE ═══ */
.mobile-topbar {
    display: none; position: fixed; top: 0; left: 0; right: 0; z-index: 200;
    height: calc(52px + env(safe-area-inset-top, 0px));
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--bg-darker); border-bottom: 1px solid var(--border);
    padding-left: 14px; padding-right: 14px;
    align-items: center; justify-content: space-between;
}
.mobile-topbar-title { font-weight: 600; font-size: 16px; color: var(--text); }
.mobile-topbar-right { display: flex; align-items: center; gap: 14px; font-size: 18px; }
.mobile-topbar-right a { color: var(--text-secondary); position: relative; }
.mobile-pm-link { position: relative; }
.mobile-pm-badge {
    position: absolute; top: -6px; right: -10px; background: var(--accent); color: #fff;
    font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
.mobile-menu-btn {
    width: 28px; height: 20px; background: none; border: none;
    cursor: pointer; padding: 0; display: flex; flex-direction: column; justify-content: space-between;
}
.mobile-menu-btn span { display: block; width: 100%; height: 2px; background: var(--text); border-radius: 1px; transition: all .25s; }
.mobile-menu-btn.active span:nth-child(1) { transform: translateY(9px) rotate(45deg); }
.mobile-menu-btn.active span:nth-child(2) { opacity: 0; }
.mobile-menu-btn.active span:nth-child(3) { transform: translateY(-9px) rotate(-45deg); }
.sidebar-overlay { display: none; position: fixed; inset: 0; z-index: 99; background: rgba(0,0,0,.55); backdrop-filter: blur(3px); }
.sidebar-overlay.open { display: block; }

@media (max-width: 768px) {
    html { overflow: hidden; height: 100%; }
    body { overflow: hidden; max-width: 100vw; height: 100%; margin: 0; padding: 0; }

    .mobile-topbar {
        display: flex;
        /* height already includes safe-area-inset-top via the base rule */
    }

    /* Non-chat pages: scroll normally below topbar */
    .main-content {
        margin-left: 0; padding: 0;
        padding-top: calc(52px + env(safe-area-inset-top, 0px));
        height: 100%; overflow-y: auto; overflow-x: hidden;
    }

    .sidebar { display: none; position: fixed; top: 0; left: 0; bottom: 0; width: 280px; z-index: 300; transform: translateX(-100%); transition: transform .25s; }
    .sidebar.open { display: flex; transform: translateX(0); }
    .chat-users-panel { display: none; }

    /* Chat pages: fixed layout filling the screen */
    .chat-container {
        display: flex; flex-direction: column;
        position: fixed;
        top: calc(52px + env(safe-area-inset-top, 0px));
        left: 0; right: 0; bottom: 0;
        overflow: hidden;
    }

    /* When inside a chat room/dialog: hide global topbar, room header becomes the top bar */
    .chat-page-active {
        top: 0 !important;
    }
    .chat-page-active .chat-room-header {
        padding-top: calc(10px + env(safe-area-inset-top, 0px));
    }

    .chat-messages-area {
        display: flex; flex-direction: column;
        flex: 1; min-height: 0; overflow: hidden;
    }
    .chat-messages {
        flex: 1; min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    .chat-input-area {
        flex-shrink: 0;
        padding: 8px 10px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
        background: var(--bg-darker);
    }

    .message { max-width: 88%; }
    .profile-header { flex-direction: column; align-items: center; text-align: center; }
    .profile-stats { justify-content: center; flex-wrap: wrap; }
    .room-card { padding: 12px 14px; }
    .dialog-item { padding: 10px 14px; gap: 10px; }
    .flex.gap-2 { flex-direction: column; }
    .card { padding: 16px; }
    .page-padded { padding: 14px; }
    .table-wrap { font-size: 12px; overflow-x: auto; }
    th, td { padding: 6px 8px; }
    .alert { margin: 10px 14px; }
}
