/* ==========================================================================
   Facturalink — sistema de disseny
   CSS propi, mobile-first, sense build (res de Vite/npm al front).
   ========================================================================== */

:root {
    /* Marca */
    --brand-50:  #ecfdf5;
    --brand-100: #d1fae5;
    --brand-400: #34d399;
    --brand-500: #10b981;
    --brand-600: #059669;
    --brand-700: #047857;
    --brand-800: #065f46;

    /* Estats */
    --danger:    #ef4444;
    --danger-bg: #fef2f2;
    --success:   #10b981;
    --success-bg:#ecfdf5;

    /* Neutres */
    --bg:        #f3f5f9;
    --surface:   #ffffff;
    --surface-2: #f9fafb;
    --text:      #0f172a;
    --muted:     #64748b;
    --border:    #e5e8f0;

    --radius-sm: 8px;
    --radius:    14px;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow:    0 8px 30px rgba(15, 23, 42, .10);

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0 0 .5rem; }
.muted { color: var(--muted); }

/* --- Marca --------------------------------------------------------------- */
.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 700; }
.brand-name { font-size: 1.05rem; }
.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 9px;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
    color: #fff; font-weight: 800;
}
.brand-mark-lg { width: 52px; height: 52px; border-radius: 14px; font-size: 1.5rem; }

/* --- Botons -------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    padding: .62rem 1.05rem; border-radius: var(--radius-sm);
    font-size: .92rem; font-weight: 600; cursor: pointer;
    border: 1px solid transparent; transition: background .15s, color .15s, box-shadow .15s;
    font-family: inherit; white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-600); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-700); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-block { width: 100%; }
.btn-lg { padding: .8rem 1.2rem; font-size: 1rem; }
.btn-sm { padding: .45rem .8rem; font-size: .85rem; }

/* --- Formularis ---------------------------------------------------------- */
.field { margin-bottom: 1.1rem; }
.label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .4rem; }
.input {
    width: 100%; padding: .72rem .85rem; font-size: .95rem; font-family: inherit;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    transition: border-color .15s, box-shadow .15s;
}
.input:focus {
    outline: none; border-color: var(--brand-500);
    box-shadow: 0 0 0 3px var(--brand-100);
}
.checkbox-row { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--muted); cursor: pointer; }

/* --- Alertes ------------------------------------------------------------- */
.alert { padding: .8rem 1rem; border-radius: var(--radius-sm); font-size: .9rem; margin-bottom: 1.1rem; }
.alert-danger { background: var(--danger-bg); color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: var(--success-bg); color: #047857; border: 1px solid #a7f3d0; }

/* --- Targetes ------------------------------------------------------------ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 1.4rem; }
.card h2 { font-size: 1.05rem; margin-bottom: .4rem; }

.meta-list { margin: 1.1rem 0 0; display: grid; gap: .6rem; }
.meta-list div { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-top: 1px solid var(--border); }
.meta-list dt { color: var(--muted); font-size: .85rem; }
.meta-list dd { margin: 0; font-weight: 600; }

/* ==========================================================================
   Login (centrat, mobile-first)
   ========================================================================== */
.guest-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.25rem; }
.auth-wrap { width: 100%; max-width: 400px; }
.auth-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 2rem 1.75rem;
}
.auth-head { text-align: center; margin-bottom: 1.6rem; }
.auth-head .brand-mark-lg { margin: 0 auto .9rem; }
.auth-head h1 { font-size: 1.4rem; }
.auth-head p { color: var(--muted); font-size: .92rem; margin: .3rem 0 0; }
.auth-foot { text-align: center; color: var(--muted); font-size: .8rem; margin-top: 1.25rem; }

