@import url('vazirmatn.css');

:root {
    --bale-primary: #00A693;
    --bale-primary-dark: #008F7F;
    --bale-primary-light: #D9FDD3;
    --bale-bg: #F0F2F5;
    --bale-sidebar: #FFFFFF;
    --bale-nav: #FFFFFF;
    --bale-text: #111B21;
    --bale-text-secondary: #667781;
    --bale-border: #E9EDEF;
    --bale-bubble-in: #FFFFFF;
    --bale-bubble-out: #D9FDD3;
    --bale-danger: #EA0038;
    --bale-link: #027EB5;
    --bale-nav-width: 72px;
    --bale-sidebar-width: 380px;
    --bale-search-width: 340px;
    --bale-radius: 12px;
    --bale-shadow: 0 8px 32px rgba(11, 20, 26, 0.16);
}

* { box-sizing: border-box; }

html, body.bale-body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    background: var(--bale-bg);
    color: var(--bale-text);
    direction: rtl;
}

.bale-app {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Nav Rail */
.bale-nav-rail {
    width: var(--bale-nav-width);
    background: var(--bale-nav);
    border-left: 1px solid var(--bale-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    flex-shrink: 0;
}

.bale-logo {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    text-decoration: none;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
}

.bale-logo picture,
.bale-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.bale-nav-toggle {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--bale-text-secondary);
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .2s, color .2s;
}

.bale-nav-toggle:hover {
    background: var(--bale-bg);
    color: var(--bale-text);
}

.bale-nav-toggle svg { width: 22px; height: 22px; }

/* Collapsed nav rail */
html.bale-nav-collapsed-init .bale-nav-rail,
body.bale-nav-collapsed .bale-nav-rail {
    width: 0;
    padding: 0;
    border-left: none;
    overflow: visible;
}

html.bale-nav-collapsed-init .bale-nav-rail > *:not(.bale-nav-toggle),
body.bale-nav-collapsed .bale-nav-rail > *:not(.bale-nav-toggle) {
    display: none;
}

html.bale-nav-collapsed-init .bale-nav-toggle,
body.bale-nav-collapsed .bale-nav-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 200;
    margin: 0;
    background: var(--bale-sidebar);
    box-shadow: var(--bale-shadow);
}

.bale-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 0;
    width: 100%;
    text-decoration: none;
    color: var(--bale-text-secondary);
    font-size: 11px;
    position: relative;
    transition: color .2s;
}

.bale-nav-item svg { width: 24px; height: 24px; }

.bale-nav-item.active {
    color: var(--bale-primary);
}

.bale-nav-item.active::after {
    content: '';
    position: absolute;
    right: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    background: var(--bale-primary);
    border-radius: 3px 0 0 3px;
}

.bale-nav-spacer { flex: 1; }

.bale-nav-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    cursor: pointer;
}

/* Sidebar */
.bale-sidebar {
    width: var(--bale-sidebar-width);
    background: var(--bale-sidebar);
    border-left: 1px solid var(--bale-border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    min-height: 0;
    overflow: hidden;
}

.bale-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    min-height: 60px;
    border-bottom: 1px solid var(--bale-border);
}

