/**
 * Company Mortgages Demo Styles
 * Sortable HTML table with summary bar and source attribution
 */

/* ========================================
   Layout
   ======================================== */
.mg-demo {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary, #fafafa);
    font-family: var(--font-sans, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif);
}

/* ========================================
   Toolbar
   ======================================== */
.mg-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-primary, #e0e0e0);
    background: var(--bg-secondary, #f5f5f5);
    flex-shrink: 0;
}

.mg-toolbar__title {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-tertiary, #888);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ========================================
   Summary Bar
   ======================================== */
.mg-summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: color-mix(in srgb, var(--accent-primary, #2563eb) 5%, var(--bg-primary, #fafafa));
    border-bottom: 1px solid var(--border-primary, #e0e0e0);
    flex-shrink: 0;
    font-size: 0.6875rem;
}

.mg-summary__count {
    font-weight: 700;
    color: var(--text-primary, #1a1a1a);
}

.mg-summary__separator {
    color: var(--text-tertiary, #aaa);
}

.mg-summary__total {
    color: var(--text-secondary, #666);
    font-variant-numeric: tabular-nums;
}

/* ========================================
   Table Wrapper
   ======================================== */
.mg-table-wrap {
    flex: 1;
    overflow-y: auto;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-secondary, #c4c4c4) transparent;
}

.mg-table-wrap::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.mg-table-wrap::-webkit-scrollbar-thumb {
    background: var(--border-secondary, #c4c4c4);
    border-radius: 3px;
}

.mg-table-wrap::-webkit-scrollbar-track {
    background: transparent;
}

/* ========================================
   Table
   ======================================== */
.mg-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.6875rem;
    line-height: 1.4;
}

/* Header */
.mg-table__th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 0.4rem 0.5rem;
    background: var(--bg-secondary, #f5f5f5);
    border-bottom: 2px solid var(--border-primary, #e0e0e0);
    color: var(--text-secondary, #666);
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s, color 0.15s;
}

.mg-table__th:hover {
    background: var(--bg-hover, rgba(0, 0, 0, 0.06));
    color: var(--text-primary, #1a1a1a);
}

.mg-table__th--sorted {
    color: var(--accent-primary, #2563eb);
    background: color-mix(in srgb, var(--accent-primary, #2563eb) 6%, var(--bg-secondary, #f5f5f5));
}

.mg-table__th--right {
    text-align: right;
}

.mg-table__th--center {
    text-align: center;
}

/* Sort indicator */
.mg-sort-icon {
    font-size: 0.5625rem;
    opacity: 0.4;
    margin-left: 0.2rem;
}

.mg-sort-icon--active {
    opacity: 1;
    color: var(--accent-primary, #2563eb);
}

/* Body cells */
.mg-table td {
    padding: 0.4rem 0.5rem;
    border-bottom: 1px solid var(--border-primary, #e0e0e0);
    color: var(--text-primary, #1a1a1a);
}

/* Alternating rows */
.mg-table tbody tr:nth-child(even) {
    background: color-mix(in srgb, var(--bg-secondary, #f5f5f5) 50%, transparent);
}

/* Hover */
.mg-table tbody tr:hover {
    background: color-mix(in srgb, var(--accent-primary, #2563eb) 4%, var(--bg-primary, #fafafa));
}

/* Amount cells */
.mg-table__amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Number cells */
.mg-table__num {
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* Date cells */
.mg-table__date {
    white-space: nowrap;
}

/* Boolean cells */
.mg-table__bool {
    text-align: center;
}

.mg-bool-badge {
    display: inline-block;
    padding: 0.1rem 0.4rem;
    border-radius: 0.625rem;
    font-size: 0.625rem;
    font-weight: 600;
    line-height: 1.4;
}

.mg-bool-badge--yes {
    background: color-mix(in srgb, var(--risk-level-1, #42B74A) 12%, transparent);
    color: var(--risk-level-1, #2d8c33);
}

.mg-bool-badge--no {
    background: color-mix(in srgb, var(--text-tertiary, #888) 10%, transparent);
    color: var(--text-tertiary, #888);
}

/* Empty state */
.mg-table__empty {
    text-align: center;
    padding: 2rem 1rem !important;
    color: var(--text-tertiary, #aaa);
    font-style: italic;
}

/* ========================================
   Source Attribution
   ======================================== */
.mg-source {
    padding: 0.25rem 0.75rem;
    text-align: right;
    flex-shrink: 0;
}

.mg-source span {
    font-size: 0.5625rem;
    color: var(--text-tertiary, #aaa);
}

/* ========================================
   Dark Theme Overrides
   ======================================== */
[data-theme="dark"] .mg-demo {
    background: var(--bg-primary, #1a1a1a);
}

[data-theme="dark"] .mg-toolbar {
    background: var(--bg-secondary, #2a2a2a);
    border-bottom-color: var(--border-primary, #444);
}

[data-theme="dark"] .mg-summary {
    background: color-mix(in srgb, var(--accent-primary, #3b82f6) 8%, var(--bg-primary, #1a1a1a));
    border-bottom-color: var(--border-primary, #444);
}

[data-theme="dark"] .mg-table__th {
    background: var(--bg-secondary, #2a2a2a);
    border-bottom-color: var(--border-primary, #444);
}

[data-theme="dark"] .mg-table__th:hover {
    background: var(--bg-hover, rgba(255, 255, 255, 0.06));
}

[data-theme="dark"] .mg-table__th--sorted {
    background: color-mix(in srgb, var(--accent-primary, #3b82f6) 10%, var(--bg-secondary, #2a2a2a));
}

[data-theme="dark"] .mg-table td {
    border-bottom-color: var(--border-primary, #444);
    color: var(--text-primary, #e0e0e0);
}

[data-theme="dark"] .mg-table tbody tr:nth-child(even) {
    background: color-mix(in srgb, var(--bg-secondary, #2a2a2a) 50%, transparent);
}

[data-theme="dark"] .mg-table tbody tr:hover {
    background: color-mix(in srgb, var(--accent-primary, #3b82f6) 6%, var(--bg-primary, #1a1a1a));
}

[data-theme="dark"] .mg-bool-badge--yes {
    background: color-mix(in srgb, var(--risk-level-1, #42B74A) 15%, transparent);
    color: var(--risk-level-1, #5cc964);
}

[data-theme="dark"] .mg-bool-badge--no {
    background: color-mix(in srgb, var(--text-tertiary, #888) 12%, transparent);
    color: var(--text-tertiary, #777);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 640px) {
    .mg-table {
        font-size: 0.625rem;
    }

    .mg-table__th,
    .mg-table td {
        padding: 0.3rem 0.35rem;
    }

    /* Hide cumulative column on small screens */
    .mg-table__th:nth-child(5),
    .mg-table td:nth-child(5) {
        display: none;
    }
}

@media (max-width: 480px) {
    /* Also hide mortgage number on very small screens */
    .mg-table__th:nth-child(4),
    .mg-table td:nth-child(4) {
        display: none;
    }
}
