/* ============================================================================
   NEPINTEL VISUALIZATION - MAIN STYLESHEET
   ============================================================================
   Comprehensive styling for the interactive D3.js force-directed graph
   visualization. Supports both light and dark color schemes.
   ============================================================================ */

/* --- ROOT & BASIC SETUP --- */
/* Color scheme support for system preference */
:root {
    color-scheme: light dark;
}

/* Global body styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f9f9f9;
    color: #333;
    overflow: hidden; /* Prevent scrolling - layout is fixed */
}

/* Dark mode body styling */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1e1e1e;
        color: #e0e0e0;
    }
}

/* --- MAIN LAYOUT --- */
/* Two-column grid: sidebar and graph area - sidebar expanded to show more case data */
#main-container {
    display: grid;
    grid-template-columns: 2.5fr 7.5fr; /* Sidebar 25%, graph 75% */
    width: 100vw;
    height: 100vh;
    gap: 0;
}

/* Graph section column with flexbox for header + content */
#graph-section {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
}

@media (prefers-color-scheme: dark) {
    #graph-section {
        border-right-color: #444;
    }
}

/* --- TOP BAR --- */
/* Header area with title, subtitle, and zoom controls */
#top-bar {
    height: 100px;
    background-color: #ffffff;
    border-bottom: 1px solid #e0e0e0;
    padding: 0 24px;
    display: flex;
    align-items: center;
    flex-shrink: 0; /* Prevent shrinking when content overflows */
}

@media (prefers-color-scheme: dark) {
    #top-bar {
        background-color: #2a2a2a;
        border-bottom-color: #444;
    }
}

/* Hamburger menu button - HIDDEN ON DESKTOP */
#hamburger-menu {
    display: none !important;
}

/* Zoom control button group */
#zoom-controls {
    display: flex;
    gap: 8px;
}

#zoom-controls button {
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 18px;
    font-weight: bold;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

@media (prefers-color-scheme: dark) {
    #zoom-controls button {
        background-color: #3a3a3a;
        border-color: #555;
        color: #e0e0e0;
    }
    #zoom-controls button:hover {
        background-color: #4a4a4a;
    }
}

/* Content wrapper for title and subtitle */
#top-bar-content {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* Main page title */
#page-title {
    margin: 0;
    font-size: 30px;
    font-weight: 700;
    line-height: 1;
}

/* Subtitle text under main title */
#page-subtitle {
    margin: 4px 0 0 0;
    font-size: 25px;
    opacity: 0.7;
    line-height: 1;
}

/* --- GRAPH CONTAINER --- */
/* Main SVG rendering area with scrolling support for zoom/pan */
#graph-container {
    flex: 1;
    position: relative;
    overflow: auto; /* Allow scrolling when zoomed in */
    background-color: #fafafa;
}

@media (prefers-color-scheme: dark) {
    #graph-container {
        background-color: #1e1e1e;
    }
}

/* SVG element for D3 visualization */
#graph-svg {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: auto; /* Allow mouse interactions */
}

/* Container for card-based layout of nodes */
#cards-container {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    gap: 60px;
    padding: 60px;
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
    justify-content: center;
    align-items: flex-start;
}

/* --- SIDEBAR --- */
/* Left panel with menu buttons and case information */
#sidebar {
    padding: 20px;
    background-color: #ffffff;
    overflow-y: auto; /* Allow vertical scroll if content exceeds height */
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    height: 100%;
}

@media (prefers-color-scheme: dark) {
    #sidebar {
        background-color: #2a2a2a;
        border-right-color: #444;
    }
}

/* --- MENU & INFO BOX --- */
/* Section headings for menu and info */
#menu h2, #info-box h3 {
    margin-top: 0;
    border-bottom: 2px solid #eee;
    padding-bottom: 8px;
    color: #cee37a;
}

@media (prefers-color-scheme: dark) {
    #menu h2, #info-box h3 {
        border-bottom-color: #444;
        color: #cee37a;

    }
}

/* Menu buttons for case selection */
#menu button {
    display: block;
    width: 100%;
    padding: 10px;
    margin-bottom: 8px;
    font-size: 14px;
    text-align: left;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

@media (prefers-color-scheme: dark) {
    #menu button {
        background-color: #3a3a3a;
        border-color: #555;
        color: #7df665;
    }
}

/* Hover state for menu buttons */
#menu button:hover {
    background-color: #e0e0e0;
}

