/* ============================================================
   🏘️ Нейро-деревня — стили
   ============================================================ */

/* --- Сброс и переменные --- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-card: #1e2a4a;
    --bg-input: #0f3460;
    --bg-hover: #253a5e;
    --text-primary: #e8e8e8;
    --text-secondary: #a0a8c0;
    --text-muted: #6a7290;
    --accent: #4fc3f7;
    --accent-hover: #29b6f6;
    --success: #66bb6a;
    --warning: #ffa726;
    --danger: #ef5350;
    --refuse: #ef5350;
    --partial: #ffa726;
    --accept: #66bb6a;
    --border: #2a3a5e;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --transition: .2s ease;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

/* --- Скроллбар --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* --- Шапка --- */
.header {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    height: 52px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    z-index: 10;
}

.header-inner {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
}

.header-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
}

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

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.status-dot.checking { background: var(--warning); animation: pulse 1s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
}

.btn {
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    transition: var(--transition);
    padding: 8px 16px;
}

.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); color: #000; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-input); color: var(--text-primary); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #e53935; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* --- Основной макет --- */
.main-layout {
    display: flex;
    height: calc(100vh - 52px);
    max-width: 1400px;
    margin: 0 auto;
    gap: 1px;
    background: var(--border);
}

.panel {
    background: var(--bg-primary);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.panel-left {
    width: 260px;
    min-width: 220px;
    flex-shrink: 0;
}

.panel-center {
    flex: 1;
    min-width: 300px;
}

.panel-right {
    width: 360px;
    min-width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.panel-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.badge {
    background: var(--accent);
    color: #000;
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 10px;
    line-height: 18px;
}

/* --- Список жителей --- */
.citizen-list {
    padding: 8px;
    flex: 1;
    overflow-y: auto;
}

.citizen-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.citizen-card:hover {
    background: var(--bg-hover);
    border-color: var(--border);
}

.citizen-card.active {
    border-color: var(--accent);
    background: var(--bg-hover);
}

.citizen-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.citizen-emoji {
    font-size: 20px;
    line-height: 1;
}

.citizen-name {
    font-weight: 600;
    font-size: 14px;
}

.citizen-status {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.citizen-mini-stats {
    display: flex;
    gap: 10px;
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-secondary);
}

.mini-stat {
    display: flex;
    align-items: center;
    gap: 3px;
}

.mini-stat .icon { font-size: 12px; }
.mini-stat .value { font-weight: 600; }

/* --- Профиль NPC --- */
.profile-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 12px;
}

.placeholder-icon { font-size: 64px; opacity: .5; }

.profile-placeholder p { font-size: 15px; }

.profile-content {
    padding: 20px;
    overflow-y: auto;
    height: 100%;
    position: relative;
}

.btn-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.btn-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    flex-shrink: 0;
}

.profile-info { flex: 1; }

.profile-info h2 {
    font-size: 20px;
    font-weight: 700;
}

.profile-job {
    font-size: 13px;
    color: var(--text-secondary);
}

.profile-age {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 8px;
}

.profile-influence {
    text-align: center;
    padding: 8px 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
}

.influence-label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
}

.influence-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--accent);
}

.profile-content h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin: 16px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

/* --- Характеристики --- */
.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.stat-bar {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
}

.stat-label {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    margin-bottom: 4px;
}

.stat-label span:last-child {
    font-weight: 600;
    color: var(--text-primary);
}

