/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --clr-bg: #f4f6f8;
    --clr-surface: #ffffff;
    --clr-border: #e3e7eb;
    --clr-text: #111827;
    --clr-muted: #6b7280;
    --clr-accent: #2563eb;
    --clr-accent-d: #1e40af;
    --clr-link: #1d4ed8;

    --font-sans: system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: "SFMono-Regular", Consolas, monospace;

    --radius: 4px;
    --shadow: 0 1px 3px rgba(0, 0, 0, .08);
    --max-w: 1100px;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-sans);
    background: var(--clr-bg);
    color: var(--clr-text);
    line-height: 1.6;
}

a {
    color: var(--clr-link);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1,
h2,
h3,
h4,
h5,
h6 {
    line-height: 1.25;
    font-weight: 700;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.container {
    max-width: var(--max-w);
    margin: 0 auto;
    padding: 0 1.25rem;
}

.clear {
    clear: both;
}

/* ── Header ───────────────────────────────────────────────────────────────── */
#site-header {
    background: var(--clr-accent);
    color: #fff;
    padding: .75rem 0;
    box-shadow: 0 2px 4px rgba(0, 0, 0, .15);
}

#site-header .container {
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-wrap: wrap;
}

#site-header h1 {
    font-size: 1.35rem;
    letter-spacing: -.3px;
}

#site-header h1 a {
    color: #fff;
}

#site-header h1 a:hover {
    text-decoration: none;
    opacity: .85;
}

#site-header nav {
    display: flex;
    gap: 1.5rem;
    font-size: .9rem;
}

#site-header nav a {
    color: rgba(255, 255, 255, .88);
    transition: color .15s;
}

#site-header nav a:hover {
    color: #fff;
    text-decoration: none;
}

/* ── Main ─────────────────────────────────────────────────────────────────── */
#site-main {
    padding: 2rem 1.25rem;
}

/* ── Footer ───────────────────────────────────────────────────────────────── */
#site-footer {
    border-top: 1px solid var(--clr-border);
    padding: 1.25rem 0;
    margin-top: 3rem;
    font-size: .8rem;
    color: var(--clr-muted);
    text-align: center;
}

/* ── Sección card ─────────────────────────────────────────────────────────── */
section {
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.75rem;
    box-shadow: var(--shadow);
}

section h2 {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--clr-muted);
    border-bottom: 2px solid var(--clr-accent);
    padding-bottom: .4rem;
    margin-bottom: 1.25rem;
}

/* ── UF / divisas ─────────────────────────────────────────────────────────── */
.uf3dias dl {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
}

.uf3dias dt {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--clr-muted);
    margin-bottom: .2rem;
}

.uf3dias dd {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--clr-accent);
}

#divisas dl {
    display: flex;
    flex-wrap: wrap;
    gap: .25rem .15rem;
    font-size: .82rem;
}

#divisas dt {
    font-weight: 700;
    background: var(--clr-bg);
    padding: .2rem .5rem;
    border-radius: var(--radius);
    margin-right: .1rem;
}

#divisas dd {
    color: var(--clr-muted);
    padding: .2rem .5rem .2rem 0;
    margin-right: .75rem;
    border-right: 1px solid var(--clr-border);
}

#divisas dd:last-child {
    border-right: none;
}

/* ── Conversor ────────────────────────────────────────────────────────────── */
.conversor-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .6rem;
    margin-bottom: 1.25rem;
}

.conversor-form label {
    display: flex;
    flex-direction: column;
    font-size: .8rem;
    color: var(--clr-muted);
    gap: .25rem;
}

.conversor-form input[type="number"],
.conversor-form select {
    font-size: .9rem;
    padding: .4rem .6rem;
    border: 1px solid var(--clr-border);
    border-radius: var(--radius);
    background: var(--clr-bg);
    color: var(--clr-text);
    outline: none;
    transition: border-color .15s;
}

.conversor-form input[type="number"]:focus,
.conversor-form select:focus {
    border-color: var(--clr-link);
}

.resultado {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--clr-accent);
    min-width: 120px;
}

/* ── Tag Cloud ────────────────────────────────────────────────────────────── */
#tag-cloud {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: .25rem .5rem;
    padding: 1rem;
    background: var(--clr-bg);
    border-radius: var(--radius);
    border: 1px solid var(--clr-border);
    margin-bottom: 1.5rem;
    line-height: 1.8;
}

#tag-cloud span {
    color: var(--clr-border);
    font-size: .9rem;
}

/* Tamaños según h1–h6 del tag cloud generado */
#tag-cloud h1 {
    font-size: 1.9rem;
}

#tag-cloud h2 {
    font-size: 1.55rem;
}

#tag-cloud h3 {
    font-size: 1.3rem;
}

#tag-cloud h4 {
    font-size: 1.1rem;
}

#tag-cloud h5 {
    font-size: .95rem;
}

#tag-cloud h6 {
    font-size: .82rem;
}

#tag-cloud h1 a,
#tag-cloud h2 a,
#tag-cloud h3 a,
#tag-cloud h4 a,
#tag-cloud h5 a,
#tag-cloud h6 a {
    color: var(--clr-accent);
    font-weight: inherit;
    white-space: nowrap;
}

