/* Fonts pròpies (servides des de /fonts: la CSP no permet fonts externes) */
@font-face { font-family: "Sweet Sans Pro"; src: url("/fonts/sweet-sans-pro-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Sweet Sans Pro"; src: url("/fonts/sweet-sans-pro-500.woff2") format("woff2"); font-weight: 500 600; font-display: swap; }
@font-face { font-family: "Sweet Sans Pro"; src: url("/fonts/sweet-sans-pro-700.woff2") format("woff2"); font-weight: 700 800; font-display: swap; }
/* Lora i Work Sans (Juvé & Camps): SIL Open Font License, vegeu /fonts/OFL-*.txt */
@font-face { font-family: "Lora"; src: url("/fonts/lora-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Lora"; src: url("/fonts/lora-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Lora"; src: url("/fonts/lora-700.woff2") format("woff2"); font-weight: 700 800; font-display: swap; }
@font-face { font-family: "Work Sans"; src: url("/fonts/work-sans-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Work Sans"; src: url("/fonts/work-sans-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Work Sans"; src: url("/fonts/work-sans-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Work Sans"; src: url("/fonts/work-sans-700.woff2") format("woff2"); font-weight: 700 800; font-display: swap; }

/* Base comuna a totes les marques */
:root {
    --bg: #f6f3ef;
    --surface: #ffffff;
    --surface-sunken: #fcfbf9;
    --icon-bg: #f1ece6;
    --text: #1e2722;
    --muted: #4e5650;
    --border: #e4ded6;
    --border-strong: #d8d1c7;
    --divider: #eee9e2;
    --on-dark: #f4efe9;
    --on-dark-muted: #d9d2c8;
    --on-dark-faint: #b9b1a6;
    --ok-bg: #e2f0e5;    --ok-fg: #1d5e33;
    --info-bg: #e2ebf7;  --info-fg: #1f4a80;
    --warn-bg: #fbeed6;  --warn-fg: #774d00;
    --error-bg: #f8e2df; --error-fg: #9a2a21;
    --neutral-bg: #ece9e4; --neutral-fg: #4b4f4c;
    --step-empty: #e4ded6;
    --radius: 14px;
    --radius-sm: 10px;

    /* Marca per defecte: Primeras Marcas */
    --brand-ink: #1e2722;
    --brand-accent: #c58b6f;
    --brand-accent-strong: #8a664e;
    --brand-accent-on-dark: #c58b6f;
    --brand-tracking: var(--brand-accent-strong);
    --font-title: "Sweet Sans Pro", "Montserrat", sans-serif;
    --font-body: "Segoe UI", system-ui, -apple-system, sans-serif;
}

/* Juvé & Camps (playbook J&C: verd, daurat, vermell; Lora + Work Sans) */
html[data-brand="jc"] {
    --brand-ink: #154634;
    --brand-accent: #af9773;
    --brand-accent-strong: #e4032c;
    --brand-accent-on-dark: #cdb48e;
    --brand-tracking: #154634;   /* verd: el vermell destacava massa */
    --font-title: "Lora", Georgia, serif;
    --font-body: "Work Sans", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 var(--font-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    border-top: 4px solid var(--brand-accent);
}

a { color: var(--brand-accent-strong); }
a:hover { color: var(--text); }

.container {
    width: 100%;
    max-width: 1120px;
    margin: 0 auto;
    padding: 0 24px;
}

main.container { flex: 1; padding-top: 36px; padding-bottom: 56px; }

h1, h2 { font-family: var(--font-title); }
h1 { font-size: 2rem; font-weight: 700; letter-spacing: -0.01em; margin: 0; line-height: 1.2; }
h2 { font-size: 1.125rem; font-weight: 700; margin: 0; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.visually-hidden {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Barra superior */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar__inner {
    max-width: 1120px; margin: 0 auto; padding: 14px 24px;
    display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; min-height: 44px; text-decoration: none; color: var(--text); }
.brand__logo { height: 26px; width: auto; display: block; }
.brand__mark { display: none; width: 32px; height: 32px; border-radius: 6px; }
.brand__divider { width: 1px; height: 24px; background: var(--border); }
.brand__app { font-family: var(--font-title); font-size: .8125rem; font-weight: 700; letter-spacing: .01em; color: var(--muted); }
.topbar__user { display: flex; align-items: center; gap: 16px; }
.topbar__customer { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; }
.topbar__name { font-weight: 600; font-size: .9375rem; }
.topbar__code { font-size: .8125rem; color: var(--muted); }
.topbar__user form { margin: 0; }

.footer { color: var(--muted); font-size: .8125rem; border-top: 1px solid var(--border); }
.footer .container { padding-top: 18px; padding-bottom: 18px; }

/* Botons i formularis */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 18px; border-radius: var(--radius-sm); border: 1px solid transparent;
    font: inherit; font-size: .9375rem; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn--primary { background: var(--brand-ink); color: #ffffff; min-height: 48px; padding: 0 22px; }
.btn--primary:hover { filter: brightness(1.15); color: #ffffff; }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--neutral-bg); color: var(--text); }
.btn--disabled { opacity: .55; cursor: default; color: var(--muted); }
.btn--disabled:hover { background: transparent; color: var(--muted); }
.btn__icon { display: none; }
.btn:focus-visible, input:focus-visible, a:focus-visible { outline: 3px solid var(--brand-accent); outline-offset: 2px; }

input {
    font: inherit; font-size: 1rem; color: var(--text); background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    min-height: 48px; padding: 0 14px; width: 100%;
}

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); font-size: .875rem; line-height: 1.45; }
.alert svg { flex: none; margin-top: 1px; }
.alert--error { background: var(--error-bg); color: var(--error-fg); }

/* Accés (Index): panell de marca + formulari */
.login-page { flex: 1; display: flex; flex-wrap: wrap; align-items: stretch; }
.login-hero {
    flex: 1 1 420px; min-width: 0; background: var(--brand-ink); color: var(--on-dark);
    padding: 56px 64px; display: flex; flex-direction: column; justify-content: space-between; gap: 48px;
}
.login-hero__logo { height: 34px; width: auto; display: block; align-self: flex-start; }
.login-hero__text { display: flex; flex-direction: column; gap: 16px; max-width: 460px; }
.login-hero__app { font-family: var(--font-title); font-size: .8125rem; font-weight: 600; letter-spacing: .01em; color: var(--brand-accent-on-dark); }
.login-hero h1 { font-size: 2.75rem; line-height: 1.1; }
.login-hero p { margin: 0; font-size: 1.0625rem; line-height: 1.55; color: var(--on-dark-muted); }
.login-hero__copy { font-size: .8125rem; color: var(--on-dark-faint); }

.login-panel { flex: 999 1 480px; min-width: 0; display: flex; align-items: center; justify-content: center; padding: 48px 24px; }
.login { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 20px; }
.login__head { display: flex; flex-direction: column; gap: 6px; }
.login__head h2 { font-size: 1.625rem; }
.login__head p, .login__help { margin: 0; color: var(--muted); line-height: 1.5; }
.login__head p { font-size: .9375rem; }
.login__help { font-size: .8125rem; }
.form { display: flex; flex-direction: column; gap: 20px; }
.form .btn--primary { width: 100%; font-size: 1rem; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .875rem; }
.field input { font-weight: 400; }

/* Error */
.notice-page { flex: 1; display: flex; align-items: center; justify-content: center; padding: 48px 24px; }
.notice {
    width: 100%; max-width: 480px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 40px 36px; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center;
}
.notice__icon { width: 56px; height: 56px; border-radius: 999px; background: var(--icon-bg); color: var(--brand-accent-strong); display: flex; align-items: center; justify-content: center; }
.notice h1 { font-size: 1.625rem; }
.notice p { margin: 0; font-size: .9375rem; line-height: 1.55; color: var(--muted); }
.notice .btn { margin-top: 8px; }

/* Llistat de comandes */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head__title { display: flex; flex-direction: column; gap: 4px; }
.page-head__customer { display: none; font-size: .8125rem; color: var(--muted); }
.page-head__count { font-size: .9375rem; color: var(--muted); }
.search { display: flex; gap: 8px; flex: 1 1 360px; max-width: 560px; flex-wrap: wrap; margin: 0; }
.search__field {
    flex: 1 1 240px; display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--muted);
}
.search__field input { border: 0; min-height: 0; padding: 0; flex: 1; min-width: 0; font-size: .9375rem; background: transparent; }
.search__field input:focus-visible { outline: none; }
.search__field:focus-within { outline: 3px solid var(--brand-accent); outline-offset: 2px; }
.search .btn { min-height: 48px; }

.empty {
    background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius);
    padding: 56px 24px; display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center;
}
.empty svg { color: var(--brand-accent-strong); }
.empty__title { font-weight: 600; font-size: 1.0625rem; }
.empty__text { color: var(--muted); max-width: 440px; font-size: .9375rem; }

.orders { display: flex; flex-direction: column; gap: 16px; }
.order { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
/* Capçalera de la comanda: número i estat a l'esquerra; dades a sota */
.order__head {
    display: grid; grid-template-columns: auto auto minmax(0, 1fr);
    grid-template-areas: "no badge ." "meta meta meta"; gap: 10px 12px; align-items: center; padding: 20px 24px;
}
.order__main { display: contents; }
.order__no { font-family: var(--font-body); grid-area: no; }
.order__head .meta { grid-area: meta; }
.order__head > .badge { grid-area: badge; }
.order__none { margin: 0; padding: 14px 24px 18px; color: var(--muted); border-top: 1px solid var(--divider); font-size: .875rem; }

.meta { display: flex; flex-wrap: wrap; gap: 6px 28px; margin: 0; font-size: .875rem; }
.meta div { display: flex; flex-direction: column; gap: 2px; }
.meta dt { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.meta dd { margin: 0; font-weight: 500; }

.shipments { list-style: none; margin: 0; padding: 0; }
.shipment {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 24px; align-items: center;
    padding: 16px 24px; border-top: 1px solid var(--divider); background: var(--surface-sunken);
}
.shipment__main { display: flex; gap: 12px; align-items: center; min-width: 0; }
.shipment__icon { flex: none; width: 36px; height: 36px; color: var(--brand-accent-strong); display: flex; align-items: center; justify-content: center; }
.shipment__text, .shipment__carrier { display: flex; flex-direction: column; min-width: 0; }
.shipment__no { font-weight: 600; font-size: .9375rem; }
.shipment__date { font-size: .8125rem; color: var(--muted); }
.shipment__carrier { font-size: .875rem; }
.shipment__agent { font-weight: 500; }
.shipment__tracking { font-size: .8125rem; color: var(--brand-tracking); font-weight: 600; }
.shipment__status { display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
.shipment__status > .badge { align-self: flex-end; }

.badge {
    display: inline-block; padding: 4px 12px; border-radius: 999px;
    font-size: .8125rem; font-weight: 600; white-space: nowrap;
}
.badge--ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge--info { background: var(--info-bg); color: var(--info-fg); }
.badge--warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge--error { background: var(--error-bg); color: var(--error-fg); }
.badge--neutral { background: var(--neutral-bg); color: var(--neutral-fg); }

/* Progrés de l'entrega: 3 segments, s'omplen amb el color de l'estat */
.steps { display: flex; gap: 4px; }
.steps span { flex: 1; height: 4px; border-radius: 2px; background: var(--step-empty); }
.steps--ok span.is-done { background: var(--ok-fg); }
.steps--info span.is-done { background: var(--info-fg); }
.steps--warn span.is-done { background: var(--warn-fg); }
.steps--error span.is-done { background: var(--error-fg); }
.steps--neutral span.is-done { background: var(--neutral-fg); }

.pager { display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 28px; flex-wrap: wrap; }
.pager__info { font-size: .875rem; color: var(--muted); }

/* Mòbil */
@media (max-width: 640px) {
    .container { padding: 0 16px; }
    main.container { padding-top: 20px; padding-bottom: 32px; }
    h1 { font-size: 1.625rem; }

    .topbar__inner { padding: 10px 16px; flex-wrap: nowrap; }
    .brand { gap: 10px; }
    .brand--has-mark .brand__logo, .brand--has-mark .brand__divider { display: none; }
    .brand--has-mark .brand__mark { display: block; }
    .brand:not(.brand--has-mark) .brand__logo { height: 20px; }
    .brand:not(.brand--has-mark) .brand__divider { display: none; }
    .topbar__customer { display: none; }
    .topbar__user .btn { width: 44px; padding: 0; }
    .btn__label { display: none; }
    .btn__icon { display: block; }

    .login-hero { flex-basis: 100%; padding: 48px 24px 32px; gap: 28px; }
    .login-hero__logo { height: 26px; }
    .login-hero h1 { font-size: 1.875rem; }
    .login-hero p { font-size: .9375rem; }
    .login-hero__copy { display: none; }
    .login-panel { padding: 28px 24px; align-items: flex-start; }

    .page-head { flex-direction: column; align-items: stretch; gap: 14px; }
    .page-head__customer { display: block; }
    .search { flex-wrap: nowrap; max-width: none; flex-basis: auto; }
    .search .btn--primary { padding: 0 16px; }

    /* Capçalera de la comanda: número a dalt; dades i estat al costat */
    .order__head {
        padding: 16px; display: grid; grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "no no" "meta badge"; gap: 10px 12px; align-items: start;
    }
    .order__main { display: contents; }
    .order__no { grid-area: no; }
    .order__head .meta { grid-area: meta; grid-template-columns: minmax(0, 1fr); }
    .order__head > .badge { grid-area: badge; }
    .order__none { padding: 12px 16px 16px; }
    .meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; }

    /* Albarà: número i data | estat; barra de progrés a tot l'ample; transport a sota */
    .shipment {
        padding: 14px 16px; grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas: "text badge" "steps steps" "carrier carrier"; gap: 10px 12px;
    }
    .shipment__main, .shipment__status { display: contents; }
    .shipment__icon { display: none; }
    .shipment__text { grid-area: text; }
    .shipment__status > .badge { grid-area: badge; align-self: start; }
    .shipment .steps { grid-area: steps; }
    .steps span { flex: 1; width: auto; }
    .shipment__carrier { grid-area: carrier; flex-direction: row; flex-wrap: wrap; justify-content: space-between; gap: 2px 12px; }
    .pager { justify-content: space-between; }
}