.stat-track {
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.stat-fill {
    height: 100%;
    border-radius: 3px;
    transition: width .5s ease;
}

.stat-fill.good { background: var(--success); }
.stat-fill.warn { background: var(--warning); }
.stat-fill.bad { background: var(--danger); }

/* --- Личность --- */
.traits {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.trait-tag {
    background: var(--bg-input);
    color: var(--accent);
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 500;
}

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

/* --- Память --- */
.memory-list {
    max-height: 200px;
    overflow-y: auto;
}

.memory-item {
    padding: 6px 0;
    font-size: 12px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    line-height: 1.5;
}

.memory-item:last-child { border-bottom: none; }
.memory-item::before { content: '• '; color: var(--accent); }

/* --- Отношения --- */
.relationship-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.relationship-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.rel-name { font-weight: 600; }
.rel-type { color: var(--text-secondary); font-size: 12px; }
.rel-value { font-weight: 600; min-width: 30px; text-align: right; }

.rel-positive { color: var(--success); }
.rel-negative { color: var(--danger); }
.rel-neutral { color: var(--text-muted); }

/* --- История команд --- */
.command-history {
    max-height: 150px;
    overflow-y: auto;
}

.cmd-item {
    padding: 5px 0;
    font-size: 12px;
    border-bottom: 1px solid var(--border);
}

.cmd-item:last-child { border-bottom: none; }
.cmd-msg { color: var(--text-secondary); }
.cmd-decision { font-weight: 600; }

.cmd-decision.accept { color: var(--accept); }
.cmd-decision.refuse { color: var(--refuse); }
.cmd-decision.partial { color: var(--partial); }

/* --- Чат --- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.msg {
    max-width: 90%;
    animation: fadeIn .3s ease;
}

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

.msg.user {
    align-self: flex-end;
}

.msg.system {
    align-self: flex-start;
}

.msg-content {
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.5;
}

.msg.user .msg-content {
    background: var(--accent);
    color: #000;
    border-bottom-right-radius: 4px;
}

.msg.system .msg-content {
    background: var(--bg-card);
    border-bottom-left-radius: 4px;
    color: var(--text-primary);
}

.msg-timestamp {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
    padding: 0 4px;
}

.msg.user .msg-timestamp { text-align: right; }

/* --- Decision badges --- */
.decision-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 1px 8px;
    border-radius: 8px;
    margin: 4px 0;
}

.decision-badge.accept {
    background: rgba(102, 187, 106, .2);
    color: var(--accept);
}

.decision-badge.refuse {
    background: rgba(239, 83, 80, .2);
    color: var(--refuse);
}

.decision-badge.partial {
    background: rgba(255, 167, 38, .2);
    color: var(--partial);
}

.stat-change {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.stat-change-item { display: flex; align-items: center; gap: 2px; }
.stat-change-item.positive { color: var(--success); }
.stat-change-item.negative { color: var(--refuse); }

.narration-text {
    font-style: italic;
    color: var(--text-secondary);
    font-size: 12px;
    margin-top: 4px;
    line-height: 1.5;
    padding-left: 8px;
    border-left: 2px solid var(--border);
}

/* --- Прямая речь NPC --- */
.speech-text {
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.6;
    margin: 6px 0 4px 0;
    padding: 8px 12px;
    background: rgba(79, 195, 247, 0.06);
    border-left: 3px solid var(--accent);
    border-radius: 0 6px 6px 0;
    font-style: normal;
    quotes: "«" "»";
}

.speech-text::before { content: "«"; color: var(--accent); font-weight: bold; }
.speech-text::after { content: "»"; color: var(--accent); font-weight: bold; }

/* --- Позиция NPC --- */
.opinion-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 8px;
    background: rgba(79, 195, 247, 0.1);
    color: var(--accent);
}

/* --- Шапка ответа NPC --- */
.npc-response-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 2px;
}

.npc-name-with-emotion {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
}

.npc-badges {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.npc-response {
    border-left: 2px solid var(--border);
    padding-left: 8px;
    margin-bottom: 8px;
}

.reason-text {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 3px;
    padding-left: 4px;
}

/* --- Ввод команды --- */
.chat-input-area {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: var(--transition);
    max-height: 80px;
}

.chat-input:focus {
    border-color: var(--accent);
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    border-radius: 50%;
    flex-shrink: 0;
}

.chat-hint {
    padding: 6px 12px 10px;
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    flex-shrink: 0;
}

.hint-example {
    color: var(--accent);
    cursor: pointer;
    transition: var(--transition);
    padding: 1px 4px;
    border-radius: 4px;
}

.hint-example:hover {
    background: var(--bg-hover);
}

/* --- Модал --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--shadow);
}

.modal h3 {
    font-size: 18px;
    margin-bottom: 12px;
}

.modal p {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 8px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* --- Утилиты --- */
.hidden { display: none !important; }
.loading {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ============================================================
   📱 МОБИЛЬНЫЕ СТИЛИ
   ============================================================ */

.mobile-only { display: none; }

/* --- Мобильная навигация --- */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    z-index: 90;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    backdrop-filter: blur(10px);
}

.mobile-nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px 16px;
    border-radius: var(--radius);
    transition: var(--transition);
    position: relative;
}

.mobile-nav-btn .nav-icon { font-size: 22px; line-height: 1; }
.mobile-nav-btn .nav-label { font-size: 10px; font-weight: 500; }

.mobile-nav-btn.active {
    color: var(--accent);
}

.mobile-nav-btn.active::after {
    content: '';
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 24px;
    height: 2px;
    background: var(--accent);
    border-radius: 1px;
}

.mobile-nav-btn:active {
    background: var(--bg-hover);
}

/* Защита от перекрытия — всгда поверх */
.mobile-nav {
    z-index: 999;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-btn { touch-action: manipulation; }

/* --- Мобильный оверлей --- */
.mobile-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 40;
    backdrop-filter: blur(4px);
    transition: opacity .3s ease;
}

/* --- Кнопка-иконка --- */
.btn-icon {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 20px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    line-height: 1;
}

.btn-icon:hover { background: var(--bg-hover); }

/* --- Планшеты (768-1024px) --- */
@media (max-width: 1024px) {
    .panel-left { width: 220px; min-width: 180px; }
    .panel-right { width: 320px; min-width: 280px; }
}

