/* ============================================================
   R Watch – Responsive Override CSS
   Mobile-first media queries for all pages
   Breakpoints: mobile ≤480px, tablet ≤768px, desktop >768px
   ============================================================ */

/* ============================================================
   BASE RESETS FOR MOBILE
   ============================================================ */

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    overflow-x: hidden;
}


img {
    max-width: 100%;
    height: auto;
}

/* ============================================================
   HAMBURGER NAVBAR (shared across all pages)
   ============================================================ */

.rw-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    gap: 5px;
    padding: 6px;
    border-radius: 10px;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

.rw-hamburger:hover {
    background: rgba(227, 27, 35, 0.08);
}

.rw-hamburger span {
    display: block;
    width: 22px;
    height: 2px;
    background: #111827;
    border-radius: 2px;
    transition: all 0.3s ease;
    transform-origin: center;
}

.rw-hamburger.open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.rw-hamburger.open span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.rw-hamburger.open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* Mobile menu drawer */
.rw-mobile-menu {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 8000;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.rw-mobile-menu.open {
    display: block;
    opacity: 1;
}

.rw-mobile-menu-panel {
    position: absolute;
    top: 0;
    right: 0;
    width: min(320px, 85vw);
    height: 100%;
    background: #ffffff;
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
}

.rw-mobile-menu.open .rw-mobile-menu-panel {
    transform: translateX(0);
}

.rw-mobile-menu-close {
    align-self: flex-start;
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #6B7280;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    margin-bottom: 1rem;
    transition: background 0.2s;
}

.rw-mobile-menu-close:hover {
    background: #F3F4F6;
    color: #111827;
}

.rw-mobile-nav-link {
    display: block;
    padding: 0.875rem 1rem;
    text-decoration: none;
    color: #111827;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 10px;
    transition: background 0.2s;
}

.rw-mobile-nav-link:hover {
    background: rgba(227, 27, 35, 0.06);
    color: #E31B23;
}

.rw-mobile-nav-divider {
    height: 1px;
    background: #E5E7EB;
    margin: 0.5rem 0;
}

/* ============================================================
   TABLET (≤768px)
   ============================================================ */

@media (max-width: 768px) {

    /* Show hamburger, hide desktop nav links */
    .rw-hamburger {
        display: flex;
    }

    /* Nav: hide desktop links */
    nav .rw-desktop-nav {
        display: none !important;
    }

    /* results.html header nav links hidden */
    header.hero.compact>div:last-child>a,
    header.hero.compact>div:last-child>button {
        display: none;
    }

    .rw-results-mobile-nav {
        display: flex !important;
        align-items: center;
        gap: 0.5rem;
    }

    /* Container padding adjustments */
    .container {
        padding: 0 1rem !important;
    }

    /* Hero section padding */
    section[style*="4rem 0 8rem"] {
        padding: 2.5rem 0 5rem !important;
    }

    /* Team page header */
    .page-header {
        padding: 3rem 0 2.5rem !important;
    }

    .page-title {
        font-size: 2.2rem !important;
        letter-spacing: -0.02em !important;
    }

    .page-subtitle {
        font-size: 1rem !important;
    }

    /* Data page */
    .data-header {
        padding: 2.5rem 0 4rem !important;
    }

    .data-title {
        font-size: 2.5rem !important;
    }

    .data-subtitle {
        font-size: 1rem !important;
    }

    .data-content-box {
        padding: 2rem !important;
        border-radius: 20px !important;
    }

    /* Footer CTA buttons */
    div[style*="display: flex; gap: 1rem; justify-content: center"] {
        flex-direction: column;
        align-items: center;
    }

    /* results.html header: hide desktop nav links, show only hamburger */
    .hero.compact .rw-desktop-nav {
        display: none !important;
    }

    .hero.compact {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 0.75rem 1rem !important;
    }

    /* results.html sidebar + layout */
    .scopus-layout {
        flex-direction: column;
        margin: 16px auto !important;
        padding: 0 12px !important;
    }

    .scopus-sidebar {
        width: 100% !important;
        min-width: unset !important;
    }

    /* scopus-main must be constrained so rw-results-scroll can
       scroll internally without affecting the page body */
    .scopus-main {
        overflow: hidden;
        width: 100%;
        min-width: 0;
    }

    /* Dashboard sidebar grid */
    .dashboard-two-col {
        grid-template-columns: 1fr !important;
    }

    /* Graph sidebar */
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100% !important;
        height: auto !important;
        max-height: 280px;
    }

    .main-content {
        height: 50vh !important;
        min-height: 300px;
    }

    /* Team section CTA */
    section[style*="marginTop: '8rem'"],
    section[style*="margin-top: 8rem"] {
        padding: 2rem 1.5rem !important;
        border-radius: 20px !important;
    }
}

