/* PDF Structure Viewer - Main Styles */

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-surface: #e8e8e8;
    --bg-hover: #dcdcdc;
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --text-muted: #808080;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --green: #16a34a;
    --red: #dc2626;
    --yellow: #ca8a04;
    --orange: #ea580c;
    --purple: #7c3aed;
    --pink: #db2777;
    --border: #d1d5db;
    --divider: #b0b0b0;

    /* Region colors */
    --color-header: #2563eb;
    --color-object: #16a34a;
    --color-stream: #7c3aed;
    --color-xref: #ea580c;
    --color-trailer: #dc2626;
    --color-eof: #dc2626;
    --color-signature: #db2777;
    --color-gap: #d1d5db;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    font-size: 13px;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
}

/* Toolbar */
header#toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    height: 48px;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.upload-btn {
    padding: 6px 16px;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 12px;
    transition: background 0.15s;
}

.upload-btn:hover {
    background: var(--accent-hover);
}

.file-info {
    color: var(--text-secondary);
    font-size: 12px;
}

.mode-toggle {
    display: flex;
    background: var(--bg-surface);
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.mode-btn {
    padding: 6px 14px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    transition: all 0.15s;
}

.mode-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
    font-weight: 600;
}

.mode-btn:hover:not(.active) {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* Revision Bar */
.revision-bar {
    display: flex;
    gap: 4px;
    padding: 6px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.revision-bar.hidden {
    display: none;
}

.revision-btn {
    padding: 4px 12px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    font-family: inherit;
    white-space: nowrap;
    transition: all 0.15s;
}

.revision-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
    font-weight: 600;
}

.revision-btn:hover:not(.active) {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Split Pane Layout */
.split-container {
    display: flex;
    height: calc(100vh - 48px);
}

.split-container.has-revisions {
    height: calc(100vh - 48px - 36px);
}

.panel {
    display: flex;
    flex-direction: column;
    min-width: 200px;
    overflow: hidden;
}

.left-panel {
    flex: 1;
}

.right-panel {
    flex: 1;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    height: 32px;
    flex-shrink: 0;
}

.panel-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.view-toggle {
    display: flex;
    gap: 2px;
}

.view-btn {
    padding: 2px 8px;
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    font-family: inherit;
    transition: all 0.15s;
}

.view-btn.active {
    color: var(--text-primary);
    border-color: var(--border);
    background: var(--bg-primary);
}

.view-btn:hover:not(.active) {
    color: var(--text-secondary);
}

.panel-content {
    flex: 1;
    overflow: auto;
    padding: 0;
}

/* Divider */
.divider {
    width: 4px;
    background: var(--border);
    cursor: col-resize;
    flex-shrink: 0;
    transition: background 0.15s;
}

.divider:hover,
.divider.dragging {
    background: var(--accent);
}

/* Source View (Left Panel) */
.source-view {
    font-size: 12px;
    line-height: 1.6;
    white-space: pre;
    tab-size: 4;
}

.source-line {
    display: flex;
    padding: 0 8px;
    min-height: 19px;
}

.source-line:hover {
    background: var(--bg-hover);
}

/* Block highlight: entire object block gets a subtle background */
.source-line.block-highlight {
    background: rgba(37, 99, 235, 0.06);
    border-left: 3px solid var(--accent);
}

/* The specific clicked line within the block gets a stronger highlight */
.source-line.highlighted {
    background: rgba(37, 99, 235, 0.12);
}

.line-number {
    color: var(--text-muted);
    text-align: right;
    padding-right: 12px;
    min-width: 48px;
    user-select: none;
    flex-shrink: 0;
}

.line-content {
    flex: 1;
    overflow-x: visible;
}

/* Region highlighting in source view */
.region-header { color: var(--color-header); }
.region-object { color: var(--color-object); }
.region-stream { color: var(--color-stream); }
.region-xref { color: var(--color-xref); }
.region-trailer { color: var(--color-trailer); }
.region-eof { color: var(--color-trailer); font-weight: bold; }
.region-signature { color: var(--color-signature); font-weight: bold; }

/* Hex View */
.hex-view .hex-row {
    display: flex;
    padding: 0 8px;
    min-height: 19px;
    font-size: 12px;
}

.hex-row:hover {
    background: var(--bg-hover);
}

.hex-row.block-highlight {
    background: rgba(37, 99, 235, 0.06);
}

.hex-offset {
    color: var(--text-muted);
    min-width: 72px;
    text-align: right;
    padding-right: 16px;
    user-select: none;
}

.hex-bytes {
    min-width: 400px;
    letter-spacing: 1px;
}

.hex-ascii {
    color: var(--text-secondary);
    padding-left: 16px;
}

/* Tree View (Right Panel) */
.tree-view {
    padding: 8px 0;
}

.tree-node {
    /* user-select enabled for copy-paste; decorative elements excluded below */
}

.tree-node-header {
    display: flex;
    align-items: flex-start;
    padding: 3px 12px;
    cursor: pointer;
    gap: 6px;
    transition: background 0.1s;
}

.tree-node-header:hover {
    background: var(--bg-hover);
}

.tree-node-header.selected {
    background: rgba(37, 99, 235, 0.1);
}

.tree-toggle {
    color: var(--text-muted);
    width: 14px;
    flex-shrink: 0;
    font-size: 10px;
    line-height: 19px;
    text-align: center;
    user-select: none;
}

/* Toggle arrows via ::before so they are excluded from clipboard */
.tree-toggle::before {
    content: "\00a0"; /* non-breaking space for leaf nodes */
}

.tree-toggle.collapsed::before {
    content: "\25b6"; /* ▶ */
}

.tree-toggle.expanded::before {
    content: "\25bc"; /* ▼ */
}

.tree-label {
    flex: 1;
    line-height: 19px;
}

.tree-key {
    color: var(--accent);
}

.tree-value {
    color: var(--text-primary);
}

.tree-type {
    color: var(--purple);
    font-size: 11px;
}

.tree-annotation {
    color: var(--text-muted);
    font-size: 11px;
    font-style: italic;
}

.tree-children {
    padding-left: 16px;
}

.tree-children.collapsed {
    display: none;
}

/* Signature-specific tree styles */
.sig-node {
    border-left: 2px solid var(--color-signature);
    margin-left: 10px;
    padding-left: 6px;
}

.sig-field {
    display: flex;
    gap: 8px;
    padding: 2px 12px;
    font-size: 12px;
}

.sig-field-key {
    color: var(--text-muted);
    min-width: 100px;
}

.sig-field-value {
    color: var(--text-primary);
}

.sig-field-value.deprecated {
    color: var(--red);
}

.sig-field-value.modern {
    color: var(--green);
}

/* Coverage bar */
.coverage-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
}

.coverage-track {
    flex: 1;
    height: 6px;
    background: var(--bg-surface);
    border-radius: 3px;
    overflow: hidden;
    max-width: 200px;
    user-select: none;
}

.coverage-fill {
    height: 100%;
    background: var(--green);
    border-radius: 3px;
    transition: width 0.3s;
}

.coverage-label {
    font-size: 11px;
    color: var(--text-secondary);
}

/* Info badge */
.info-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.18);
    border-radius: 4px;
    font-size: 11px;
    color: var(--accent);
    margin: 2px 12px;
}

