/* =============================================================================
   INLINE DIFF STYLES

   These styles control the visibility and appearance of diff elements
   injected into Javadoc HTML files. By default, diff annotations are hidden.
   When the user toggles "Show changes", the .show-diff class is added to body,
   revealing the diff styling.
   ============================================================================= */

/* -----------------------------------------------------------------------------
   DEFAULT STATE: Hide diff-specific elements
   ----------------------------------------------------------------------------- */

/* Diff badges are hidden by default */
.diff-badge {
    display: none;
}

/* -----------------------------------------------------------------------------
   BADGE COLUMN - Collapsed by default, expands when diff is active
   ----------------------------------------------------------------------------- */

/* Badge column cells - completely collapsed by default */
.ghidra-diff-badge-col {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    overflow: hidden !important;
    visibility: hidden;
}

/* Badge column header and data cells (for tables) - collapsed by default */
th.ghidra-diff-badge-col:not(.colFirst),
td.ghidra-diff-badge-col {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    padding: 0 !important;
    border: none !important;
    overflow: hidden !important;
    font-size: 0 !important; /* Hide text when collapsed */
}

/* Header cells that also have colFirst - hide content but keep structure (only when diff is OFF) */
body:not(.show-diff) th.colFirst.ghidra-diff-badge-col {
    width: 0 !important;
    min-width: 0 !important;
    max-width: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    text-indent: -9999px; /* Hide text without changing font-size */
}

/* Badge column for div-based tables (modern format) - hidden by default */
div.ghidra-diff-badge-col {
    display: none;
}

/* Old signature display is hidden by default */
.diff-old-signature {
    display: none;
}

/* Removed elements are completely hidden by default */
[data-diff="removed"] {
    display: none !important;
}

/* -----------------------------------------------------------------------------
   DIFF BADGE STYLES (visible when .show-diff is active)
   ----------------------------------------------------------------------------- */

body.show-diff .diff-badge {
    display: inline-block;
    font-size: 0.65em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 8px;
    vertical-align: middle;
    text-decoration: none !important;
}

/* Badge colors - light mode */
.diff-badge--added,
.diff-badge--introduced {
    background-color: rgba(40, 167, 69, 0.15);
    color: #28a745;
    border: 1px solid rgba(40, 167, 69, 0.3);
}

.diff-badge--removed {
    background-color: rgba(220, 53, 69, 0.15);
    color: #dc3545;
    border: 1px solid rgba(220, 53, 69, 0.3);
}

.diff-badge--modified {
    background-color: rgba(255, 193, 7, 0.15);
    color: #b38600;
    border: 1px solid rgba(255, 193, 7, 0.3);
}

/* -----------------------------------------------------------------------------
   SIGNATURE DIFF DISPLAY (visible when .show-diff is active)
   ----------------------------------------------------------------------------- */

/* Container for the +/- signature diff */
.diff-signatures {
    display: none;
}

body.show-diff .diff-signatures {
    display: block;
    font-size: 0.9em;
    margin: 8px 0;
    border-radius: 4px;
    overflow: hidden;
    font-family: "SF Mono", Monaco, Consolas, monospace;
}

