/* ==========================================================================
   River of Time – Shared Styles for Citizen & Historian Dashboards
   ========================================================================== */

#history-pane,
#river-view {
    min-height: 600px;
    position: relative;
    background-color: var(--bg-secondary, #f8fafc);
    color: var(--text-primary, #0f172a);
}

.river-container {
    width: 100%;
    height: 100%;
    min-height: 520px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: visible;
    padding: 0;
}

.river-container[data-mode="historian"] {
    --river-horizontal-padding: 180px;
}

.river-container[data-mode="citizen"] {
    /* Citizen UX: reduced padding for better vertical centering */
    --river-viewport-top-padding: 60px;
    --river-viewport-bottom-padding: 100px;
}

#time-river-container {
    width: 100%;
    min-height: 640px;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: visible;
}
#time-river-container .river-container {
    min-height: 640px;
    padding-bottom: 180px; /* место для плавающих контролов и эпох */
}

/* Header Styles */
.river-header {
    position: absolute;
    top: 1rem;
    left: 1rem;
    width: clamp(220px, 30vw, 320px);
    padding: 0.9rem 1rem;
    border: 1px solid rgba(15, 23, 42, 0.06);
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 12;
    border-radius: 16px;
    box-shadow: 0 15px 35px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.river-header h1 {
    font-size: 1rem;
    margin: 0;
}

.river-floating-controls {
    position: absolute;
    right: 1rem;
    bottom: 1rem;
    width: clamp(240px, 28vw, 360px);
    background: rgba(15, 23, 42, 0.92);
    color: #f8fafc;
    border-radius: 20px;
    padding: 1rem 1.1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    box-shadow: 0 25px 60px rgba(15, 23, 42, 0.35);
    z-index: 20;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* Citizen "cinematic narration" panel */
.river-narration-panel {
    position: absolute;
    left: 1rem;
    bottom: 1rem;
    width: clamp(280px, 34vw, 520px);
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    border: 1px solid rgba(148, 163, 184, 0.35);
    border-radius: 18px;
    padding: 12px 14px;
    box-shadow: 0 20px 55px rgba(15, 23, 42, 0.18);
    z-index: 21;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.river-container[data-mode="citizen"] .river-narration-panel {
    /* Citizen UX: keep panel inside the river container (not sticky to the dashboard header). */
    position: absolute;
}

.river-narration-panel.is-collapsed {
    width: clamp(220px, 26vw, 360px);
    padding: 10px 12px;
    gap: 8px;
}

.river-narration-panel.is-collapsed .river-narration-body {
    display: none;
}

.river-narration-panel.is-collapsed .river-narration-sub {
    display: none;
}

.river-narration-panel.is-collapsed .river-narration-title {
    font-size: 0.9rem;
}

.river-narration-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.river-narration-title {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.river-narration-sub {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.river-narration-actions {
    display: flex;
    gap: 8px;
}

.river-narration-btn {
    border: 1px solid rgba(148, 163, 184, 0.35);
    background: rgba(241, 245, 249, 0.9);
    color: var(--text-primary);
    border-radius: 12px;
    padding: 6px 10px;
    font-weight: 700;
    cursor: pointer;
}

.river-narration-btn:hover {
    background: rgba(226, 232, 240, 0.95);
}

.river-narration-body {
    max-height: 180px;
    overflow: auto;
    font-size: 0.88rem;
    line-height: 1.45;
    color: var(--text-primary);
    white-space: pre-wrap;
}
/* Citizen UX: floating controls should stay visible and be draggable */
.river-container[data-mode="citizen"] .river-floating-controls {
    position: fixed;
}
.river-container[data-mode="citizen"] .river-floating-controls {
    /* Citizen UX: compact + light controls panel (combined with layers) */
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    color: var(--text-primary);
    border: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 20px 55px rgba(15, 23, 42, 0.22);
    border-radius: 16px;
    padding: 0.75rem 0.8rem;
    width: clamp(220px, 26vw, 300px);
    gap: 0.65rem;
}

/* Citizen dashboard: dock controls into the right sidebar (no floating panels) */
.river-floating-controls.is-docked-sidebar {
    position: static !important;
    inset: auto !important;
    width: 100% !important;
    max-width: none !important;
    box-shadow: none !important;
    border-radius: 12px !important;
    margin: 0 !important;
    touch-action: auto !important;
    user-select: auto !important;
}

.river-floating-controls.is-docked-sidebar.is-dragging {
    cursor: default !important;
}
.river-container[data-mode="citizen"] .river-floating-controls.is-dragging {
    box-shadow: 0 26px 70px rgba(15, 23, 42, 0.3);
}
.river-container[data-mode="citizen"] .river-floating-controls .section-title {
    color: var(--text-muted);
    font-size: 0.66rem;
}
.river-container[data-mode="citizen"] .river-floating-controls .river-layers-section {
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    padding-bottom: 0.5rem;
}
.river-container[data-mode="citizen"] .river-floating-controls .button-row button {
    background: rgba(15, 23, 42, 0.04);
    color: var(--text-primary);
    border: 1px solid rgba(148, 163, 184, 0.4);
    padding: 0.3rem 0.65rem;
    border-radius: 10px;
    font-size: 0.75rem;
}
.river-container[data-mode="citizen"] .river-floating-controls .button-row button:hover {
    background: rgba(15, 23, 42, 0.07);
}
.river-container[data-mode="citizen"] .river-floating-controls .river-view-btn {
    background: rgba(37, 99, 235, 0.08);
    color: var(--info);
    border-color: rgba(37, 99, 235, 0.25);
}
.river-container[data-mode="citizen"] .river-floating-controls .river-view-btn.active {
    background: var(--info);
    color: var(--text-inverse);
    box-shadow: 0 10px 22px rgba(37, 99, 235, 0.35);
}
.river-container[data-mode="citizen"] .river-floating-controls .toggle-btn.active {
    background: rgba(16, 185, 129, 0.18);
    border-color: rgba(16, 185, 129, 0.45);
    color: var(--success);
    box-shadow: 0 10px 22px rgba(16, 185, 129, 0.25);
}
.river-container[data-mode="citizen"] .river-floating-controls .epoch-section {
    border-top: 1px solid rgba(15, 23, 42, 0.08);
    padding-top: 0.55rem;
}
.river-container[data-mode="citizen"] .river-floating-controls .epoch-btn {
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    color: var(--text-primary);
}
.river-container[data-mode="citizen"] .river-floating-controls .epoch-btn:hover {
    background: rgba(226, 232, 240, 0.9);
}
.time-river-modal .river-container[data-mode="citizen"] .river-floating-controls {
    /* Modal UX: keep controls inside the modal canvas (fixed would pin to viewport and overlap modal header). */
    position: absolute;
}
.river-floating-controls {
    user-select: none;
    touch-action: none;
}
.river-floating-controls.is-dragging {
    cursor: grabbing;
    box-shadow: 0 28px 70px rgba(15, 23, 42, 0.45);
}

/* Historian: node drag-and-drop (professional workflow) */
.code-node.is-dragging-node {
    cursor: grabbing;
    opacity: 0.98;
    transform: translate(-50%, -50%) scale(1.02);
    box-shadow: 0 22px 48px rgba(15, 23, 42, 0.32);
    z-index: 40;
}

.code-node.position-dirty {
    outline: 2px dashed rgba(249, 115, 22, 0.9);
    outline-offset: 3px;
}
.river-floating-controls .control-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.river-floating-controls .section-title {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: rgba(248, 250, 252, 0.7);
    margin: 0;
}

.river-floating-controls .button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.river-floating-controls .button-row button {
    border: none;
    border-radius: 12px;
    padding: 0.35rem 0.9rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    background: color-mix(in srgb, var(--bg-primary) 8%, transparent);
    color: #f8fafc;
    transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.river-floating-controls .button-row button:hover {
    transform: translateY(-1px);
    background: color-mix(in srgb, var(--bg-primary) 18%, transparent);
}

.river-floating-controls .river-view-btn {
    flex: 1;
    min-width: 70px;
    text-align: center;
    background: rgba(99, 102, 241, 0.2);
    color: #c7d2fe;
}

.river-floating-controls .river-view-btn.active {
    background: var(--primary);
    color: var(--text-inverse);
    box-shadow: 0 8px 18px rgba(99, 102, 241, 0.35);
}

.river-floating-controls .toggle-btn.active {
    background: var(--warning);
    color: var(--text-inverse);
    box-shadow: 0 8px 18px rgba(249, 115, 22, 0.45);
}

.river-floating-controls .epoch-section {
    border-top: 1px solid rgba(248, 250, 252, 0.08);
    padding-top: 0.6rem;
}

.river-floating-controls .epoch-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    max-height: 130px;
    overflow-y: auto;
}

.river-floating-controls .epoch-btn {
    border: 1px solid rgba(226, 232, 240, 0.2);
    border-radius: 999px;
    padding: 0.25rem 0.65rem;
    font-size: 0.7rem;
    background: rgba(248, 250, 252, 0.08);
    color: #e2e8f0;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.river-floating-controls .epoch-btn:hover {
    background: color-mix(in srgb, var(--bg-primary) 18%, transparent);
}

/* Viewport & Content */
.river-viewport {
    flex: 1;
    overflow: hidden;
    position: relative;
    cursor: grab;
    background: radial-gradient(circle at 30% 40%, rgba(96, 165, 250, 0.06), transparent 55%),
                radial-gradient(circle at 70% 60%, rgba(167, 139, 250, 0.06), transparent 60%),
                var(--bg-primary, #fff);
    border-radius: 26px;
    box-shadow: 0 35px 90px rgba(15, 23, 42, 0.25);
    height: 100%;
    /*
      Industrial sizing:
      - Avoid hardcoded 760px that breaks on smaller screens and wastes space on larger ones.
      - Keep a stable, readable canvas height that adapts with the viewport.
    */
    min-height: clamp(560px, 85dvh, 1200px);
    /*
      Use CSS vars so JS/CSS can control "air" consistently.
      NOTE: top padding here affects perceived "air" above the whole canvas.
    */
    padding: var(--river-viewport-top-padding, 72px) var(--river-horizontal-padding, 180px) var(--river-viewport-bottom-padding, 180px);
    display: flex;
    align-items: center; /* Center content vertically; pan/zoom still controls exact camera */
}

.river-content {
    min-height: 100%;
    margin: auto 0; /* vertical centering inside flex viewport */
    flex: 0 0 auto;
}

.river-viewport:active {
    cursor: grabbing;
}

.river-viewport.is-panning {
    cursor: grabbing;
}

/* Fullscreen mode */
.river-container.river-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 9999;
    background: var(--bg-primary, #fff);
}

.river-container.river-fullscreen .river-floating-controls {
    position: fixed;
    right: 2rem;
    bottom: 2rem;
}

.river-container.river-fullscreen .river-header,
.river-container.river-fullscreen .stats-panel,
.river-container.river-fullscreen .cultural-codes-legend {
    display: none;
}

/* Floating toolbar (Historian) */
.river-floating-controls.draggable {
    cursor: grab;
}

.river-floating-controls .toolbar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.river-floating-controls .toolbar-grip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 6px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--bg-primary) 10%, transparent);
}

.river-floating-controls .toolbar-collapse-btn {
    border: none;
    background: color-mix(in srgb, var(--bg-primary) 10%, transparent);
    color: #f8fafc;
    border-radius: 10px;
    padding: 4px 8px;
    cursor: pointer;
}

.river-floating-controls .toolbar-body {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.river-floating-controls .toolbar-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.river-floating-controls.collapsed {
    width: 40px;
    padding: 0.6rem;
}

.river-floating-controls.collapsed .toolbar-body {
    display: none;
}

/* Minimap */
.river-minimap {
    position: absolute;
    bottom: 80px;
    right: 1rem;
    width: 200px;
    height: 120px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 8px;
    box-shadow: var(--shadow-lg, 0 10px 15px -3px rgb(0 0 0 / 0.1));
    z-index: 25;
}

.river-minimap.is-hidden {
    display: none;
}

.river-content {
    position: relative;
    transform-origin: 0 0;
    box-sizing: border-box;
    /* Padding removed — viewport already provides "air"; double padding wasted ~432px vertical space */
    padding: 0;
}

/* Citizen UX: a bit more breathing room above cards */
.river-container[data-mode="citizen"] {
    /* More "air" for readability (requested) */
    --river-top-padding: 170px;
    --river-viewport-top-padding: 160px;
    --river-viewport-bottom-padding: 200px;
}

/* Citizen UX: in the central dashboard pane add a small "empty layer" above the river canvas
   so the first cards don't stick to the top boundary of the content area. */
body[data-dashboard-theme="citizen"] #history-pane #time-river-container {
    padding-top: 14px;
    box-sizing: border-box;
}

/* Citizen UX: avoid double horizontal padding (JS already applies `horizontalPadding` in coordinates). */
.river-container[data-mode="citizen"] .river-viewport {
    padding-left: 0;
    padding-right: 0;
}
.river-container[data-mode="citizen"] .river-content {
    padding-left: 0;
    padding-right: 0;
}

.historian-dashboard.sidebars-collapsed .river-viewport,
.historian-dashboard.sidebars-collapsed .river-content {
    --river-horizontal-padding: 80px;
}

/* Toggle: hide/show horizons (scale tracks) */
.river-container.river-horizons-hidden .scale-tracks {
    display: none;
}

/* Ensure drag-pan works reliably across browsers (Panzoom recommendation) */
.river-viewport {
    touch-action: none;
}

/* Timeline axis (years) */
.timeline-axis {
    position: absolute;
    top: 18px;
    left: 0;
    right: 0;
    height: 52px;
    pointer-events: none;
    z-index: 3;
}

.timeline-marker {
    position: absolute;
    top: 0;
    height: 100%;
    width: 1px;
    background: rgba(148, 163, 184, 0.35);
}

.timeline-marker::after {
    content: '';
    position: absolute;
    top: 34px;
    left: 50%;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    transform: translateX(-50%);
    background: rgba(99, 102, 241, 0.45);
}

.timeline-marker .marker-label {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    font-size: 0.72rem;
    font-weight: 700;
    color: rgba(15, 23, 42, 0.85);
    padding: 0.18rem 0.45rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    border: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
    white-space: nowrap;
}

.history-toolbar {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-radius: 14px;
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    border: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.15);
    margin-bottom: 1rem;
    gap: 0.5rem;
}

/* Слои знаний (Город, Район, …) в одну строку — больше места для реки */
.history-layer-badges {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
}

.history-toolbar-btn {
    border: none;
    background: rgba(99, 102, 241, 0.12);
    color: #312e81;
    border-radius: 999px;
    padding: 0.45rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-toolbar-btn.primary {
    background: var(--primary);
    color: var(--text-inverse);
    box-shadow: 0 12px 25px rgba(99, 102, 241, 0.35);
}

.history-toolbar-btn:hover {
    transform: translateY(-2px);
}

.history-toolbar-btn.zoom-btn-toolbar {
    background: rgba(99, 102, 241, 0.18);
    color: #4338ca;
    padding: 0.4rem 0.7rem;
    font-size: 1.1rem;
    font-weight: 700;
    min-width: 36px;
    text-align: center;
    line-height: 1;
}

.history-toolbar-btn.zoom-btn-toolbar:hover {
    background: rgba(99, 102, 241, 0.32);
}

.history-toolbar-btn.zoom-btn-toolbar i {
    font-size: 1rem;
}

.history-layer-chip {
    border: none;
    background: rgba(15, 23, 42, 0.05);
    color: var(--text-primary);
    border-radius: 999px;
    padding: 0.3rem 0.8rem;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.history-layer-chip .history-layer-count {
    font-weight: 600;
    color: var(--success);
}

.history-layer-chip.active {
    background: rgba(16, 185, 129, 0.12);
    color: var(--success);
}

/* Scale tracks */
.scale-tracks {
    position: absolute;
    inset: 0;
    pointer-events: none;
    /* Ensure horizon names are visible even when nodes overlay the tracks */
    z-index: 4;
    box-sizing: border-box;
}

.scale-track {
    position: absolute;
    left: 0;
    right: auto; /* width is controlled by JS to span the full timeline */
    height: 110px;
    border-radius: 18px;
    padding: 12px 0;
    z-index: 4;
    transition: opacity 0.2s ease;
    box-sizing: border-box;
}

.scale-track::before {
    content: '';
    position: absolute;
    /* Use fixed padding so the horizon line stays aligned with pinned labels
       (percent-based padding becomes huge on wide canvases). */
    left: 18px;
    right: 18px;
    top: 50%;
    height: 2px;
    background: rgba(148, 163, 184, 0.55);
    transform: translateY(-50%);
}

.scale-track .scale-label {
    position: absolute;
    left: 24px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(15, 23, 42, 0.85);
    z-index: 6;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--bg-primary) 85%, transparent);
    border: 1px solid rgba(226, 232, 240, 0.9);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
}

.scale-track.scale-track-technical .scale-label {
    color: #f8fafc;
    background: rgba(15, 23, 42, 0.55);
    border: 1px solid rgba(226, 232, 240, 0.18);
}

.scale-track[data-scale="5"] { background: rgba(248,113,113,0.16); }
.scale-track[data-scale="4"] { background: rgba(167,139,250,0.16); }
.scale-track[data-scale="3"] { background: rgba(96,165,250,0.16); }
.scale-track[data-scale="2"] { background: rgba(52,211,153,0.16); }
.scale-track[data-scale="1"] { background: rgba(26,188,156,0.16); }
.scale-track[data-scale="0"] { background: repeating-linear-gradient(135deg, rgba(148,163,184,0.15) 0px, rgba(148,163,184,0.15) 24px, transparent 24px, transparent 48px); }
.scale-track[data-scale="-1"] { background: linear-gradient(90deg, rgba(30,64,175,0.25), rgba(30,64,175,0.15)); }
.scale-track[data-scale="-2"] { background: linear-gradient(90deg, rgba(49,46,129,0.35), rgba(49,46,129,0.2)); }
.scale-track[data-scale="-1"],
.scale-track[data-scale="-2"] {
    border: 1px solid color-mix(in srgb, var(--bg-primary) 15%, transparent);
}

/* SVG Layer */
.river-connections-layer,
.connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 1;
}

.connection-link {
    fill: none;
    stroke: rgba(148, 163, 184, 0.4);
    stroke-width: 2px;
    pointer-events: none;
    transition: stroke 0.3s;
}

.connection-link.type-cause_effect { stroke: rgba(248, 113, 113, 0.6); stroke-dasharray: 5,5; }
.connection-link.type-correlation { stroke: rgba(96, 165, 250, 0.6); }
.connection-link.type-conflict { stroke: rgba(251, 146, 60, 0.6); }

/* Nodes Layer */
.river-nodes-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
}