.book-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 11px;
}

.book-link:hover {
    text-decoration: underline;
}

/* DSS section */
.dss-summary {
    display: flex;
    gap: 16px;
    padding: 4px 12px;
    font-size: 12px;
}

.dss-stat {
    display: flex;
    gap: 4px;
}

.dss-stat-label {
    color: var(--text-muted);
}

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

/* Certificate info */
.cert-info {
    padding: 4px 12px;
    font-size: 12px;
}

.cert-field {
    display: flex;
    gap: 8px;
}

.cert-field-label {
    color: var(--text-muted);
    min-width: 60px;
}

.cert-field-value {
    color: var(--text-primary);
    word-break: break-all;
}

/* Empty state */
.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 14px;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--divider);
}

/* Loading spinner */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.loading::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 8px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Tooltip for annotations */
.annotation-tooltip {
    position: relative;
    cursor: help;
}

.annotation-tooltip .tooltip-content {
    display: none;
    position: absolute;
    left: 0;
    top: 100%;
    z-index: 100;
    padding: 8px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    font-style: normal;
    color: var(--text-primary);
    max-width: 400px;
    white-space: normal;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.annotation-tooltip:hover .tooltip-content {
    display: block;
}

/* Object Inspector Panel */
.object-inspector {
    background: var(--bg-secondary);
    border-bottom: 2px solid var(--accent);
    padding: 8px 12px;
    flex-shrink: 0;
    max-height: 220px;
    overflow-y: auto;
}

.object-inspector.hidden {
    display: none;
}

.inspector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.inspector-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
}

.inspector-close {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
    padding: 0 4px;
    line-height: 1;
    user-select: none;
}

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

.inspector-type {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(22, 163, 74, 0.1);
    border: 1px solid rgba(22, 163, 74, 0.25);
    border-radius: 4px;
    font-size: 11px;
    color: var(--green);
    margin-bottom: 6px;
}

.inspector-annotation {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 4px;
}

.inspector-book-link {
    display: inline-block;
    color: var(--accent);
    font-size: 11px;
    text-decoration: none;
    margin-bottom: 6px;
}

.inspector-book-link:hover {
    text-decoration: underline;
}

.inspector-keys {
    font-size: 11px;
    margin-bottom: 4px;
}

.inspector-keys-label {
    color: var(--text-muted);
}

.inspector-keys-list {
    color: var(--green);
}

.inspector-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    margin-bottom: 4px;
}

.stream-badge {
    background: rgba(124, 58, 237, 0.1);
    border: 1px solid rgba(124, 58, 237, 0.25);
    color: var(--purple);
}

