/**
 * Chatgo Modern Design System & Responsive Styles
 * Theme: Dark Neon / Indigo Glassmorphism
 */

:root {
    --bg-color: #0b0e14;
    --sidebar-color: #121824;
    --card-color: #1a2235;
    --card-hover: #222d46;
    --accent-color: #3b82f6;
    --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --border-color: #232d42;
    --incoming-bg: #232c3f;
    --outgoing-bg: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    --scrollbar-thumb: #2d3b56;
    --scrollbar-track: #0e131d;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

html, body {
    width: 100%;
    height: 100dvh;
    min-height: 100vh;
    overflow: hidden;
    background-color: var(--bg-color);
    color: var(--text-primary);
}

body {
    display: flex;
    position: relative;
}

/* App Main Layout Container */
.app-container {
    width: 100vw;
    height: 100dvh;
    display: flex;
    position: relative;
    overflow: hidden;
    background: radial-gradient(circle at top right, #1e1b4b 0%, var(--bg-color) 60%);
}

/* --- Sidebar / Chat list --- */
.sidebar {
    width: 360px;
    min-width: 320px;
    max-width: 420px;
    height: 100%;
    background-color: rgba(18, 24, 36, 0.9);
    border-right: 1px solid var(--border-color);
    backdrop-filter: blur(16px);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.sidebar-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(18, 24, 36, 0.4);
}

.brand {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    background: var(--accent-gradient);
    border-radius: 50%;
    box-shadow: 0 0 10px rgba(59, 130, 246, 0.6);
}

.dev-badge {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.3);
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 6px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

.dev-logout-btn {
    background: rgba(239, 68, 68, 0.12);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.25);
    padding: 5px 9px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.dev-logout-btn:hover {
    background: rgba(239, 68, 68, 0.25);
    color: #ffffff;
    border-color: rgba(239, 68, 68, 0.4);
}

.settings-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    transition: color 0.2s ease, transform 0.2s ease;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.settings-btn:hover {
    color: var(--text-primary);
    transform: rotate(45deg);
}

.search-container {
    padding: 14px 20px;
    position: relative;
}

.search-input {
    width: 100%;
    background-color: rgba(26, 34, 53, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 11px 16px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: all 0.2s ease;
}

.search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
    background-color: var(--card-color);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px 12px 12px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 6px;
    position: relative;
    border: 1px solid transparent;
}

.chat-item:hover {
    background-color: rgba(34, 45, 70, 0.4);
    border-color: rgba(59, 130, 246, 0.1);
}

.chat-item.active {
    background-color: var(--card-color);
    border-color: var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.avatar {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    background: var(--accent-gradient);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    color: white;
    font-size: 15px;
    text-transform: uppercase;
    position: relative;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.25);
}

.channel-badge {
    position: absolute;
    bottom: -3px;
    right: -3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: #2563eb;
    font-size: 9px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 700;
    border: 2px solid var(--bg-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.channel-badge.telegram, .channel-badge.telegram_personal { background-color: #24A1DE; }
.channel-badge.whatsapp { background-color: #25D366; }
.channel-badge.vk { background-color: #4C75A3; }
.channel-badge.instagram { background-color: #E1306C; }
.channel-badge.max { background-color: #f59e0b; }

.chat-details {
    flex: 1;
    min-width: 0;
}

.chat-name-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-time {
    font-size: 11px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.chat-last-message-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-last-message {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 8px;
}

.unread-badge {
    background: var(--accent-gradient);
    color: white;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 20px;
    min-width: 18px;
    text-align: center;
    box-shadow: 0 2px 6px rgba(59, 130, 246, 0.4);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* --- Right Workspace Area / Chat Window --- */
.chat-window {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    background-color: transparent;
    position: relative;
    overflow: hidden;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.empty-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.chat-content {
    height: 100%;
    display: none;
    flex-direction: column;
}

.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    background-color: rgba(18, 24, 36, 0.5);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 5;
}

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

.header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--accent-gradient);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    font-size: 14px;
}

.header-name {
    font-weight: 600;
    font-size: 16px;
}

.header-status {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #10b981;
    box-shadow: 0 0 6px #10b981;
}

.back-button {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 22px;
    cursor: pointer;
    margin-right: 8px;
    padding: 4px;
    line-height: 1;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background-image: radial-gradient(rgba(59, 130, 246, 0.03) 1px, transparent 1px);
    background-size: 20px 20px;
}

.message-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 70%;
}

.message-wrapper.incoming {
    align-self: flex-start;
}

.message-wrapper.outgoing {
    align-self: flex-end;
    align-items: flex-end;
}

.message-bubble {
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}

.message-wrapper.incoming .message-bubble {
    background-color: var(--incoming-bg);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border-color);
}

.message-wrapper.outgoing .message-bubble {
    background: var(--outgoing-bg);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-meta {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 5px;
    padding: 0 4px;
}

/* Message input bar */
.input-bar {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    background-color: rgba(18, 24, 36, 0.7);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    gap: 12px;
}

.message-form {
    flex: 1;
    display: flex;
    gap: 12px;
    align-items: center;
}

.input-textarea {
    flex: 1;
    background-color: rgba(14, 19, 29, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 13px 18px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    resize: none;
    height: 48px;
    max-height: 120px;
    transition: all 0.2s ease;
}

.input-textarea:focus {
    border-color: var(--accent-color);
    background-color: rgba(14, 19, 29, 1);
}

.send-button {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: var(--accent-gradient);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s ease;
    box-shadow: 0 4px 10px rgba(59, 130, 246, 0.3);
    flex-shrink: 0;
}

.send-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 14px rgba(59, 130, 246, 0.4);
}

.send-button:active {
    transform: translateY(0);
}

.send-button svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* --- Channels Management Panel --- */
.channels-panel {
    flex: 1;
    height: 100%;
    display: none;
    flex-direction: column;
    background-color: transparent;
    z-index: 5;
    padding: 24px;
    overflow-y: auto;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
}

.panel-title {
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.close-panel-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    transition: transform 0.2s ease;
    padding: 4px 8px;
    line-height: 1;
}

.close-panel-btn:hover {
    transform: scale(1.15);
}

.channels-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.channel-card {
    background-color: var(--card-color);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s ease;
}

.channel-card:hover {
    border-color: rgba(59, 130, 246, 0.3);
    background-color: var(--card-hover);
}

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

.channel-type-badge {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: white;
    text-transform: uppercase;
}

.channel-type-badge.telegram, .channel-type-badge.telegram_personal { background-color: #24A1DE; }
.channel-type-badge.whatsapp { background-color: #25D366; }
.channel-type-badge.vk { background-color: #4C75A3; }
.channel-type-badge.instagram { background-color: #E1306C; }
.channel-type-badge.max { background-color: #f59e0b; }

.channel-card-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.channel-card-name {
    font-weight: 600;
    font-size: 15px;
}

.channel-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.channel-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.channel-status.connected {
    background-color: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.channel-status.disconnected {
    background-color: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.delete-channel-btn {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.delete-channel-btn:hover {
    background-color: #ef4444;
    color: white;
}

.add-channel-btn {
    background: var(--accent-gradient);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    transition: all 0.2s ease;
    width: 100%;
}

.add-channel-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

.btn-tg-connect {
    background: linear-gradient(135deg, #24A1DE 0%, #1d82b4 100%);
    color: white;
    border: none;
    border-radius: 12px;
    padding: 12px 20px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 12px rgba(36, 161, 222, 0.3);
    transition: all 0.2s ease;
    margin-bottom: 12px;
    width: 100%;
}

.btn-tg-connect:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(36, 161, 222, 0.4);
}

/* --- Modal Overlays and Windows (Global) --- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    background-color: rgba(11, 14, 20, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 16px;
    overflow-y: auto;
}

.modal-content {
    background-color: var(--card-color);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    width: 100%;
    max-width: 480px;
    padding: 24px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.6);
    animation: slideUpModal 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    position: relative;
    margin: auto;
}

@keyframes slideUpModal {
    from { transform: translateY(16px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 4px;
}

.modal-close:hover {
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    background-color: rgba(14, 19, 29, 0.8);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 11px 14px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
}

.form-control:focus {
    border-color: var(--accent-color);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 10px;
    padding: 10px 16px;
    cursor: pointer;
    font-weight: 500;
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-primary {
    background: var(--accent-gradient);
    border: none;
    color: white;
    border-radius: 10px;
    padding: 10px 20px;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary:hover {
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.instruction-box {
    background-color: rgba(59, 130, 246, 0.05);
    border: 1px dashed rgba(59, 130, 246, 0.25);
    border-radius: 10px;
    padding: 12px;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 16px;
    word-break: break-all;
}

/* Telegram Personal Connect Modal Styles */
.tg-connect-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 8px 0;
}

.tg-steps-list {
    text-align: left;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 18px 14px 34px;
    margin-bottom: 20px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-secondary);
    width: 100%;
}

.tg-steps-list strong {
    color: var(--text-primary);
}

.tg-qr-wrapper {
    background: #ffffff;
    padding: 14px;
    border-radius: 18px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 14px;
    width: 248px;
    height: 248px;
    position: relative;
}

.tg-qr-img {
    width: 220px;
    height: 220px;
    display: block;
    border-radius: 8px;
}

.tg-qr-spinner {
    color: #3b82f6;
    font-size: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.tg-status-text {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 14px;
    min-height: 20px;
}

.tg-switch-mode-btn {
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    transition: opacity 0.2s ease;
    margin-top: 8px;
}

.tg-switch-mode-btn:hover {
    opacity: 0.8;
}

.tg-phone-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 14px;
    text-align: left;
}

.tg-code-input {
    letter-spacing: 6px;
    font-size: 20px;
    font-weight: 700;
    text-align: center;
}

.tg-success-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

/* --- Access Denied Overlay (Global) --- */
.access-denied-overlay {
    display: none;
    position: fixed;
    inset: 0;
    width: 100vw;
    height: 100dvh;
    background-color: rgba(11, 14, 20, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 9999;
    justify-content: center;
    align-items: center;
    padding: 24px;
}

.overlay-card {
    background-color: var(--card-color);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 40px;
    max-width: 420px;
    width: 100%;
    text-align: center;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.overlay-icon {
    font-size: 56px;
    margin-bottom: 20px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: inline-block;
}

.overlay-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-primary);
}

.overlay-desc {
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-secondary);
}

/* --- Scrollbars --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 10px;
}

/* --- Responsive Styles for Mobile (< 768px) --- */
@media (max-width: 768px) {
    .sidebar {
        width: 100vw;
        max-width: 100vw;
    }

    .sidebar.hidden {
        display: none !important;
    }

    .chat-window {
        width: 100vw;
        height: 100dvh;
        position: fixed;
        inset: 0;
        background-color: var(--bg-color);
        z-index: 20;
        display: none;
        flex-direction: column;
    }

    .chat-window.active {
        display: flex !important;
    }

    .back-button {
        display: block !important;
    }

    .modal-content {
        max-width: 94%;
        padding: 20px 16px;
        border-radius: 16px;
    }

    .tg-qr-wrapper {
        width: 210px;
        height: 210px;
    }

    .tg-qr-img {
        width: 190px;
        height: 190px;
    }

    .message-wrapper {
        max-width: 85%;
    }
}