.cultural-streams {
    position: absolute;
    inset: 0;
    pointer-events: none;
    mix-blend-mode: screen;
    opacity: 0.5;
}

.cultural-stream {
    position: absolute;
    left: 0;
    width: 100%;
    height: 48px;
    border-radius: 999px;
    filter: blur(1px);
    transition: opacity 0.2s ease;
}

.cultural-stream.active {
    opacity: 0.9;
}

.river-layer-labels {
    position: absolute;
    top: 50%;
    right: 1.5rem;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 14;
    /* Don't block pan/drag on the river. Individual buttons remain interactive. */
    pointer-events: none;
}

.river-layer-labels.is-hidden {
    display: none;
}

.river-layer-item {
    background: rgba(15, 23, 42, 0.72);
    color: var(--text-inverse);
    border-radius: 999px;
    padding: 0.35rem 0.9rem;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    border: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease;
    pointer-events: auto;
}

.river-layer-item.active {
    background: var(--info);
    color: var(--text-primary);
    transform: translateX(-4px);
}

.river-layer-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.river-container[data-mode="citizen"] .river-layer-labels {
    right: 0.85rem;
    gap: 0.35rem;
    opacity: 0.92;
}

.river-container[data-mode="citizen"] .river-layer-item {
    padding: 0.25rem 0.6rem;
    font-size: 0.68rem;
    letter-spacing: 0.03em;
}

