:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --ink: #1c2421;
  --muted: #5f6b66;
  --line: #dde3e0;
  --accent: #0f6e5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f1ed;
  --ok: #1d7a46;
  --ok-soft: #e2f3e8;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --error: #a32020;
  --error-soft: #fbe6e6;
  --info: #2c5d8a;
  --info-soft: #e5eef7;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--accent); }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; }
h2 { font-size: 1.05rem; margin: 0; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .92em; }

/* Barra superior */
.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 600; }
.brand-mark { display: inline-grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-weight: 700; letter-spacing: .04em; border-radius: 6px; padding: 4px 8px; font-size: .85rem; }
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 6px; font-weight: 500; }
.mainnav a:hover { color: var(--ink); background: var(--bg); }
.mainnav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.userbox { display: flex; align-items: center; gap: 12px; }
.userbox form { margin: 0; }
.username { color: var(--muted); font-size: .9rem; }
.lang-form select { padding: 4px 6px; font-size: .8rem; width: auto; }

/* Pàgina */
.page { max-width: 1200px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.head-actions form { margin: 0; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; }
.eyebrow a { color: inherit; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 + .card { margin-top: 16px; }
.section-title { font-size: .95rem; margin-bottom: 12px; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head .section-title { margin: 0; }
.card > .section-title:not(:first-of-type) { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.notes { white-space: normal; color: var(--muted); margin: 12px 0 0; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

/* Botons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #b9c4bf; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #0b5a4b; border-color: #0b5a4b; }
.btn-ghost { background: transparent; }
.btn-link { background: none; border: none; color: var(--accent); padding: 8px 4px; }
.btn-link:hover { text-decoration: underline; }
.btn-sm { padding: 4px 10px; font-size: .85rem; }
.btn-block { width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Formularis */
input[type="text"], input[type="search"], input[type="password"], input[type="tel"], input[type="email"],
input[type="date"], input[type="number"], input:not([type]), select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: inherit; background: var(--surface); color: var(--ink);
}
textarea { resize: vertical; }
label { font-weight: 500; font-size: .9rem; }
.stack { display: grid; gap: 14px; }
.stack label { display: grid; gap: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.form-grid > div { display: grid; gap: 4px; align-content: start; }
.form-grid > div:has(textarea) { grid-column: 1 / -1; }
.form-grid > div:has(input[type="checkbox"]) { grid-template-columns: auto 1fr; align-items: center; column-gap: 8px; }
.form-grid > div:has(input[type="checkbox"]) > input { order: -1; }
.form-grid > div:has(input[type="checkbox"]) > .helptext,
.form-grid > div:has(input[type="checkbox"]) > .errorlist { grid-column: 1 / -1; }
.helptext { color: var(--muted); font-size: .8rem; }
.errorlist { list-style: none; margin: 0; padding: 0; color: var(--error); font-size: .85rem; }
.errorlist-row { color: var(--error); font-size: .8rem; margin-top: 4px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.actions.split { justify-content: space-between; flex-wrap: wrap; }
.actions.split > div { display: flex; gap: 8px; flex-wrap: wrap; }
.searchbar { display: flex; gap: 8px; margin-bottom: 16px; align-items: center; }
.searchbar input { max-width: 420px; }

/* Taules */
.table-wrap { overflow-x: auto; }
.card.table-wrap { padding: 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: #fafbfa; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover td { background: #fafcfb; }
.table .num { text-align: right; width: 1%; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table .dose { text-align: center; width: 72px; font-variant-numeric: tabular-nums; }
.table .center { text-align: center; }
.table td.mono { white-space: nowrap; }
.table .right { text-align: right; }
.table td form { margin: 0; display: inline; }
.card .table th:first-child, .card .table td:first-child { padding-left: 20px; }
.lines .out-blister td { background: #fbfcfd; color: var(--muted); }
.lines-edit td { padding: 6px 8px; }
.lines-edit .col-med { min-width: 260px; }
.lines-edit .dose select { width: 64px; padding: 6px; text-align: center; }
.lines-edit input[type="text"] { min-width: 120px; }

/* Etiquetes i missatges */
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.tag-ok { background: var(--ok-soft); color: var(--ok); }
.tag-warn { background: var(--warn-soft); color: var(--warn); }
.tag-info { background: var(--info-soft); color: var(--info); }
.messages { display: grid; gap: 8px; margin-bottom: 16px; }
.msg { padding: 10px 14px; border-radius: 6px; background: var(--info-soft); color: var(--info); }
.msg-success { background: var(--ok-soft); color: var(--ok); }
.msg-error { background: var(--error-soft); color: var(--error); }
.msg-warning { background: var(--warn-soft); color: var(--warn); margin-top: 12px; }

/* Historial */
.history { border-top: 1px solid var(--line); padding: 10px 0; }
.history:first-of-type { border-top: none; }
.history summary { cursor: pointer; display: flex; gap: 16px; flex-wrap: wrap; align-items: baseline; }
.history .table-wrap { margin: 12px 0; }

/* Accés */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 32px; }
.auth-card h1 { font-size: 1.35rem; margin-bottom: 6px; }
.auth-card .stack { margin-top: 20px; }
.auth-card .stack > div { display: grid; gap: 4px; }
.auth-brand { margin-bottom: 20px; }
.steps { padding-left: 20px; color: var(--muted); }
.qr { display: block; margin: 12px auto; background: #fff; padding: 8px; border: 1px solid var(--line); border-radius: 8px; }
.secret { font-size: .85rem; color: var(--muted); text-align: center; }
.secret code { display: block; margin-top: 6px; word-break: break-all; font-family: var(--mono); color: var(--ink); }

@media (max-width: 1100px) {
  .topbar { flex-wrap: wrap; gap: 8px 16px; padding: 10px 16px; }
  .mainnav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .username { display: none; }
  .page { padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .searchbar { flex-wrap: wrap; }
}

/* Superadministrador */
.support-banner { display: flex; align-items: center; justify-content: center; gap: 16px; flex-wrap: wrap; padding: 8px 24px; background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid #ecd9a8; font-size: .9rem; }
.support-banner form { margin: 0; }
.btn-warn { border-color: var(--warn); color: var(--warn); }
.inline-form { display: flex !important; gap: 6px; align-items: center; }
.inline-form input { min-width: 180px; padding: 4px 8px; }
.table.compact td { padding: 6px 12px; font-size: .88rem; }
.auth-links { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.auth-links form { margin: 0; }

/* Capsa del pacient */
.scanbar label { font-size: 1rem; }
.scanbar-row { display: flex; gap: 8px; margin: 8px 0 4px; }
.scanbar-row input { font-size: 1.05rem; padding: 10px 12px; font-family: var(--mono); }
.stock-row.has-alerts { border-left: 4px solid var(--warn); }
.stock-head { display: flex; gap: 16px; align-items: center; }
.stock-title { flex: 1; min-width: 0; }
.stock-title h2 { font-size: 1rem; }
.stock-title p { margin: 2px 0 0; font-size: .88rem; }
.pill-photo { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #fff; }
.stock-figures { display: flex; gap: 20px; text-align: right; }
.figure { display: block; font-size: 1.35rem; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.1; }
.figure-label { font-size: .75rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stock-row .table-wrap { margin-top: 12px; border-top: 1px solid var(--line); }
.alerts { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 4px; }
.alerts li { padding: 6px 10px; border-radius: 6px; font-size: .9rem; }
.alert-warning { background: var(--warn-soft); color: var(--warn); }
.alert-error { background: var(--error-soft); color: var(--error); }
.text-error { color: var(--error); font-weight: 600; }
.product { display: flex; gap: 16px; align-items: center; }
.product img { width: 96px; height: 96px; object-fit: contain; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.product h2 { font-size: 1rem; }
.product p { margin: 4px 0 0; }
.box-remove { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.table td.right { white-space: nowrap; }
@media (max-width: 800px) {
  .stock-head, .product { flex-wrap: wrap; }
}
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-size: .75rem; font-weight: 700; }
.med-cell { display: flex; align-items: center; gap: 10px; }
.pill-thumb { width: 32px; height: 32px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); }

/* SPD */
.tag-error { background: var(--error-soft); color: var(--error); }
.tag:not([class*="tag-"]) { background: var(--bg); color: var(--muted); }
.card.table-wrap > .card-head { padding: 16px 20px 0; }
.period-picker { display: flex; gap: 8px; align-items: center; }
.period-picker input { width: auto; }
.period-picker label { white-space: nowrap; }
ul.plain { margin: 6px 0; padding-left: 18px; }
.table tr.row-error td { background: var(--error-soft); }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.timeline li { display: grid; gap: 2px; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.timeline li strong { color: var(--muted); }
.timeline li.done { border-color: #b9dcc7; background: var(--ok-soft); color: var(--ink); }
.timeline li.done strong { color: var(--ok); }
.timeline li.current { border-color: var(--warn); background: var(--warn-soft); }
.timeline li.current strong { color: var(--warn); }
.timeline li.cancelled { background: var(--error-soft); border-color: #eab8b8; color: var(--error); }
.deliver-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.deliver-card p { margin: 0; }
.grid-2 + section.card, .grid-2 + .grid-2 { margin-top: 16px; }
form.card > .form-grid + .actions { margin-top: 16px; }

/* Dies concrets i observacions ressaltades */
.hl { display: inline-block; background: #1c2421; color: #fff; font-weight: 700; padding: 0 6px; border-radius: 4px; font-size: .85em; }
.days-cell .weekdays, .days-cell ul { display: flex; gap: 2px; list-style: none; margin: 0; padding: 0; }
.days-cell label { display: grid; justify-items: center; font-size: .72rem; font-weight: 500; color: var(--muted); gap: 0; }
.days-cell input { margin: 0; }

/* Inspecció */
.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; border-radius: 6px 6px 0 0; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tabs a[aria-current="page"] { color: var(--accent); border-bottom-color: var(--accent); }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 12px; }

/* Importació */
.steps-list { margin: 0 0 16px; padding-left: 20px; color: var(--muted); }
.stat-row { display: flex; gap: 32px; flex-wrap: wrap; margin-bottom: 12px; }
.secret-list { margin: 12px 0; }
.scanbar-inline { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.scanbar-inline label { font-weight: 600; }

/* Contrasenya */
.card.narrow { max-width: 520px; }
.card.narrow .stack > div { display: grid; gap: 4px; }
.inline-card { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.inline-card .section-title { margin-bottom: 4px; }
a.username { text-decoration: none; color: var(--muted); }
a.username:hover { color: var(--accent); text-decoration: underline; }

/* Ajuda */
.help-button { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); color: var(--accent); font-weight: 700; text-decoration: none; background: var(--surface); }
.help-button:hover { background: var(--accent-soft); border-color: var(--accent); }
.auth { display: grid; place-items: center; align-content: center; gap: 12px; }
.auth-help { text-align: center; margin: 0; font-size: .9rem; }
.help-search label { font-weight: 600; font-size: 1rem; }
.help-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.help-card { text-decoration: none; color: inherit; margin: 0; transition: border-color .15s; }
.help-card:hover { border-color: var(--accent); }
.help-card h2 { font-size: 1rem; color: var(--accent); margin-bottom: 4px; }
.help-card p { margin: 0; font-size: .9rem; }
.help-result { display: grid; gap: 2px; padding: 10px 0; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.help-result:first-of-type { border-top: none; }
.help-result strong { color: var(--accent); }
.help-snippet { color: var(--muted); font-size: .88rem; }
.help-article { max-width: 820px; line-height: 1.6; }
.help-article section { padding: 4px 0 16px; border-bottom: 1px solid var(--line); scroll-margin-top: 80px; }
.help-article section:last-child { border-bottom: none; }
.help-article section:target { background: var(--accent-soft); margin: 0 -20px; padding: 4px 20px 16px; border-radius: 6px; }
.help-article h2 { font-size: 1.1rem; margin: 16px 0 8px; }
.help-article ol, .help-article ul { padding-left: 22px; }
.help-article li { margin-bottom: 4px; }
.help-article code { font-family: var(--mono); background: var(--bg); padding: 1px 6px; border-radius: 4px; }
.help-note { background: var(--info-soft); color: var(--info); padding: 8px 12px; border-radius: 6px; }
.help-pager { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Suport */
.support-link { text-decoration: none; color: var(--muted); font-weight: 500; padding: 4px 8px; border-radius: 6px; }
.support-link:hover, .support-link[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.help-contact { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.ticket-form { max-width: 760px; }
.ticket-form .stack > div { display: grid; gap: 4px; }
.ticket-form ul { list-style: none; padding: 0; margin: 4px 0 0; display: grid; gap: 4px; }
.ticket-form ul label { font-weight: 400; display: flex; gap: 8px; align-items: center; }
.thread { display: grid; gap: 12px; margin-bottom: 16px; max-width: 820px; }
.bubble { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; margin-right: 15%; }
.bubble.from-support { background: var(--accent-soft); border-color: #b9dcc7; margin: 0 0 0 15%; }
.bubble header { margin-bottom: 6px; font-size: .9rem; }
.bubble-body { white-space: normal; line-height: 1.55; }
.bubble .btn { margin-top: 8px; }
.ticket-form fieldset { border: none; padding: 0; margin: 0; }
.ticket-form legend { font-weight: 500; font-size: .9rem; margin-bottom: 6px; padding: 0; }
.ticket-form fieldset > div { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px; }
.ticket-form fieldset label { display: flex; align-items: center; gap: 8px; font-weight: 400; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.ticket-form fieldset label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.signature-help { background: var(--info-soft); color: var(--info); padding: 8px 12px; border-radius: 6px; margin-bottom: 12px; }