/* Change summary text above the diff */
.diff-summary {
    padding: 6px 10px;
    font-size: 0.95em;
    color: #555;
    font-style: italic;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

html.dark-mode .diff-summary {
    color: #d1d5db;
    border-bottom-color: rgba(255, 255, 255, 0.1);
}

/* Individual signature lines */
.diff-sig {
    padding: 6px 10px;
    white-space: pre-wrap;
    word-break: break-word;
}

.diff-sig code {
    background: transparent;
    padding: 0;
    font-size: inherit;
}

/* Old signature line (red) */
.diff-sig--old {
    background-color: rgba(220, 53, 69, 0.1);
    border-left: 3px solid #dc3545;
}

/* New signature line (green) */
.diff-sig--new {
    background-color: rgba(40, 167, 69, 0.1);
    border-left: 3px solid #28a745;
}

/* +/- prefix */
.diff-sig-prefix {
    font-weight: 700;
    margin-right: 8px;
    user-select: none;
}

.diff-sig--old .diff-sig-prefix {
    color: #dc3545;
}

.diff-sig--new .diff-sig-prefix {
    color: #28a745;
}

/* Inline diff highlights - only visible when show-diff is active */
/* Used in signature diffs (which are inside .diff-signatures, already hidden) */
/* and in throws/params sections (need explicit show-diff scoping) */
.diff-inline-del {
    color: inherit;
}

.diff-inline-add {
    color: inherit;
}

/* When show-diff is active, color the inline additions/deletions */
body.show-diff .diff-inline-del,
body.show-diff .diff-inline-del a,
body.show-diff .diff-inline-del code {
    color: #dc3545;
}

body.show-diff .diff-inline-add,
body.show-diff .diff-inline-add a,
body.show-diff .diff-inline-add code {
    color: #28a745;
}

/* Removed throws - hidden by default, shown with strikethrough when diff mode is on */
.diff-removed-throws {
    display: none;
}

body.show-diff .diff-removed-throws {
    display: block;
}

body.show-diff dd.diff-removed-throws {
    display: list-item;
}

body.show-diff .diff-removed-throws .diff-inline-del {
    text-decoration: line-through;
}

/* -----------------------------------------------------------------------------
   SHOW DIFF STATE: Badge column expansion
   ----------------------------------------------------------------------------- */

/* Badge column - expanded when diff is active */
body.show-diff .ghidra-diff-badge-col {
    width: auto !important;
    min-width: 70px !important;
    max-width: none !important;
    padding: 4px 6px !important;
    visibility: visible;
    overflow: visible !important;
}

/* Badge column data cells for table-based layouts (legacy format) */
body.show-diff td.ghidra-diff-badge-col {
    width: auto !important;
    min-width: 70px !important;
    max-width: none !important;
    padding: 4px 6px !important;
    vertical-align: middle;
    text-align: center;
    overflow: visible !important;
    font-size: inherit !important;
}

/* Header cell with colFirst - match Javadoc header styling exactly */
body.show-diff th.colFirst.ghidra-diff-badge-col {
    width: auto !important;
    min-width: 70px !important;
    max-width: none !important;
    overflow: visible !important;
    text-indent: 0; /* Restore text visibility */
    vertical-align: top; /* Match Javadoc header alignment */
    text-align: left; /* Match Javadoc header alignment */
    padding: 8px 3px 3px 7px !important; /* Match Javadoc th.colFirst padding exactly */
}

/* Header cells without colFirst (fallback) */
body.show-diff th.ghidra-diff-badge-col:not(.colFirst) {
    width: auto !important;
    min-width: 70px !important;
    max-width: none !important;
    padding: 4px 6px !important;
    vertical-align: middle;
    text-align: center;
    overflow: visible !important;
    font-size: inherit !important;
    font-weight: bold;
}

/* Badge column for div-based tables (modern format) - show as flex for centering */
body.show-diff div.ghidra-diff-badge-col {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-width: 70px !important;
}

/* Header cell in modern format - match Javadoc table-header styling exactly */
body.show-diff div.table-header.ghidra-diff-badge-col {
    display: block !important;
    text-align: left;
    font-weight: bold;
    font-size: 0.93em !important;
    padding-top: 8px !important;
    padding-bottom: 3px !important;
    padding-right: 0 !important;
    vertical-align: top;
}

/* Modern format: adjust grid to include badge column */
body.show-diff .summary-table.three-column-summary {
    grid-template-columns: auto 1fr 1fr 2fr !important;
}

body.show-diff .summary-table.two-column-summary {
    grid-template-columns: auto 1fr 2fr !important;
}

/* Fallback for summary tables without explicit column count */
body.show-diff div.summary-table {
    grid-template-columns: auto auto 1fr 2fr !important;
}

/* -----------------------------------------------------------------------------
   SHOW DIFF STATE: Background highlights for changed sections
   ----------------------------------------------------------------------------- */

/* Show removed elements (both section and summary table rows) */
body.show-diff [data-diff="removed"] {
    display: block !important;
}

/* Summary table removed rows need appropriate display */
body.show-diff div[data-diff="removed"] {
    display: block !important;
}

/* IMPORTANT: Badge column cells with data-diff="removed" need flex for centering */
/* This must come after the generic removed rule to override it */
body.show-diff div.ghidra-diff-badge-col[data-diff="removed"] {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

/* Legacy table rows need table-row display */
body.show-diff tr[data-diff="removed"] {
    display: table-row !important;
}

/* Removed detail sections get special styling (new format only) */
body.show-diff section[data-diff="removed"] {
    background-color: rgba(220, 53, 69, 0.08);
    border-left: 3px solid #dc3545;
    padding-left: 10px;
    margin: 5px 0;
    opacity: 0.8;
}


/* Added elements get a green highlight (new format only) */
body.show-diff section[data-diff="added"] {
    background-color: rgba(40, 167, 69, 0.08);
    border-left: 3px solid #28a745;
    padding-left: 10px;
}

/* Modified elements get a yellow/amber highlight (new format only) */
body.show-diff section[data-diff="modified"] {
    background-color: rgba(255, 193, 7, 0.08);
    border-left: 3px solid #ffc107;
    padding-left: 10px;
}

/* Introduced types (whole class is new) */
body.show-diff [data-diff="introduced"] {
    background-color: rgba(23, 162, 184, 0.08);
    border-left: 3px solid #17a2b8;
    padding-left: 10px;
}

/* Summary table row styling - new format (divs) */
body.show-diff div.col-first[data-diff="removed"],
body.show-diff div.col-second[data-diff="removed"],
body.show-diff div.col-last[data-diff="removed"],
body.show-diff div.ghidra-diff-badge-col[data-diff="removed"] {
    background-color: rgba(220, 53, 69, 0.12) !important;
}

body.show-diff div.col-first[data-diff="added"],
body.show-diff div.col-second[data-diff="added"],
body.show-diff div.col-last[data-diff="added"],
body.show-diff div.ghidra-diff-badge-col[data-diff="added"] {
    background-color: rgba(40, 167, 69, 0.12) !important;
}

body.show-diff div.col-first[data-diff="modified"],
body.show-diff div.col-second[data-diff="modified"],
body.show-diff div.col-last[data-diff="modified"],
body.show-diff div.ghidra-diff-badge-col[data-diff="modified"] {
    background-color: rgba(255, 193, 7, 0.12) !important;
}

/* Summary table row styling - legacy format (tr/td/th) */
body.show-diff tr[data-diff="removed"] td,
body.show-diff tr[data-diff="removed"] th {
    background-color: rgba(220, 53, 69, 0.12) !important;
}

body.show-diff tr[data-diff="added"] td,
body.show-diff tr[data-diff="added"] th {
    background-color: rgba(40, 167, 69, 0.12) !important;
}

body.show-diff tr[data-diff="modified"] td,
body.show-diff tr[data-diff="modified"] th {
    background-color: rgba(255, 193, 7, 0.12) !important;
}


body.show-diff div[data-diff] .diff-badge {
    text-decoration: none !important;
}

/* -----------------------------------------------------------------------------
   DARK MODE ADJUSTMENTS
   ----------------------------------------------------------------------------- */

/* Badge colors - dark mode */
html.dark-mode .diff-badge--added,
html.dark-mode .diff-badge--introduced {
    background-color: rgba(134, 239, 172, 0.2);
    color: #86efac;
    border-color: rgba(134, 239, 172, 0.4);
}

html.dark-mode .diff-badge--removed {
    background-color: rgba(252, 165, 165, 0.2);
    color: #fca5a5;
    border-color: rgba(252, 165, 165, 0.4);
}

html.dark-mode .diff-badge--modified {
    background-color: rgba(253, 230, 138, 0.2);
    color: #fde68a;
    border-color: rgba(253, 230, 138, 0.4);
}

/* Signature diff - dark mode */
html.dark-mode .diff-sig--old {
    background-color: rgba(252, 165, 165, 0.15);
    border-left-color: #fca5a5;
}

html.dark-mode .diff-sig--new {
    background-color: rgba(134, 239, 172, 0.15);
    border-left-color: #86efac;
}

html.dark-mode .diff-sig--old .diff-sig-prefix {
    color: #fca5a5;
}

html.dark-mode .diff-sig--new .diff-sig-prefix {
    color: #86efac;
}

html.dark-mode body.show-diff .diff-inline-del,
html.dark-mode body.show-diff .diff-inline-del a,
html.dark-mode body.show-diff .diff-inline-del code {
    color: #fca5a5;
}

html.dark-mode body.show-diff .diff-inline-add,
html.dark-mode body.show-diff .diff-inline-add a,
html.dark-mode body.show-diff .diff-inline-add code {
    color: #86efac;
}

/* Section highlights - dark mode (new format only) */
html.dark-mode body.show-diff section[data-diff="removed"] {
    background-color: rgba(252, 165, 165, 0.15) !important;
    border-left: 3px solid #fca5a5 !important;
}

html.dark-mode body.show-diff section[data-diff="added"] {
    background-color: rgba(134, 239, 172, 0.15) !important;
    border-left: 3px solid #86efac !important;
}

html.dark-mode body.show-diff section[data-diff="modified"] {
    background-color: rgba(253, 230, 138, 0.15) !important;
    border-left: 3px solid #fde68a !important;
}

html.dark-mode body.show-diff [data-diff="introduced"] {
    background-color: rgba(125, 211, 252, 0.15) !important;
    border-left: 3px solid #7dd3fc !important;
}

/* Summary table rows - dark mode (all columns including badge) */
html.dark-mode body.show-diff div.col-first[data-diff="removed"],
html.dark-mode body.show-diff div.col-second[data-diff="removed"],
html.dark-mode body.show-diff div.col-last[data-diff="removed"],
html.dark-mode body.show-diff div.ghidra-diff-badge-col[data-diff="removed"] {
    background-color: rgba(252, 165, 165, 0.2) !important;
}

html.dark-mode body.show-diff div.col-first[data-diff="added"],
html.dark-mode body.show-diff div.col-second[data-diff="added"],
html.dark-mode body.show-diff div.col-last[data-diff="added"],
html.dark-mode body.show-diff div.ghidra-diff-badge-col[data-diff="added"] {
    background-color: rgba(134, 239, 172, 0.2) !important;
}

html.dark-mode body.show-diff div.col-first[data-diff="modified"],
html.dark-mode body.show-diff div.col-second[data-diff="modified"],
html.dark-mode body.show-diff div.col-last[data-diff="modified"],
html.dark-mode body.show-diff div.ghidra-diff-badge-col[data-diff="modified"] {
    background-color: rgba(253, 230, 138, 0.2) !important;
}

/* Summary table rows - dark mode - legacy format (tr/td/th) */
html.dark-mode body.show-diff tr[data-diff="removed"] td,
html.dark-mode body.show-diff tr[data-diff="removed"] th {
    background-color: rgba(252, 165, 165, 0.2) !important;
}

html.dark-mode body.show-diff tr[data-diff="added"] td,
html.dark-mode body.show-diff tr[data-diff="added"] th {
    background-color: rgba(134, 239, 172, 0.2) !important;
}

html.dark-mode body.show-diff tr[data-diff="modified"] td,
html.dark-mode body.show-diff tr[data-diff="modified"] th {
    background-color: rgba(253, 230, 138, 0.2) !important;
}

/* -----------------------------------------------------------------------------
   LEGACY JAVADOC PADDING CONSISTENCY
   These rules ensure consistent padding between light and dark modes to prevent
   page shifting when toggling themes.
   ----------------------------------------------------------------------------- */

/* Deeply nested blockList items (individual method/field detail sections) */
ul.blockList ul.blockList ul.blockList li.blockList,
ul.blockList ul.blockList ul.blockListLast li.blockList {
    padding: 15px;
    margin-bottom: 15px;
}

/* Method/field name headers in legacy format */
ul.blockList ul.blockList ul.blockList li.blockList h3,
ul.blockList ul.blockList ul.blockList li.blockList h4,
ul.blockList ul.blockList ul.blockListLast li.blockList h3,
ul.blockList ul.blockList ul.blockListLast li.blockList h4,
div.details ul.blockList ul.blockList ul.blockList li.blockList h4,
div.details ul.blockList ul.blockList ul.blockListLast li.blockList h4 {
    padding: 8px 12px;
    margin-bottom: 10px;
}

/* Section heading margins for legacy format */
html.dark-mode section.detail h3,
html.dark-mode body.class-declaration-page .details h3,
html.dark-mode body.class-declaration-page .summary h3 {
    margin: 0 0 6px -8px;
}

/* Apply same margin in light mode */
section.detail h3,
body.class-declaration-page .details h3,
body.class-declaration-page .summary h3 {
    margin: 0 0 6px -8px;
}

/* Legacy diff wrapper styling - wrapper itself is transparent, just a container */
.diff-member-wrapper {
    box-sizing: border-box;
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Remove default margins from ul.blockList inside wrapper so wrapper fits content tightly */
.diff-member-wrapper > ul.blockList {
    margin: 0 !important;
    padding: 0 !important;
}

/* Target the ul.blockList INSIDE the wrapper for border - light mode */
body.show-diff .diff-member-wrapper[data-diff="added"] > ul.blockList {
    background-color: #e8f5e9 !important;
    border-left: 3px solid #28a745 !important;
}
body.show-diff .diff-member-wrapper[data-diff="removed"] > ul.blockList {
    background-color: #ffebee !important;
    border-left: 3px solid #dc3545 !important;
}
body.show-diff .diff-member-wrapper[data-diff="modified"] > ul.blockList {
    background-color: #fff8e1 !important;
    border-left: 3px solid #ffc107 !important;
}

/* Target li.blockList for background (it often has its own bg that overrides parent) */
body.show-diff .diff-member-wrapper[data-diff="added"] > ul.blockList > li.blockList {
    background-color: #e8f5e9 !important;
    border-left: none !important;
}
body.show-diff .diff-member-wrapper[data-diff="removed"] > ul.blockList > li.blockList {
    background-color: #ffebee !important;
    border-left: none !important;
}
body.show-diff .diff-member-wrapper[data-diff="modified"] > ul.blockList > li.blockList {
    background-color: #fff8e1 !important;
    border-left: none !important;
}

/* Target the ul.blockList INSIDE the wrapper for border - dark mode */
html.dark-mode body.show-diff .diff-member-wrapper[data-diff="added"] > ul.blockList {
    background-color: #1b3d2f !important;
    border-left: 3px solid #86efac !important;
}
html.dark-mode body.show-diff .diff-member-wrapper[data-diff="removed"] > ul.blockList {
    background-color: #3d1b1b !important;
    border-left: 3px solid #fca5a5 !important;
}
html.dark-mode body.show-diff .diff-member-wrapper[data-diff="modified"] > ul.blockList {
    background-color: #3d3a1b !important;
    border-left: 3px solid #fde68a !important;
}

/* Target li.blockList for background - dark mode */
html.dark-mode body.show-diff .diff-member-wrapper[data-diff="added"] > ul.blockList > li.blockList {
    background-color: #1b3d2f !important;
    border-left: none !important;
}
html.dark-mode body.show-diff .diff-member-wrapper[data-diff="removed"] > ul.blockList > li.blockList {
    background-color: #3d1b1b !important;
    border-left: none !important;
}
html.dark-mode body.show-diff .diff-member-wrapper[data-diff="modified"] > ul.blockList > li.blockList {
    background-color: #3d3a1b !important;
    border-left: none !important;
}