/* Citizen UX: horizons must be visible (user feedback).
   Keep it compact but show the name (truncate). */
.river-container[data-mode="citizen"] .river-layer-item .river-layer-name {
    display: inline;
    max-width: 88px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Citizen: layer chips live inside the unified floating controls panel */
.river-container[data-mode="citizen"] .river-floating-controls .river-layer-labels {
    position: static;
    top: auto;
    right: auto;
    transform: none;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0.35rem;
    pointer-events: auto;
    opacity: 1;
}
.river-container[data-mode="citizen"] .river-floating-controls .river-layer-item {
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-primary);
    border: 1px solid rgba(148, 163, 184, 0.35);
    padding: 0.25rem 0.55rem;
    font-size: 0.68rem;
    letter-spacing: 0.01em;
    transform: none;
}
.river-container[data-mode="citizen"] .river-floating-controls .river-layer-item:hover {
    background: rgba(148, 163, 184, 0.18);
    transform: translateY(-1px);
}
.river-container[data-mode="citizen"] .river-floating-controls .river-layer-item.active {
    background: rgba(37, 99, 235, 0.16);
    border-color: rgba(37, 99, 235, 0.45);
    color: #1e3a8a;
    transform: none;
}
.river-container[data-mode="citizen"] .river-floating-controls .river-layer-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.08);
    color: var(--text-primary);
    font-weight: 700;
    font-size: 0.66rem;
}
.river-container[data-mode="citizen"] .river-floating-controls .river-layer-item.active .river-layer-count {
    background: rgba(37, 99, 235, 0.22);
}

