/* ============================================================================
   NEPINTEL MOBILE - MOBILE-RESPONSIVE STYLESHEET
   ============================================================================
   Complete mobile-responsive design for screens <= 768px
   Implements: List View, Detail View, Actor Selection, Bottom Sheet
   ============================================================================ */

:root {
    --brand-bg: #1a1a1a;
    --brand-surface: #2c2c2c;
    --brand-primary: #4a90e2;
    --brand-primary-muted: #314D72;
    --brand-secondary: #50e3c2;
    --brand-text: #e0e0e0;
    --brand-text-muted: #a0a0a0;
    --brand-border: #444444;
    --brand-overlay-bg: rgba(0, 0, 0, 0.6);
}

/* ============================================================================
   MOBILE LAYOUT OVERRIDES
   ============================================================================ */

@media (max-width: 768px) {
    /* Hide desktop elements */
    #mobile-warning {
        display: none !important;
    }

    /* Override main container layout */
    #main-container {
        display: flex;
        flex-direction: column;
        grid-template-columns: unset;
        width: 100vw;
        height: 100vh;
        gap: 0;
    }

    /* Hide desktop sidebar */
    #sidebar {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 0;
        height: 0;
        border-right: none;
        padding: 0;
        overflow: hidden;
        z-index: 100;
    }

    /* Graph section takes full screen */
    #graph-section {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    /* Hide desktop graph SVG and show mobile screens instead */
    #graph-container {
        display: none !important;
    }

    /* Show mobile screens */
    #mobile-screens {
        display: flex !important;
        flex: 1;
        width: 100%;
        height: 100%;
    }

    /* Enable mobile screen display on mobile only */
    .mobile-screen {
        display: none !important;
    }

    .mobile-screen.active {
        display: flex !important;
    }

    /* Show hamburger menu */
    #hamburger-menu {
        display: flex !important;
        width: 44px;
        height: 44px;
        padding: 8px;
        background: none;
        border: none;
        cursor: pointer;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 6px;
        position: relative;
        z-index: 50;
    }

    #hamburger-menu span {
        display: block;
        width: 24px;
        height: 2px;
        background-color: var(--brand-text);
        border-radius: 2px;
        transition: all 0.3s ease;
    }

    #hamburger-menu.open span:nth-child(1) {
        transform: rotate(45deg) translate(8px, 8px);
    }

    #hamburger-menu.open span:nth-child(2) {
        opacity: 0;
    }

    #hamburger-menu.open span:nth-child(3) {
        transform: rotate(-45deg) translate(7px, -7px);
    }

    /* Adjust top bar for mobile */
    #top-bar {
        height: auto;
        padding: 12px 16px;
        gap: 12px;
        border-bottom: 1px solid var(--brand-border);
        background-color: var(--brand-surface);
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    #top-bar-content {
        flex: 1;
        min-width: 0;
    }

    #page-title {
        font-size: 18px;
        margin: 0;
        color: var(--brand-text);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    #page-subtitle {
        font-size: 12px;
        margin: 4px 0 0 0;
        color: var(--brand-text-muted);
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* Hide zoom controls on mobile */
    #zoom-controls {
        display: none;
    }

    /* Enable bottom sheet on mobile */
    .mobile-bottom-sheet {
        display: none;
    }

    .mobile-bottom-sheet.active {
        display: flex !important;
    }

    .mobile-bottom-sheet-overlay {
        display: none;
    }

    .mobile-bottom-sheet-overlay.active {
        display: block !important;
    }
}

/* ============================================================================
   MOBILE SCREENS & VIEWS
   ============================================================================ */

/* Mobile view screens container - HIDDEN ON DESKTOP */
#mobile-screens {
    display: none;
    flex: 1;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

/* Shared screen styling - hidden by default on desktop */
.mobile-screen {
    display: none !important;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background-color: var(--brand-bg);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-screen.active {
    display: flex !important;
}

/* ============================================================================
   SCREEN 1: LIST VIEW
   ============================================================================ */

#mobile-screen-list {
    padding: 0;
}

/* List view header */
.mobile-list-header {
    background-color: var(--brand-surface);
    padding: 24px 16px;
    border-bottom: 1px solid var(--brand-border);
    flex-shrink: 0;
}

.mobile-list-header h1 {
    margin: 0;
    font-size: 24px;
    font-weight: 700;
    color: var(--brand-text);
}

.mobile-list-header p {
    margin: 8px 0 0 0;
    font-size: 14px;
    color: var(--brand-text-muted);
}

/* List container */
.mobile-list-container {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 0;
}

