:root {
    /* Pelaikan Design System */
    --bg: #ffffff;
    --muted: #6b7280;
    --border: #e5e7eb;
    --card-bg: #f9fafb;
    --card-hover: #f3f4f6;
    --rubric-primary: #b91c1c;      /* Main burgundy */
    --rubric-secondary: #991b1b;
    --rubric-light: #fecaca;
    --earth-primary: #92400e;        /* Brown */
    --earth-secondary: #78350f;
    --positive: #16a34a;
    --negative: #dc2626;
    --warn: #d97706;
    --radius: 8px;
    --font-main: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
    font-family: var(--font-main);
    color: #111827;
    background: #f3f4f6;
    margin: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header / Dashboard */
.header {
    background: white;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    flex-shrink: 0;
    z-index: 20;
}

.header-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-logo {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
}

.header-title h1 {
    font-size: 16px;
    margin: 0;
    color: var(--rubric-primary);
    font-weight: 700;
}

.header-meta {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
}

/* Beta Disclaimer Banner */
.beta-disclaimer {
    background: #fff3cd;
    border-bottom: 1px solid #ffc107;
    padding: 8px 24px;
    font-size: 12px;
    color: #856404;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.beta-disclaimer strong {
    color: #856404;
}

.beta-disclaimer a {
    color: var(--rubric-primary);
    text-decoration: none;
    font-weight: 500;
}

.beta-disclaimer a:hover {
    text-decoration: underline;
}

.dashboard-stats {
    display: flex;
    gap: 16px;
    align-items: center;
}

.stat-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    padding: 4px 8px;
    background: var(--card-bg);
    border-radius: 4px;
    border: 1px solid var(--border);
}

.btn {
    background: var(--rubric-primary);
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    font-weight: 500;
}

.btn:hover {
    background: var(--rubric-secondary);
}

/* Layout */
.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Document Pane (Left) */
.doc-pane {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #e5e5e5;
}

.page-container {
    background: white;
    width: 100%;
    max-width: 800px;
    min-height: 1000px; /* Reduced minimum height */
    /* height: auto !important;  <-- Removing this force override to allow JS to handle it if needed, 
                                     but actually 'min-height' + content flow usually works best without explicit 'height'. 
                                     Let's try standard flow behavior. */
    margin-bottom: 24px;
    padding: 48px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    position: relative;
    overflow: visible; /* Allow content to be seen if it somehow overflows, but layout should expand */
    height: auto; /* Let it grow naturally */
}

/* Sigil watermark overlay */
.page-container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('https://pelaikan-app.web.app/assets/Sigil.png');
    background-repeat: no-repeat;
    background-position: center center;
    background-size: 800px auto; /* Fit to shape, maintaining aspect ratio */
    opacity: 0.25; /* Substantial transparency for watermark effect */
    pointer-events: none; /* Ensure text is selectable */
    z-index: 0;
}

.page-container > * {
    position: relative;
    z-index: 1;
}

.page-number {
    position: absolute;
    top: 16px;
    right: 24px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

.doc-content {
    font-size: 14px;
    line-height: 1.6;
}

/* Audit Pane (Right) */
.audit-pane {
    width: 420px;
    background: white;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.audit-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    background: var(--card-bg);
}

.audit-header h4 {
    margin: 0 0 8px 0;
    color: var(--rubric-primary);
    font-size: 14px;
}

.filter-bar {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.filter-btn {
    background: white;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
    color: var(--muted);
    font-weight: 500;
}

.filter-btn.active {
    border-color: var(--rubric-primary);
    color: var(--rubric-primary);
    background: #fff5f5;
    font-weight: 600;
}

.citation-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    scroll-behavior: smooth;
}

/* Audit Cards */
.audit-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    background: white;
    transition: all 0.2s ease;
    font-size: 13px;
    cursor: pointer;
}

.audit-card:hover {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

.audit-card.active {
    border-color: var(--rubric-primary);
    box-shadow: 0 0 0 1px var(--rubric-primary);
}

.card-header {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    border-radius: var(--radius) var(--radius) 0 0;
}

.card-cite-id {
    font-weight: 600;
    font-size: 12px;
    color: #374151;
}

.status-badge {
    font-size: 10px;
    text-transform: uppercase;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    letter-spacing: 0.02em;
}

/* Status badges - VERIFIED (green) */
.status-verified, .status-supports { 
    background: #dcfce7; 
    color: #166534; 
}
.status-partial {
    background: #f0fdf4;
    color: #15803d;
}

/* Status badges - ISSUES (red) */
.status-issues, .status-disputes { 
    background: #fee2e2; 
    color: #991b1b; 
}

/* Status badges - UNRESOLVED (yellow/orange) */
.status-unresolved, .status-warning { 
    background: #fef3c7; 
    color: #92400e; 
}
.status-blocked {
    background: #fff7ed;
    color: #c2410c;
}

/* Status badges - NEUTRAL (gray) */
.status-neutral, .status-wet {
    background: #f3f4f6;
    color: #6b7280;
}

.card-body {
    padding: 12px;
}

.meta-row {
    display: grid;
    grid-template-columns: 70px 1fr;
    margin-bottom: 8px;
    gap: 8px;
    font-size: 12px;
}

.meta-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-align: right;
}

