* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #f0f2f5;
    --sidebar-bg: #1a1a2e;
    --sidebar-hover: #252542;
    --card-bg: #ffffff;
    --text: #1c1e21;
    --text-secondary: #65676b;
    --accent: #0084ff;
    --accent-glow: rgba(0, 132, 255, 0.2);
    --success: #31a24c;
    --danger: #e41e3f;
    --warning: #f7b928;
    --border: #e4e6eb;
    --radius: 18px;
    --radius-sm: 12px;
    --shadow: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --transition: 0.15s ease;
}

html, body { height: 100%; overflow: hidden; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    display: flex;
    position: relative;
    transition: background 0.3s, color 0.3s;
    font-size: 15px;
}

body.dark-theme {
    --bg: #18191a;
    --sidebar-bg: #242526;
    --sidebar-hover: #3a3b3c;
    --card-bg: #242526;
    --text: #e4e6eb;
    --text-secondary: #b0b3b8;
    --border: #3e4042;
    --shadow: 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
}

/* САЙДБАР */
.sidebar {
    width: 260px; min-width: 260px;
    background: var(--sidebar-bg);
    color: var(--text);
    padding: 16px 10px;
    position: fixed; left: 0; top: 0; bottom: 0; overflow-y: auto;
    z-index: 100; transition: transform 0.25s ease;
    display: flex; flex-direction: column; gap: 8px;
    border-right: 1px solid var(--border);
}