/* ==========================================================================
   Zona autenticada
   ========================================================================== */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner {
    max-width: 1120px; margin: 0 auto; padding: .8rem 1.25rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.topbar-user { display: flex; align-items: center; gap: .9rem; }
.user-name { font-size: .9rem; font-weight: 600; color: var(--muted); }

.page { padding: 1.5rem 1.25rem 3rem; }
.container { max-width: 1120px; margin: 0 auto; }
.page-head { margin-bottom: 1.25rem; }
.page-head h1 { font-size: 1.5rem; }
.page-head p { margin: .25rem 0 0; }

/* --- Responsive ---------------------------------------------------------- */
@media (max-width: 480px) {
    .brand-name { display: none; }
    .user-name { max-width: 8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ==========================================================================
   Navegació principal
   ========================================================================== */
.topnav { display: flex; gap: .15rem; flex: 1; margin: 0 1rem; overflow-x: auto; }
.topnav a {
    padding: .45rem .7rem; border-radius: var(--radius-sm); font-size: .9rem;
    color: var(--muted); font-weight: 550; white-space: nowrap;
}
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.topnav a.active { background: var(--brand-50); color: var(--brand-700); }

.lang-switcher { display: inline-flex; gap: .1rem; }
.lang-opt {
    padding: .25rem .45rem; font-size: .75rem; font-weight: 700;
    border-radius: 6px; color: var(--muted);
}
.lang-opt.active { background: var(--brand-50); color: var(--brand-700); }

/* --- Capçalera de pàgina --------------------------------------------------- */
.page-head-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.actions-row { display: flex; gap: .5rem; flex-wrap: wrap; }

/* --- Graelles --------------------------------------------------------------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-gap { gap: 1.25rem; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

/* --- Targetes d'estadístiques ----------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.25rem; }
@media (max-width: 720px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
    display: flex; flex-direction: column; gap: .15rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow-sm);
}
.stat-num { font-size: 1.7rem; font-weight: 750; letter-spacing: -.02em; }
.stat-label { font-size: .82rem; color: var(--muted); }
.stat-amber .stat-num { color: #b45309; }
.stat-red .stat-num { color: var(--danger); }

/* --- Taules ------------------------------------------------------------------ */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
    text-align: left; padding: .65rem 1rem; font-size: .75rem; text-transform: uppercase;
    letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--border);
}
.table td { padding: .65rem 1rem; border-bottom: 1px solid var(--border-2, #eef0f5); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .num { text-align: right; white-space: nowrap; }
.strong { font-weight: 600; color: var(--text); }
.actions-cell { text-align: right; white-space: nowrap; }
.actions-cell form { display: inline; }

/* --- Semàfor del rellotge legal ------------------------------------------------ */
.light { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .3rem; }
.light-green { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.light-amber { background: #f59e0b; box-shadow: 0 0 0 3px #fffbeb; }
.light-red { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }
.deadline-red { color: #b91c1c; font-weight: 600; }
.deadline-amber { color: #b45309; font-weight: 600; }

/* --- Badges d'estat -------------------------------------------------------------- */
.badge {
    display: inline-flex; align-items: center; padding: .18rem .55rem;
    border-radius: 999px; font-size: .72rem; font-weight: 650; line-height: 1.4;
}
.badge-rebuda { background: #eff6ff; color: #1d4ed8; }
.badge-acceptada { background: var(--success-bg); color: #047857; }
.badge-rebutjada { background: var(--danger-bg); color: #b91c1c; }
.badge-pagada { background: var(--brand-50); color: var(--brand-700); }
.badge-emesa { background: #f5f3ff; color: #6d28d9; }
.badge-entregada { background: #ecfeff; color: #0e7490; }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* --- Pestanyes ---------------------------------------------------------------------- */
.tabs { display: flex; gap: .25rem; margin: 1rem 0; border-bottom: 1px solid var(--border); }
.tab {
    padding: .5rem .9rem; font-size: .9rem; font-weight: 600; color: var(--muted);
    border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--brand-700); border-bottom-color: var(--brand-600); }

/* --- Pujada de fitxers ----------------------------------------------------------------- */
.upload-panel { display: none; margin-bottom: 1.25rem; }
.upload-panel.open { display: block; }
.dropzone {
    position: relative; border: 2px dashed var(--border); border-radius: var(--radius);
    padding: 1.6rem; text-align: center; color: var(--muted); transition: border-color .15s, background .15s;
}
.dropzone.drag { border-color: var(--brand-500); background: var(--brand-50); }
.dropzone input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

/* --- Alertes extra ------------------------------------------------------------------------ */
.alert-warning { background: #fffbeb; color: #b45309; border: 1px solid #fde68a; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert a { font-weight: 650; text-decoration: underline; }

/* --- Estat buit ------------------------------------------------------------------------------ */
.empty-state { text-align: center; color: var(--muted); padding: 2.4rem 1.4rem; }

/* --- Filtres de l'arxiu ------------------------------------------------------------------------ */
.filter-bar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filter-bar .input { width: auto; flex: 1 1 140px; }
.filter-bar input[type=search] { flex: 2 1 220px; }

/* --- Render de factura --------------------------------------------------------------------------- */
.invoice-doc { padding: 1.6rem; }
.invoice-doc-head { display: flex; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap; }
.invoice-doc-seller { font-size: 1.15rem; }
.invoice-doc-meta table td { padding: .12rem .5rem .12rem 0; font-size: .9rem; }
.invoice-doc-buyer {
    margin: 1rem 0; padding: .7rem .9rem; background: var(--surface-2);
    border-radius: var(--radius-sm); font-size: .9rem;
}
.invoice-lines th { background: var(--surface-2); }
.invoice-doc-totals { display: flex; justify-content: flex-end; margin-top: 1rem; }
.invoice-doc-totals table td { padding: .25rem 0 .25rem 2rem; font-size: .95rem; }
.invoice-doc-totals .total-row td { font-weight: 750; font-size: 1.1rem; border-top: 2px solid var(--text); padding-top: .5rem; }
.invoice-doc-foot { margin-top: 1.2rem; font-size: .85rem; border-top: 1px solid var(--border); padding-top: .8rem; }

/* --- Historial (timeline) --------------------------------------------------------------------------- */
.timeline { list-style: none; margin: .8rem 0 0; padding: 0; }
.timeline li { position: relative; display: flex; gap: .7rem; padding: 0 0 1rem 0; }
.timeline li:not(:last-child)::before {
    content: ''; position: absolute; left: 5px; top: 14px; bottom: 0; width: 2px; background: var(--border);
}
.timeline-dot {
    flex: 0 0 auto; width: 12px; height: 12px; border-radius: 50%;
    background: var(--brand-500); margin-top: 4px; box-shadow: 0 0 0 3px var(--brand-50);
}

/* --- Adreça de bústia --------------------------------------------------------------------------------- */
.inbox-address {
    display: block; margin-top: .5rem; padding: .6rem .8rem; background: var(--surface-2);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-size: .9rem; word-break: break-all;
}

/* --- Plans de preus -------------------------------------------------------------------------------------- */
.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; margin-top: 1.5rem; }
@media (max-width: 860px) { .plan-grid { grid-template-columns: 1fr; max-width: 420px; margin-left: auto; margin-right: auto; } }
.plan-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.6rem; box-shadow: var(--shadow-sm); display: flex; flex-direction: column;
}
.plan-featured { border-color: var(--brand-500); box-shadow: 0 8px 30px rgba(5,150,105,.12); }
.plan-tag {
    align-self: flex-start; font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--brand-700); background: var(--brand-50);
    padding: .2rem .55rem; border-radius: 999px; margin-bottom: .7rem;
}
.plan-price { font-size: 2rem; font-weight: 780; margin: .3rem 0 .8rem; }
.plan-price .muted { font-size: 1rem; font-weight: 500; }
.plan-features { list-style: none; margin: 0 0 1.2rem; padding: 0; flex: 1; }
.plan-features li { padding: .32rem 0 .32rem 1.4rem; position: relative; font-size: .92rem; color: var(--muted); }
.plan-features li::before { content: '✓'; position: absolute; left: 0; color: var(--brand-600); font-weight: 700; }

/* --- Llistes simples i paginació ---------------------------------------------------------------------------- */
.plain-list { list-style: none; margin: .4rem 0 0; padding: 0; font-size: .88rem; }
.plain-list li { padding: .25rem 0; }
.pagination-wrap { margin-top: 1rem; }
.pagination-wrap nav { font-size: .9rem; }

.auth-alt { text-align: center; margin-top: 1.2rem; font-size: .9rem; color: var(--muted); }
.auth-alt a { color: var(--brand-700); font-weight: 650; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-danger-ghost { background: transparent; color: #b91c1c; border-color: #fecaca; }
.btn-danger-ghost:hover { background: var(--danger-bg); }

/* ==========================================================================
   Landing
   ========================================================================== */
.landing-body { background: var(--surface); }
.landing-container { max-width: 1040px; margin: 0 auto; padding: 0 1.25rem; }
.landing-header { border-bottom: 1px solid var(--border); position: sticky; top: 0; background: rgba(255,255,255,.92); backdrop-filter: blur(8px); z-index: 20; }
.landing-header-inner { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1.25rem; }
.landing-nav { display: flex; align-items: center; gap: .6rem; }

.hero { padding: 4.5rem 0 3.5rem; text-align: center; background: linear-gradient(180deg, var(--brand-50) 0%, var(--surface) 100%); }
.hero h1 { font-size: clamp(1.8rem, 4.5vw, 3rem); max-width: 780px; margin: 0 auto; letter-spacing: -.02em; }
.hero-sub { font-size: clamp(1rem, 2vw, 1.2rem); color: var(--muted); max-width: 640px; margin: 1rem auto 1.6rem; }
.hero-ctas { display: flex; gap: .8rem; justify-content: center; flex-wrap: wrap; margin-bottom: .8rem; }

.landing-section { padding: 3.5rem 0; }
.landing-section h2 { font-size: clamp(1.4rem, 3vw, 1.9rem); margin-bottom: .8rem; }
.landing-law { background: var(--bg); }
.law-dates { display: flex; gap: 1.25rem; margin: 1.4rem 0; flex-wrap: wrap; }
.law-date {
    flex: 1 1 220px; background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 1.1rem 1.3rem; display: flex; flex-direction: column; gap: .2rem;
}
.law-when { font-size: 1.25rem; font-weight: 750; color: var(--brand-700); text-transform: capitalize; }

.feat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.25rem; margin-top: 1.5rem; }
@media (max-width: 720px) { .feat-grid { grid-template-columns: 1fr; } }
.feat-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; }
.feat-icon { font-size: 1.6rem; display: block; margin-bottom: .5rem; }
.feat-card h3 { font-size: 1.05rem; margin-bottom: .35rem; }

.landing-pricing { background: var(--bg); }
.landing-verifactu .verifactu-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; margin: 1.4rem 0; }
@media (max-width: 720px) { .landing-verifactu .verifactu-cols { grid-template-columns: 1fr; } }

.faq-list { max-width: 760px; }
.faq-item { border-bottom: 1px solid var(--border); padding: .3rem 0; }
.faq-item summary { padding: .7rem 0; font-weight: 650; cursor: pointer; list-style: none; }
.faq-item summary::after { content: '+'; float: right; color: var(--muted); }
.faq-item[open] summary::after { content: '–'; }
.faq-item p { padding-bottom: .8rem; }

.landing-cta { background: var(--brand-50); }
.landing-footer { border-top: 1px solid var(--border); padding: 1.4rem 0; font-size: .85rem; color: var(--muted); }

/* --- Mockup de la bústia a la landing ------------------------------------- */
.hero-mock {
    max-width: 620px; margin: 2.5rem auto 0; background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-lg, 0 20px 50px rgba(15,23,42,.15)); overflow: hidden; text-align: left;
}
.mock-bar {
    display: flex; align-items: center; gap: .4rem; padding: .7rem 1rem;
    background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.mock-dot { width: 10px; height: 10px; border-radius: 50%; background: #d1d5db; }
.mock-title { margin-left: .6rem; font-size: .82rem; font-weight: 650; color: var(--muted); }
.mock-table { width: 100%; border-collapse: collapse; }
.mock-table td { padding: .8rem 1rem; border-bottom: 1px solid var(--border-2, #eef0f5); font-size: .9rem; }
.mock-table tr:last-child td { border-bottom: 0; }
.mock-name { font-weight: 600; }
.mock-amount { text-align: right; font-weight: 650; white-space: nowrap; }
.mock-deadline { text-align: right; font-size: .82rem; font-weight: 600; white-space: nowrap; }
.mock-red { color: #b91c1c; }
.mock-amber { color: #b45309; }
@media (max-width: 520px) { .mock-name { max-width: 8rem; overflow: hidden; text-overflow: ellipsis; } }
