/* ---------- Envoltorio, tamaño y tema ---------- */
.tgh-wrap {
    --tgh-bg: transparent;
    --tgh-surface: rgba(128, 128, 128, .12);
    --tgh-line: rgba(128, 128, 128, .28);
    --tgh-text: inherit;
    --tgh-title: inherit;
    --tgh-muted: inherit;
    --tgh-accent: #3ea6ff;
    --tgh-track: rgba(128, 128, 128, .18);
    --tgh-up: #3ecf8e;
    --tgh-down: #ff6b6b;

    container-type: inline-size;
    box-sizing: border-box;
    max-width: 100%;
    margin: 1em 0;
    color: var(--tgh-text);
}
.tgh-wrap * { box-sizing: border-box; }

/* Oscuro sobrio */
.tgh-theme-oscuro {
    --tgh-bg: #14171c;
    --tgh-surface: #1a1e25;
    --tgh-line: #272c35;
    --tgh-text: #cfd5de;
    --tgh-title: #e6e9ee;
    --tgh-muted: #8a93a2;
    --tgh-accent: #6b8cae;
    --tgh-track: #222730;
    --tgh-up: #6fae8a;
    --tgh-down: #c47474;
    background: var(--tgh-bg);
    border: 1px solid var(--tgh-line);
    border-radius: 10px;
    padding: 16px 18px;
}
.tgh-theme-claro {
    --tgh-bg: #ffffff;
    --tgh-surface: #f4f6f8;
    --tgh-line: #dde2e8;
    --tgh-text: #2b3440;
    --tgh-title: #151b23;
    --tgh-muted: #6b7686;
    --tgh-accent: #4f7aa6;
    --tgh-track: #e8ecf0;
    --tgh-up: #2f8f5b;
    --tgh-down: #b94a4a;
    background: var(--tgh-bg);
    border: 1px solid var(--tgh-line);
    border-radius: 10px;
    padding: 16px 18px;
}

/* Ubicación en un lateral */
.tgh-left   { float: left;  margin: .25em 1.25em 1em 0; }
.tgh-right  { float: right; margin: .25em 0 1em 1.25em; }
.tgh-center { margin-left: auto; margin-right: auto; }

/* Se puede arrastrar la esquina inferior derecha para cambiar el tamaño */
.tgh-resizable { resize: both; overflow: auto; min-width: 200px; min-height: 140px; }
.tgh-fixed-h   { overflow: auto; }

/* En pantallas angostas los laterales pasan a ocupar todo el ancho */
@media (max-width: 600px) {
    .tgh-left, .tgh-right { float: none; width: 100% !important; margin: 1em 0; }
}

/* ---------- Contenido ---------- */
.tgh { color: inherit; }
.tgh-title { margin: 0 0 .2em; font-size: 1.1em; font-weight: 600; color: var(--tgh-title); letter-spacing: .01em; }
.tgh-sub   { margin: 0 0 .9em; font-size: .82em; color: var(--tgh-muted); opacity: .9; }
.tgh-note  { margin: .9em 0 0; font-size: .72em; color: var(--tgh-muted); opacity: .75; }
.tgh-empty { color: var(--tgh-muted); font-style: italic; }

.tgh-list { list-style: none; margin: 0; padding: 0; }
.tgh-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 3px 12px;
    padding: 7px 0;
    border-bottom: 1px solid var(--tgh-line);
}
.tgh-row:last-child { border-bottom: 0; }
.tgh-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--tgh-title); }
.tgh-val  { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tgh-val small { color: var(--tgh-muted); }
.tgh-bar  { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--tgh-track); overflow: hidden; }
.tgh-bar i { display: block; height: 100%; background: var(--tgh-accent); }

.tgh-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.tgh-card { border: 1px solid var(--tgh-line); border-radius: 8px; padding: 12px 14px; background: var(--tgh-surface); }
.tgh-theme-heredar .tgh-card { background: transparent; }
.tgh-card header { margin-bottom: 6px; }
.tgh-card h4 { margin: 0; font-size: .9em; font-weight: 600; color: var(--tgh-muted); text-transform: none; }
.tgh-total { font-size: 1.55em; font-weight: 700; line-height: 1.2; color: var(--tgh-title); font-variant-numeric: tabular-nums; }
.tgh-delta { font-size: .78em; font-weight: 600; }
.tgh-up    { color: var(--tgh-up); }
.tgh-down  { color: var(--tgh-down); }
.tgh-card footer { margin-top: 6px; font-size: .75em; color: var(--tgh-muted); }

.tgh-scroll { overflow-x: auto; max-width: 100%; }
.tgh-table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.tgh-table th, .tgh-table td { padding: 7px 10px; border-bottom: 1px solid var(--tgh-line); text-align: right; white-space: nowrap; }
.tgh-table th { color: var(--tgh-muted); font-weight: 600; font-size: .85em; }
.tgh-table th:first-child, .tgh-table td:first-child { text-align: left; }

/* ---------- Se adapta al ancho del propio cuadro (no de la pantalla) ---------- */
@container (max-width: 300px) {
    .tgh-val small { display: none; }
    .tgh-sub { display: none; }
    .tgh-title { font-size: 1em; }
    .tgh-row { padding: 5px 0; }
    .tgh-grid { grid-template-columns: 1fr; }
}
@container (max-width: 220px) {
    .tgh-row { grid-template-columns: 1fr; }
    .tgh-val { text-align: left; font-size: .85em; }
}
