/*
 * Estils base de l'aplicació (assets locals, sense CDN).
 *
 * Fase 1: full d'estils propi i lleuger amb variables i utilitats mínimes.
 * El pipeline de build de Tailwind s'afegirà a la Fase 13 (polit); la UI
 * intermèdia funciona amb aquest CSS sense dependències externes.
 */

:root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f242e;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --primary: #4f8cff;
    --ok: #34d399;
    --border: #2a2f3a;
    --radius: 12px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.container {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1rem;
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
}

.brand {
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
    font-size: 1.1rem;
}

.nav a {
    color: var(--muted);
    text-decoration: none;
    margin-left: 1rem;
}
.nav a:hover { color: var(--text); }

main.container { padding-top: 2rem; padding-bottom: 2rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.card__title { margin: 0 0 .5rem; font-size: 1.4rem; }

.muted { color: var(--muted); }

.status {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    margin: 1rem 0;
    padding: .4rem .75rem;
    border-radius: 999px;
    background: var(--surface-2);
    font-size: .9rem;
}
.status--ok .dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--ok);
    box-shadow: 0 0 0 4px rgba(52, 211, 153, .15);
}

.meta {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: .25rem 1rem;
    margin: 1rem 0;
}
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-variant-numeric: tabular-nums; }

.notice {
    background: var(--surface-2);
    border-left: 3px solid var(--primary);
    padding: .75rem 1rem;
    border-radius: 6px;
    color: var(--muted);
}

.btn {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: .5rem .9rem;
    font-size: .9rem;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }

.footer {
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: .85rem;
    padding: 1.25rem 0;
    margin-top: 2rem;
}
.footer__inner { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.langswitch a { color: var(--muted); text-decoration: none; padding: 0 .25rem; }
.langswitch a[aria-current="true"] { color: var(--text); font-weight: 700; }
.langswitch--center { text-align: center; margin-top: 1rem; }

/* Accessibilitat: enllaç de salt */
.skip-link {
    position: absolute; left: -999px; top: 0; z-index: 100;
    background: var(--primary); color: #fff; padding: .5rem .9rem; border-radius: 0 0 8px 0;
}
.skip-link:focus { left: 0; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Navegació autenticada */
.nav { display: flex; align-items: center; gap: 1rem; }
.nav__user { color: var(--muted); font-size: .85rem; }
.linkbtn {
    background: none; border: 0; color: var(--muted);
    cursor: pointer; font: inherit; padding: 0;
}
.linkbtn:hover { color: var(--text); }
.linkbtn--danger { color: #f87171; }

/* Formularis */
label { display: block; margin: .75rem 0 .25rem; font-size: .9rem; }
input, select {
    width: 100%; padding: .55rem .65rem; background: var(--bg); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px; font-size: .95rem;
}
.row { display: flex; gap: 1rem; }
.row > div { flex: 1; }
.btn--ghost { background: var(--surface-2); border: 1px solid var(--border); }

/* Targetes i graella */
.card__subtitle { margin: 0 0 1rem; font-size: 1.1rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 720px) { .grid2 { grid-template-columns: 1fr; } }

/* Avisos */
.alert { padding: .75rem 1rem; border-radius: 8px; margin: 1rem 0; font-size: .9rem; }
.alert--err { background: rgba(248,113,113,.12); border: 1px solid #f87171; color: #fecaca; }
.alert--ok { background: rgba(52,211,153,.12); border: 1px solid var(--ok); color: #bbf7d0; }

/* Taules */
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th, .table td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 600; }

/* Etiquetes */
.badge {
    display: inline-block; padding: .1rem .5rem; border-radius: 999px;
    background: var(--surface-2); border: 1px solid var(--border);
    font-size: .75rem; color: var(--muted);
}
.badge--ok { color: var(--ok); border-color: var(--ok); }

/* Llista d'auditoria */
.loglist { list-style: none; padding: 0; margin: 0; }
.loglist li {
    display: flex; align-items: center; gap: .6rem;
    padding: .4rem 0; border-bottom: 1px solid var(--border); font-size: .85rem;
}
.loglist time { margin-left: auto; }

/* Codi */
.codeblock {
    display: block; background: var(--bg); border: 1px solid var(--border);
    border-radius: 8px; padding: .6rem .75rem; font-size: 1.05rem;
    letter-spacing: .05em; word-break: break-all;
}
.codeblock--sm { font-size: .8rem; letter-spacing: 0; }

/* Capçalera de pàgina amb total */
.pagehead {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem;
}
.pagehead .card__title { margin: 0; }
.networth { text-align: right; display: flex; flex-direction: column; }
.networth strong { font-size: 1.3rem; }
.pos { color: var(--ok); }
.neg { color: #f87171; }

/* Filtres */
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 0; }
.filters select, .filters input {
    width: auto; flex: 1 1 130px; margin: 0;
}
.filters .btn { margin: 0; }

/* Accions de fila */
.rowactions { display: flex; gap: .6rem; align-items: center; white-space: nowrap; }
.rowactions form { display: inline; margin: 0; }

/* Paginació */
.pagination { display: flex; align-items: center; gap: 1rem; margin-top: 1rem; }
.pagination .btn { margin: 0; }

/* KPIs i gràfics del dashboard */
.kpis { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.kpi {
    flex: 1; min-width: 130px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: .8rem 1rem;
}
.kpi span { display: block; font-size: .8rem; }
.kpi strong { font-size: 1.25rem; }
.chart { width: 100%; height: auto; max-height: 220px; }
.chart--donut { max-width: 200px; }
.chartrow { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.legend { list-style: none; padding: 0; margin: 0; font-size: .85rem; }
.legend li { margin: .2rem 0; display: flex; align-items: center; }
.legend-inline { font-size: .75rem; font-weight: normal; color: var(--muted); margin-left: .5rem; }
.dot2 { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin: 0 .35rem; }

/* Subnavegació (pestanyes) */
.subnav { display: flex; gap: .5rem; margin: 0 0 1rem; border-bottom: 1px solid var(--border); }
.subnav a {
    padding: .5rem .9rem; color: var(--muted); text-decoration: none;
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subnav a.active { color: var(--text); border-bottom-color: var(--primary); }
.subnav a:hover { color: var(--text); }

/* Barres de progrés (pressupostos/objectius) */
.budget { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.budget__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .4rem; }
.budget__meta { font-size: .85rem; margin-top: .35rem; }
.bar { background: var(--surface-2); border-radius: 999px; height: 9px; overflow: hidden; }
.bar__fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }
.bar__fill--warn { background: #f59e0b; }
.bar__fill--over { background: #f87171; }
.bar__fill--ok2 { background: var(--ok); }
.inline-add { display: flex; gap: .5rem; margin-top: .5rem; }
.inline-add input { width: auto; flex: 1; margin: 0; }
.inline-add .btn { margin: 0; }

/* Registre d'actualitzacions */
.logbox {
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    padding: .75rem; font-size: .8rem; overflow-x: auto; white-space: pre-wrap;
    color: var(--muted); max-height: 320px;
}

/* Xat IA */
.chat { display: flex; flex-direction: column; gap: .75rem; }
.chat__q { background: var(--surface-2); border-radius: 8px; padding: .5rem .75rem; }
.chat__a { border-left: 3px solid var(--primary); padding: .25rem .75rem; }

/* Arbre de categories */
.cat-parent {
    display: flex; justify-content: space-between; align-items: center;
    padding: .5rem 0; border-bottom: 1px solid var(--border); margin-top: .5rem;
}
.cat-child {
    display: flex; justify-content: space-between; align-items: center;
    padding: .3rem 0 .3rem 1.5rem; font-size: .9rem; color: var(--muted);
    border-bottom: 1px solid var(--border);
}
.cat-child .cat-name { color: var(--text); }

/* Pantalla d'autenticació */
body.auth {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
}
.auth__box { width: 100%; max-width: 380px; padding: 1rem; }
.auth__brand { font-size: 1.6rem; font-weight: 700; text-align: center; }
.auth__tag { text-align: center; margin: .25rem 0 1.25rem; }