/* --- Мобильные (< 768px) --- */
@media (max-width: 767px) {
    .mobile-only { display: flex; }
    .desktop-only { display: none !important; }

    .header {
        padding: 0 12px;
        height: 48px;
    }

    .header-title { font-size: 15px; }

    .header-status { 
        font-size: 11px;
        gap: 4px;
    }

    .header-inner { gap: 8px; }

    .btn-small { 
        padding: 4px 8px; 
        font-size: 11px; 
    }

    /* Главный лэйаут — только чат виден */
    .main-layout {
        height: calc(100vh - 48px - 56px); /* header + mobile nav */
        padding-bottom: 0;
    }

    /* Панели становятся модальными окнами */
    .panel-left,
    .panel-center {
        position: fixed;
        top: 48px;
        left: 0;
        right: 0;
        bottom: 56px;
        width: 100%;
        min-width: unset;
        z-index: 50;
        transform: translateX(100%);
        transition: transform .3s ease;
        border-radius: 16px 16px 0 0;
        border-top: 2px solid var(--accent);
    }

    .panel-left.open,
    .panel-center.open {
        transform: translateX(0);
    }

    .panel-right {
        width: 100%;
        min-width: unset;
    }

    .panel-left .panel-header {
        padding: 16px 16px 12px;
    }

    .close-panel {
        margin-left: auto;
        font-size: 18px;
        padding: 4px 10px;
        border-radius: 50%;
        background: var(--bg-hover);
    }

    .close-panel:hover { background: var(--border); }

    /* Список жителей на мобилках */
    .citizen-list {
        padding: 4px 12px 12px;
    }

    .citizen-card {
        padding: 8px 10px;
        margin-bottom: 4px;
    }

    .citizen-card-header { gap: 6px; }
    .citizen-emoji { font-size: 18px; }
    .citizen-name { font-size: 13px; }
    .citizen-status { font-size: 10px; }
    .citizen-mini-stats { gap: 8px; font-size: 10px; margin-top: 4px; }
    .mini-stat .icon { font-size: 11px; }
    .mini-stat .value { font-weight: 500; }

    /* Профиль на мобилках */
    .panel-center .profile-content {
        padding: 16px;
    }

    .profile-header {
        flex-wrap: wrap;
        gap: 10px;
    }

    .profile-avatar {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }

    .profile-info h2 { font-size: 17px; }
    .profile-job { font-size: 12px; }
    .profile-age { font-size: 11px; }

    .profile-influence {
        padding: 6px 12px;
    }

    .influence-value { font-size: 18px; }
    .profile-content h3 { font-size: 12px; margin: 12px 0 8px; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
    .stat-bar { padding: 6px 8px; }
    .stat-label { font-size: 11px; }
    .stat-track { height: 5px; }

    .traits { gap: 4px; }
    .trait-tag { font-size: 11px; padding: 2px 8px; }

    .memory-item { font-size: 11px; padding: 4px 0; }
    .relationship-item { font-size: 12px; padding: 5px 8px; }

    /* Чат на мобилках */
    .panel-right .panel-header {
        padding: 10px 14px;
    }

    .chat-messages {
        padding: 8px 10px;
        gap: 6px;
    }

    .msg { max-width: 95%; }
    .msg-content { padding: 6px 10px; font-size: 12px; }

    .msg.user .msg-timestamp { text-align: right; }

    .decision-badge { font-size: 10px; padding: 1px 6px; }

    .speech-text {
        font-size: 13px;
        padding: 6px 10px;
        margin: 4px 0 2px;
    }

    .narration-text { font-size: 11px; }
    .reason-text { font-size: 11px; }

    .stat-change { font-size: 11px; gap: 6px; }
    .npc-response-header { gap: 4px; }
    .npc-name-with-emotion { font-size: 13px; }
    .npc-badges { gap: 4px; }

    /* Поле ввода на мобилках */
    .chat-input-area {
        padding: 8px 10px;
        gap: 6px;
    }

    .chat-input {
        font-size: 14px; /* чтобы не зумило на iOS */
        padding: 8px 10px;
    }

    .btn-send { width: 38px; height: 38px; font-size: 16px; }

    .chat-hint {
        padding: 4px 10px 8px;
        font-size: 10px;
    }

    .hint-example { font-size: 10px; }

    /* Модальные окна */
    .modal {
        padding: 20px;
        max-width: 90%;
        width: 90%;
        margin: 0 16px;
    }

    .modal h3 { font-size: 16px; }
    .modal p { font-size: 12px; }
    .modal-actions { gap: 6px; margin-top: 16px; }
    .modal-actions .btn { font-size: 12px; padding: 6px 14px; }

    /* Мобильная навигация видна */
    .mobile-nav { display: flex; }

    /* Убираем лишнее */
    ::-webkit-scrollbar { width: 3px; }
}

/* --- Очень маленькие экраны (< 400px) --- */
@media (max-width: 400px) {
    .header-title { font-size: 13px; }
    .header-status { font-size: 10px; }
    .chat-input { font-size: 13px; }

    .stats-grid { grid-template-columns: 1fr; }

    .profile-header { flex-direction: column; align-items: flex-start; }
    .profile-influence { align-self: flex-start; }
}
}
