/**
 * DeFi Lending Protocols Dashboard - Stylesheet
 *
 * Styles for the multi-protocol lending analysis web application.
 *
 * Design goals (short):
 * - Viewport safety: global border-box and overflow-x hidden avoid accidental horizontal scroll.
 * - Information density: center-aligned table with compact cells and clear groupings.
 * - Readability: sticky first two columns and sticky rightmost metric column.
 * - Visual cues: color-coded APYs, gray-out on cap reached, explicit USD sublines.
 */

/* ==================== General Styles ==================== */

html {
    box-sizing: border-box;
}

*, *:before, *:after {
    box-sizing: inherit;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    margin: 0;
    padding: 20px;
    background-color: #f5f5f5;
    overflow-x: hidden; /* Prevent horizontal scroll */
}

.container {
    width: 100%;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    padding: 30px;
}

h1 {
    text-align: center;
    color: #333;
    margin-bottom: 30px;
    font-size: 3em;
    font-weight: bold;
    font-family: 'Smokum', serif;
    letter-spacing: 0.1em;
}

/* ==================== Controls & Inputs ==================== */

.controls {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.hide-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
    user-select: none;
}

.chain-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

label {
    font-weight: 600;
    color: #555;
}

select {
    padding: 8px 12px;
    border: 2px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

select:focus {
    outline: none;
    border-color: #007bff;
}

button {
    padding: 10px 20px;
    background: #007bff;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s;
}

button:hover {
    background: #0056b3;
}

button:disabled {
    background: #6c757d;
    cursor: not-allowed;
}

/* ==================== Status Indicators ==================== */

.loading {
    text-align: center;
    padding: 40px;
    color: #666;
}

/* Skeleton loader covering ~2 folds */
.skeleton-container { padding: 12px; }
.skeleton-row { display: grid; grid-template-columns: 180px 180px repeat(14, 1fr); gap: 8px; margin-bottom: 12px; }
.skeleton-block { height: 49.5px; border-radius: 6px; background: linear-gradient(90deg, #eee 25%, #f5f5f5 37%, #eee 63%); background-size: 400% 100%; animation: shimmer 1.2s ease-in-out infinite; }

@keyframes shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.error {
    background: #f8d7da;
    color: #721c24;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 20px;
    border: 1px solid #f5c6cb;
}

.info-panel {
    display: none;
    margin-bottom: 20px;
    padding: 15px;
    background: #e7f3ff;
    border-radius: 8px;
    color: #0066cc;
}

.hidden {
    display: none;
}

/* ==================== Tag Styles ==================== */

.isolated-tag {
    background: #e3f2fd; /* Original light blue */
    color: #1976d2; /* Original dark blue */
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px; /* Original size */
    font-weight: 600; /* Original weight */
    text-transform: uppercase; /* Original style */
    letter-spacing: 0.5px; /* Original spacing */
    margin-top: 4px; /* Add some space above */
    display: block; /* Force to a new line */
    width: fit-content; /* Prevent it from taking full cell width */
    margin-left: auto; /* Center the block */
    margin-right: auto; /* Center the block */
}

.market-tag {
    background-color: #fd7e14; /* Orange */
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: bold;
    margin-top: 4px; /* Add some space above */
    display: block; /* Force to a new line */
    width: fit-content; /* Prevent it from taking full cell width */
    margin-left: auto; /* Center the block */
    margin-right: auto; /* Center the block */
}

.emode-tag {
    background: #e8f5e9; /* light green */
    color: #2e7d32; /* dark green */
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: none;
    letter-spacing: 0.25px;
    margin-top: 4px;
    display: block;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
}

.leverage-tag {
    color: #6c757d; /* Gray color for the tag */
    font-size: 12px;
    margin-left: 4px;
}

/* ==================== Table Styles ==================== */

.table-container {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #ddd;
}

/* Hide gray rows when toggle active */
.hide-gray-active tr.cap-reached-row,
.hide-gray-active tr.non-collateral-row.cap-reached-row {
    display: none;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    font-size: 14px;
}

th {
    background: #f8f9fa;
    padding: 15px 12px;
    text-align: center;
    font-weight: 600;
    color: #555;
    border-bottom: 2px solid #ddd;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Set consistent widths for sticky left columns to avoid gaps.
 * Inline JS computes max observed widths and sets these CSS variables.
 */
:root {
    --first-col-width: auto;
    --second-col-width: auto;
}

/* Sticky left columns */
th.sticky-left-1,
td.sticky-left-1 {
    position: sticky;
    left: 0;
    width: var(--first-col-width);
    min-width: var(--first-col-width);
    box-shadow: 2px 0 0 #ddd;
}

th.sticky-left-2,
td.sticky-left-2 {
    position: sticky;
    left: var(--first-col-width);
    width: var(--second-col-width);
    min-width: var(--second-col-width);
    box-shadow: 2px 0 0 #ddd;
}

/* Sticky right column */
th.sticky-right,
td.sticky-right {
    position: sticky;
    right: 0;
    box-shadow: -2px 0 0 #ddd;
}

/* Higher z-index for headers and ensure background for body cells */
th.sticky-left-1, th.sticky-left-2, th.sticky-right { z-index: 11; background: #f8f9fa; }
td.sticky-left-1, td.sticky-left-2, td.sticky-right { z-index: 6; background: #fff; }

/* Tighter padding for sticky data cells */
td.sticky-left-1, td.sticky-left-2 {
    padding-left: 4px;
    padding-right: 4px;
}

/* Ensure sticky columns have proper background on hover */
tr:hover td.sticky-left-1,
tr:hover td.sticky-left-2,
tr:hover td.sticky-right {
    background: #e9ecef;
}

td {
    padding: 12px;
    border-bottom: 1px solid #eee;
    text-align: center;
}

tr:hover {
    background: #f8f9fa;
}

.asset-symbol {
    font-weight: 600;
    color: #333;
}

.amount {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 13px;
}

/* ==================== APY Color Coding ==================== */

.apy-positive {
    color: #28a745;
    font-weight: 600;
}

.apy-zero {
    color: #6c757d;
}

.delta-apy-positive {
    color: #28a745;
    font-weight: 700;
}

.delta-apy-negative {
    color: #dc3545;
    font-weight: 700;
}

.delta-apy-zero {
    color: #6c757d;
    font-weight: 600;
}

.combination-row {
    transition: background-color 0.2s;
}

.combination-row:hover {
    background: #f8f9fa;
}

.asset-pair {
    font-weight: 500;
}

/* ==================== Non-Collateral Asset Styles ==================== */

.non-collateral-row {
    /* background-color: #f8f9fa; */
}

.non-collateral-text {
    color: #6c757d;
    font-style: italic;
    font-size: 13px;
    font-weight: 400;
}

/* ==================== Cap Utilization Styles ==================== */

.utilization-pct {
    font-size: 13px;
    color: #6c757d;
    font-weight: 500;
}

.utilization-red {
    color: #dc3545 !important;
    font-weight: 700;
}

.cap-reached-row {
    color: #adb5bd !important;
}

.cap-reached-row * {
    color: #adb5bd !important;
}

.cap-reached-row .utilization-red {
    color: #dc3545 !important;
    font-weight: 700;
}

.cap-reached-row:hover {
    background: #e9ecef;
}

.cap-reached-row:hover * {
    color: #adb5bd !important;
}

/* ==================== Misc ==================== */

.na-text {
    color: #6c757d;
    font-style: italic;
    font-size: 13px;
}

.leverage-tag {
    color: #6c757d;
    font-size: 12px;
    margin-left: 4px;
}

/* ==================== USD Value Styles ==================== */

.usd-value {
    color: #6c757d;
    font-size: 12px;
    font-weight: 400;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    display: block;
    margin: 0;
}
