/* ═══════════════════════════════════════════════════════
   GRID DOCUMENT LIBRARY + OFFICIAL FORMAT STYLES
   ═══════════════════════════════════════════════════════ */

/* ── Document library status widget ── */
.doc-lib-empty {
  font-size: 11px;
  color: var(--muted);
  padding: 8px 0;
}

.doc-lib-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 0;
}

.doc-lib-item {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 14px;
  padding: 4px 10px 4px 8px;
  font-size: 10.5px;
  color: var(--text2);
}

.doc-lib-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
}

.doc-lib-label {
  white-space: nowrap;
}

/* ── Missing document inline prompt ── */
.missing-doc-prompt {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(245, 158, 11, 0.08);
  border: 1px solid rgba(245, 158, 11, 0.25);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 8px 0;
}

.missing-doc-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.missing-doc-text {
  flex: 1;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
}

.missing-doc-text strong {
  color: var(--amber);
}

.missing-doc-upload-btn {
  background: var(--amber);
  color: #1a1308;
  font-size: 11px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.missing-doc-upload-btn:hover {
  opacity: 0.85;
}

/* ── Official BIR section headers ── */
.bir-section-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border2);
}

.bir-section-id {
  font-size: 11px;
  font-weight: 700;
  color: var(--ondo-light);
  font-family: monospace;
}

.bir-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

/* ── Official BIR table — matches real document exactly ── */
.bir-table-wrap {
  margin: 12px 0 20px;
  overflow-x: auto;
}

.bir-table-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 8px;
}

.bir-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.bir-table thead th {
  background: var(--surface2);
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--border2);
  white-space: nowrap;
  font-size: 10px;
  text-transform: none;
}

.bir-table tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.bir-table .bir-code {
  font-family: monospace;
  font-size: 10px;
  color: var(--muted);
}

.bir-table .bir-name {
  color: var(--text);
  font-weight: 500;
}

.bir-table .bir-num {
  text-align: right;
  font-family: monospace;
  color: var(--text2);
}

.bir-table .bir-pct {
  text-align: right;
  font-family: monospace;
  font-weight: 600;
  color: var(--text);
}

/* ── GRID Trace — audit log viewer ── */
.trace-list{display:flex;flex-direction:column;gap:10px}
.trace-item{
  background:var(--surface);border:1px solid var(--border2);
  border-radius:8px;padding:12px 14px;
}
.trace-row1{display:flex;align-items:center;justify-content:space-between;margin-bottom:6px}
.trace-type{
  font-size:10px;font-weight:600;letter-spacing:0.04em;text-transform:uppercase;
  color:var(--ondo-light);background:var(--ondo-pale);
  padding:2px 8px;border-radius:10px;
}
.trace-type[data-type="data_correction"]{
  color:#fff;background:var(--amber);
}
.trace-item:has([data-type="data_correction"]){
  border-left:3px solid var(--amber);
}
.trace-date{font-size:11px;color:var(--muted)}
.trace-label{font-size:13px;color:var(--text);font-weight:500;margin-bottom:6px}
.trace-sources{display:flex;flex-wrap:wrap;gap:5px;margin-bottom:6px}
.trace-source-tag{
  font-size:10px;color:var(--text2);background:var(--surface2);
  border:1px solid var(--border);padding:2px 7px;border-radius:5px;
}
.trace-flagged{font-size:11.5px;color:var(--amber);margin-bottom:6px}
.trace-meta{font-size:10.5px;color:var(--dim)}

/* ── Source citation chip — Google AI Overview style ── */
.source-citation{
  display:inline-flex;align-items:center;gap:5px;
  margin-bottom:6px;padding:3px 9px;
  background:var(--surface2);border:1px solid var(--border2);
  border-radius:12px;font-size:10.5px;color:var(--text2);
  cursor:pointer;user-select:none;width:fit-content;
}
.source-citation:hover{background:var(--surface3);color:var(--text)}
.source-citation-icon{font-size:10px}
.source-citation-label{font-weight:600}
.source-citation-caret{font-size:8px;color:var(--muted)}

.trace-inline-card{
  margin:6px 0 8px;background:var(--surface2);
  border:1px solid var(--border2);border-radius:8px;
  padding:10px 12px;font-size:11.5px;
}
.source-list{display:flex;flex-direction:column;gap:6px;margin-bottom:6px}
.source-item{
  display:flex;align-items:center;gap:8px;
  padding:6px 8px;background:var(--surface);
  border:1px solid var(--border);border-radius:6px;
  font-size:11px;color:var(--text2);text-decoration:none;
}
.source-item-link{cursor:pointer}
.source-item-link:hover{border-color:var(--ondo-light);background:var(--ondo-pale)}
.source-item-icon{font-size:12px;flex-shrink:0}
.source-item-name{flex:1;color:var(--text)}
.source-item-open{
  font-size:10px;font-weight:600;color:var(--ondo-light);
  flex-shrink:0;white-space:nowrap;
}
.source-item-nolink{
  font-size:9.5px;color:var(--dim);flex-shrink:0;
  font-style:italic;white-space:nowrap;
}