#tag-cloud h1 a:hover,
#tag-cloud h2 a:hover,
#tag-cloud h3 a:hover,
#tag-cloud h4 a:hover,
#tag-cloud h5 a:hover,
#tag-cloud h6 a:hover {
    color: var(--clr-accent-d);
    text-decoration: none;
}

/* ── Tag cloud artículos ──────────────────────────────────────────────────── */
#tgc {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    /* Evita que los ítems de grid se desborden fuera de su columna */
    align-items: start;
}

.tgd {
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius);
    padding: 1rem;
    box-shadow: var(--shadow);
    /* min-width: 0 es crítico en CSS Grid para evitar overflow de texto */
    min-width: 0;
    /* El contenido se contiene dentro de la tarjeta */
    overflow: hidden;
    word-break: break-word;
    overflow-wrap: break-word;
}

.tgd h1,
.tgd h2,
.tgd h3,
.tgd h4,
.tgd h5,
.tgd h6 {
    font-size: .95rem;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--clr-muted);
    border-bottom: 2px solid var(--clr-accent);
    padding-bottom: .35rem;
    margin-bottom: .75rem;
    /* Reset explícito para no heredar estilos del tag cloud padre */
    font-weight: 700;
    line-height: 1.3;
}

/* Ocultar el div .roll que el HTML generado incluye dentro de .roll-up */
.roll {
    display: none;
}

.tgd ul {
    list-style: none;
}

.tgd li {
    padding: .6rem 0;
    border-bottom: 1px solid var(--clr-border);
    font-size: .88rem;
    /* Evita que el contenido del li se desborde */
    min-width: 0;
    overflow: hidden;
}

.tgd li:last-child {
    border-bottom: none;
}

.tgd li h3 {
    font-size: .88rem;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    border: none;
    padding: 0;
    margin: 0 0 .25rem;
    color: var(--clr-text);
    /* Trunca el titular en 2 líneas */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tgd li h3 a {
    color: var(--clr-link);
}

.tgd li h3 a:hover {
    color: var(--clr-accent);
}

.tgd li h3 img {
    vertical-align: middle;
    margin-left: .3rem;
    opacity: .7;
}

.tgd li p {
    color: var(--clr-muted);
    font-size: .82rem;
    line-height: 1.45;
    margin: 0;
    /* Trunca la descripción en 3 líneas */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tgd li p span {
    font-weight: 700;
    color: var(--clr-text);
    margin-right: .3rem;
    font-size: .78rem;
}

/* ── Noticias del día con imagen ──────────────────────────────────────────── */
#noticias-dia {
    background: var(--clr-surface);
    border: 1px solid var(--clr-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1.75rem;
    box-shadow: var(--shadow);
}

#noticias-dia h2.titulo {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: .5px;
    text-transform: uppercase;
    color: var(--clr-muted);
    border-bottom: 2px solid var(--clr-accent);
    padding-bottom: .4rem;
    margin-bottom: 1.25rem;
}

#noticias-dia dl {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

#noticias-dia dl dt a {
    font-size: .88rem;
    font-weight: 600;
    color: var(--clr-link);
    display: block;
    margin-bottom: .4rem;
}

#noticias-dia dl dt a:hover {
    color: var(--clr-accent);
}

#noticias-dia dl dd.foto img {
    width: 100%;
    height: 170px;
    object-fit: cover;
    border-radius: var(--radius);
    display: block;
    background: var(--clr-bg);
}

/* ── Lista de noticias (tema) ─────────────────────────────────────────────── */
.noticias-lista {
    list-style: none;
}

.noticias-lista li {
    padding: 1rem 0;
    border-bottom: 1px solid var(--clr-border);
}

.noticias-lista li:last-child {
    border-bottom: none;
}

.noticias-lista h3 {
    font-size: .95rem;
    margin-bottom: .35rem;
}

.noticias-lista h3 a {
    color: var(--clr-link);
}

.noticias-lista h3 a:hover {
    color: var(--clr-accent);
}

.noticias-lista p {
    font-size: .82rem;
    color: var(--clr-muted);
    line-height: 1.5;
}

/* ── Link "volver al día anterior" ───────────────────────────────────────── */
#hoy {
    margin-bottom: 1rem;
    font-size: .82rem;
}

#hoy a {
    display: inline-block;
    padding: .3rem .75rem;
    border: 1px solid var(--clr-border);
    border-radius: var(--radius);
    color: var(--clr-muted);
    font-size: .8rem;
    transition: border-color .15s, color .15s;
}

#hoy a:hover {
    border-color: var(--clr-accent);
    color: var(--clr-accent);
    text-decoration: none;
}

/* ── Titles sin sección ───────────────────────────────────────────────────── */
h2.titulo {
    font-size: 1.25rem;
    margin-bottom: 1.25rem;
    padding-bottom: .5rem;
    border-bottom: 2px solid var(--clr-border);
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    #site-header h1 {
        font-size: 1.1rem;
    }

    #site-header nav {
        gap: 1rem;
        font-size: .8rem;
    }

    .uf3dias dl {
        gap: 1rem;
    }

    .uf3dias dd {
        font-size: 1.1rem;
    }

    #tgc {
        grid-template-columns: 1fr;
    }

    #noticias-dia dl {
        grid-template-columns: 1fr;
    }

    .conversor-form {
        flex-direction: column;
        align-items: flex-start;
    }
}