.bale-sidebar-header h1 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.bale-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    color: var(--bale-text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.bale-icon-btn:hover { background: var(--bale-bg); }

.bale-chat-item-muted { font-size: 12px; margin-inline-start: 4px; opacity: .7; }

.bale-mute-btn { position: relative; }
.bale-mute-btn.is-muted { color: var(--bale-danger, #c0392b); }
.bale-mute-btn.is-muted::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 20%;
    right: 20%;
    height: 2px;
    background: currentColor;
    transform: rotate(-45deg);
    border-radius: 2px;
}

.bale-notify-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: #E7F8F5;
    font-size: 13px;
    color: var(--bale-text);
}

.bale-notify-banner[hidden] { display: none; }
.bale-notify-banner[role="button"] { cursor: pointer; }
.bale-notify-banner[role="button"]:hover { filter: brightness(.97); }
.bale-notify-banner .close { margin-right: auto; cursor: pointer; }

.push-enable-body { text-align: center; }
.push-enable-icon { font-size: 48px; margin-bottom: 12px; }
.push-enable-desc {
    font-size: 14px;
    line-height: 1.7;
    color: var(--bale-text-secondary, #667781);
    margin: 0 0 20px;
}
.push-enable-status {
    font-size: 13px;
    margin: -8px 0 12px;
    color: var(--bale-primary);
}
.push-enable-status.error { color: #c0392b; }
.push-enable-btn { width: 100%; margin-bottom: 8px; }
.push-enable-later {
    width: 100%;
    background: transparent;
    color: var(--bale-text-secondary, #667781);
}

.push-manage-desc {
    font-size: 13px;
    line-height: 1.7;
    color: var(--bale-text-secondary, #667781);
    margin: 0 0 16px;
}
.push-manage-list { display: flex; flex-direction: column; gap: 8px; }
.push-manage-empty {
    text-align: center;
    font-size: 13px;
    color: var(--bale-text-secondary, #667781);
    padding: 16px 0;
}
.push-manage-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border: 1px solid var(--bale-border, #E9EDEF);
    border-radius: 10px;
}
.push-manage-info { flex: 1; min-width: 0; }
.push-manage-title {
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}
.push-manage-current {
    font-size: 11px;
    font-weight: 500;
    color: var(--bale-primary);
    background: #E7F8F5;
    border-radius: 6px;
    padding: 1px 6px;
}
.push-manage-meta {
    font-size: 12px;
    color: var(--bale-text-secondary, #667781);
    margin-top: 3px;
}
.push-manage-delete {
    flex-shrink: 0;
    font-size: 13px;
    color: #c0392b;
    background: transparent;
    border: 1px solid #c0392b;
    border-radius: 8px;
    padding: 5px 14px;
    cursor: pointer;
}
.push-manage-delete:hover { background: #c0392b; color: #fff; }
.push-manage-delete:disabled { opacity: .6; cursor: default; }

.bale-tabs {
    display: flex;
    padding: 0 8px;
    border-bottom: 1px solid var(--bale-border);
    overflow-x: auto;
}

.bale-tab {
    flex: 1;
    text-align: center;
    padding: 12px 8px;
    font-size: 13px;
    color: var(--bale-text-secondary);
    cursor: pointer;
    border: none;
    background: none;
    position: relative;
    white-space: nowrap;
    text-decoration: none;
}

.bale-tab.active {
    color: var(--bale-primary);
    font-weight: 600;
}

.bale-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    background: var(--bale-primary);
    border-radius: 3px 3px 0 0;
}

.bale-tab-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--bale-primary);
    color: #fff;
    border-radius: 999px;
    font-size: 11px;
    margin-right: 4px;
}

.bale-chat-list { flex: 1; min-height: 0; overflow-y: auto; }

.bale-chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--bale-border);
    transition: background .15s;
}

.bale-chat-item:hover, .bale-chat-item.active {
    background: #F0F2F5;
}

.bale-chat-item.active { background: #E7F8F5; }

.bale-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: #DFE5E7;
}

.bale-avatar-sm { width: 40px; height: 40px; }
.bale-avatar-lg { width: 100px; height: 100px; }

.bale-chat-item-body { flex: 1; min-width: 0; }

.bale-chat-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.bale-chat-item-name {
    font-weight: 500;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bale-chat-item-time {
    font-size: 12px;
    color: var(--bale-text-secondary);
    flex-shrink: 0;
}

.bale-chat-item-preview {
    font-size: 13px;
    color: var(--bale-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bale-unread-badge {
    min-width: 20px;
    height: 20px;
    background: var(--bale-primary);
    color: #fff;
    border-radius: 999px;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.bale-verified {
    color: #1DA1F2;
    font-size: 14px;
    margin-right: 2px;
}

/* Main area */
.bale-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    position: relative;
    background: #E4DDD6;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c8c0b8' fill-opacity='0.25'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.bale-scroll-to-bottom {
    position: absolute;
    right: 22px;
    bottom: 84px;
    z-index: 20;
    width: 46px;
    height: 46px;
    border: none;
    border-radius: 50%;
    background: var(--bale-surface, #fff);
    color: var(--bale-text-secondary, #54656f);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18), 0 2px 8px rgba(0, 0, 0, 0.12);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateY(8px) scale(0.85);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.bale-scroll-to-bottom svg {
    width: 24px;
    height: 24px;
}

.bale-scroll-to-bottom.is-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.bale-scroll-to-bottom:hover {
    color: var(--bale-primary, #168f7c);
}

.bale-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--bale-text-secondary);
    text-align: center;
    padding: 40px;
}

.bale-empty-state img { width: 280px; opacity: .85; margin-bottom: 24px; }

.bale-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bale-sidebar);
    border-bottom: 1px solid var(--bale-border);
    min-height: 60px;
}

.bale-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.bale-chat-header-name { font-weight: 600; font-size: 15px; }
.bale-chat-header-status { font-size: 13px; color: var(--bale-text-secondary); }

.bale-chat-header-actions { display: flex; gap: 4px; }

.bale-pinned-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    padding: 8px 12px;
    background: #F8FAFA;
    border-bottom: 1px solid var(--bale-border);
    border-right: 3px solid var(--bale-primary);
}

.bale-pinned-bar.hidden { display: none; }

.bale-pinned-bar-inner {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.bale-pinned-nav {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--bale-primary);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bale-pinned-nav:hover { background: rgba(0, 168, 132, 0.1); }
.bale-pinned-nav.hidden { display: none; }

.bale-pinned-bar-content { text-align: right; flex: 1; min-width: 0; }
.bale-pinned-file-icon { width: 32px; height: 32px; font-size: 9px; flex-shrink: 0; }
.bale-pinned-file-icon.hidden { display: none; }

.bale-pinned-bar-title {
    color: var(--bale-primary);
    font-size: 13px;
    font-weight: 500;
}

.bale-pinned-bar-preview {
    font-size: 12px;
    color: var(--bale-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bale-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 60px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.bale-date-separator {
    align-self: center;
    background: var(--bale-surface);
    padding: 4px 12px;
    border-radius: 8px;
    font-size: 12px;
    color: var(--bale-text-secondary);
    margin: 12px 0;
    box-shadow: 0 1px 2px rgba(0,0,0,.08);
}

.bale-message {
    max-width: 65%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.bale-message-inner {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    max-width: 100%;
}

.bale-message-inner .bale-bubble {
    flex: 1;
    min-width: 0;
}

.bale-msg-menu-btn {
    display: none;
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    padding: 0;
    margin-bottom: 6px;
    border: none;
    background: transparent;
    color: var(--bale-text-secondary);
    opacity: 0.45;
    border-radius: 50%;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 2;
    transition: opacity 0.15s ease, background 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.bale-msg-menu-btn:active,
.bale-msg-menu-btn:focus-visible {
    opacity: 0.9;
    background: rgba(0, 0, 0, 0.06);
    outline: none;
}

/* RTL: flex-start = راست، flex-end = چپ */
.bale-message.incoming { align-self: flex-end; }
.bale-message.outgoing { align-self: flex-start; }

.bale-bubble {
    padding: 6px 8px 4px;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(0,0,0,.08);
    position: relative;
    overflow: hidden;
    max-width: 100%;
    min-width: 0;
}

.bale-message.incoming .bale-bubble { background: var(--bale-bubble-in); }
.bale-message.outgoing .bale-bubble { background: var(--bale-bubble-out); }

.bale-message.selected .bale-bubble {
    outline: 2px solid var(--bale-primary);
    outline-offset: 2px;
}

.bale-message.highlighted .bale-bubble {
    outline: 2px solid var(--bale-primary);
    outline-offset: 2px;
    animation: bale-highlight-pulse 1.5s ease;
}

@keyframes bale-highlight-pulse {
    0%, 100% { outline-color: var(--bale-primary); }
    50% { outline-color: transparent; }
}

.bale-forward-label {
    font-size: 12px;
    color: var(--bale-link);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.bale-forward-label-link {
    cursor: pointer;
    transition: opacity 0.15s ease;
}

.bale-forward-label-link:hover,
.bale-forward-label-link:focus-visible {
    opacity: 0.85;
    outline: none;
}

.bale-reply-preview {
    border-right: 3px solid var(--bale-primary);
    padding: 4px 8px;
    margin-bottom: 4px;
    background: rgba(0,0,0,.04);
    border-radius: 4px;
    font-size: 12px;
    color: var(--bale-text-secondary);
}

.bale-reply-preview[data-reply-to] {
    cursor: pointer;
    transition: background 0.15s ease;
}

.bale-reply-preview[data-reply-to]:hover,
.bale-reply-preview[data-reply-to]:focus-visible {
    background: rgba(0, 166, 147, 0.1);
    outline: none;
}

.bale-bubble-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.bale-bubble-text .bale-message-link { color: var(--bale-link); text-decoration: underline; }
.bale-bubble-text .bale-message-link:hover { text-decoration: none; }

.bale-file-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    min-width: 0;
    max-width: 100%;
    width: 100%;
    text-decoration: none;
    color: inherit;
    border-radius: 8px;
    box-sizing: border-box;
}
.bale-file-download {
    cursor: pointer;
    transition: background 0.15s ease;
}
.bale-file-download:hover {
    background: rgba(0, 0, 0, 0.04);
}
.bale-file-info { flex: 1; min-width: 0; }
.bale-file-info .bale-file-name,
.bale-profile-file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bale-file-dl-icon {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bale-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
}

.bale-file-icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #7B68EE;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

.bale-file-name { font-size: 14px; font-weight: 500; }
.bale-file-size { font-size: 12px; color: var(--bale-text-secondary); }

.bale-voice-player {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 200px;
    padding: 4px 0;
}

.bale-voice-play {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bale-link);
    border: none;
    color: #fff;
    cursor: pointer;
}

.bale-message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
    font-size: 11px;
    color: var(--bale-text-secondary);
}

.bale-ticks { color: var(--bale-text-secondary); }
.bale-ticks.read { color: #53BDEB; }

.bale-reactions {
    display: flex;
    gap: 2px;
    margin-top: -8px;
    margin-bottom: 4px;
    align-self: flex-end;
}

.bale-message.outgoing .bale-reactions { align-self: flex-start; }

.bale-reaction-chip {
    background: var(--bale-surface);
    border: 1px solid var(--bale-border);
    border-radius: 999px;
    padding: 2px 6px;
    font-size: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.bale-typing-indicator {
    font-size: 13px;
    color: var(--bale-primary);
    padding: 4px 16px;
    font-style: italic;
}

.bale-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 16px;
    background: var(--bale-sidebar);
}

.bale-reply-bar {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bale-surface-alt);
    border-top: 1px solid var(--bale-border);
    font-size: 13px;
}

.bale-reply-bar.visible { display: flex; }

.bale-input-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--bale-surface);
    border-radius: 24px;
    padding: 4px 12px;
    border: 1px solid var(--bale-border);
    min-width: 0;
}

.bale-input-wrap input, .bale-input-wrap textarea {
    flex: 1;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 14px;
    padding: 8px 4px;
    resize: none;
    max-height: 120px;
    background: transparent;
}

.bale-picker-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(11, 20, 26, .32);
    z-index: 90;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.bale-picker-backdrop.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.bale-attach-menu {
    position: absolute;
    bottom: calc(100% + 8px);
    inset-inline-start: 16px;
    background: var(--bale-surface);
    border-radius: var(--bale-radius);
    box-shadow: var(--bale-shadow);
    padding: 8px 0;
    min-width: 200px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.bale-attach-menu.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.bale-attach-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    cursor: pointer;
    font-size: 14px;
}

.bale-attach-item:hover { background: var(--bale-bg); }

.bale-attach-item .icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
}

.bale-attach-item .icon.photo { background: #7B68EE; }
.bale-attach-item .icon.file { background: #FF9500; }
.bale-attach-item .icon.location { background: #34C759; }
.bale-attach-item .icon.gift { background: #FF2D55; }
.bale-attach-item .icon.money { background: #00A693; }

/* Search panel */
.bale-search-panel {
    width: var(--bale-search-width);
    background: var(--bale-sidebar);
    border-left: 1px solid var(--bale-border);
    display: none;
    flex-direction: column;
    flex-shrink: 0;
}

.bale-search-panel.visible { display: flex; }

.bale-search-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--bale-border);
}

.bale-search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bale-bg);
    border-radius: 24px;
    padding: 8px 16px;
    margin: 12px 16px;
}

.bale-search-box input {
    border: none;
    background: none;
    outline: none;
    flex: 1;
    font-family: inherit;
    font-size: 14px;
}

/* Contacts */
.bale-action-list { padding: 8px 0; }

.bale-action-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    cursor: pointer;
    font-size: 14px;
}

.bale-action-item:hover { background: var(--bale-bg); }

.bale-action-item .icon-circle {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bale-primary-light);
    color: var(--bale-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.bale-section-label {
    padding: 8px 20px;
    font-size: 12px;
    color: var(--bale-text-secondary);
    background: var(--bale-bg);
}

/* Modals */
.bale-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 20, 26, .4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.bale-overlay.visible { display: flex; }

.bale-modal {
    background: #fff;
    border-radius: 16px;
    width: 90%;
    max-width: 440px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--bale-shadow);
}

.bale-modal-lg { max-width: 520px; }

.bale-modal-header {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 20px 16px;
    position: relative;
    border-bottom: 1px solid var(--bale-border);
}

.bale-modal-header h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}

.bale-modal-close {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--bale-text-secondary);
}

.bale-modal-body { padding: 20px; overflow-y: auto; }

.bale-modal-tabs {
    display: flex;
    border-bottom: 1px solid var(--bale-border);
}

.bale-modal-tab {
    flex: 1;
    text-align: center;
    padding: 14px;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 14px;
    color: var(--bale-text-secondary);
    cursor: pointer;
    position: relative;
}

.bale-modal-tab.active {
    color: var(--bale-primary);
    font-weight: 600;
}

.bale-modal-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 15%;
    right: 15%;
    height: 3px;
    background: var(--bale-primary);
    border-radius: 3px 3px 0 0;
}

.bale-form-field {
    margin-bottom: 16px;
}

.bale-form-field label {
    display: block;
    font-size: 13px;
    color: var(--bale-text-secondary);
    margin-bottom: 6px;
}

.bale-form-field input, .bale-form-field select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--bale-border);
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
}