.stats-panel {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: grid;
    grid-template-columns: repeat(3, minmax(80px, 1fr));
    gap: 0.5rem;
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    border-radius: 14px;
    padding: 0.6rem;
    z-index: 12;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.18);
}

.stat-item {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.stat-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
}

.overlay {
    /* Industrial UX: overlay should cover the viewport, not only the container box */
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 13;
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.info-modal {
    /* Industrial UX: center on screen and constrain to viewport */
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(720px, calc(100vw - 2rem));
    max-width: 720px;
    max-height: min(82vh, calc(100vh - 2rem));
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    border-radius: 18px;
    box-shadow: 0 25px 60px rgba(15, 23, 42, 0.35);
    padding: 1.5rem;
    display: none;
    flex-direction: column;
    gap: 1rem;
    z-index: 15;
    overflow: auto;
}

.info-modal.active {
    display: flex;
}

.connection-form {
    margin-top: 0.5rem;
    border-top: 1px solid rgba(226, 232, 240, 0.8);
    padding-top: 1rem;
    display: none;
    flex-direction: column;
    gap: 0.75rem;
}

.connection-form textarea {
    width: 100%;
    min-height: 80px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.5rem 0.6rem;
    font-size: 0.85rem;
    resize: vertical;
}

.connection-form.active {
    display: flex;
}

.connection-summary {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.river-container.linking-mode {
    cursor: crosshair;
}

.river-container.linking-mode .code-node {
    opacity: 0.65;
}

.river-container.linking-mode .code-node:hover {
    opacity: 1;
}

.info-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
}

.info-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: color 0.2s ease;
}

