:root {
    --bg-body: #05050a;
    --bg-sidebar: rgba(20, 20, 30, 0.7);
    --bg-main: rgba(10, 10, 15, 0.8);
    --bg-msg-in: rgba(255, 255, 255, 0.08);
    --bg-msg-out: #5288c1;
    --text-main: #ffffff;
    --text-muted: #8b93a5;
    --border-color: rgba(255, 255, 255, 0.1);
    --accent: #6a5acd;
    --accent-glow: rgba(106, 90, 205, 0.5);
    --hover: rgba(255, 255, 255, 0.05);
    --danger: #ff4757;
    --warning: #ffa502;
    --success: #2ed573;
    --verified: #1e90ff;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
[data-theme="light"] {
    --bg-body: #e0e5ec; --bg-sidebar: rgba(255, 255, 255, 0.8); --bg-main: rgba(240, 240, 245, 0.9);
    --bg-msg-in: #ffffff; --bg-msg-out: #e1ffc7;
    --text-main: #2c3e50; --text-muted: #7f8c8d; --border-color: rgba(0,0,0,0.1); --hover: rgba(0,0,0,0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg-body); color: var(--text-main); height: 100vh; overflow: hidden; font-size: 14px; background-image: radial-gradient(circle at 15% 50%, rgba(106, 90, 205, 0.15), transparent 25%), radial-gradient(circle at 85% 30%, rgba(255, 71, 87, 0.1), transparent 25%); }
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; outline: none; }
input { font-family: inherit; outline: none; border: none; }
a { color: var(--accent); text-decoration: none; cursor: pointer; }
.hidden { display: none !important; }

.glass { background: rgba(20, 20, 30, 0.6); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border: 1px solid var(--border-color); }
[data-theme="light"] .glass { background: rgba(255, 255, 255, 0.7); }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }

/* АВТОРИЗАЦИЯ */
.auth-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 9999; background: var(--bg-body); }
.auth-box { width: 100%; max-width: 400px; padding: 40px; background: rgba(20, 20, 30, 0.8); backdrop-filter: blur(20px); border-radius: 24px; border: 1px solid var(--border-color); box-shadow: 0 20px 50px rgba(0,0,0,0.5), 0 0 30px var(--accent-glow); text-align: center; }
.auth-logo { width: 80px; height: 80px; margin: 0 auto 20px; background: linear-gradient(135deg, var(--accent), #8a2be2); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: white; box-shadow: 0 0 20px var(--accent-glow); }
.auth-logo svg { width: 40px; height: 40px; }
.auth-box h1 { font-size: 28px; margin-bottom: 8px; background: linear-gradient(to right, #fff, #aaa); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.subtitle { color: var(--text-muted); margin-bottom: 30px; }
.auth-err { color: var(--danger); font-size: 13px; min-height: 20px; margin-bottom: 10px; text-align: left; }
.input-group { margin-bottom: 15px; text-align: left; position: relative; }
.input-group input { width: 100%; padding: 14px; background: rgba(0,0,0,0.3); border: 1px solid var(--border-color); border-radius: 12px; color: var(--text-main); font-size: 16px; transition: 0.3s; }
.input-group input:focus { border-color: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }
.input-group .prefix { position: absolute; padding: 14px; color: var(--text-muted); font-weight: bold; }
.input-group .prefix + input { padding-left: 35px; }
.auth-btn { width: 100%; padding: 14px; background: linear-gradient(135deg, var(--accent), #4b0082); color: white; border-radius: 12px; font-weight: bold; font-size: 16px; box-shadow: 0 4px 15px var(--accent-glow); transition: 0.3s; }
.auth-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 20px var(--accent-glow); }
.auth-switch { margin-top: 20px; color: var(--text-muted); font-size: 14px; }
.auth-switch a { font-weight: bold; margin-left: 5px; color: var(--accent); }

/* БАННЕР */
.frozen-banner { position: fixed; top: 0; left: 0; right: 0; background: linear-gradient(90deg, var(--danger), #ff6b81); color: white; padding: 12px; font-weight: bold; z-index: 10000; display: flex; justify-content: center; align-items: center; box-shadow: 0 4px 15px rgba(255, 71, 87, 0.4); }
.frozen-content { display: flex; align-items: center; gap: 10px; }
.frozen-content svg { width: 20px; height: 20px; }

/* КАРКАС */
.app-layout { display: flex; height: 100vh; }
.sidebar { width: 380px; background: var(--bg-sidebar); backdrop-filter: blur(20px); border-right: 1px solid var(--border-color); display: flex; flex-direction: column; flex-shrink: 0; z-index: 10; }
.sidebar-header { padding: 15px; border-bottom: 1px solid var(--border-color); }
.nav-tabs { display: flex; gap: 5px; background: rgba(0,0,0,0.3); padding: 5px; border-radius: 12px; }
.nav-tab { flex: 1; padding: 8px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--text-muted); transition: 0.2s; }
.nav-tab.active { background: var(--accent); color: white; box-shadow: 0 2px 10px var(--accent-glow); }
.search-container { padding: 15px 15px 0; position: relative; }
.search-input-wrap { display: flex; align-items: center; background: rgba(0,0,0,0.3); border-radius: 12px; padding: 0 12px; border: 1px solid var(--border-color); }
.search-input-wrap svg { width: 18px; height: 18px; color: var(--text-muted); }
.search-input-wrap input { flex: 1; padding: 12px 10px; background: transparent; color: var(--text-main); }
.search-result { position: absolute; top: 100%; left: 15px; right: 15px; background: rgba(20,20,30,0.95); border: 1px solid var(--border-color); border-radius: 12px; margin-top: 8px; padding: 12px; z-index: 100; box-shadow: 0 10px 25px rgba(0,0,0,0.5); backdrop-filter: blur(20px); }
.search-result.not-found { color: var(--text-muted); text-align: center; }
.search-result.found { cursor: pointer; display: flex; align-items: center; gap: 12px; }
.search-result.found:hover { background: var(--hover); }

.chat-list { flex: 1; overflow-y: auto; padding: 10px 0; }
.chat-item { display: flex; align-items: center; padding: 12px 15px; cursor: pointer; transition: 0.2s; border-left: 3px solid transparent; margin: 2px 10px; border-radius: 12px; }
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: rgba(106, 90, 205, 0.2); border-left-color: var(--accent); }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: linear-gradient(135deg, #444, #222); color: white; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: bold; flex-shrink: 0; background-size: cover; background-position: center; margin-right: 15px; box-shadow: 0 4px 10px rgba(0,0,0,0.3); }
.chat-info { flex: 1; min-width: 0; }
.chat-name { font-weight: 600; margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; }
.chat-preview { color: var(--text-muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.verified-badge { color: var(--verified); width: 16px; height: 16px; fill: currentColor; filter: drop-shadow(0 0 3px rgba(30, 144, 255, 0.5)); }
.sidebar-footer { display: flex; align-items: center; padding: 15px; border-top: 1px solid var(--border-color); cursor: pointer; background: rgba(0,0,0,0.2); transition: 0.2s; }
.sidebar-footer:hover { background: var(--hover); }
.avatar-sm { width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, #444, #222); color: white; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: bold; flex-shrink: 0; background-size: cover; background-position: center; }
.sidebar-footer .user-info { flex: 1; margin-left: 12px; }
.sidebar-footer .user-name { font-weight: 600; font-size: 15px; }
.sidebar-footer .user-status { color: var(--accent); font-size: 12px; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); transition: 0.2s; }
.icon-btn:hover { background: var(--hover); color: var(--text-main); }
.icon-btn svg { width: 20px; height: 20px; }

/* ГЛАВНАЯ ЧАСТЬ */
.main-content { flex: 1; display: flex; flex-direction: column; position: relative; background: var(--bg-main); }
.view { display: flex; flex-direction: column; height: 100%; width: 100%; }
.view.hidden { display: none !important; }
.back-btn { display: none; }

/* ЧАТ */
.chat-area { display: flex; flex-direction: column; height: 100%; width: 100%; }
.chat-header { display: flex; align-items: center; padding: 10px 20px; border-bottom: 1px solid var(--border-color); z-index: 5; }
.chat-header-info { margin-left: 12px; cursor: pointer; }
.chat-title { font-weight: 600; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.chat-status { font-size: 12px; color: var(--text-muted); }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 75%; padding: 10px 14px; border-radius: 16px; position: relative; font-size: 15px; line-height: 1.4; word-wrap: break-word; animation: msgIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
@keyframes msgIn { from { opacity: 0; transform: translateY(15px) scale(0.9); } to { opacity: 1; transform: translateY(0) scale(1); } }
.msg:not(.me) { background: var(--bg-msg-in); align-self: flex-start; border-bottom-left-radius: 4px; border: 1px solid var(--border-color); }
.msg.me { background: linear-gradient(135deg, var(--accent), #4b0082); color: white; align-self: flex-end; border-bottom-right-radius: 4px; box-shadow: 0 4px 15px var(--accent-glow); }
.msg .time { font-size: 11px; color: rgba(255,255,255,0.6); float: right; margin: 4px 0 0 10px; }
[data-theme="light"] .msg.me .time { color: rgba(0,0,0,0.5); }
.msg img { max-width: 100%; border-radius: 10px; margin-bottom: 5px; }
.msg.system { align-self: center; background: rgba(255,255,255,0.05); border: 1px solid var(--border-color); text-align: center; font-size: 13px; max-width: 90%; border-radius: 12px; backdrop-filter: blur(10px); }
.chat-input-area { padding: 15px 20px; border-top: 1px solid var(--border-color); display: flex; align-items: center; gap: 10px; z-index: 5; }
.chat-input-area input { flex: 1; padding: 14px 20px; border-radius: 24px; background: rgba(0,0,0,0.3); color: var(--text-main); border: 1px solid var(--border-color); transition: 0.3s; }
.chat-input-area input:focus { border-color: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }
.send-btn { background: var(--accent); color: white; box-shadow: 0 0 15px var(--accent-glow); }
.send-btn:hover { transform: scale(1.05); }
.chat-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; color: var(--text-muted); }
.empty-icon { width: 80px; height: 80px; margin-bottom: 20px; opacity: 0.2; }

/* НАСТРОЙКИ */
.page-header { display: flex; align-items: center; justify-content: space-between; padding: 15px 20px; border-bottom: 1px solid var(--border-color); }
.page-header h2 { font-size: 18px; font-weight: 600; flex: 1; text-align: center; }
.settings-list { padding: 20px; max-width: 700px; margin: 0 auto; width: 100%; overflow-y: auto; }
.settings-item { display: flex; align-items: center; padding: 15px; border-radius: 16px; cursor: pointer; transition: 0.2s; margin-bottom: 5px; }
.settings-item:hover { background: rgba(255,255,255,0.05); transform: translateX(5px); }
.settings-icon { width: 45px; height: 45px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: white; margin-right: 18px; flex-shrink: 0; box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
.settings-icon svg { width: 24px; height: 24px; }
.settings-text { flex: 1; }
.settings-title { font-weight: 600; font-size: 16px; margin-bottom: 3px; }
.settings-desc { font-size: 13px; color: var(--text-muted); }
.bg-blue { background: linear-gradient(135deg, #3390ec, #1e5aa8); } .bg-orange { background: linear-gradient(135deg, #f5a623, #b87b15); } .bg-green { background: linear-gradient(135deg, #4caf50, #2e7d32); } .bg-red { background: linear-gradient(135deg, #e53935, #b71c1c); } .bg-purple { background: linear-gradient(135deg, #9c27b0, #6a1b9a); }

/* ПРОФИЛЬ */
.profile-view-container { padding: 40px 20px; max-width: 600px; margin: 0 auto; width: 100%; display: flex; flex-direction: column; align-items: center; }
.profile-avatar-lg { width: 120px; height: 120px; border-radius: 50%; background: var(--accent); margin-bottom: 20px; background-size: cover; background-position: center; font-size: 40px; display: flex; align-items: center; justify-content: center; box-shadow: 0 10px 30px var(--accent-glow); border: 4px solid rgba(255,255,255,0.1); }
.profile-name { font-size: 28px; font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.profile-username { color: var(--accent); font-size: 16px; margin-bottom: 15px; }
.profile-bio { color: var(--text-main); text-align: center; margin-bottom: 20px; line-height: 1.5; }
.profile-official-text { color: var(--text-muted); font-size: 13px; text-align: center; background: rgba(255,255,255,0.05); padding: 15px; border-radius: 12px; margin-bottom: 20px; width: 100%; border: 1px solid var(--border-color); }

/* МАГАЗИН И 3D NFT (СТИЛЬ КАК НА ФОТО) */
.shop-container { padding: 20px; max-width: 900px; margin: 0 auto; width: 100%; overflow-y: auto; }
.balance-badge { background: rgba(0,0,0,0.5); border: 1px solid var(--border-color); padding: 6px 16px; border-radius: 20px; font-weight: bold; color: var(--warning); }
.nft-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 15px; margin-top: 20px; }
.nft-card { position: relative; background: #1a1a24; border-radius: 16px; overflow: hidden; cursor: pointer; transition: 0.3s; aspect-ratio: 1; border: 1px solid rgba(255,255,255,0.05); }
.nft-card:hover { transform: translateY(-5px) scale(1.02); box-shadow: 0 10px 25px rgba(0,0,0,0.5), 0 0 15px var(--accent-glow); border-color: var(--accent); }
.nft-badge { position: absolute; top: 0; right: 0; background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(0,0,0,0.5)); padding: 4px 12px; border-bottom-left-radius: 12px; font-size: 12px; font-weight: bold; z-index: 2; backdrop-filter: blur(5px); }
.nft-canvas { position: absolute; inset: 0; }
.nft-canvas canvas { width: 100% !important; height: 100% !important; }
.nft-price { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; font-weight: bold; color: var(--warning); z-index: 2; text-shadow: 0 2px 4px #000; }

/* РЕДАКТОР */
.editor-container { max-width: 700px; margin: 0 auto; padding: 20px; width: 100%; overflow-y: auto; }
.editor-title { width: 100%; font-size: 28px; font-weight: bold; background: transparent; border: none; border-bottom: 1px solid var(--border-color); color: var(--text-main); padding: 10px 0; margin-bottom: 20px; }
.editor-toolbar { display: flex; gap: 8px; margin-bottom: 15px; }
.editor-toolbar button { padding: 8px 12px; border-radius: 8px; background: var(--bg-sidebar); border: 1px solid var(--border-color); }
.editor-content { min-height: 400px; padding: 20px; border-radius: 12px; border: 1px solid var(--border-color); background: rgba(0,0,0,0.2); outline: none; line-height: 1.6; font-size: 16px; }
.btn-primary { padding: 10px 20px; background: var(--accent); color: white; border-radius: 10px; font-weight: 600; box-shadow: 0 0 10px var(--accent-glow); }
.publish-result { margin-top: 15px; padding: 15px; background: var(--bg-sidebar); border: 1px solid var(--accent); border-radius: 12px; }

/* АДМИН */
.admin-content { padding: 20px; max-width: 800px; margin: 0 auto; width: 100%; overflow-y: auto; }
.admin-card { background: rgba(255,255,255,0.03); border: 1px solid var(--border-color); border-radius: 16px; padding: 20px; margin-bottom: 15px; transition: 0.2s; }
.admin-card:hover { border-color: rgba(255,255,255,0.2); }
.admin-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 15px; }
.admin-actions button { padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; border: 1px solid var(--border-color); transition: 0.2s; }
.admin-actions button:hover { background: rgba(255,255,255,0.1); }
.btn-red { color: var(--danger); border-color: var(--danger); }
.btn-green { color: var(--success); border-color: var(--success); }
.btn-blue { color: var(--accent); border-color: var(--accent); }

/* МОДАЛКИ */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(5px); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 20px; }
.modal-box { padding: 30px; border-radius: 20px; width: 100%; max-width: 420px; position: relative; box-shadow: 0 20px 50px rgba(0,0,0,0.5); }
.modal-close { position: absolute; top: 15px; right: 15px; font-size: 24px; color: var(--text-muted); }
.modal-box h3 { margin-bottom: 20px; font-size: 20px; }
.modal-box input, .modal-box textarea { width: 100%; padding: 14px; background: rgba(0,0,0,0.3); border: 1px solid var(--border-color); border-radius: 12px; color: var(--text-main); margin-bottom: 15px; }
.modal-box button.submit { width: 100%; padding: 14px; background: linear-gradient(135deg, var(--accent), #4b0082); color: white; border-radius: 12px; font-weight: bold; }

/* ТОСТ */
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%) translateY(100px); background: var(--bg-sidebar); border: 1px solid var(--accent); color: var(--text-main); padding: 14px 28px; border-radius: 30px; transition: transform 0.3s; z-index: 2000; box-shadow: 0 10px 30px rgba(0,0,0,0.5), 0 0 15px var(--accent-glow); }
.toast.show { transform: translateX(-50%) translateY(0); }

/* МОБИЛЬНАЯ */
@media (max-width: 768px) {
    .sidebar { width: 100%; }
    .main-content { position: fixed; inset: 0; z-index: 100; display: none; background: var(--bg-main); }
    .main-content.active { display: flex; }
    .back-btn { display: flex; margin-right: 10px; }
    .chat-empty { display: none; }
}
/* Responsive layout improvements */
.sidebar { width: min(430px, 38vw); }
.chat-header, .chat-input-area { padding: 16px 24px; }
.chat-messages { padding: 24px; }
.msg { font-size: 16px; max-width: 82%; }
.admin-extra { display:flex; flex-wrap:wrap; gap:8px; margin-top:10px; }
.admin-extra input { min-width:120px; padding:9px; border-radius:8px; color:var(--text-main); background:var(--bg-main); border:1px solid var(--border-color); }
@media(max-width:900px){.sidebar{width:34vw;min-width:260px}.msg{max-width:90%}}
@media(max-width:600px){.sidebar{width:100%;min-width:0}.main-content{width:100%}.chat-messages{padding:12px}.chat-header,.chat-input-area{padding:10px 12px}.msg{max-width:94%;font-size:15px}}

#shopView, .nav-tab[data-tab='shop'] {display:none!important}

html,body{width:100%;min-height:100%;height:100dvh;overflow:hidden}
@media(max-width:768px){
 body{font-size:16px;background-image:none}
 .app-layout{height:100dvh;min-height:100dvh;width:100%;overflow:hidden}
 .sidebar{width:100%;max-width:none}
 .main-content{width:100%;min-width:0;height:100dvh}
 #mainContent.active{display:flex}
 .chat-area,.view{height:100dvh;min-height:0}
 .chat-header{padding:10px 12px;min-height:60px}
 .chat-messages{padding:12px;overflow-y:auto}
 .msg{max-width:88%;font-size:16px}
 .chat-input-area{padding:8px;gap:6px;padding-bottom:max(8px,env(safe-area-inset-bottom))}
 .chat-input-area input{min-width:0;padding:12px}
 .icon-btn{width:38px;height:38px;flex-shrink:0}
 .page-header{padding:12px}
 .admin-content,.settings-list{overflow:auto;max-height:calc(100dvh - 60px)}
}

/* Mobile stability: prevent overlays from swallowing controls and force a usable viewport */
@media (max-width: 768px) {
  html, body { width:100%; height:100%; height:100dvh; overflow:hidden; }
  #authScreen { z-index:10000; overflow-y:auto; padding:16px; }
  .auth-box { width:min(100%, 440px); margin:auto; padding:24px; }
  .app-layout { position:fixed; inset:0; width:100%; height:100%; height:100dvh; }
  .sidebar { flex:0 0 100%; width:100%; min-width:0; }
  .main-content { position:fixed; inset:0; height:100%; height:100dvh; z-index:100; }
  .main-content.active { display:flex !important; }
  .main-content:not(.active) { display:none !important; }
  button, input, a, [onclick] { touch-action: manipulation; }
}