.meta-value {
    color: #111827;
    word-break: break-word;
}

.meta-value.citation-text {
    font-family: var(--font-mono);
    font-size: 11px;
    font-style: italic;
    color: #374151;
}

.rationale-box {
    background: #f8fafc;
    border-left: 3px solid var(--rubric-secondary);
    padding: 8px 12px;
    margin-top: 8px;
    color: #334155;
    font-size: 12px;
    line-height: 1.5;
}

.source-link {
    display: inline-flex;
    align-items: center;
    color: var(--rubric-primary);
    text-decoration: none;
    font-weight: 500;
    font-size: 11px;
    margin-top: 4px;
}

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

/* Main 3-column layout */
.report-container {
    display: flex;
    min-height: calc(100vh - 120px);
}

/* Side panels for citation cards */
.citation-panel {
    width: 320px;
    background: white;
    border-right: 1px solid #ddd;
    overflow-y: auto;
    padding: 20px;
    transition: transform 0.3s ease;
    position: sticky;
    top: 120px;
    height: calc(100vh - 120px);
}

.citation-panel.left-panel {
    border-right: 1px solid #ddd;
}

.citation-panel.right-panel {
    border-left: 1px solid #ddd;
    border-right: none;
}

.citation-panel.hidden {
    transform: translateX(-100%);
}

.citation-panel.right-panel.hidden {
    transform: translateX(100%);
}

.panel-header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #eee;
}

.panel-header h3 {
    color: #c41e3a;
    font-size: 18px;
}

/* Citation Elements in Text */
.citation-element {
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    padding: 0 2px;
    border-radius: 2px;
}

/* VERIFIED: Successful verification (green) - supports, partial, quote-exact, quote-close */
.citation-element.citation-verified { 
    border-color: var(--positive); 
    background: #f0fdf4; 
}

/* ISSUES: Verification found problems (red) - contradicts, wrong_document, hallucination, quote-mismatch, unrelated */
.citation-element.citation-issues { 
    border-color: var(--negative); 
    background: #fef2f2; 
}

/* UNRESOLVED: Resolution failed or incomplete (yellow/orange) - blocked, insufficient, error */
.citation-element.citation-unresolved { 
    border-color: var(--warn); 
    background: #fffbeb; 
}

/* NEUTRAL: Not actual citations (gray) - wet, comment */
.citation-element.citation-neutral {
    border-color: var(--muted);
    background: #f8f9fa;
}

/* Legacy class aliases for backward compatibility */
.citation-element.citation-supports { 
    border-color: var(--positive); 
    background: #f0fdf4; 
}
.citation-element.citation-disputes { 
    border-color: var(--negative); 
    background: #fef2f2; 
}
.citation-element.citation-warning { 
    border-color: var(--warn); 
    background: #fffbeb; 
}
.citation-element.citation-wet {
    border-color: var(--muted);
    background: #f8f9fa;
}

.citation-element.active {
    background: #2563eb;
    color: white;
    border-color: #2563eb;
}

.citation-element sup { 
    color: inherit; 
    font-weight: 600; 
}

/* Footnotes */
.footnotes-area {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 2px solid #eee;
    font-size: 0.85em;
}

.footnote-item {
    margin-bottom: 4px;
    padding: 2px 0;
    line-height: 1.4;
    border-radius: 4px;
    font-size: 0.85em;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.badge-footnote, .badge-inline-citation {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 999px;
    font-size: 11px;
    border: 1px solid #d1d5db;
    font-weight: 500;
    margin-right: 4px;
    vertical-align: baseline;
}
.badge-footnote {
    background: #eff6ff;
    border-color: #bfdbfe;
    color: #1e40af;
}
.badge-inline-citation {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}

/* Legacy support for old classes */
.footnote-ref, .footnote-reference {
    font-weight: bold;
    color: var(--rubric-primary);
    margin-right: 5px;
}

.footnote-content {
    display: inline;
    font-size: 0.85em;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Print Override */
@media print {
    .audit-pane, .header { display: none; }
    .workspace { display: block; }
    .doc-pane { padding: 0; background: white; }
    .page-container { 
        box-shadow: none; 
        padding: 0; 
        margin: 0; 
        page-break-after: always; 
    }
    body { 
        height: auto; 
        overflow: visible; 
        background: white; 
    }
}