.trace-card-row{
  display:flex;align-items:flex-start;gap:8px;
  padding:4px 0;border-bottom:1px solid var(--border);
}
.trace-card-row:last-child{border-bottom:none}
.trace-card-label{
  flex-shrink:0;width:80px;color:var(--muted);
  font-weight:600;text-transform:uppercase;font-size:9.5px;
  letter-spacing:0.04em;padding-top:1px;
}
.trace-card-value{color:var(--text2);flex:1}
.trace-card-mono{font-family:monospace;font-size:11px}
.trace-card-empty{color:var(--dim);font-style:italic}
.trace-card-warning{color:var(--amber);font-size:11px}
.trace-card-meta{color:var(--dim);font-size:10px}

/* ── Report markdown rendering — replaces literal asterisks/hashes ── */
.report-heading{
  color:var(--text);font-weight:700;margin:18px 0 8px;line-height:1.3;
}
h2.report-heading{font-size:17px;border-bottom:1px solid var(--border2);padding-bottom:6px}
h3.report-heading{font-size:15px}
h4.report-heading{font-size:13.5px;color:var(--text2)}
.report-para{color:var(--text);font-size:13.5px;line-height:1.6;margin-bottom:10px}
.report-list{margin:8px 0 14px 4px;padding-left:18px}
.report-list li{color:var(--text);font-size:13.5px;line-height:1.6;margin-bottom:5px}
.report-para strong, .report-list strong{color:var(--ondo);font-weight:700}
.report-divider{border:none;border-top:1px solid var(--border2);margin:18px 0}

/* ── Quarterly comparison table ── */
.report-table-wrap{margin:16px 0;overflow-x:auto;border:1px solid var(--border2);border-radius:8px}
.report-table{width:100%;border-collapse:collapse;font-size:12.5px}
.report-table thead th{
  background:var(--surface2);color:var(--text2);font-weight:600;text-align:left;
  padding:9px 12px;border-bottom:1px solid var(--border2);white-space:nowrap;
}
.report-table tbody td{padding:8px 12px;border-bottom:1px solid var(--border);color:var(--text)}
.report-table tbody tr:last-child td{border-bottom:none}
.report-table-num{text-align:right;font-family:var(--mono);white-space:nowrap}
.report-table-total{font-weight:700;color:var(--ondo);background:var(--ondo-pale)}

/* ── Institution detail modal — clickable ontology connections ── */
.detail-modal-overlay{
  position:fixed;inset:0;background:rgba(15,15,20,0.55);z-index:9000;
  display:flex;align-items:center;justify-content:center;padding:20px;
}
.detail-modal{
  background:var(--bg);border-radius:14px;max-width:640px;width:100%;
  max-height:85vh;overflow-y:auto;position:relative;padding:24px;
  box-shadow:0 12px 40px rgba(0,0,0,0.25);
}
.detail-modal-close{
  position:absolute;top:14px;right:16px;background:none;border:none;
  font-size:22px;color:var(--muted);cursor:pointer;line-height:1;
}
.detail-modal-close:hover{color:var(--text)}
.detail-header{margin-bottom:18px;padding-bottom:14px;border-bottom:1px solid var(--border2)}
.detail-code{font-family:var(--mono);font-size:11px;color:var(--muted);margin-bottom:4px}
.detail-title{font-size:18px;font-weight:700;color:var(--text);margin:0 0 6px}
.detail-meta{font-size:12px;color:var(--text2)}
.detail-section{margin-bottom:18px}
.detail-section-title{
  font-size:11px;font-weight:600;letter-spacing:.06em;text-transform:uppercase;
  color:var(--muted);margin-bottom:10px;
}
.detail-stat-row{display:flex;gap:18px;flex-wrap:wrap;font-size:12.5px;color:var(--text2)}
.detail-stat-row strong{color:var(--text)}
.detail-project-list{display:flex;flex-direction:column;gap:6px;max-height:320px;overflow-y:auto}
.detail-project-row{
  display:flex;align-items:center;gap:10px;padding:8px 10px;
  background:var(--surface2);border:1px solid var(--border);border-radius:7px;font-size:12px;
}
.detail-project-name{flex:1;color:var(--text)}
.detail-project-amount{font-family:var(--mono);color:var(--text2);white-space:nowrap}
.detail-project-pct{font-weight:700;white-space:nowrap;min-width:48px;text-align:right}
.pct-good{color:var(--green)}
.pct-watch{color:var(--amber)}
.pct-none{color:var(--dim)}
.detail-empty{color:var(--dim);font-style:italic;font-size:12.5px}

/* ── Institution row — clear, visible clickable affordance ── */
.institution-row{transition:background .12s}
.institution-row:hover{background:var(--ondo-pale) !important}
.institution-row:active{background:var(--ondo-pale) !important;opacity:0.85}
