/* =========================================
   PAGES/DATABASE.CSS
   Database Registry Layout
   ========================================= */

/* Database Methodology Section */
.db-methodology-wrapper {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--color-border-light);
}

.db-methodology-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.db-methodology-grid h4 {
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.db-methodology-grid ul {
    margin-left: 1.2rem;
    margin-bottom: 0;
}

.db-methodology-note {
    margin-top: 1rem;
    color: var(--color-text-tertiary);
    display: flex;
    gap: 0.4rem;
}

.highlight {
    color: var(--color-success);
    font-weight: 600;
}



/* Sticky Controls & View Toggle */
.sticky-controls {
    position: sticky;
    top: 72px;
    /* Clear navbar */
    z-index: 950;
    background-color: var(--color-bg);
    /* Match page background */
    padding: 1.5rem 0 0.5rem;
    margin-bottom: 0.5rem;
    transition: all 0.3s ease;
}



body.navbar-hidden .sticky-controls {
    top: 0;
}

.view-toggle {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding: 0 1rem;
    /* Align with search input inside filter-bar */
}

.toggle-btn {
    font-family: var(--font-serif);
    padding: 0.8rem 1.5rem;
    /* Larger padding */
    border: 1px solid var(--color-border);
    background: white;
    cursor: pointer;
    border-radius: 6px;
    font-size: var(--fs-small);
    transition: all 0.2s;
    flex: 1;
    /* Make standard equal width */
    text-align: center;
    max-width: 200px;
    /* Optional cap */
}

.toggle-btn:hover {
    border-color: var(--color-text-tertiary);
}

.toggle-btn.active {
    background: var(--color-text);
    color: white;
    border-color: var(--color-text);
}

.toggle-btn span {
    color: inherit;
    /* Prevent browser overrides (blue text on mobile) */
}

/* Filter Bar */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--color-bg-surface);
    border-radius: 8px;
}

.filter-bar .search-bar {
    flex: 1;
    min-width: 200px;
    height: 42px;
    padding: 0 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-family: var(--font-serif);
    font-size: var(--fs-small);
    line-height: 42px;
    box-sizing: border-box;
    margin: 0;
}

.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.filter-select {
    height: 42px;
    padding: 0 2rem 0 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-family: var(--font-serif);
    font-size: var(--fs-small);
    background: white;
    cursor: pointer;
    line-height: 42px;
    box-sizing: border-box;
    margin: 0;
}

.filter-select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Results Summary */
.results-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    font-size: var(--fs-small);
    color: var(--color-text-secondary);
}

#resultsCount {
    font-weight: 500;
}

#resultsTotals {
    font-weight: 500;
}

.text-loss {
    color: var(--color-danger) !important;
}

.text-saved {
    color: var(--color-success) !important;
}

.clear-filters-btn {
    margin-top: 1rem;
    padding: 0.5rem 1rem;
    background: var(--color-text);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-family: var(--font-serif);
}

/* Case Table Wrapper */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 2rem;
    border: 1px solid var(--color-border-light);
    border-radius: 8px;
    background: white;
}

/* Case Table */
.case-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    min-width: 800px;
    /* Ensure content doesn't squash too much */
}

.case-table thead {
    background: var(--color-bg-surface);
}

.case-table th {
    font-weight: 500;
    text-align: left;
    padding: 1rem;
    font-size: var(--fs-tiny);
    color: var(--color-text-secondary);
    border-bottom: 1px solid var(--color-border-light);
}

.case-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.case-table th.sortable:hover {
    color: var(--color-text);
}

.case-table th svg {
    width: 14px;
    height: 14px;
    vertical-align: middle;
    margin-left: 4px;
    opacity: 0.5;
}

.case-row {
    cursor: pointer;
    border-bottom: 1px solid var(--color-bg-surface-hover);
    transition: background 0.15s;
}

.case-row:hover {
    background: var(--color-bg-surface);
}

.case-row td {
    padding: 1.2rem 1rem;
    font-size: var(--fs-small);
    vertical-align: top;
    line-height: 1.4;
}

/* Amounts & Success Bars */
.loss-amount {
    font-weight: 700;
    color: var(--color-text);
    font-size: 1rem;
}

.saved-amount {
    color: var(--color-success);
    font-size: var(--fs-tiny);
    font-weight: 600;
    margin-top: 2px;
}

.success-container {
    height: 4px;
    background: var(--color-border-light);
    margin-top: 8px;
    border-radius: 2px;
    width: 80px;
    overflow: hidden;
}

.success-bar {
    height: 100%;
    background: currentColor;
    border-radius: 2px;
    transition: width 0.6s ease-out;
}

.success-high {
    color: var(--color-success);
}

.success-medium {
    color: var(--color-warning);
}

.success-low {
    color: var(--color-danger);
}

/* Tags & Labels */
.chain-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text-secondary);
}

.chain-icon {
    width: 16px;
    height: 16px;
    border-radius: 50%;
}

.tag {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: var(--fs-tiny);
    font-weight: 500;
    margin-right: 4px;
}

.tag.multisig {
    background: #fee2e2;
    color: #991b1b;
}

.tag.council {
    background: #fef3c7;
    color: #92400e;
}

.tag.gov {
    background: #d1fae5;
    color: #065f46;
}

.tag.proactive {
    background: #e0f2fe;
    color: #075985;
}

.rationale-badge {
    margin-left: 6px;
    display: inline-flex;
    align-items: center;
    color: var(--color-text-tertiary);
    /* Standardized grey */
    cursor: help;
    vertical-align: middle;
    transition: color 0.2s;
}

.rationale-badge:hover {
    color: var(--color-text-secondary);
}

