/* ── Reset / Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 14px; color: #1f2937; background: #f0f4f8; }

/* ── App shell ───────────────────────────────────────────────────────────── */
.app-wrapper { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.app-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.25rem; height: 52px; min-height: 52px;
    background: #0f4c81; color: #fff; gap: 1rem; flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
.header-left { display: flex; align-items: center; gap: 1rem; min-width: 0; }
.app-title { font-weight: 700; font-size: 1rem; letter-spacing: .02em; white-space: nowrap; color: #fff; }
.db-name { font-size: .9rem; color: #93c5fd; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
.parse-date { font-size: .75rem; color: #64a4dd; white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: .5rem; flex-shrink: 0; }

.app-body { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
    width: 210px; min-width: 210px; background: #1e2d40; color: #cbd5e1;
    overflow-y: auto; padding: .5rem 0; flex-shrink: 0;
}
.nav-link {
    display: flex; align-items: center; gap: .55rem;
    padding: .55rem 1rem; text-decoration: none; color: #94a3b8;
    transition: background .12s, color .12s; border-left: 3px solid transparent;
}
.nav-link:hover { background: #263447; color: #e2e8f0; }
.nav-link.active { background: #0f3a61; color: #e0f0ff; border-left-color: #3b82f6; }
.nav-icon { font-size: 1rem; width: 1.1rem; text-align: center; flex-shrink: 0; }
.nav-label { flex: 1; font-size: .82rem; font-weight: 500; }
.nav-count { font-size: .72rem; background: rgba(255,255,255,.1); color: #94a3b8; padding: .1rem .45rem; border-radius: 10px; }
.nav-link.active .nav-count { background: rgba(59,130,246,.25); color: #93c5fd; }
.nav-section-sep { height: 1px; background: rgba(255,255,255,.07); margin: .4rem .75rem; }

/* ── Main content ────────────────────────────────────────────────────────── */
.main-content { flex: 1; overflow-y: auto; padding: 1.5rem; }

.section-header { margin-bottom: 1.25rem; }
.section-title { font-size: 1.15rem; font-weight: 700; color: #0f4c81; margin: 0 0 .2rem; }
.section-subtitle { font-size: .82rem; color: #6b7280; margin: 0; }

/* ── Overview cards ──────────────────────────────────────────────────────── */
.overview-meta { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.meta-card { background: #fff; border-radius: 8px; padding: .75rem 1rem; border: 1px solid #e5e7eb; flex: 1; min-width: 160px; }
.meta-card-label { font-size: .73rem; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: .05em; margin-bottom: .25rem; }
.meta-card-value { font-size: 1.05rem; font-weight: 700; color: #0f4c81; }

.overview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; }
.stat-card {
    background: #fff; border-radius: 8px; padding: 1rem; border: 1px solid #e5e7eb;
    text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s;
    display: block;
}
.stat-card:hover { border-color: #3b82f6; box-shadow: 0 2px 12px rgba(59,130,246,.15); }
.stat-card-count { font-size: 1.6rem; font-weight: 700; color: #0f4c81; line-height: 1; margin-bottom: .3rem; }
.stat-card-label { font-size: .8rem; color: #6b7280; font-weight: 500; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.dt-wrapper { background: #fff; border-radius: 8px; border: 1px solid #e5e7eb; overflow: hidden; }
table.dataTable { width: 100% !important; border-collapse: collapse; }
table.dataTable thead th {
    background: #f8fafc; color: #374151; font-size: .78rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .04em; padding: .7rem .9rem;
    border-bottom: 2px solid #e5e7eb; white-space: nowrap;
}
table.dataTable tbody td { padding: .6rem .9rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
table.dataTable tbody tr:last-child td { border-bottom: none; }
table.dataTable tbody tr:hover td { background: #f0f7ff; cursor: pointer; }
table.dataTable tbody tr.selected td { background: #dbeafe; }

/* DataTables controls */
div.dataTables_wrapper { padding: 1rem; }
div.dataTables_wrapper div.dataTables_filter input { border: 1px solid #d1d5db; border-radius: 6px; padding: .4rem .7rem; font-size: .85rem; }
div.dataTables_wrapper div.dataTables_filter input:focus { outline: none; border-color: #0f4c81; box-shadow: 0 0 0 3px rgba(15,76,129,.1); }
div.dataTables_wrapper div.dataTables_length select { border: 1px solid #d1d5db; border-radius: 6px; padding: .35rem .5rem; font-size: .85rem; }
div.dataTables_wrapper div.dataTables_info { font-size: .8rem; color: #6b7280; }
div.dataTables_paginate .paginate_button { border-radius: 5px !important; font-size: .82rem !important; }
div.dataTables_paginate .paginate_button.current { background: #0f4c81 !important; color: #fff !important; border-color: #0f4c81 !important; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge { display: inline-block; font-size: .7rem; font-weight: 700; padding: .15rem .5rem; border-radius: 10px; vertical-align: middle; }
.badge-text       { background: #dbeafe; color: #1e40af; }
.badge-number     { background: #d1fae5; color: #065f46; }
.badge-date       { background: #fef3c7; color: #92400e; }
.badge-time       { background: #fce7f3; color: #9d174d; }
.badge-timestamp  { background: #ede9fe; color: #5b21b6; }
.badge-container  { background: #f3f4f6; color: #374151; }
.badge-calc       { background: #fff7ed; color: #c2410c; }
.badge-summary    { background: #ecfdf5; color: #065f46; }
.badge-global     { background: #fef9c3; color: #713f12; font-size: .65rem; }
.badge-yes        { background: #dcfce7; color: #166534; }
.badge-no         { background: #f3f4f6; color: #9ca3af; }
.badge-fm         { background: #dbeafe; color: #1e40af; }
.badge-ext        { background: #f3e8ff; color: #7c3aed; }

/* ── No-data state ───────────────────────────────────────────────────────── */
.no-data-state { display: flex; align-items: center; justify-content: center; flex: 1; padding: 2rem; }
.no-data-card { background: #fff; border-radius: 12px; border: 2px dashed #d1d5db; padding: 3rem 2rem; text-align: center; max-width: 420px; }
.no-data-card h2 { color: #374151; margin: 0 0 .5rem; font-size: 1.15rem; }
.no-data-card p { color: #6b7280; margin: 0 0 1.5rem; line-height: 1.5; font-size: .9rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .45rem .9rem; border-radius: 6px; font-size: .85rem; font-weight: 600; cursor: pointer; border: 1px solid transparent; transition: background .12s, border-color .12s; text-decoration: none; }
.btn-primary { background: #0f4c81; color: #fff; border-color: #0f4c81; }
.btn-primary:hover { background: #1a5fa0; border-color: #1a5fa0; }
.btn-outline { background: transparent; color: #fff; border-color: rgba(255,255,255,.4); }
.btn-outline:hover { background: rgba(255,255,255,.1); border-color: rgba(255,255,255,.7); }
.btn-ghost { background: transparent; color: rgba(255,255,255,.75); border-color: transparent; }
.btn-ghost:hover { color: #fff; background: rgba(255,255,255,.1); }
.btn-sm { padding: .3rem .65rem; font-size: .78rem; }
.btn-danger { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; }

/* ── Dialogs ─────────────────────────────────────────────────────────────── */
dialog { border: none; border-radius: 10px; padding: 0; box-shadow: 0 8px 40px rgba(0,0,0,.25); max-height: 90vh; overflow: hidden; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); margin: 0; }
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid #e5e7eb; flex-shrink: 0; }
.dialog-header h2 { margin: 0; font-size: 1rem; color: #0f4c81; }
.close-btn { background: none; border: none; font-size: 1.4rem; color: #9ca3af; cursor: pointer; line-height: 1; padding: 0 .25rem; }
.close-btn:hover { color: #374151; }
.dialog-body { padding: 1.25rem; overflow-y: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.25rem; }

/* Upload dialog */
.upload-dialog { width: 480px; max-width: 95vw; }
.upload-field label { display: block; margin-bottom: .35rem; font-size: .85rem; font-weight: 600; color: #374151; }
.upload-field input[type=file] { display: block; width: 100%; border: 2px dashed #d1d5db; border-radius: 6px; padding: .75rem; font-size: .85rem; cursor: pointer; background: #f9fafb; }
.upload-field input[type=file]:focus { outline: none; border-color: #0f4c81; }
.upload-status { margin-top: .75rem; padding: .6rem .85rem; border-radius: 6px; font-size: .85rem; }
.upload-status.success { background: #dcfce7; border: 1px solid #86efac; color: #166534; }
.upload-status.error { background: #fef2f2; border: 1px solid #fca5a5; color: #991b1b; }
.upload-status.loading { background: #eff6ff; border: 1px solid #93c5fd; color: #1e40af; }

/* Detail dialog */
.detail-dialog { width: 1240px; max-width: 95vw; }
.detail-props { display: grid; grid-template-columns: 140px 1fr; gap: .4rem .75rem; align-items: start; }
.detail-prop-label { font-size: .78rem; font-weight: 700; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; padding-top: .1rem; }
.detail-prop-value { font-size: .875rem; color: #1f2937; word-break: break-word; }
.detail-divider { grid-column: 1 / -1; height: 1px; background: #f1f5f9; margin: .5rem 0; }
.detail-list { margin: .5rem 0 0; padding: 0; list-style: none; }
.detail-list li { padding: .3rem .6rem; font-size: .8rem; font-family: 'SFMono-Regular', Consolas, monospace; color: #374151; border-bottom: 1px solid #f1f5f9; }
.detail-list li:last-child { border-bottom: none; }
.detail-list li.disabled { color: #9ca3af; text-decoration: line-through; }
.detail-code { margin: .5rem 0 0; padding: .75rem 1rem; background: #1e293b; color: #e2e8f0; border-radius: 6px; font-family: 'SFMono-Regular', Consolas, monospace; font-size: .8rem; white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow-y: auto; }
.detail-section-title { font-size: .78rem; font-weight: 700; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; margin: 1rem 0 .35rem; }
.detail-section-count { font-weight: 400; font-size: .72rem; color: #9ca3af; text-transform: none; letter-spacing: 0; }
.detail-table { width: 100%; border-collapse: collapse; margin-top: .35rem; font-size: .8rem; }
.detail-table th { background: #f8fafc; padding: .4rem .6rem; text-align: left; font-weight: 700; color: #374151; border-bottom: 1px solid #e5e7eb; }
.detail-table td { padding: .4rem .6rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.detail-table tr:last-child td { border-bottom: none; }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.text-muted { color: #9ca3af; font-style: italic; font-size: .8rem; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid #93c5fd; border-top-color: #0f4c81; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: middle; margin-right: .35rem; }
@keyframes spin { to { transform: rotate(360deg); } }

a.table-link { color: #0f4c81; text-decoration: none; }
a.table-link:hover { text-decoration: underline; }

/* ── Relationship graph ──────────────────────────────────────────────────── */
#rel-graph { width: 100%; height: calc(100vh - 185px); border: 1px solid #e5e7eb; border-radius: 8px; background: #f8fafc; }

/* ── Header search ───────────────────────────────────────────────────────── */
.header-search { display: flex; align-items: center; flex: 1; max-width: 380px; margin: 0 1rem; }
.header-search-input {
    width: 100%; padding: .35rem .75rem; border-radius: 20px;
    border: 1.5px solid rgba(255,255,255,.3); background: rgba(255,255,255,.12);
    color: #fff; font-size: .82rem; outline: none;
    transition: background .15s, border-color .15s;
}
.header-search-input::placeholder { color: rgba(255,255,255,.55); }
.header-search-input:focus { background: rgba(255,255,255,.2); border-color: rgba(255,255,255,.6); }

/* ── Broken references ───────────────────────────────────────────────────── */
.broken-clean { display:flex; align-items:flex-start; gap:1rem; padding:1.25rem 1.5rem; background:#f0fdf4; border:1px solid #bbf7d0; border-radius:8px; color:#166534; }
.broken-clean-icon { font-size:1.5rem; color:#16a34a; flex-shrink:0; line-height:1; }
.broken-group { margin-bottom:1.75rem; }
.broken-group-header { display:flex; align-items:center; flex-wrap:wrap; gap:.5rem; padding:.4rem 0; border-bottom:2px solid #fecaca; margin-bottom:.25rem; }
.broken-group-label { font-size:.78rem; font-weight:700; text-transform:uppercase; letter-spacing:.05em; color:#dc2626; }
.broken-group-count { font-size:.72rem; background:#fee2e2; color:#dc2626; padding:.1rem .45rem; border-radius:10px; }
.broken-group-link { font-size:.75rem; color:#6b7280; text-decoration:none; }
.broken-group-link:hover { color:#0f4c81; text-decoration:underline; }
.broken-group-desc { font-size:.75rem; color:#9ca3af; margin-left:auto; }
.broken-table { width:100%; border-collapse:collapse; font-size:.83rem; }
.broken-table th { background:#fef2f2; padding:.4rem .75rem; text-align:left; font-weight:600; color:#6b7280; font-size:.73rem; text-transform:uppercase; letter-spacing:.04em; border-bottom:1px solid #fecaca; }
.broken-table td { padding:.4rem .75rem; border-bottom:1px solid #fef2f2; }
.broken-table tr:last-child td { border-bottom:none; }
.broken-source { color:#111827; font-weight:500; width:50%; }
.broken-ref { color:#dc2626; font-family:'SFMono-Regular',Consolas,monospace; font-size:.8rem; }

/* ── Search results ──────────────────────────────────────────────────────── */
.search-empty { color: #6b7280; font-size: .9rem; padding: 2rem 0; }
.search-group { margin-bottom: 1.5rem; }
.search-group-header {
    display: flex; align-items: center; gap: .6rem;
    padding: .4rem 0 .4rem; border-bottom: 2px solid #e5e7eb; margin-bottom: .25rem;
}
.search-group-label { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: #0f4c81; }
.search-group-count { font-size: .72rem; background: #dbeafe; color: #1d4ed8; padding: .1rem .45rem; border-radius: 10px; }
.search-group-link { margin-left: auto; font-size: .75rem; color: #6b7280; text-decoration: none; }
.search-group-link:hover { color: #0f4c81; text-decoration: underline; }
.search-table { width: 100%; border-collapse: collapse; }
.search-row { cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.search-row:hover { background: #f0f7ff; }
.search-primary { padding: .4rem .6rem; font-size: .85rem; color: #111827; font-weight: 500; width: 45%; }
.search-secondary { padding: .4rem .6rem; font-size: .78rem; color: #6b7280; }