/* ============================================================
   MOBILE (≤640px)
   ============================================================ */

@media (max-width: 640px) {

    /* Hero headline scaling */
    .rw-hero-title {
        font-size: 2rem !important;
        letter-spacing: -0.03em !important;
    }

    /* Search card: stack inputs vertically */
    .rw-search-grid {
        grid-template-columns: 1fr !important;
    }

    .search-card-container {
        padding: 1.25rem !important;
        border-radius: 16px !important;
    }

    /* Recent searches */
    .rw-recent-searches {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    /* Results header */
    .results-header-row {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }

    .hero.compact {
        padding: 0.75rem 1rem !important;
    }

    /* Dashboard */
    .rw-chart-grid {
        grid-template-columns: 1fr !important;
    }

    /* Details page */
    .rw-stat-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    .rw-rindex-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    .rw-chart-subject-grid {
        grid-template-columns: 1fr !important;
    }

    /* Details page: fixed footer hidden on small screens */
    footer.fixed {
        display: none !important;
    }

    /* Data page */
    .data-title {
        font-size: 2rem !important;
    }

    .data-content-box {
        padding: 1.25rem !important;
        border-radius: 16px !important;
    }

    /* Team page */
    .page-title {
        font-size: 1.85rem !important;
    }

    .team-card {
        border-radius: 24px !important;
    }

    /* Buttons touch targets */
    .btn-primary,
    .btn-secondary,
    button {
        min-height: 44px;
    }

    /* Table within rw-results-scroll: let the outer container scroll,
       not the table wrapper itself */
    .rw-results-scroll .rw-table-wrapper {
        overflow: visible;
        width: 100%;
    }

    /* Fallback: tables outside the scroll container stay x-scrollable */
    .rw-table-wrapper:not(.rw-results-scroll *) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    /* Toast notifications */
    .toast-container {
        bottom: 12px;
        right: 12px;
        left: 12px;
    }

    .toast {
        max-width: 100%;
        min-width: unset;
    }
}

/* ============================================================
   EXTRA SMALL (≤480px)
   ============================================================ */

@media (max-width: 480px) {

    .rw-hero-title {
        font-size: 1.75rem !important;
    }

    .rw-stat-grid {
        grid-template-columns: 1fr !important;
    }

    .rw-rindex-grid {
        grid-template-columns: 1fr !important;
    }

    /* details.html: action buttons stack */
    .rw-paper-actions {
        flex-direction: column !important;
    }

    .rw-paper-actions button,
    .rw-paper-actions a {
        width: 100% !important;
        justify-content: center !important;
    }

    /* data.html: info grid single column */
    .info-grid {
        grid-template-columns: 1fr !important;
    }

    /* Pagination controls */
    .pagination-controls {
        gap: 10px !important;
        padding: 20px 0 !important;
    }

    #page-indicator {
        font-size: 0.85rem;
    }
}

/* ============================================================
   MOBILE FILTER PANEL TOGGLE (results.html)
   ============================================================ */

.rw-filter-toggle-btn {
    display: none;
    width: 100%;
    padding: 0.75rem 1rem;
    background: #ffffff;
    border: 1.5px solid #E5E7EB;
    border-radius: 10px;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: #111827;
    cursor: pointer;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 1rem;
    transition: border-color 0.2s;
    min-height: 44px;
}

.rw-filter-toggle-btn:hover {
    border-color: #E31B23;
    color: #E31B23;
}

.rw-filter-toggle-btn i {
    font-size: 0.85rem;
    transition: transform 0.2s;
}

.rw-filter-toggle-btn.active i {
    transform: rotate(180deg);
}