body:not(.dark-theme) .sidebar {
    background: #ffffff;
    color: #1c1e21;
    border-right: 1px solid #e4e6eb;
}
body:not(.dark-theme) .sidebar-nav a { color: #65676b; }
body:not(.dark-theme) .sidebar-nav a:hover { background: #f0f2f5; color: #1c1e21; }
body:not(.dark-theme) .sidebar-nav a.active { background: rgba(0, 132, 255, 0.1); color: #0084ff; }
body:not(.dark-theme) .sidebar-header h2 { color: #0084ff; }
body:not(.dark-theme) .sidebar-city { color: #65676b; }
body:not(.dark-theme) .sidebar-footer select { background: #f0f2f5; color: #1c1e21; border-color: #e4e6eb; }
body:not(.dark-theme) .sidebar-footer select option { background: #fff; color: #1c1e21; }
body:not(.dark-theme) .sidebar-online { color: #65676b; }
body:not(.dark-theme) .sidebar-weather { color: #65676b; }
body:not(.dark-theme) .sidebar-footer { border-top: 1px solid #e4e6eb; }
body:not(.dark-theme) .sidebar-header { border-bottom: 1px solid #e4e6eb; }

.sidebar-header { text-align: center; padding: 4px 0 12px; border-bottom: 1px solid var(--border); }
.sidebar-header h2 { font-size: 17px; font-weight: 700; color: #0084ff; letter-spacing: -0.3px; }
.sidebar-city { font-size: 10px; color: var(--text-secondary); margin-top: 1px; text-transform: uppercase; letter-spacing: 1px; }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px; border-radius: 8px;
    color: #b0b3b8; font-size: 14px; font-weight: 400;
    cursor: pointer; transition: all var(--transition);
    white-space: nowrap;
}
.sidebar-nav a:hover { background: var(--sidebar-hover); color: #e4e6eb; }
.sidebar-nav a.active { background: rgba(0, 132, 255, 0.15); color: #0084ff; font-weight: 600; }

.sidebar-footer { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid var(--border); }
.sidebar-online { text-align: center; font-size: 11px; color: var(--text-secondary); padding: 2px; }
.sidebar-footer select {
    width: 100%; padding: 8px 10px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--sidebar-bg);
    color: #e4e6eb; font-size: 12px; outline: none; cursor: pointer;
}
.sidebar-footer select option { background: var(--sidebar-bg); color: #e4e6eb; }
.sidebar-weather { text-align: center; font-size: 11px; color: var(--text-secondary); padding: 4px; }

/* БУРГЕР */
.menu-btn { display: none; position: fixed; top: 12px; left: 12px; z-index: 200; background: var(--card-bg); color: var(--text); border: 1px solid var(--border); width: 40px; height: 40px; border-radius: 50%; font-size: 18px; cursor: pointer; box-shadow: var(--shadow-md); align-items: center; justify-content: center; }
.overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; backdrop-filter: blur(2px); }
.overlay.active { display: block; }

/* ОСНОВНАЯ ОБЛАСТЬ */
.main { margin-left: 260px; flex: 1; display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 10;
}
.topbar h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.city-badge {
    font-size: 11px; color: var(--accent); background: rgba(0, 132, 255, 0.08);
    padding: 4px 12px; border-radius: 20px; border: 1px solid rgba(0, 132, 255, 0.15);
    font-weight: 500;
}
.content { flex: 1; overflow-y: auto; padding: 10px 14px 14px; -webkit-overflow-scrolling: touch; }

/* КАРТОЧКИ */
.card {
    background: var(--card-bg); padding: 14px; border-radius: 10px;
    margin-bottom: 8px; border: 1px solid var(--border);
    box-shadow: var(--shadow); transition: all var(--transition); overflow: hidden;
}
.card:hover { box-shadow: var(--shadow-md); }
.card h4 { font-size: 15px; font-weight: 600; margin-bottom: 4px; word-break: break-word; }
.card p { font-size: 14px; color: var(--text-secondary); margin-bottom: 3px; word-break: break-word; }
.card .price { font-weight: 700; color: var(--success); font-size: 16px; }
.card .contact { color: var(--accent); font-weight: 500; word-break: break-all; }
.card .meta { font-size: 11px; color: #8a8d91; margin-top: 4px; }
.card-photo { width: 100%; height: 150px; overflow: hidden; border-radius: 8px 8px 0 0; margin: -14px -14px 10px -14px; }
.card-photo img { width: 100%; height: 100%; object-fit: cover; }
.photos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 4px; margin-bottom: 10px; }
.photos-grid img { width: 100%; height: 110px; object-fit: cover; border-radius: 8px; }

/* ФОРМЫ */
input, textarea, select, button {
    width: 100%; padding: 10px 12px; margin: 3px 0;
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 15px; font-family: var(--font); outline: none;
    background: var(--card-bg); color: var(--text); transition: all var(--transition);
}
body.dark-theme input, body.dark-theme textarea, body.dark-theme select { background: #3a3b3c; border-color: #4e4f50; color: #e4e6eb; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }
textarea { resize: vertical; min-height: 80px; }
input[type="file"] { padding: 6px; font-size: 13px; }
button { background: var(--accent); color: #fff; border: none; cursor: pointer; font-weight: 600; padding: 10px 16px; font-size: 15px; border-radius: 8px; }
button:hover { opacity: 0.9; }
button.secondary { background: #e4e6eb; color: var(--text); border: 1px solid var(--border); }
body.dark-theme button.secondary { background: #3a3b3c; color: #e4e6eb; border-color: #4e4f50; }

/* ЧАТ */
.chat-wrapper { display: flex; flex-direction: column; height: calc(100vh - 120px); }
.chat-box { flex: 1; overflow-y: auto; background: var(--bg); padding: 10px; border-radius: 0; margin-bottom: 6px; border: none; display: flex; flex-direction: column; gap: 6px; }
body.dark-theme .chat-box { background: var(--bg); }
.chat-msg { 
    padding: 8px 12px; background: var(--card-bg); border-radius: 18px; 
    max-width: 80%; align-self: flex-start; box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
body.dark-theme .chat-msg { background: #3a3b3c; border-color: #4e4f50; }
.chat-msg .user { font-weight: 600; color: var(--accent); font-size: 11px; }
.chat-msg .text { font-size: 15px; color: var(--text); word-break: break-word; overflow-wrap: break-word; line-height: 1.4; }
.chat-msg .time { font-size: 9px; color: #8a8d91; float: right; margin-top: 2px; }
.chat-input-row { display: flex; gap: 6px; }
.chat-input-row input { 
    flex: 1; border-radius: 24px; padding: 10px 16px; 
    background: var(--card-bg); border: 1px solid var(--border); 
    font-size: 15px; word-break: break-word; overflow-wrap: break-word;
}
body.dark-theme .chat-input-row input { background: #3a3b3c; border-color: #4e4f50; }
.chat-input-row input:focus { border-color: var(--accent); }
.chat-input-row button { width: 40px; height: 40px; border-radius: 50%; padding: 0; display: flex; align-items: center; justify-content: center; font-size: 18px; }

/* ОТВЕТЫ В ЧАТЕ */
.msg-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 3px; }
.msg-actions { display: flex; gap: 6px; }
.msg-action-btn { width: auto; padding: 2px 8px; font-size: 11px; background: transparent; color: var(--text-secondary); border: none; cursor: pointer; font-weight: 500; }
.msg-action-btn:hover { color: var(--accent); }
.reply-quote { font-size: 12px; color: var(--accent); background: rgba(0,132,255,0.08); padding: 4px 8px; border-radius: 6px; margin-bottom: 4px; border-left: 3px solid var(--accent); cursor: pointer; word-break: break-word; }
.reply-quote:hover { background: rgba(0,132,255,0.15); }
.chat-reply-bar { margin-bottom: 6px; }
.reply-preview { font-size: 13px; color: var(--accent); background: rgba(0,132,255,0.1); padding: 8px 10px; border-radius: 10px; display: flex; justify-content: space-between; align-items: center; word-break: break-word; }
.cancel-reply { width: auto; padding: 3px 8px; font-size: 13px; background: transparent; color: var(--danger); border: none; cursor: pointer; }

/* СЧЁТЧИК СИМВОЛОВ */
.char-counter { text-align: right; font-size: 11px; color: var(--text-secondary); padding: 3px 6px 0; }

/* БЕЙДЖ УВЕДОМЛЕНИЙ */
.nav-badge {
    display: inline-block;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border-radius: 9px;
    padding: 0 5px;
    margin-left: auto;
}

/* ПРОФИЛЬ */
.profile-info { text-align: center; padding: 16px; }
.profile-avatar { width: 72px; height: 72px; background: #e4e6eb; border-radius: 50%; margin: 0 auto 10px; display: flex; align-items: center; justify-content: center; font-size: 30px; color: #8a8d91; background-size: cover; background-position: center; }
.profile-info h3 { font-size: 18px; margin-bottom: 2px; font-weight: 700; }
.profile-info p { font-size: 14px; color: var(--text-secondary); }

/* TOAST */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; max-width: 320px; }
.toast { padding: 12px 16px; border-radius: 10px; color: #fff; font-size: 14px; font-weight: 500; box-shadow: 0 6px 24px rgba(0,0,0,0.25); animation: slideIn 0.3s ease; cursor: pointer; }
.toast-success { background: #31a24c; }
.toast-error { background: #e41e3f; }
.toast-info { background: #0084ff; }
.toast-warning { background: #f7b928; color: #1c1e21; }
@keyframes slideIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-thumb { background: #c1c4c8; border-radius: 3px; }
body.dark-theme ::-webkit-scrollbar-thumb { background: #5b5c5e; }
.loading { background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); background-size: 400px 100%; animation: shimmer 1.5s infinite; border-radius: 10px; height: 50px; }
body.dark-theme .loading { background: linear-gradient(90deg, #3a3b3c 25%, #4e4f50 50%, #3a3b3c 75%); }
@keyframes shimmer { 0% { background-position: -200px 0; } 100% { background-position: 200px 0; } }

/* ПЛАВАЮЩАЯ КНОПКА */
.mobile-add-btn {
    display: none;
    position: fixed; bottom: 24px; right: 24px;
    width: 56px; height: 56px; border-radius: 50%;
    background: var(--accent); color: #fff; font-size: 28px;
    border: none; box-shadow: 0 6px 20px rgba(0, 132, 255, 0.5);
    z-index: 200; cursor: pointer; align-items: center; justify-content: center;
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: 280px; }
    .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,0.5); }
    .main { margin-left: 0; }
    .menu-btn { display: flex; }
    .topbar { padding-left: 56px; }
    .chat-wrapper { height: calc(100vh - 140px); }
    .card { padding: 12px; }
    .card-photo { margin: -12px -12px 8px -12px; height: 140px; }
    .mobile-add-btn { display: flex !important; }
    #addPostBtn { display: none; }
}