.bale-form-field input:focus { border-color: var(--bale-primary); }

.bale-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border-radius: 24px;
    border: none;
    font-family: inherit;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity .2s;
}

.bale-btn:disabled { opacity: .5; cursor: not-allowed; }

.bale-btn-primary {
    background: var(--bale-primary);
    color: #fff;
    width: 100%;
}

.bale-btn-primary:hover:not(:disabled) { background: var(--bale-primary-dark); }

.bale-btn-outline {
    background: var(--bale-surface, #fff);
    color: var(--bale-primary);
    border: 1px solid var(--bale-primary);
}

.bale-btn-group {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

.bale-btn-group .bale-btn { flex: 1; }

.bale-search-result {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-top: 1px solid var(--bale-border);
    border-bottom: 1px solid var(--bale-border);
}

.bale-search-result-clickable {
    cursor: pointer;
    border-radius: 8px;
    padding: 12px;
    margin-top: 8px;
    transition: background 0.15s;
}

.bale-search-result-clickable:hover,
.bale-search-result-clickable:focus-visible {
    background: var(--bale-hover, #F0F4F8);
    outline: none;
}

.bale-search-result-hint {
    margin-right: auto;
    font-size: 13px;
    color: var(--bale-primary);
    font-weight: 500;
}

.bale-contact-delete {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--bale-text-secondary, #667781);
    font-size: 20px;
    line-height: 1;
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.bale-chat-item:hover .bale-contact-delete,
.bale-contact-delete:focus-visible {
    opacity: 1;
}

.bale-contact-delete:hover {
    background: rgba(192, 57, 43, 0.1);
    color: #c0392b;
}

.contact-item-pending {
    cursor: default;
}

.contact-item-pending .bale-avatar {
    filter: grayscale(1);
    opacity: 0.7;
}

.contact-item-pending .bale-chat-item-preview {
    color: var(--bale-text-secondary, #667781);
    font-style: italic;
}

.bale-contact-invite {
    flex-shrink: 0;
    border: none;
    background: var(--bale-primary, #1f8af2);
    color: #fff;
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 14px;
    cursor: pointer;
    transition: opacity 0.15s;
}

.bale-contact-invite:hover {
    opacity: 0.9;
}

.bale-context-menu {
    position: fixed;
    background: var(--bale-surface);
    border-radius: 8px;
    box-shadow: var(--bale-shadow);
    padding: 6px 0;
    min-width: 180px;
    max-height: calc(100vh - 16px);
    overflow-y: auto;
    z-index: 1500;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease, visibility 0.15s ease;
}

.bale-context-menu.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.bale-context-item {
    padding: 10px 20px;
    font-size: 14px;
    cursor: pointer;
}

.bale-context-item:hover { background: var(--bale-bg); }
.bale-context-item.danger { color: var(--bale-danger); }

.bale-header-menu-wrap { position: relative; }

.bale-header-menu {
    position: absolute;
    top: calc(100% + 6px);
    inset-inline-end: 0;
    background: var(--bale-surface);
    border-radius: 8px;
    box-shadow: var(--bale-shadow);
    padding: 6px 0;
    min-width: 210px;
    z-index: 1500;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity 0.15s ease, visibility 0.15s ease, transform 0.15s ease;
}

.bale-header-menu.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.bale-header-menu-item {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    border: none;
    background: none;
    text-align: start;
    color: inherit;
    font-family: inherit;
    font-size: 14px;
}

.bale-header-menu-item .bale-svg-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--bale-text-secondary);
}

.bale-selection-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: var(--bale-nav-width);
    background: var(--bale-sidebar);
    border-top: 1px solid var(--bale-border);
    padding: 12px 24px;
    display: none;
    align-items: center;
    gap: 24px;
    z-index: 200;
}

.bale-selection-bar.visible { display: flex; }

.bale-emoji-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    inset-inline-start: 56px;
    width: 340px;
    background: var(--bale-surface);
    border-radius: var(--bale-radius);
    box-shadow: var(--bale-shadow);
    padding: 12px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
}

.bale-emoji-picker.visible {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}

.bale-emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    max-height: 200px;
    overflow-y: auto;
}

.bale-emoji-grid span {
    font-size: 22px;
    cursor: pointer;
    text-align: center;
    padding: 4px;
    border-radius: 6px;
}

.bale-emoji-grid span:hover { background: var(--bale-bg); }

.bale-profile-modal .profile-top {
    text-align: center;
    padding: 24px 20px;
}

.bale-profile-actions {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin: 16px 0;
}

.bale-profile-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
    color: var(--bale-text-secondary);
}

