/* ============================================================
   🗺️ КАРТА + ДАШБОРД — СТИЛИ
   ============================================================ */

/* ---- TOP TOOLBAR ---- */
#top-toolbar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
    height: 46px; background: linear-gradient(135deg, #1a237e, #283593);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 12px; color: white; box-shadow: 0 2px 10px rgba(0,0,0,0.3);
}
.toolbar-left { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.toolbar-left strong { font-weight: 700; }
.toolbar-stats { display: flex; gap: 4px; margin-left: 6px; }
.toolbar-stats span {
    background: rgba(255,255,255,0.15); border-radius: 10px;
    padding: 1px 8px; font-size: 10px; font-weight: 600;
    color: rgba(255,255,255,0.75); min-width: 28px; text-align: center;
}
.toolbar-center { display: flex; gap: 2px; }
.tb-btn {
    padding: 8px 16px; border: none; background: rgba(255,255,255,0.12);
    color: rgba(255,255,255,0.85); font-size: 13px; cursor: pointer;
    font-weight: 500; border-radius: 6px; transition: 0.2s;
}
.tb-btn:hover { background: rgba(255,255,255,0.22); color: white; }
.tb-btn.active { background: rgba(255,255,255,0.28); color: white; font-weight: 700; }
.tb-btn.tb-start { background: #2e7d32; color: white; font-weight: 700; }
.tb-btn.tb-start:hover { background: #388e3c; }
.tb-btn.tb-nav { font-weight: 600; font-size: 14px; padding: 8px 20px; letter-spacing: 0.3px; background: rgba(255,255,255,0.18); }
.tb-btn.tb-nav:hover { background: rgba(255,255,255,0.28); }
.toolbar-right { display: flex; gap: 6px; }

/* ---- NAV DROPDOWN ---- */
.nav-dropdown-wrapper { position: relative; }
.nav-dropdown {
    display: none; position: absolute; top: calc(100% + 4px); left: 0;
    min-width: 270px; background: #fff; border-radius: var(--radius-md);
    box-shadow: 0 8px 32px rgba(0,0,0,0.2); z-index: 2000;
    padding: 6px 0; animation: dropdownIn 0.2s ease;
}
.nav-dropdown.open { display: block; }
@keyframes dropdownIn {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}
.nav-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 10px 18px; border: none; background: none;
    font-size: 14px; color: var(--text); cursor: pointer; text-align: left;
    transition: background 0.15s; font-family: inherit;
}
.nav-item:hover { background: #f0f4ff; }
.nav-item .nav-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }
.nav-divider { height: 1px; background: var(--border); margin: 4px 12px; }

/* ---- MAP ---- */
#map-container {
    position: fixed; top: 46px; left: 0; right: 0; bottom: 42px;
    background: #e8e4d8; z-index: 1;
}
#map-container .leaflet-container { width: 100%; height: 100%; }
/* Zoom control — центр по вертикали */
#map-container .leaflet-top.leaflet-left {
    top: 50% !important;
    transform: translateY(-50%);
}
#map-container .leaflet-control-zoom {
    top: 0 !important;
    transform: none;
}
/* Скрыть атрибуцию */
#map-container .leaflet-bottom.leaflet-right {
    display: none !important;
}

/* ---- MINI DASHBOARD (floating on map, bottom-left) ---- */
#mini-dashboard {
    position: absolute; bottom: 10px; left: 10px; z-index: 1000;
    background: rgba(255,255,255,0.94); border-radius: 12px;
    padding: 8px 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.18);
    font-size: 11px; line-height: 1.5; min-width: 175px;
    backdrop-filter: blur(6px); border: 1px solid rgba(0,0,0,0.08);
    cursor: pointer; transition: all 0.2s;
}
#mini-dashboard:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.25); transform: translateY(-2px); }
#mini-dashboard .mini-row { padding: 1px 0; }
#mini-dashboard .mini-time { font-weight: 700; font-size: 12px; color: #1a237e; }