/* Line-level explanation in inspector */
.inspector-line-explain {
    background: rgba(22, 163, 74, 0.05);
    border: 1px solid rgba(22, 163, 74, 0.12);
    border-radius: 4px;
    padding: 6px 10px;
    margin-bottom: 8px;
}

.inspector-line-code {
    font-size: 12px;
    font-weight: 600;
    color: var(--green);
    margin-bottom: 4px;
    font-family: inherit;
}

.inspector-line-text {
    font-size: 12px;
    color: var(--text-primary);
    line-height: 1.5;
    margin-bottom: 2px;
}

/* Separator between line-level and object-level info */
.inspector-line-explain + .inspector-type,
.inspector-line-explain + .inspector-annotation {
    margin-top: 4px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════════════
   Verification UI
   ═══════════════════════════════════════════════════════════════════════ */

/* Trust store banner */
.trust-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 12px;
    margin: 4px 12px;
    border-radius: 4px;
    font-size: 11px;
}

.trust-banner.trust-empty {
    background: rgba(202, 138, 4, 0.08);
    border: 1px solid rgba(202, 138, 4, 0.2);
    color: var(--yellow);
}

.trust-banner.trust-loaded {
    background: rgba(22, 163, 74, 0.08);
    border: 1px solid rgba(22, 163, 74, 0.2);
    color: var(--green);
}

.trust-banner-label {
    font-weight: 600;
}

.trust-upload-btn {
    padding: 2px 10px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    font-family: inherit;
    transition: all 0.15s;
}

.trust-upload-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Verification summary box */
.verification-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    margin: 4px 12px;
    border-radius: 4px;
    font-size: 12px;
}

.verification-summary.verification-pass {
    background: rgba(22, 163, 74, 0.08);
    border: 1px solid rgba(22, 163, 74, 0.2);
    color: var(--green);
}

.verification-summary.verification-fail {
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid rgba(220, 38, 38, 0.2);
    color: var(--red);
}

.verification-summary.verification-warn {
    background: rgba(202, 138, 4, 0.08);
    border: 1px solid rgba(202, 138, 4, 0.2);
    color: var(--yellow);
}

.verification-icon {
    font-size: 14px;
    line-height: 1;
    flex-shrink: 0;
    user-select: none;
}

.verification-text {
    line-height: 1.4;
}

/* Signature status badge */
.sig-status-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    margin-left: 8px;
    vertical-align: middle;
    user-select: none;
}

.sig-status-valid {
    background: rgba(22, 163, 74, 0.12);
    color: var(--green);
}

.sig-status-invalid {
    background: rgba(220, 38, 38, 0.12);
    color: var(--red);
}

.sig-status-valid_but_untrusted {
    background: rgba(202, 138, 4, 0.12);
    color: var(--yellow);
}

.sig-status-indeterminate {
    background: rgba(128, 128, 128, 0.12);
    color: var(--text-muted);
}

/* Signature node border colors based on verification status */
.sig-node.sig-valid {
    border-left-color: var(--green);
}

.sig-node.sig-invalid {
    border-left-color: var(--red);
}

.sig-node.sig-untrusted {
    border-left-color: var(--yellow);
}

.sig-node.sig-indeterminate {
    border-left-color: var(--text-muted);
}

/* Verification details section */
.verification-details {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px dashed var(--border);
}

/* Verification field rows */
.verify-field {
    display: flex;
    gap: 8px;
    padding: 1px 12px;
    font-size: 12px;
    line-height: 1.6;
}

.verify-field-key {
    color: var(--text-muted);
    min-width: 130px;
    flex-shrink: 0;
}

.verify-field-value {
    word-break: break-word;
}

.verify-pass {
    color: var(--green);
}

.verify-fail {
    color: var(--red);
}

.verify-warn {
    color: var(--yellow);
}

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

.verify-check-msg {
    color: var(--text-muted);
    font-size: 11px;
}

/* ═══════════════════════════════════════════════════════════════════════
   Revision Highlighting (Source View)
   ═══════════════════════════════════════════════════════════════════════ */

/* Subtle warm tint for lines within the selected revision */
.source-line.revision-highlight {
    background: rgba(234, 88, 12, 0.07);
    border-left: 3px solid var(--orange);
}

.source-line.revision-highlight:hover {
    background: rgba(234, 88, 12, 0.12);
}

/* Top boundary of revision range */
.source-line.revision-boundary-top {
    border-top: 1px solid rgba(234, 88, 12, 0.45);
}

/* Bottom boundary of revision range */
.source-line.revision-boundary-bottom {
    border-bottom: 1px solid rgba(234, 88, 12, 0.45);
}

/* Hex view revision highlighting */
.hex-row.revision-highlight {
    background: rgba(234, 88, 12, 0.07);
    border-left: 3px solid var(--orange);
}

.hex-row.revision-highlight:hover {
    background: rgba(234, 88, 12, 0.12);
}

.hex-row.revision-boundary-top {
    border-top: 1px solid rgba(234, 88, 12, 0.45);
}

.hex-row.revision-boundary-bottom {
    border-bottom: 1px solid rgba(234, 88, 12, 0.45);
}