.bale-profile-action.danger { color: var(--bale-danger); }

.bale-profile-info {
    padding: 0 20px 16px;
}

.bale-info-row {
    padding: 12px 0;
    border-bottom: 1px solid var(--bale-border);
}

.bale-info-row label {
    display: block;
    font-size: 12px;
    color: var(--bale-text-secondary);
    margin-bottom: 4px;
}

.bale-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.bale-switch {
    width: 44px;
    height: 24px;
    background: #ccc;
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background .2s;
}

.bale-switch.on {
    background: var(--bale-primary);
}

.bale-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: #fff;
    border-radius: 50%;
    transition: transform .2s;
}

.bale-switch.on::after { transform: translateX(20px); }

.bale-settings-list { padding: 0; }

.bale-settings-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--bale-border);
    cursor: pointer;
    font-size: 14px;
}

.bale-settings-item:hover { background: var(--bale-bg); }

.bale-settings-item span.lang-value {
    margin-right: auto;
    color: var(--bale-text-secondary);
    font-size: 13px;
}

.connection-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #FFF3CD;
    color: #856404;
    text-align: center;
    padding: 10px;
    font-size: 13px;
    z-index: 2000;
}

.connection-banner.hidden { display: none; }

.connection-banner.reconnected {
    background: #D4EDDA;
    color: #155724;
}