/* ---- MAP FLOATING BLOCKS ---- */
.map-floating-block {
    position: absolute; z-index: 900;
    background: rgba(255,255,255,0.94); border-radius: 10px;
    padding: 10px 14px; box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    font-size: 11px; backdrop-filter: blur(6px);
    border: 1px solid rgba(0,0,0,0.08);
    transition: opacity 0.3s; max-width: 280px;
}
.map-floating-block:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.2); }
.map-floating-block-clickable { cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
.map-floating-block-clickable:hover { transform: translateY(-2px); box-shadow: 0 6px 24px rgba(21,101,192,0.2); }

@media (max-width: 768px) {
    .map-floating-block { display: none; }
}
#map-schedule-icon { transition: transform 0.2s, box-shadow 0.2s; }
#map-schedule-icon:hover { transform: scale(1.1); box-shadow: 0 4px 16px rgba(21,101,192,0.3); }
#mini-dashboard .mini-weather { color: #555; font-size: 10px; }
#mini-dashboard .mini-divider { height: 1px; background: #e0e0e0; margin: 4px 0; }
#mini-dashboard .mini-budget { font-weight: 700; font-size: 13px; color: #1a237e; }
#mini-dashboard .mini-budget-delta { font-size: 10px; padding-left: 18px; }
#mini-dashboard .mini-live {
    font-size: 9px; color: #2e7d32; font-weight: 700; margin-top: 4px;
    animation: livePulse 2s infinite;
}
@keyframes livePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ---- BOTTOM PANEL ---- */
#bottom-panel {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000;
    background: white; border-top: 2px solid #1a237e;
    transition: height 0.3s ease; overflow: hidden;
}
#bottom-panel.panel-collapsed { height: 42px; }
#bottom-panel.panel-expanded { height: 500px; }
.panel-handle {
    height: 42px; display: flex; align-items: center; gap: 8px;
    padding: 0 16px; cursor: pointer; user-select: none;
    background: #fafbfc; font-weight: 600; font-size: 13px;
}
.panel-handle:hover { background: #f0f2f5; }
.panel-handle-icon { transition: 0.3s; font-size: 10px; }
.panel-expanded .panel-handle-icon { transform: rotate(180deg); }
.panel-content { padding: 0 16px 16px; overflow-y: auto; max-height: calc(500px - 42px); }
#sessions-list { max-height: none; overflow: visible; }
.panel-tab { display: none; }
.panel-tab.active { display: block; }

/* Layer toggles */
.layer-toggles { display: flex; flex-direction: column; gap: 2px; }
.layer-group-header {
    display: flex; align-items: center; gap: 6px;
    padding: 6px 10px; cursor: pointer; font-size: 12px; font-weight: 700;
    color: #444; border-radius: 6px; margin-top: 6px; user-select: none;
    background: #f5f6f8; transition: 0.15s;
}
.layer-group-header:hover { background: #e8eaf0; }
.layer-group-header .lg-arrow { font-size: 9px; transition: 0.2s; width: 14px; text-align: center; }
.layer-group-header.open .lg-arrow { transform: rotate(90deg); }
.layer-group-header .lg-count { font-size: 10px; color: #999; margin-left: auto; }
.layer-group-items { display: none; flex-wrap: wrap; gap: 4px; padding: 4px 0 4px 18px; }
.layer-group-items.open { display: flex; }

.layer-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 14px; font-size: 11px; cursor: pointer;
    border: 2px solid transparent; transition: 0.15s; font-weight: 500;
    background: #f8f9fa; color: #555;
}
.layer-chip:hover { background: #e8eaf0; }
.layer-chip.active { border-color: #1a237e; background: #f0f4ff; color: #1a237e; font-weight: 700; }
.layer-chip .lc-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.layer-chip .lc-badge {
    font-size: 9px; background: #ddd; color: #666; border-radius: 8px;
    padding: 0 5px; min-width: 18px; text-align: center; font-weight: 700;
}
.layer-chip.active .lc-badge { background: #1a237e; color: white; }

/* Mini metrics in panel */
.mini-metrics-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mini-metric-card {
    background: #f8f9fa; border-radius: 8px; padding: 10px; text-align: center;
    font-size: 11px; transition: 0.2s;
}
.mini-metric-card:hover { transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.08); }
.mini-metric-card .mm-val { font-size: 20px; font-weight: 800; }
.mini-metric-card .mm-label { color: #666; margin-top: 2px; }
.mm-green { color: #2e7d32; } .mm-red { color: #c62828; } .mm-yellow { color: #e65100; } .mm-blue { color: #1565c0; }

/* ---- FULL DASHBOARD MODAL (fullscreen with 5% margins) ---- */
.dash-overlay {
    display: none; position: fixed; inset: 0; z-index: 2000;
    background: rgba(0,0,0,0.55);
    backdrop-filter: blur(3px);
}
.dash-overlay.open { display: block; }
.dash-panel {
    position: fixed; z-index: 2001;
    top: 5vh; left: 5vw; right: 5vw; bottom: 5vh;
    width: auto; max-width: none; height: auto;
    background: white; box-shadow: 0 8px 40px rgba(0,0,0,0.35);
    display: flex; flex-direction: column;
    border-radius: 16px; overflow: hidden;
    transform: scale(0.95); opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.25s ease;
}
.dash-overlay.open .dash-panel { transform: scale(1); opacity: 1; }
.dash-panel .dash-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 24px; border-bottom: 1px solid #e5e7eb;
    background: #fafbfc; flex-shrink: 0;
}
.dash-panel .dash-header h2 { font-size: 18px; color: #1a237e; margin: 0; }
.dash-panel .dash-close {
    width: 36px; height: 36px; border: none; background: #eee; border-radius: 50%;
    font-size: 18px; cursor: pointer; transition: 0.2s;
}
.dash-panel .dash-close:hover { background: #ddd; }

/* Dashboard tabs */
.dash-tabs {
    display: flex; overflow-x: auto; border-bottom: 1px solid #e5e7eb;
    background: #fafbfc; padding: 0 16px;
}
.dash-tab {
    padding: 12px 18px; border: none; background: none; font-size: 13px;
    cursor: pointer; font-weight: 500; color: #666; white-space: nowrap;
    border-bottom: 3px solid transparent; transition: 0.2s;
}
.dash-tab:hover { color: #1a237e; }
.dash-tab.active { color: #1a237e; font-weight: 700; border-bottom-color: #1a237e; }

.dash-content {
    flex: 1; overflow-y: auto; padding: 20px 24px;
}
.dash-content .dash-panel { display: none; }
.dash-content .dash-panel.active { display: block; }

/* KPI Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.kpi-card {
    background: white; border-radius: 12px; padding: 16px; border: 1px solid #e5e7eb;
    transition: 0.2s;
}
.kpi-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.08); transform: translateY(-2px); }
.kpi-card .kpi-icon { font-size: 28px; margin-bottom: 6px; }
.kpi-card .kpi-value { font-size: 26px; font-weight: 800; }
.kpi-card .kpi-label { font-size: 12px; color: #888; margin-top: 2px; }
.kpi-card .kpi-trend { font-size: 11px; font-weight: 700; margin-top: 4px; }
.kpi-trend.up { color: #2e7d32; } .kpi-trend.down { color: #c62828; }

/* Chart containers */
.chart-wrap {
    background: white; border-radius: 12px; padding: 16px; border: 1px solid #e5e7eb;
    margin-bottom: 16px;
}
.chart-wrap h4 { margin: 0 0 10px; font-size: 14px; color: #1a237e; }
.chart-wrap canvas { max-height: 280px; }

/* Stat rows */
.stat-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
.stat-row .sr-label { color: #666; }
.stat-row .sr-value { font-weight: 600; }

/* Alert banners */
.alert-banner { padding: 12px 16px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; font-weight: 600; }
.alert-red { background: #ffebee; color: #c62828; border-left: 4px solid #c62828; }
.alert-yellow { background: #fff8e1; color: #e65100; border-left: 4px solid #e65100; }
.alert-green { background: #e8f5e9; color: #2e7d32; border-left: 4px solid #2e7d32; }

/* Health score gauge */
.health-gauge {
    text-align: center; padding: 20px;
}
.health-circle {
    width: 120px; height: 120px; border-radius: 50%; margin: 0 auto 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 36px; font-weight: 800; color: white;
    background: conic-gradient(#2e7d32 0deg, #2e7d32 calc(var(--health)*3.6deg), #e0e0e0 calc(var(--health)*3.6deg));
}

/* History timeline */
.timeline { position: relative; padding-left: 24px; }
.timeline::before {
    content: ''; position: absolute; left: 8px; top: 0; bottom: 0;
    width: 2px; background: #e0e0e0;
}
.timeline-item {
    position: relative; margin-bottom: 16px; padding: 12px 16px;
    background: #f8f9fa; border-radius: 8px; font-size: 13px;
}
.timeline-item::before {
    content: ''; position: absolute; left: -20px; top: 16px;
    width: 10px; height: 10px; border-radius: 50%; background: #1a237e;
}
.timeline-item.approved::before { background: #2e7d32; }
.timeline-item.rejected::before { background: #c62828; }
.timeline-item .tl-date { font-size: 11px; color: #888; }
.timeline-item .tl-topic { font-weight: 600; margin: 4px 0; }
.timeline-item .tl-effects { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tl-chip {
    font-size: 10px; padding: 2px 8px; border-radius: 10px; font-weight: 600;
}
.tl-chip.pos { background: #e8f5e9; color: #2e7d32; }
.tl-chip.neg { background: #ffebee; color: #c62828; }

/* Status bar in modal */
.dash-updated {
    text-align: right; font-size: 11px; color: #999; padding: 8px 0;
}

@media (max-width: 768px) {
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .mini-metrics-grid { grid-template-columns: repeat(2, 1fr); }
    .dash-tabs { gap: 0; }
    .dash-tab { padding: 10px 12px; font-size: 11px; }
    .toolbar-center { display: none; }
}

/* ---- Session chips ---- */
.session-filters {
    display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap;
}
.sf-chip {
    padding: 4px 12px; border-radius: 14px; font-size: 11px; cursor: pointer;
    border: 2px solid #e0e0e0; background: white; font-weight: 500; color: #666;
    transition: 0.15s;
}
.sf-chip:hover { border-color: #1a237e; color: #1a237e; }
.sf-chip.active { background: #1a237e; color: white; border-color: #1a237e; }

/* Override session-stats item style to chips */

/* ======== SESSION CHIPS GRID ======== */
#sessions-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 8px;
}
#sessions-list .session-item {
    display: flex !important;
    flex-direction: column !important;
    padding: 10px 12px !important;
    border-radius: 10px !important;
    background: #fff !important;
    border: 1px solid #e5e7eb !important;
    cursor: pointer;
    transition: all 0.15s;
    gap: 6px !important;
    min-width: 0;
}
#sessions-list .session-item:hover {
    border-color: #1a237e !important;
    box-shadow: 0 2px 8px rgba(26,35,126,0.10);
    transform: translateY(-1px);
}
#sessions-list .session-item .session-header {
    display: flex; align-items: center; gap: 6px;
}
#sessions-list .session-item .session-type {
    font-size: 10px; color: #555; background: #f0f2f5; padding: 2px 8px; border-radius: 6px;
    font-weight: 600; text-transform: uppercase;
}
#sessions-list .session-item .session-status {
    font-size: 11px; font-weight: 700; margin-left: auto;
    padding: 1px 8px; border-radius: 6px;
}
#sessions-list .session-item .session-status.completed { background: #e8f5e9; color: #1b5e20; }
#sessions-list .session-item .session-status.running { background: #fff3e0; color: #bf360c; }
#sessions-list .session-item .session-status.failed,
#sessions-list .session-item .session-status.cancelled { background: #fce4ec; color: #880e4f; }
#sessions-list .session-item .session-meta {
    display: flex; gap: 10px;
}
#sessions-list .session-item .session-stat {
    display: flex; align-items: center; gap: 4px; font-size: 12px;
}
#sessions-list .session-item .session-stat-value {
    font-weight: 700; color: #1a237e; font-size: 14px;
}
#sessions-list .session-item .session-stat-label { color: #999; font-size: 10px; }
#sessions-list .session-item .session-date {
    font-size: 10px; color: #999; border-top: 1px solid #f0f0f0; padding-top: 4px;
}

/* Responsive */
@media (max-width: 700px) {
    #sessions-list { grid-template-columns: 1fr; }
}

/* ======== MOBILE: dropdown → full-width menu ======== */
.tb-burger {
    display: none;
    padding: 8px 10px; border: none; background: rgba(255,255,255,0.15);
    color: white; font-size: 20px; cursor: pointer; border-radius: 6px;
    transition: 0.2s;
}
.tb-burger:hover { background: rgba(255,255,255,0.25); }

@media (max-width: 768px) {
    #top-toolbar { padding: 0 8px; justify-content: space-between; }
    .toolbar-left strong { display: inline; }
    .tb-burger { display: block; order: 10; }
    .toolbar-right { order: 5; }
    .nav-dropdown-wrapper { position: static; }
    #toolbar-menu {
        display: none;
        position: absolute; top: 46px; left: 0; right: 0;
        background: #1a237e; flex-direction: column; padding: 6px;
        box-shadow: 0 4px 12px rgba(0,0,0,0.3); z-index: 999;
    }
    #toolbar-menu.open { display: flex; }
    .nav-dropdown {
        display: flex !important; flex-direction: column;
        position: static; width: 100%; border-radius: 0;
        box-shadow: none; background: transparent;
        padding: 0; animation: none;
    }
    .nav-item {
        color: rgba(255,255,255,0.85); padding: 10px 14px;
        border-radius: 4px; font-size: 14px;
    }
    .nav-item:hover { background: rgba(255,255,255,0.15); color: #fff; }
    .nav-divider { background: rgba(255,255,255,0.15); }
    .tb-btn.tb-nav { width: 100%; text-align: left; display: none; }
    .toolbar-center { flex: 1; }
}

@media (max-width: 400px) {
    .toolbar-left span { font-size: 11px; }
    .tb-btn.tb-start { font-size: 10px; padding: 5px 8px; }
}

/* ======== AGENT MODAL ======== */
.agent-modal-content { max-width: 550px; max-height: 85vh; }
.agent-card-header {
    display: flex; align-items: center; gap: 14px;
    padding: 16px; background: linear-gradient(135deg,#1a237e,#283593);
    border-radius: var(--radius-md); color: #fff; margin-bottom: 14px;
}
.agent-card-avatar {
    width: 56px; height: 56px; border-radius: 50%;
    background: rgba(255,255,255,0.2); display: flex; align-items: center;
    justify-content: center; font-size: 28px; flex-shrink: 0;
}
.agent-card-info { flex: 1; }
.agent-card-name { font-size: 18px; font-weight: 700; }
.agent-card-role { font-size: 12px; opacity: 0.85; margin-top: 2px; }
.agent-card-meta { font-size: 11px; opacity: 0.7; margin-top: 4px; }
.agent-tabs { display: flex; gap: 2px; margin-bottom: 12px; border-bottom: 2px solid var(--border); }
.agent-tab {
    padding: 8px 16px; border: none; background: none; font-size: 13px;
    cursor: pointer; color: var(--text-muted); font-weight: 500;
    border-bottom: 2px solid transparent; margin-bottom: -2px;
    transition: 0.2s;
}
.agent-tab:hover { color: var(--text); }
.agent-tab.active { color: #1a237e; border-bottom-color: #1a237e; font-weight: 700; }
.agent-stat-row {
    display: flex; justify-content: space-between; padding: 8px 0;
    border-bottom: 1px solid #f0f0f0; font-size: 13px;
}
.agent-stat-label { color: var(--text-muted); }
.agent-stat-value { font-weight: 600; }
.agent-risk-bar {
    height: 6px; background: #eee; border-radius: 3px; margin-top: 4px; overflow: hidden;
}
.agent-risk-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }
.agent-relation-row {
    display: flex; align-items: center; gap: 8px; padding: 6px 0;
    border-bottom: 1px solid #f5f5f5; font-size: 12px;
}
.agent-relation-bar {
    flex: 1; height: 6px; background: #eee; border-radius: 3px; overflow: hidden;
}
.agent-relation-fill { height: 100%; border-radius: 3px; }
.agent-diary-entry {
    background: #faf5ff; border-left: 3px solid #9c27b0;
    border-radius: 4px; padding: 8px 12px; margin-bottom: 8px; font-size: 12px; line-height: 1.5;
}

/* ======== FLOATING DRAGGABLE START BTN ======== */
#btn-start-session.floaty {
    position: fixed !important; z-index: 1500;
    bottom: 60px; right: 16px;
    padding: 12px 20px; font-size: 14px;
    border-radius: 28px; box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    cursor: grab; transition: box-shadow 0.2s;
}
#btn-start-session.floaty:active { cursor: grabbing; box-shadow: 0 8px 24px rgba(0,0,0,0.35); }
#btn-start-session.floaty:hover { transform: none; }