@media (prefers-color-scheme: dark) {
    #menu button:hover {
        background-color: #2a3f03;
    }
}

/* Active/selected state for menu buttons */
#menu button.active {
    background-color: #007bff;
    color: white;
    border-color: #0056b3;
    font-weight: bold;
}

/* Information display box for case details */
#info-box {
    margin-top: 20px;
    background-color: #fdfdfd;
    border: 1px solid #eee;
    border-radius: 4px;
    padding: 20px;
    min-height: 400px;
    flex-grow: 1;
}

@media (prefers-color-scheme: dark) {
    #info-box {
        background-color: #333;
        border-color: #555;
    }
}

/* Case summary text styling */
#info-summary {
    font-size: 14px;
    line-height: 1.6;
}

/* --- ACTOR CARDS/NODES --- */
/* Card container for node content display */
.actor-card {
    min-width: 260px;
    min-height: 140px;
    padding: 18px;
    background-color: #ffffff;
    border: 1px solid #e6e6e6;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.2s;
    position: relative;
    z-index: 10;
    aspect-ratio: 1.857; /* 260/140 = 1.857 */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

@media (prefers-color-scheme: dark) {
    .actor-card {
        background-color: #2a2a2a;
        border-color: #444;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    }
}

/* Hover effect for cards */
.actor-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

@media (prefers-color-scheme: dark) {
    .actor-card:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    }
}

/* Card title/actor name */
.actor-card-title {
    margin: 0 0 12px 0;
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@media (prefers-color-scheme: dark) {
    .actor-card-title {
        color: #e0e0e0;
    }
}

/* Actor description/definition text */
.actor-card-definition {
    margin: 0 0 12px 0;
    font-size: 16px;
    line-height: 1.5;
    opacity: 0.8;
    word-wrap: break-word;
    overflow-wrap: break-word;
    flex-grow: 1; /* Take remaining vertical space */
}

@media (prefers-color-scheme: dark) {
    .actor-card-definition {
        color: #e0e0e0;
    }
}

/* Case-specific overlay text (shown when case is selected) */
.actor-card-overlay {
    margin: 12px 0 0 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.4;
    color: #300302;
    display: none; /* Hidden by default */
    word-wrap: break-word;
    overflow-wrap: break-word;
}

@media (prefers-color-scheme: dark) {
    .actor-card-overlay {
        color: #510404;
    }
}

/* SVG node rectangles (background of cards) */
.node rect {
    fill: #ffffff;
    stroke: #e6e6e6;
    stroke-width: 1px;
}

@media (prefers-color-scheme: dark) {
    .node rect {
        fill: #2a2a2a;
        stroke: #444;
    }
}

/* --- SVG EDGES & ARROWS --- */
/* Link paths connecting nodes (curves with clockwise direction) */
.link {
    stroke: #999;
    stroke-opacity: 0.6;
    stroke-width: 4px;
    fill: none; /* Important: paths need no fill */
}

/* First direction link (A -> B): Blue color */
.link-direction-first {
    stroke: #0066cc;
    stroke-opacity: 0.7;
    stroke-width: 4px;
    fill: none;
}

@media (prefers-color-scheme: dark) {
    .link-direction-first {
        stroke: #66b3ff;
        stroke-opacity: 0.8;
    }
}

/* Reverse direction link (B -> A): Green color */
.link-direction-reverse {
    stroke: #00a86b;
    stroke-opacity: 0.7;
    stroke-width: 4px;
    fill: none;
}

@media (prefers-color-scheme: dark) {
    .link-direction-reverse {
        stroke: #66ff99;
        stroke-opacity: 0.8;
    }
}

/* Arrow line styling for directed edges */
.edge-arrow {
    stroke: #9aa0a6;
    stroke-width: 2px;
    fill: none;
    marker-end: url(#arrowhead); /* Reference to SVG marker */
}

@media (prefers-color-scheme: dark) {
    .edge-arrow {
        stroke: #888;
    }
}

/* Labels displayed on edges (e.g., relationship type) */
.link-label {
    font-size: 24px;
    fill: #555;
    text-anchor: middle;
    pointer-events: none;
    background-color: #fafafa;
    padding: 4px 8px;
    font-weight: 600;
}

@media (prefers-color-scheme: dark) {
    .link-label {
        fill: #aaa;
        background-color: #1e1e1e;
    }
}

/* First direction label (A -> B): Blue text */
.link-label-first {
    font-size: 24px;
    fill: #0066cc;
    text-anchor: middle;
    pointer-events: none;
    background-color: #fafafa;
    padding: 4px 8px;
    font-weight: 600;
}

@media (prefers-color-scheme: dark) {
    .link-label-first {
        fill: #66b3ff;
        background-color: #1e1e1e;
    }
}

/* Reverse direction label (B -> A): Green text */
.link-label-reverse {
    font-size: 24px;
    fill: #00a86b;
    text-anchor: middle;
    pointer-events: none;
    background-color: #fafafa;
    padding: 4px 8px;
    font-weight: 600;
}

@media (prefers-color-scheme: dark) {
    .link-label-reverse {
        fill: #66ff99;
        background-color: #1e1e1e;
    }
}

/* Text labels for edges */
.edge-label-text {
    font-size: 16px;
    fill: #666;
    pointer-events: none;
    text-anchor: middle;
}

@media (prefers-color-scheme: dark) {
    .edge-label-text {
        fill: #aaa;
    }
}

/* SVG marker definitions (arrow heads) */
defs marker {
    overflow: visible; /* Allow marker to display outside viewBox */
}

/* Arrow head polygon fill color */
defs marker polygon {
    fill: #9aa0a6;
}

@media (prefers-color-scheme: dark) {
    defs marker polygon {
        fill: #888;
    }
}

/* --- NODE MODAL/POPUP --- */
/* Modal backdrop overlay */
.node-modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

/* Modal content box */
.node-modal-content {
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    animation: modalZoomIn 0.3s ease-out;
}

@media (prefers-color-scheme: dark) {
    .node-modal-content {
        background-color: #2a2a2a;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    }
}

/* Modal header with title and close button */
.node-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 2px solid #eee;
}

@media (prefers-color-scheme: dark) {
    .node-modal-header {
        border-bottom-color: #444;
    }
}

.node-modal-header h2 {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
}

@media (prefers-color-scheme: dark) {
    .node-modal-header h2 {
        color: #e0e0e0;
    }
}

/* Close button (X) */
.node-modal-close {
    background: none;
    border: none;
    font-size: 32px;
    cursor: pointer;
    color: #999;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.node-modal-close:hover {
    color: #333;
}

@media (prefers-color-scheme: dark) {
    .node-modal-close {
        color: #666;
    }
    .node-modal-close:hover {
        color: #e0e0e0;
    }
}

/* Modal body content */
.node-modal-body {
    padding: 24px;
}

/* Node definition text in modal */
.node-modal-definition {
    margin: 0;
    font-size: 16px;
    line-height: 1.6;
    color: #333;
}

@media (prefers-color-scheme: dark) {
    .node-modal-definition {
        color: #e0e0e0;
    }
}

/* Zoom in animation for modal */
@keyframes modalZoomIn {
    from {
        transform: scale(0.9);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==========================================
   MOBILE RESPONSIVE DESIGN (max-width: 768px)
   ========================================== */

@media (max-width: 768px) {
    /* Mobile users are shown a desktop recommendation message instead */
    /* The page does not load the D3 graph on mobile devices */
}

/* ========================================
   TABLET RESPONSIVE DESIGN (768px < width < 1024px)
   ======================================== */

@media (max-width: 1024px) and (min-width: 769px) {
    /* Reduce sidebar width on tablets */
    #main-container {
        grid-template-columns: 1.5fr 8.5fr;
    }

    #sidebar {
        max-height: 100vh;
    }

    #info-box {
        min-height: 300px;
    }

    /* Reduce modal size on tablets */
    .node-modal-content {
        max-width: 85vw;
    }

    /* Slightly reduce font sizes */
    body {
        font-size: 14px;
    }

    .actor-card {
        min-width: 200px;
        min-height: 120px;
    }

    /* Hide mobile hamburger menu on tablet */
    #hamburger-menu {
        display: none;
    }
}

/* ========================================
   LANDSCAPE MOBILE (max-height: 500px)
   ======================================== */

@media (max-height: 500px) {
    #main-container {
        grid-template-rows: auto 1fr;
    }

    #sidebar {
        max-height: 30vh;
    }

    #graph-section {
        height: 70vh;
    }

    #top-bar {
        height: 50px;
    }

    #menu {
        max-height: 40px;
    }

    #info-box {
        max-height: 60px;
        padding: 8px;
    }

    #info-box h2 {
        font-size: 12px;
        margin-bottom: 4px;
    }

    #info-box p {
        font-size: 11px;
    }

    .node-modal-content {
        max-height: 80vh;
    }
}