@media (max-width: 900px) {
    .rw-filter-toggle-btn {
        display: flex;
    }

    .scopus-sidebar {
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    .scopus-sidebar.collapsed {
        max-height: 48px !important;
        overflow: hidden;
    }

    .scopus-sidebar.collapsed .filter-group,
    .scopus-sidebar.collapsed .filter-actions-bottom,
    .scopus-sidebar.collapsed .sidebar-header {
        display: none;
    }
}

/* ============================================================
   INLINE STYLE OVERRIDES (React inline styles in JSX)
   These target specific hardcoded inline values using CSS
   specificity with attribute selectors and media queries
   ============================================================ */

/* index.html hero heading */
@media (max-width: 640px) {

    /* h2 inside the hero container */
    .container h2[style],
    section h2[style] {
        font-size: clamp(1.75rem, 6vw, 3rem) !important;
        letter-spacing: -0.025em !important;
    }

    /* Paragraph subtitle */
    section p[style*="1.25rem"] {
        font-size: 1rem !important;
        margin-bottom: 2.5rem !important;
    }

    /* Search card grid */
    div[style*="gridTemplateColumns: '1fr 1.8fr"] {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    /* Dashboard chart grid */
    div[style*="gridTemplateColumns: '1fr 1fr'"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    /* Dashboard outer grid (filter + charts) */
    div[style*="gridTemplateColumns: 'minmax(320px"] {
        grid-template-columns: 1fr !important;
    }

    /* details.html stat grid */
    div[class*="grid-cols-4"],
    div[class*="grid-cols-2"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* details.html paper title */
    h2[style*="2.25rem"] {
        font-size: 1.4rem !important;
        line-height: 1.3 !important;
    }

    /* details.html seed paper section padding */
    section[style*="padding: '2rem'"] {
        padding: 1.25rem !important;
    }
}

@media (max-width: 480px) {
    div[class*="grid-cols-4"] {
        grid-template-columns: 1fr !important;
    }

    /* details.html action buttons */
    div[style*="flexWrap: 'wrap'"] {
        flex-direction: column !important;
    }
}

/* ============================================================
   TOUCH DEVICE IMPROVEMENTS
   ============================================================ */

@media (hover: none) and (pointer: coarse) {

    /* Larger tap targets */
    .btn-primary,
    .btn-secondary {
        min-height: 48px;
        min-width: 48px;
    }

    /* Remove hover transforms on touch */
    .glass-card:hover {
        transform: none;
    }

    .team-card:hover {
        transform: none !important;
    }

    .info-card:hover {
        transform: none !important;
    }

    /* Better scroll on iOS */
    .scopus-sidebar,
    .filter-content,
    .modal-body,
    .rw-mobile-menu-panel {
        -webkit-overflow-scrolling: touch;
    }
}

/* ============================================================
   CARD LAYOUT: transform table into cards on mobile
   (Specifically for results.html .scopus-results-container)
   ============================================================ */


@media (max-width: 900px) {

    /* Vertical-only scroll container for the results box */
    .rw-results-scroll {
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        border: 1px solid #E5E7EB;
        border-radius: 10px;
        background: #fff;
        width: 100%;
    }

    /* Hide the real column header row */
    .rw-results-scroll thead {
        display: none;
    }

    /* Table, wrapper, tbody → block so rows stack */
    .rw-results-scroll .scopus-results-container,
    .rw-results-scroll .rw-table-wrapper,
    .rw-results-scroll tbody {
        display: block;
        width: 100%;
    }



    /* Each row = a modern card */
    .rw-results-scroll .scopus-row {
        display: flex !important;
        flex-direction: column !important;
        padding: 1.5rem !important;
        border-bottom: 1px solid #F3F4F6;
        background: #fff;
        gap: 0.75rem !important;
    }

    .rw-results-scroll .scopus-row:hover {
        background: #F9FAFB !important;
    }

    /* Reset all cells to block/flex */
    .rw-results-scroll .scopus-row td {
        display: block !important;
        padding: 0 !important;
        border: none !important;
        width: 100% !important;
        text-align: left !important;
    }

    /* 1. TOP ROW: Index + Labels */
    .rw-results-scroll .col-index {
        order: 1;
        display: flex !important;
        align-items: center;
        gap: 0.75rem;
        margin-bottom: -0.25rem;
    }

    .rw-results-scroll .row-number {
        color: #94a3b8;
        font-size: 0.85rem;
        font-weight: 700;
    }

    .rw-results-scroll .doc-meta-badges {
        display: flex !important;
        align-items: center;
        gap: 0.5rem;
        margin: 0 !important;
    }

    .rw-results-scroll .doc-type-label {
        font-size: 0.7rem;
        font-weight: 800;
        color: #64748b;
        letter-spacing: 0.05em;
    }

    /* 2. TITLE */
    .rw-results-scroll .col-title {
        order: 2;
    }

    .rw-results-scroll .col-title .doc-title {
        font-size: 1.05rem !important;
        line-height: 1.4 !important;
        color: #E31B23 !important;
        font-weight: 700 !important;
        display: block;
        margin-bottom: 0.5rem;
    }

    /* 3. YEAR */
    .rw-results-scroll .col-year {
        order: 3;
        font-size: 0.9rem !important;
        color: #374151 !important;
        font-weight: 600 !important;
    }

    /* 4. AUTHORS */
    .rw-results-scroll .col-authors {
        order: 4;
        font-size: 0.85rem !important;
        color: #6B7280 !important;
        line-height: 1.5;
    }

    /* 5. JOURNAL/SOURCE */
    .rw-results-scroll .col-source {
        order: 5;
    }

    .rw-results-scroll .source-title {
        font-size: 0.9rem !important;
        font-weight: 700 !important;
        color: #111827 !important;
    }

    .rw-results-scroll .col-citations {
        order: 6;
        margin-top: 0.25rem;
        display: flex !important;
        align-items: center;
        gap: 0.4rem;
    }

    .rw-results-scroll .citation-badge::before {
        content: "Citations: ";
        font-weight: 600;
        color: #374151;
        margin-right: 4px;
    }

    .rw-results-scroll .citation-badge {
        background: #F3F4F6 !important;
        border-radius: 6px !important;
        padding: 2px 8px !important;
        font-size: 0.8rem !important;
        font-weight: 700 !important;
        color: #E31B23 !important;
    }

    /* Hide redundant elements in card view */
    .rw-results-scroll .doc-links,
    .rw-results-scroll .abstract-container {
        order: 7;
        /* Keep them at the very bottom if toggled */
    }

    /* Remove previous separators */
    .rw-results-scroll .col-source::before,
    .rw-results-scroll .col-year::before,
    .rw-results-scroll .col-citations::before {
        display: none !important;
    }
}

/* Scrollbar for the results box */
.rw-results-scroll::-webkit-scrollbar {
    width: 4px;
}

.rw-results-scroll::-webkit-scrollbar-track {
    background: #F3F4F6;
    border-radius: 10px;
}

.rw-results-scroll::-webkit-scrollbar-thumb {
    background: #D1D5DB;
    border-radius: 10px;
}

.rw-results-scroll::-webkit-scrollbar-thumb:hover {
    background: #E31B23;
}

/* Graph Page Specifics */
@media (max-width: 900px) {
    .app-container {
        flex-direction: column !important;
    }

    /* Fixed Sidebar on mobile */
    .sidebar {
        width: 100% !important;
        position: relative !important;
        max-height: 400px;
        overflow-y: auto;
        transition: all 0.3s ease;
    }

    /* Collapse logic */
    .sidebar.collapsed {
        display: none !important;
    }

    /* Mobile Floating Filter Toggle */
    .rw-filter-toggle-btn {
        display: flex !important;
        position: fixed;
        bottom: 1.5rem;
        left: 50%;
        transform: translateX(-50%);
        z-index: 2000;
        width: auto;
        height: 48px;
        padding: 0 1.5rem;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(8px);
        border-radius: 24px;
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12), 0 4px 10px rgba(227, 27, 35, 0.1);
        align-items: center;
        justify-content: center;
        border: 1.5px solid var(--primary);
        color: var(--primary);
        cursor: pointer;
        font-weight: 700;
        font-size: 0.95rem;
        gap: 8px;
        transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .rw-filter-toggle-btn.active {
        background: var(--primary) !important;
        color: white !important;
        box-shadow: 0 10px 30px rgba(227, 27, 35, 0.3);
    }

    .graph-container {
        height: calc(100vh - 60px) !important;
    }
}

/* Global collapse for results sidebar too */
.scopus-sidebar.collapsed {
    display: none !important;
}