/* Login */
.bale-login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #E7F8F5 0%, #F0F2F5 100%);
}

.bale-login-card {
    background: #fff;
    border-radius: 20px;
    padding: 40px;
    width: 90%;
    max-width: 400px;
    box-shadow: var(--bale-shadow);
    text-align: center;
}

.bale-login-logo {
    display: block;
    width: 64px;
    height: 64px;
    margin: 0 auto 20px;
}

.bale-login-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* Error pages */
.bale-error-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(135deg, #E7F8F5 0%, #F0F2F5 100%);
}

.bale-error-card {
    background: #fff;
    border-radius: 20px;
    padding: 40px 32px;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--bale-shadow);
    text-align: center;
}

.bale-error-card--rate-limit {
    border-top: 4px solid #F59E0B;
}

.bale-error-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: #E7F8F5;
    color: var(--bale-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.bale-error-card--rate-limit .bale-error-icon {
    background: #FEF3C7;
    color: #D97706;
}

.bale-error-code {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--bale-text-secondary);
}

.bale-error-title {
    margin: 0 0 12px;
    font-size: 24px;
    font-weight: 700;
}

.bale-error-message {
    margin: 0 0 20px;
    font-size: 15px;
    line-height: 1.7;
    color: var(--bale-text-secondary);
}

