"""Small shared UI building blocks for a consistent look across pages."""

import streamlit as st


def hero(icon, title, subtitle=None, key=None):
    """A branded page header: icon + title, a thin blue-to-orange accent
    rule underneath, and an optional subtitle."""
    container = st.container(key=key) if key else st.container()
    with container:
        st.markdown(f"## {icon} {title}")
        st.html(
            "<div style='height:4px;border-radius:999px;margin:-0.6rem 0 0.9rem 0;"
            "background:linear-gradient(90deg,var(--primary-color,#1B5EAB) 0%,#E8792E 100%);'></div>"
        )
        if subtitle:
            st.caption(subtitle)


def stat_card(icon, label, value, accent="blue"):
    """A bordered KPI tile: icon, label, big value — used in place of a
    plain st.metric for a slightly more designed dashboard feel."""
    colors = {
        "blue": "#1B5EAB",
        "orange": "#E8792E",
        "green": "#1E8E5A",
        "red": "#D64545",
    }
    color = colors.get(accent, colors["blue"])
    with st.container(border=True):
        st.markdown(
            f"<span style='color:{color};font-size:1.3rem;line-height:1;'>{icon}</span> "
            f"<span style='color:var(--text-color,#5C6B7A);font-size:0.85rem;'>{label}</span>",
            unsafe_allow_html=True,
        )
        st.markdown(
            f"<div style='font-size:1.7rem;font-weight:700;margin-top:0.2rem;'>{value}</div>",
            unsafe_allow_html=True,
        )