/* Case study item */
.mobile-case-item {
    display: flex;
    flex-direction: column;
    padding: 16px;
    margin: 8px 12px;
    background-color: var(--brand-surface);
    border: 1px solid var(--brand-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.mobile-case-item:active {
    background-color: var(--brand-primary-muted);
    transform: scale(0.98);
}

.mobile-case-item-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--brand-text);
    margin-bottom: 8px;
}

.mobile-case-item-description {
    margin: 0;
    font-size: 13px;
    color: var(--brand-text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ============================================================================
   SCREEN 2: DETAIL VIEW
   ============================================================================ */

#mobile-screen-detail {
    padding: 0;
}

/* Detail view header */
.mobile-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--brand-surface);
    padding: 12px 16px;
    border-bottom: 1px solid var(--brand-border);
    flex-shrink: 0;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 40;
}

.mobile-detail-header-back {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--brand-text);
    font-size: 24px;
    padding: 0;
    flex-shrink: 0;
}

.mobile-detail-header-title {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    color: var(--brand-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.mobile-detail-header-switch {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--brand-text);
    font-size: 18px;
    padding: 0;
    flex-shrink: 0;
}

/* Actor chips container */
.mobile-actors-scroll {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    background-color: var(--brand-bg);
    border-bottom: 1px solid var(--brand-border);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    /* flex-shrink: 0; */
    scroll-behavior: smooth;
}

/* Hide scrollbar for cleaner look */
.mobile-actors-scroll::-webkit-scrollbar {
    height: 2px;
}

.mobile-actors-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.mobile-actors-scroll::-webkit-scrollbar-thumb {
    background: var(--brand-border);
    border-radius: 2px;
}

/* Actor chip button */
.mobile-actor-chip {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    background-color: var(--brand-surface);
    border: 1px solid var(--brand-border);
    border-radius: 20px;
    cursor: pointer;
    color: var(--brand-text);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all 0.2s ease;
    user-select: none;
}

.mobile-actor-chip:active {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
    color: white;
}

.mobile-actor-chip.active {
    background-color: var(--brand-primary);
    border-color: var(--brand-primary);
    color: white;
}

/* Detail view scrollable content */
.mobile-detail-content {
    flex: 1;
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    scrollbar-color: #2d5016 transparent;
    scrollbar-width: thin;
    scroll-behavior: smooth;
}

/* Force scrollbar visibility on webkit browsers */
.mobile-detail-content::-webkit-scrollbar-thumb {
    opacity: 1 !important;
}

/* Prevent scrollbar from fading */
.mobile-detail-content {
    --scrollbar-bg: #2d5016;
}

.mobile-detail-content::-webkit-scrollbar {
    width: 12px;
    opacity: 1;
}

.mobile-detail-content::-webkit-scrollbar-track {
    background: transparent;
    opacity: 1;
}

.mobile-detail-content::-webkit-scrollbar-thumb {
    background: #2d5016;
    border-radius: 6px;
    min-height: 40px;
    opacity: 1 !important;
    visibility: visible !important;
}

.mobile-detail-content::-webkit-scrollbar-thumb:hover {
    background: #3d6b1f;
}

/* =========================================================================
   MOBILE: ALWAYS-VISIBLE CUSTOM SCROLLBAR OVERLAY
   On many mobile browsers, native scrollbars auto-hide. We hide the native
   scrollbar in mobile view and draw our own always-visible overlay track.
   ========================================================================= */
@media (max-width: 768px) {
    /* Hide native scrollbar on mobile to avoid duplicate bars */
    .mobile-detail-content {
        position: relative;
        scrollbar-width: none; /* Firefox */
        scrollbar-gutter: stable both-edges; /* Reserve gutter when possible */
    }
    .mobile-detail-content::-webkit-scrollbar {
        width: 0 !important; /* WebKit */
        height: 0 !important;
    }

    /* Overlay track pinned to the right; absolute so it doesn't affect layout */
    .mobile-detail-content .custom-scrollbar {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        width: 8px;
        height: 100%;
        z-index: 5;
        pointer-events: none; /* allow interactions with content */
    }

    .mobile-detail-content .custom-scrollbar-thumb {
        position: absolute;
        top: 0;
        right: 0;
        width: 8px;
        min-height: 24px; /* ensure usable size */
        background: #2d5016;
        border-radius: 6px;
        opacity: 1;
    }
}

/* Actor detail card */
.mobile-actor-detail-card {
    background-color: var(--brand-surface);
    border: 1px solid var(--brand-border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
}

.mobile-actor-detail-card-title {
    margin: 0 0 8px 0;
    font-size: 18px;
    font-weight: 700;
    color: var(--brand-text);
}

.mobile-actor-detail-card-definition {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: var(--brand-text-muted);
    line-height: 1.5;
}

.mobile-actor-detail-card-overlay {
    margin: 12px 0 0 0;
    padding: 12px;
    background-color: var(--brand-primary-muted);
    border-left: 3px solid var(--brand-primary);
    border-radius: 4px;
    font-size: 13px;
    color: var(--brand-text);
    line-height: 1.5;
    display: none;
}

.mobile-actor-detail-card-overlay.active {
    display: block;
}

/* Case summary section */
.mobile-case-summary-section {
    background-color: var(--brand-surface);
    border: 1px solid var(--brand-border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
}

.mobile-case-summary-section h3 {
    margin: 0 0 8px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--brand-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mobile-case-summary-section p {
    margin: 0;
    font-size: 14px;
    color: var(--brand-text);
    line-height: 1.6;
}

/* ============================================================================
   BOTTOM SHEET COMPONENT
   ============================================================================ */

/* Bottom sheet overlay - HIDDEN ON DESKTOP */
.mobile-bottom-sheet-overlay {
    display: none !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--brand-overlay-bg);
    z-index: 200;
    animation: fadeIn 0.3s ease-out;
}

.mobile-bottom-sheet-overlay.active {
    display: block !important;
}

/* Bottom sheet container - HIDDEN ON DESKTOP */
.mobile-bottom-sheet {
    display: none !important;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: 80vh;
    background-color: var(--brand-surface);
    border-radius: 12px 12px 0 0;
    z-index: 210;
    animation: slideUp 0.3s ease-out;
    flex-direction: column;
}

.mobile-bottom-sheet.active {
    display: flex !important;
}

/* Drag handle at top of sheet */
.mobile-bottom-sheet-handle {
    display: flex;
    justify-content: center;
    padding: 12px;
    border-bottom: 1px solid var(--brand-border);
    flex-shrink: 0;
}

.mobile-bottom-sheet-handle::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background-color: var(--brand-border);
    border-radius: 2px;
}

/* Sheet header */
.mobile-bottom-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--brand-border);
    flex-shrink: 0;
}

