:root {
  --bg: #0f1115; --bg2: #161922; --bg3: #1e222e;
  --text: #ffffff; --text2: #8b95a8;
  --accent: #5c7cfa; --accent-h: #4263eb;
  --border: #2a2f3e; --shadow: 0 4px 20px rgba(0,0,0,0.4);
  --radius: 16px; --trans: 0.2s ease;
  --premium: linear-gradient(135deg, #7c5cff, #3b82f6);
  --danger: #ef4444; --success: #10b981; --warning: #f59e0b;
}
[data-theme="light"] {
  --bg: #f5f7fa; --bg2: #ffffff; --bg3: #e9edf3;
  --text: #0f172a; --text2: #64748b;
  --border: #dfe3ea; --shadow: 0 4px 20px rgba(0,0,0,0.08);
}
* { box-sizing: border-box; margin: 0; padding: 0; outline: none; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; transition: background var(--trans), color var(--trans); }
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; border: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }

@keyframes fadeUp { from { opacity:0; transform: translateY(12px); } to { opacity:1; transform: translateY(0); } }
@keyframes pulse { 0%,100% { opacity:1; } 50% { opacity:0.5; } }

.auth-wrap { height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top right, rgba(92,124,250,0.15), transparent 40%); overflow-y: auto; }
.auth-card { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; width: 95%; max-width: 400px; box-shadow: var(--shadow); animation: fadeUp 0.4s ease; }
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head h1 { font-size: 26px; background: var(--premium); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.tabs { display: flex; gap: 6px; background: var(--bg3); padding: 4px; border-radius: 12px; margin-bottom: 20px; }
.tab { flex:1; padding: 10px; text-align: center; border-radius: 10px; font-weight: 500; color: var(--text2); transition: var(--trans); cursor: pointer; }
.tab.active { background: var(--accent); color: #fff; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.input { width: 100%; padding: 12px 14px; background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; color: var(--text); font-size: 15px; transition: var(--trans); }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(92,124,250,0.2); }
.code-inputs { display: flex; gap: 8px; justify-content: center; }
.code-inputs input { width: 42px; height: 48px; text-align: center; font-size: 18px; font-weight: 600; background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; color: var(--text); }
.btn { width: 100%; padding: 13px; border-radius: 12px; font-weight: 600; font-size: 15px; margin-top: 10px; transition: var(--trans); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-h); transform: translateY(-1px); }
.btn-premium { background: var(--premium); color: #fff; }
.btn-glass { background: rgba(255,255,255,0.05); border: 1px solid var(--border); color: var(--text2); }
.btn-glass:hover { background: rgba(255,255,255,0.1); }
.err-msg { color: #ef4444; font-size: 13px; text-align: center; margin-top: 8px; min-height: 18px; }
.form-panel { display: none; }
.form-panel.active { display: block; animation: fadeUp 0.3s; }

.app { display: flex; height: 100vh; }
.sidebar { width: 340px; background: var(--bg2); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: relative; z-index: 10; }
.header { height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--border); }
.header h2 { font-size: 18px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; background: var(--bg3); color: var(--text); display: grid; place-items: center; transition: var(--trans); font-size: 14px; }
.icon-btn:hover { background: var(--accent); color: #fff; }
.profile-bar { padding: 12px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.profile-bar:hover { background: var(--bg3); }
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: var(--accent); display: grid; place-items: center; font-weight: 600; font-size: 18px; color: #fff; flex-shrink: 0; }
.profile-info h4 { font-size: 15px; display: flex; align-items: center; gap: 6px; }
.profile-info p { font-size: 12px; color: var(--text2); }
.badge-premium { background: var(--premium); padding: 2px 6px; border-radius: 6px; font-size: 10px; color: #fff; }
.bal { margin-left: auto; font-weight: 600; color: var(--accent); font-size: 14px; }

.folders { display: flex; gap: 6px; padding: 8px 16px; overflow-x: auto; border-bottom: 1px solid var(--border); }
.folder { padding: 6px 14px; border-radius: 16px; background: var(--bg3); color: var(--text2); font-size: 13px; cursor: pointer; white-space: nowrap; }
.folder.active { background: var(--accent); color: #fff; }

.chat-list { flex: 1; overflow-y: auto; padding: 8px; }
.chat-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px; cursor: pointer; transition: var(--trans); }
.chat-item:hover, .chat-item.active { background: var(--bg3); }
.chat-item.pinned { border-left: 3px solid var(--accent); }
.chat-info { flex: 1; min-width: 0; }
.chat-top { display: flex; justify-content: space-between; margin-bottom: 4px; }
.chat-name { font-weight: 500; font-size: 15px; }
.chat-time { font-size: 11px; color: var(--text2); }
.chat-last { font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--accent); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 10px; }
.pin-icon { color: var(--accent); font-size: 12px; margin-left: 4px; }

.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg); position: relative; }
.chat-header { height: 60px; display: flex; align-items: center; gap: 12px; padding: 0 16px; border-bottom: 1px solid var(--border); background: var(--bg2); }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; scroll-behavior: smooth; }

.msg { max-width: 70%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.4; position: relative; transition: var(--trans); }
.msg.mine { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.other { align-self: flex-start; background: var(--bg3); border-bottom-left-radius: 4px; }
.msg.pinned { border: 1px solid var(--accent); }
.msg.edited::after { content: 'πεδ.'; font-size: 10px; opacity: 0.7; margin-left: 4px; }
.msg-reply { display: block; background: rgba(0,0,0,0.15); padding: 4px 8px; border-radius: 6px; margin-bottom: 6px; font-size: 12px; border-left: 3px solid var(--accent-h); cursor: pointer; }
.msg-reply b { display: block; margin-bottom: 2px; }
.msg-time { font-size: 10px; opacity: 0.7; margin-top: 4px; text-align: right; }
.msg-reactions { position: absolute; bottom: -10px; right: 8px; background: var(--bg2); border: 1px solid var(--border); border-radius: 12px; padding: 2px 6px; font-size: 12px; display: flex; gap: 4px; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
.msg-actions { position: absolute; top: -28px; right: 0; background: var(--bg3); border-radius: 8px; display: flex; gap: 4px; padding: 4px; opacity: 0; transition: var(--trans); border: 1px solid var(--border); }
.msg:hover .msg-actions { opacity: 1; }
.msg-action-btn { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 4px; font-size: 12px; background: transparent; color: var(--text); }
.msg-action-btn:hover { background: var(--accent); color: #fff; }

.msg.photo { padding: 4px; max-width: 260px; border-radius: 12px; overflow: hidden; }
.msg.photo img { width: 100%; border-radius: 10px; display: block; cursor: pointer; }
.msg.voice { min-width: 220px; display: flex; align-items: center; gap: 10px; }
.msg.voice .play-btn { width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,0.2); display: grid; place-items: center; cursor: pointer; flex-shrink: 0; }
.msg.voice audio { max-width: 180px; height: 36px; }
.msg.video-circle { width: 180px; height: 180px; padding: 2px; border-radius: 50%; overflow: hidden; border: 2px solid var(--accent); align-self: flex-end; }
.msg.video-circle video { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.msg.sticker { background: transparent !important; padding: 0; }
.msg.sticker .emoji-big { font-size: 120px; }
.msg.file { display: flex; align-items: center; gap: 10px; min-width: 220px; }
.msg.file .file-icon { font-size: 32px; }
.msg.file a { color: inherit; text-decoration: underline; }

.input-area { padding: 12px; border-top: 1px solid var(--border); background: var(--bg2); display: flex; flex-direction: column; gap: 8px; }
.reply-bar { width: 100%; background: var(--bg3); padding: 10px; border-radius: 12px; border-left: 3px solid var(--accent); display: none; justify-content: space-between; align-items: center; }
.reply-bar.active { display: flex; }
.reply-bar-info h5 { font-size: 13px; margin-bottom: 2px; }
.reply-bar-info p { font-size: 11px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
.msg-input-wrap { display: flex; gap: 10px; align-items: center; width: 100%; }
.msg-input { flex: 1; background: var(--bg3); border: 1px solid var(--border); color: var(--text); padding: 12px 14px; border-radius: 24px; font-size: 14px; }
.send-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; transition: var(--trans); }
.send-btn:hover { background: var(--accent-h); transform: scale(1.05); }

.ctx-menu { position: fixed; background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; padding: 6px; min-width: 180px; z-index: 200; box-shadow: var(--shadow); display: none; animation: fadeUp 0.2s; }
.ctx-item { padding: 10px 12px; border-radius: 8px; font-size: 14px; display: flex; align-items: center; gap: 10px; cursor: pointer; transition: var(--trans); }
.ctx-item:hover { background: var(--bg); color: var(--accent); }
.ctx-item.danger:hover { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 300; display: none; place-items: center; backdrop-filter: blur(5px); padding: 20px; overflow-y: auto; }
.modal.active { display: grid; }
.modal-box { background: var(--bg2); width: 100%; max-width: 500px; border-radius: 16px; padding: 20px; box-shadow: var(--shadow); animation: fadeUp 0.3s; max-height: 90vh; overflow-y: auto; }
.modal-large { max-width: 700px; }
.modal-xl { max-width: 900px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { font-size: 18px; }

.search-results { max-height: 300px; overflow-y: auto; margin-top: 12px; }
.search-res-item { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 10px; cursor: pointer; transition: var(--trans); }
.search-res-item:hover { background: var(--bg3); }
.search-msg-item { padding: 10px; background: var(--bg3); border-radius: 10px; margin-bottom: 8px; cursor: pointer; }
.search-msg-item:hover { background: var(--border); }
.search-msg-chat { font-size: 11px; color: var(--accent); margin-bottom: 4px; }
.search-msg-text { font-size: 13px; }

.emoji-picker { position: absolute; bottom: 80px; left: 12px; background: var(--bg3); border: 1px solid var(--border); border-radius: 12px; padding: 12px; display: none; max-width: 320px; flex-wrap: wrap; gap: 6px; z-index: 50; box-shadow: var(--shadow); }
.emoji-picker.active { display: flex; }
.emoji-picker span { font-size: 24px; cursor: pointer; padding: 4px; border-radius: 6px; }
.emoji-picker span:hover { background: var(--bg); }

.profile-header { position: relative; }
.banner-img { width: 100%; height: 150px; object-fit: cover; border-radius: 12px; background: var(--premium); }
.profile-avatar-large { width: 100px; height: 100px; border-radius: 50%; border: 4px solid var(--bg2); margin: -50px auto 0; display: block; background: var(--accent); }
.profile-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.privacy-option { display: flex; justify-content: space-between; align-items: center; padding: 12px; background: var(--bg3); border-radius: 10px; margin-bottom: 8px; }
.privacy-option select { background: var(--bg2); color: var(--text); border: 1px solid var(--border); padding: 6px 10px; border-radius: 8px; }

.session-item { display: flex; justify-content: space-between; align-items: center; padding: 12px; background: var(--bg3); border-radius: 10px; margin-bottom: 8px; }
.session-item.current { border: 2px solid var(--accent); }
.session-info h5 { font-size: 14px; }
.session-info p { font-size: 12px; color: var(--text2); }

.folder-create { display: flex; gap: 8px; margin-top: 12px; }
.folder-chats { margin-top: 12px; }
.folder-chat-item { display: flex; justify-content: space-between; padding: 8px; background: var(--bg3); border-radius: 8px; margin-bottom: 4px; }

.transfer-form { background: var(--bg3); padding: 16px; border-radius: 12px; margin-top: 12px; }
.transaction-item { display: flex; justify-content: space-between; padding: 10px; border-bottom: 1px solid var(--border); }
.transaction-item.income { color: var(--success); }
.transaction-item.expense { color: var(--danger); }

.gift-listing { background: var(--bg3); padding: 12px; border-radius: 12px; text-align: center; cursor: pointer; transition: var(--trans); }
.gift-listing:hover { transform: translateY(-2px); }
.gift-listing .price-tag { background: var(--accent); color: #fff; padding: 4px 8px; border-radius: 8px; font-size: 12px; margin-top: 8px; display: inline-block; }

.sticker-pack { background: var(--bg3); padding: 12px; border-radius: 12px; margin-bottom: 12px; }
.sticker-pack-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sticker-item { font-size: 40px; cursor: pointer; padding: 8px; border-radius: 8px; text-align: center; }
.sticker-item:hover { background: var(--bg); }
.sticker-item img { width: 100%; height: 60px; object-fit: contain; }

.gif-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-height: 400px; overflow-y: auto; }
.gif-item { cursor: pointer; border-radius: 8px; overflow: hidden; }
.gif-item img { width: 100%; height: 120px; object-fit: cover; }

.ticket-item { padding: 12px; background: var(--bg3); border-radius: 10px; margin-bottom: 8px; cursor: pointer; }
.ticket-item.open { border-left: 3px solid var(--success); }
.ticket-item.in_progress { border-left: 3px solid var(--warning); }
.ticket-item.closed { border-left: 3px solid var(--text2); }
.support-message { padding: 10px; border-radius: 10px; margin-bottom: 8px; max-width: 80%; }
.support-message.admin { background: var(--accent); color: #fff; align-self: flex-end; }
.support-message.user { background: var(--bg3); }

.report-item { padding: 12px; background: var(--bg3); border-radius: 10px; margin-bottom: 8px; }
.report-actions { display: flex; gap: 8px; margin-top: 8px; }

.announcement { background: var(--bg3); padding: 16px; border-radius: 12px; margin-bottom: 12px; border-left: 4px solid var(--accent); }
.announcement.pinned { border-left-color: var(--warning); }

.bot-item { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--bg3); border-radius: 10px; margin-bottom: 8px; }
.bot-token { font-family: monospace; font-size: 11px; background: var(--bg); padding: 4px 8px; border-radius: 4px; word-break: break-all; }
.webapp-item { padding: 12px; background: var(--bg3); border-radius: 10px; margin-bottom: 8px; }

.admin-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--bg3); padding: 16px; border-radius: 12px; }
.stat-card .num { font-size: 28px; font-weight: 700; color: var(--accent); }
.stat-card .label { font-size: 12px; color: var(--text2); }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { padding: 10px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px; }
.admin-table th { color: var(--text2); font-weight: 500; }
.admin-tabs { display: flex; gap: 8px; overflow-x: auto; padding: 12px; border-bottom: 1px solid var(--border); }
.admin-tab { padding: 8px 16px; background: var(--bg3); border-radius: 8px; cursor: pointer; white-space: nowrap; }
.admin-tab.active { background: var(--accent); color: #fff; }
.admin-section { padding: 20px; }

.premium-card { background: var(--premium); padding: 20px; border-radius: 16px; color: #fff; margin-bottom: 16px; }
.premium-plans { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.premium-plan { background: var(--bg3); padding: 16px; border-radius: 12px; text-align: center; cursor: pointer; transition: var(--trans); border: 2px solid transparent; }
.premium-plan:hover { border-color: var(--accent); }
.premium-plan .price { font-size: 20px; font-weight: 700; margin: 8px 0; }

.gifts-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.gift-item { background: var(--bg3); padding: 12px; border-radius: 12px; text-align: center; cursor: pointer; transition: var(--trans); }
.gift-item:hover { transform: translateY(-2px); }
.gift-item .emoji { font-size: 40px; }
.gift-item .price { font-size: 12px; color: var(--accent); margin-top: 4px; }

.payment-methods { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-top: 12px; }
.payment-method { background: var(--bg3); padding: 16px; border-radius: 12px; text-align: center; cursor: pointer; transition: var(--trans); }
.payment-method:hover { background: var(--accent); color: #fff; }
.payment-method i { font-size: 28px; margin-bottom: 8px; }

.mobile-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg2); border-top: 1px solid var(--border); padding: 8px 0; z-index: 50; }
.mobile-nav a { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--text2); font-size: 11px; text-decoration: none; padding: 6px; }
.mobile-nav a.active { color: var(--accent); }
.mobile-nav i { font-size: 20px; }

.theme-toggle { position: fixed; top: 16px; right: 16px; z-index: 100; width: 40px; height: 40px; border-radius: 50%; background: var(--bg3); border: 1px solid var(--border); color: var(--text); display: grid; place-items: center; transition: var(--trans); }
.theme-toggle:hover { transform: rotate(20deg); }

@media (max-width: 900px) {
  .sidebar { width: 100%; position: absolute; left: -100%; height: 100%; z-index: 40; transition: left 0.3s; }
  .sidebar.open { left: 0; }
  .mobile-nav { display: flex; justify-content: space-around; }
  .chat-area { width: 100%; }
  .msg { max-width: 85%; }
  .msg-actions { opacity: 1; }
  .premium-plans { grid-template-columns: 1fr; }
  .gifts-grid { grid-template-columns: repeat(2, 1fr); }
  .payment-methods { grid-template-columns: 1fr; }
  .sticker-grid { grid-template-columns: repeat(3, 1fr); }
  .gif-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-large, .modal-xl { max-width: 95%; }
}