.bale-error-retry {
    margin: 0 0 20px;
    padding: 12px 16px;
    border-radius: 12px;
    background: #FEF3C7;
    color: #92400E;
    font-size: 14px;
}

.bale-error-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.bale-error-actions .bale-btn {
    width: 100%;
}

.bale-error-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    background: transparent;
    color: var(--bale-text-secondary);
    border: 1px solid var(--bale-border);
}

.bale-error-request-id {
    margin: 24px 0 0;
    font-size: 12px;
    color: var(--bale-text-secondary);
}

.bale-error-request-id code {
    font-size: 11px;
    background: var(--bale-bg);
    padding: 2px 6px;
    border-radius: 6px;
}

.bale-otp-display {
    background: var(--bale-highlight-bg, #E7F8F5);
    border-radius: 10px;
    padding: 12px;
    margin: 12px 0;
    font-size: 14px;
    color: var(--bale-primary-dark);
}

.bale-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    justify-content: center;
    margin: 12px 0;
}

.hidden { display: none !important; }

.bale-media-caption {
    margin-top: 4px;
    padding-top: 4px;
}

.bale-media-compose {
    background: var(--bale-sidebar);
    border-top: 1px solid var(--bale-border);
    padding: 10px 16px 8px;
}

.bale-media-compose-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.bale-media-compose-count {
    flex: 1;
    font-size: 13px;
    color: var(--bale-text-secondary);
}