.info-close:hover {
    color: var(--text-primary);
}

.info-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.4rem;
}

.info-modal .info-tag {
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
}

.info-body {
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    overflow-y: auto;
    max-height: 220px;
}

.info-editor {
    border-top: 1px solid rgba(226, 232, 240, 0.8);
    padding-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.info-readonly-hint {
    border-top: 1px solid rgba(226, 232, 240, 0.8);
    padding: 1rem;
    border-radius: 12px;
    background: rgba(226, 232, 240, 0.35);
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    text-align: center;
}

.editor-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.editor-field label {
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.editor-field input,
.editor-field select {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
}

.editor-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.editor-actions button {
    flex: 1;
    min-width: 140px;
    padding: 0.5rem 0.6rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.editor-actions .btn-primary {
    background: var(--primary);
    color: var(--text-inverse);
    border-color: var(--primary);
}

.editor-actions .btn-danger {
    background: color-mix(in srgb, var(--danger) 15%, var(--bg-primary));
    color: var(--danger);
    border-color: #fecaca;
}

.editor-actions button:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.15);
}

/* === НОВЫЙ СТИЛЬ КАРТОЧЕК — inner container + воздух + масштаб === */
.code-node {
    --card-air: 16px;
    --card-category-color: var(--node-color, #94a3b8);
    position: absolute;
    display: flex;
    flex-direction: column;
    width: 280px;
    min-height: auto;
    padding: var(--card-air);
    background: transparent;
    transform: translate(-50%, -50%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.code-node .node-inner {
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    border-radius: 16px;
    padding: 14px 16px 12px;
    border: 1px solid rgba(15, 23, 42, 0.06);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.08);
    border-top: 3px solid var(--card-category-color);
    transition: box-shadow 0.25s ease, transform 0.25s ease;
    position: relative;
    overflow: hidden;
}

.code-node:hover {
    z-index: 30;
}
.code-node:hover .node-inner {
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08), 0 20px 48px rgba(15, 23, 42, 0.16);
    transform: translateY(-2px);
}

/* Масштаб — визуальное различие */
.code-node[data-scale="5"] { --card-air: 20px; width: 300px; }
.code-node[data-scale="4"] { --card-air: 18px; width: 290px; }
.code-node[data-scale="3"] { --card-air: 16px; width: 280px; }
.code-node[data-scale="2"] { --card-air: 14px; width: 260px; }
.code-node[data-scale="1"] { --card-air: 12px; width: 240px; }

/* === Action bar (appears on hover) === */
.code-node .node-actions {
    display: flex;
    gap: 4px;
    padding-top: 8px;
    border-top: 1px solid rgba(15, 23, 42, 0.06);
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: opacity 0.2s ease, max-height 0.2s ease;
}
.code-node:hover .node-actions {
    opacity: 1;
    max-height: 40px;
}
.node-action-btn {
    flex: 1;
    padding: 4px 0;
    border: 1px solid rgba(15, 23, 42, 0.1);
    border-radius: 8px;
    background: var(--bg-elevated);
    cursor: pointer;
    font-size: 0.7rem;
    text-align: center;
    transition: all 0.15s ease;
}
.node-action-btn:hover {
    background: var(--bg-secondary, #f8fafc);
    border-color: var(--primary, #8b5cf6);
    color: var(--primary, #8b5cf6);
}
.node-action-btn.danger:hover {
    border-color: var(--danger);
    color: var(--danger);
}

/* Анимации появления / удаления */
@keyframes cardAppear {
    from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
    to   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes cardDisappear {
    from { opacity: 1; transform: translate(-50%, -50%) scale(1); }
    to   { opacity: 0; transform: translate(-50%, -50%) scale(0.9); }
}
.code-node.appearing {
    animation: cardAppear 0.3s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
.code-node.removing {
    animation: cardDisappear 0.2s ease forwards;
    pointer-events: none;
}

/* Linking mode */
.code-node.link-source {
    outline: 2px solid var(--primary, #8b5cf6);
    outline-offset: 4px;
}
.code-node.link-target-hover .node-inner {
    box-shadow: 0 0 0 3px var(--primary, #8b5cf6), 0 20px 48px rgba(15, 23, 42, 0.16);
}

.code-node .node-collapse-btn {
    appearance: none;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: color-mix(in srgb, var(--bg-primary) 92%, transparent);
    color: rgba(15, 23, 42, 0.85);
    width: 24px;
    height: 24px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    line-height: 1;
    padding: 0;
    box-shadow: 0 6px 14px rgba(15, 23, 42, 0.12);
    transition: transform 0.15s ease, background 0.15s ease;
}

.code-node .node-collapse-btn:hover {
    transform: translateY(-1px);
    background: rgba(248, 250, 252, 1);
}

/* Citizen UX: collapsed cards stay compact and don't expand on hover */
.river-container[data-mode="citizen"] .code-node.is-collapsed {
    min-height: 56px !important;
}

.river-container[data-mode="citizen"] .code-node.is-collapsed .node-preview,
.river-container[data-mode="citizen"] .code-node.is-collapsed .node-thumbnail {
    display: none !important;
}

.code-node .node-title {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 6px;
}

.code-node .node-preview {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    line-height: 1.5;
}

.connection-path {
    fill: none;
    stroke: rgba(99, 102, 241, 0.65);
    stroke-width: 3.5px;
    filter: drop-shadow(0 6px 12px rgba(15, 23, 42, 0.25));
    transition: stroke 0.2s ease, stroke-width 0.2s ease, opacity 0.2s ease;
    opacity: 0.92;
}

.connection-path.highlighted {
    stroke-width: 4px;
    opacity: 0.95;
    stroke: #f97316;
}
.river-node {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 180px;
    cursor: pointer;
    transition: transform 0.2s;
    transform: translate(-50%, -50%); /* Center origin */
}

.river-node:hover {
    transform: translate(-50%, -50%) scale(1.05);
    z-index: 10;
}

.node-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--node-color, #94a3b8);
    border: 3px solid white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 8px;
}

.node-content {
    background: var(--bg-elevated);
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    text-align: center;
    width: 100%;
    border-left: 4px solid var(--node-color, #94a3b8);
}

.node-date {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 2px;
}

.node-technical-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 600;
    margin-left: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.node-technical-badge.badge-draft {
    background: rgba(49, 46, 129, 0.15);
    color: #312e81;
}

.node-technical-badge.badge-archive {
    background: rgba(30, 64, 175, 0.15);
    color: var(--info);
}

.node-title {
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Categories Colors */
.category-political { --node-color: #FF6B6B; }
.category-event { --node-color: #4ECDC4; }
.category-urban { --node-color: #45B7D1; }
.category-social { --node-color: #96CEB4; }
.category-person { --node-color: #FFCC00; }
.category-culture { --node-color: #9D50BB; }
.category-heritage { --node-color: #D4AC0D; }

/* States */
.river-container.loading::after {
    content: "Загрузка истории...";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.2rem;
    color: var(--text-muted);
}

.empty-state, .error-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 1.1rem;
}

.error-state {
    color: var(--danger);
}

/* Undated Zone */
.river-node.undated {
    opacity: 0.7;
}
.river-node.undated .node-content {
    border-style: dashed;
}

/* === RESPONSIVE === */
@media (max-width: 1200px) {
    .river-viewport {
        --river-horizontal-padding: 80px;
        padding-top: var(--river-viewport-top-padding, 48px);
        padding-bottom: var(--river-viewport-bottom-padding, 100px);
        border-radius: 16px;
    }
    .code-node { width: 240px; }
}
@media (max-width: 768px) {
    .river-viewport {
        --river-horizontal-padding: 24px;
        padding-top: 32px;
        padding-bottom: 60px;
        border-radius: 8px;
        min-height: 400px;
    }
    .code-node { width: 200px; min-height: auto; }
    .code-node .node-title { font-size: 0.8rem; }
    .code-node .node-preview { display: none; }
}
@media (max-width: 480px) {
    .river-viewport {
        --river-horizontal-padding: 8px;
        padding-top: 16px;
        padding-bottom: 32px;
        min-height: 300px;
    }
    .code-node { width: 170px; }
}