.rationale-badge svg {
    width: 14px;
    height: 14px;
}

.source-link {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    color: var(--color-text-secondary);
    margin-left: 4px;
    transition: color 0.2s;
}

.source-link:hover {
    color: var(--color-text);
}

.source-link svg {
    width: 14px;
    /* Standardized size */
    height: 14px;
}

/* Stable Column Widths */
.case-table th:nth-child(1),
.case-table td:nth-child(1) {
    width: 120px;
}

.case-table th:nth-child(2),
.case-table td:nth-child(2) {
    width: 25%;
}

.case-table th:nth-child(3),
.case-table td:nth-child(3) {
    width: 180px;
}

.case-table th:nth-child(4),
.case-table td:nth-child(4) {
    width: 20%;
}

/* Modal Styles (Database Case Details) */
/* Modal Styles (Database Case Details) */
.case-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    visibility: hidden;
    /* Ensure it's hidden */
}

.case-modal.active {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
}

.modal-content {
    background: white;
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: translateY(20px);
    transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1);
}

.case-modal.active .modal-content {
    transform: translateY(0);
}

.modal-content-inner {
    display: flex;
    flex-direction: column;
    max-height: 100%;
    width: 100%;
}

.modal-header {
    padding: 2rem;
    border-bottom: 1px solid var(--color-border-light);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
}

.modal-meta {
    margin-top: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
    color: var(--color-text-secondary);
    font-size: var(--fs-small);
}

.modal-close {
    position: absolute;
    top: 1.5rem;
    right: 1.5rem;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-text-tertiary);
    cursor: pointer;
    line-height: 1;
    z-index: 10;
}

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

.modal-body {
    padding: 1.5rem 2rem 2.5rem;
    overflow-y: auto;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    padding: 1.25rem;
    background: var(--color-bg-surface);
    border-radius: 8px;
    border: 1px solid var(--color-border-light);
}

.stat-label {
    display: block;
    font-size: var(--fs-tiny);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-tertiary);
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.stat-value {
    display: block;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
}

.stat-card.loss .stat-value {
    color: var(--color-danger);
}

.stat-card.saved .stat-value {
    color: var(--color-success);
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2.5rem;
}

.modal-section h3 {
    font-size: var(--fs-tiny);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-tertiary);
    margin-bottom: 1rem;
    font-weight: 600;
    border-bottom: 1px solid var(--color-border-light);
    padding-bottom: 0.5rem;
}

.info-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.info-item {
    display: flex;
    justify-content: space-between;
}

.info-label {
    color: var(--color-text-secondary);
    font-size: var(--fs-small);
}

.info-value {
    font-weight: 500;
    color: var(--color-text);
    font-size: var(--fs-small);
}

.modal-narrative {
    font-family: var(--font-serif);
    font-size: 1.1rem;
    line-height: 1.6;
    color: var(--color-text);
    margin-bottom: 2.5rem;
}

.rationale-section {
    background: var(--color-bg-surface);
    padding: 1.5rem;
    border-radius: 8px;
    border: 1px solid var(--color-border-light);
    font-size: var(--fs-small);
}

.rationale-section h3 {
    margin-top: 0;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--color-text);
    border: none;
    padding: 0;
}

.rationale-content {
    line-height: 1.5;
    color: var(--color-text-secondary);
    font-size: var(--fs-small);
}

.modal-footer {
    padding: 1.5rem 2rem;
    background: var(--color-bg-surface);
    border-top: 1px solid var(--color-border-light);
    display: flex;
    justify-content: flex-end;
}


/* Methodology Expandable Section */
.expandable-header {
    /* Inherits shared styles */
    font-family: var(--font-sans);
    font-size: var(--fs-small);
    color: var(--color-text-secondary);
    padding: 0.5rem 0;
    font-weight: 500;
}

.expandable-header:hover {
    background: var(--color-bg-surface);
}

/* Redundant styles removed (overflow, transition, max-height handled in layout.css) */

/* Mobile Responsive Overrides for Database */
@media (max-width: 768px) {
    .registry-container {
        padding-left: 2rem;
        padding-right: 2rem;
    }

    .case-table {
        min-width: 720px;
    }

    .case-row td {
        padding: 0.95rem 0.75rem;
    }

    .view-toggle {
        padding: 0 0.5rem;
    }

    .toggle-btn {
        max-width: none;
    }

    .sticky-controls {
        opacity: 1;
        pointer-events: auto;
    }

    .filter-bar {
        flex-direction: column;
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .filter-bar .search-bar {
        width: 100%;
        height: 42px;
        min-height: 42px;
        line-height: normal;
        padding: 0 0.75rem;
        border-radius: 6px;
        font-size: var(--fs-small);
        border: 1px solid var(--color-border);
        box-sizing: border-box;
        -webkit-appearance: none;
        appearance: none;
        margin: 0;
    }

    .filter-group {
        width: 100%;
        gap: 0.5rem;
    }

    .filter-select {
        flex: 1;
        width: 100%;
    }

    /* Restore visibility of all columns on mobile */
    .case-table th:nth-child(4),
    .case-table td:nth-child(4),
    .case-table th:nth-child(5),
    .case-table td:nth-child(5) {
        display: table-cell;
    }

    .modal-stats {
        flex-direction: column;
    }

    /* Modal Mobile Fixes */
    .modal-content {
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .modal-body {
        padding: 1.5rem;
        -webkit-overflow-scrolling: touch;
    }

    .stat-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .detail-grid {
        grid-template-columns: 1fr;
        gap: 1.5rem;
    }

    .modal-header h2 {
        font-size: 1.5rem;
    }
}