.mobile-bottom-sheet-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--brand-text);
}

.mobile-bottom-sheet-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--brand-text);
    font-size: 24px;
    padding: 0;
}

/* Sheet content */
.mobile-bottom-sheet-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
}

/* Case item in bottom sheet */
.mobile-sheet-case-item {
    display: flex;
    flex-direction: column;
    padding: 12px;
    margin: 4px 0;
    background-color: var(--brand-bg);
    border: 1px solid var(--brand-border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.mobile-sheet-case-item:active {
    background-color: var(--brand-primary-muted);
    transform: scale(0.98);
}

.mobile-sheet-case-item.current {
    background-color: var(--brand-primary-muted);
    border-color: var(--brand-primary);
}

.mobile-sheet-case-item-label {
    font-size: 11px;
    color: var(--brand-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.mobile-sheet-case-item-title {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--brand-text);
}

/* ============================================================================
   ANIMATIONS
   ============================================================================ */

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

@keyframes slideDown {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(100%);
    }
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

.mobile-hidden {
    display: none;
}

.mobile-visible {
    display: block;
}

/* Safe area support for notched devices */
@supports (padding: max(0px)) {
    .mobile-safe-top {
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .mobile-safe-bottom {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .mobile-safe-left {
        padding-left: max(12px, env(safe-area-inset-left));
    }

    .mobile-safe-right {
        padding-right: max(12px, env(safe-area-inset-right));
    }
}

/* ============================================================================
   SCROLLING IMPROVEMENTS
   ============================================================================ */

/* Smooth scrolling on iOS */
.mobile-screen,
.mobile-actors-scroll,
.mobile-detail-content,
.mobile-list-container,
.mobile-bottom-sheet-content {
    -webkit-overflow-scrolling: touch;
}

/* Prevent bounce on iOS */
body {
    overscroll-behavior: none;
}

/* ============================================================================
   MOBILE TOUCH IMPROVEMENTS
   ============================================================================ */

/* Larger tap targets */
button {
    min-height: 44px;
    min-width: 44px;
}

/* Remove default button styling on mobile */
.mobile-actor-chip,
.mobile-detail-header-back,
.mobile-detail-header-switch,
.mobile-bottom-sheet-close {
    -webkit-tap-highlight-color: transparent;
    -webkit-appearance: none;
    appearance: none;
}

/* ============================================================================
   LIGHT MODE SUPPORT (if needed)
   ============================================================================ */

@media (prefers-color-scheme: light) {
    :root {
        --brand-bg: #ffffff;
        --brand-surface: #f5f5f5;
        --brand-primary: #2563eb;
        --brand-primary-muted: #dbeafe;
        --brand-secondary: #10b981;
        --brand-text: #1f2937;
        --brand-text-muted: #6b7280;
        --brand-border: #e5e7eb;
    }
}