.bale-media-compose-send-btn {
    padding: 6px 16px;
    font-size: 13px;
}

.bale-media-compose-previews {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 8px;
    margin-bottom: 8px;
}

.bale-media-compose-item {
    position: relative;
    flex: 0 0 72px;
    width: 72px;
    text-align: center;
}

.bale-media-compose-thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 8px;
    background: var(--bale-surface-alt);
    display: block;
}

.bale-media-compose-vid-badge {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 18px;
    text-shadow: 0 1px 4px rgba(0,0,0,.5);
    pointer-events: none;
}

.bale-media-compose-file-icon {
    width: 72px;
    height: 72px;
    border-radius: 8px;
    background: var(--bale-surface-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--bale-primary);
}

.bale-media-compose-name {
    display: block;
    font-size: 10px;
    color: var(--bale-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 4px;
}

.bale-media-compose-remove {
    position: absolute;
    top: -4px;
    inset-inline-end: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: var(--bale-danger, #e74c3c);
    color: #fff;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
}

.bale-media-compose-caption {
    margin: 0;
}

.bale-copy-toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: rgba(0, 0, 0, 0.78);
    color: #fff;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.bale-copy-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
    html, body.bale-body {
        height: 100%;
        overflow: hidden;
        touch-action: manipulation;
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    .bale-app {
        touch-action: manipulation;
    }

    .bale-input-wrap input,
    .bale-input-wrap textarea,
    .bale-body input,
    .bale-body select,
    .bale-body textarea {
        font-size: 16px;
    }

    /* Admin panel uses _ChatLayout but needs full-page scroll on mobile */
    html:has(.bale-admin-app),
    body.bale-body:has(.bale-admin-app) {
        height: auto;
        min-height: 100%;
        overflow-x: hidden;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .bale-app {
        overflow-x: hidden;
        height: 100dvh;
        height: 100svh;
        min-height: -webkit-fill-available;
    }

    .bale-sidebar {
        flex: 1;
        min-width: 0;
        width: auto;
    }

    .bale-main { display: none; }
    .bale-app.chat-open .bale-sidebar { display: none; }
    .bale-app.chat-open .bale-main,
    .bale-app.bale-app-standalone .bale-main {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-width: 0;
        min-height: 0;
        width: auto;
        height: 100%;
        max-height: 100dvh;
        overflow: hidden;
        overflow-x: hidden;
    }

    .bale-app.bale-app-standalone .bale-main.bale-main-plain {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .bale-app.chat-open #chatMain,
    .bale-app.bale-app-standalone #chatMain {
        position: relative;
    }

    .bale-app.chat-open .bale-messages,
    .bale-app.bale-chat-private .bale-messages,
    .bale-app.bale-chat-group .bale-messages,
    .bale-app.bale-chat-channel .bale-messages {
        flex: 1;
        min-height: 0;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .bale-app.chat-open .bale-input-area,
    .bale-app.chat-open .bale-reply-bar,
    .bale-app.chat-open .bale-media-compose,
    .bale-app.chat-open .bale-voice-recording-bar {
        flex-shrink: 0;
    }

    .bale-chat-header {
        padding: 10px 12px;
        min-width: 0;
        gap: 8px;
    }
    .bale-chat-header-info { flex: 1; min-width: 0; }
    .bale-chat-header-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .bale-chat-header-actions { flex-shrink: 0; }

    .bale-chat-item { padding: 12px; }

    .bale-messages {
        padding: 10px 8px;
        overflow-x: hidden;
    }
    .bale-message { max-width: 90%; }
    .bale-chat-channel .bale-message,
    .bale-chat-group .bale-message { max-width: 95%; }
    .bale-msg-menu-btn { display: inline-flex; }

    .bale-voice-player { min-width: 0; max-width: 100%; }

    .bale-input-area { padding: 10px 12px; }

    .bale-attach-menu,
    .bale-emoji-picker {
        inset-inline-start: auto;
        inset-inline-end: 12px;
    }

    .bale-emoji-picker {
        width: min(360px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
    }

    .bale-selection-bar {
        right: var(--bale-nav-width);
        left: 0;
    }

    .bale-search-panel { display: none !important; }
    .bale-search-panel.visible {
        display: flex !important;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: var(--bale-nav-width);
        width: auto;
        z-index: 150;
        border-left: none;
    }
}
