:root {
  --primary: #2563eb;
  --bg: #f4f6fa; --card: #fff; --text: #111827; --muted: #6b7280; --line: #e5e7eb; --soft: #f9fafb;
  --green: #059669; --amber: #d97706; --red: #dc2626; --blue: #2563eb; --gray: #6b7280;
  --radius: 12px; --side: 240px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1115; --card: #181b21; --text: #e5e7eb; --muted: #9ca3af; --line: #2a2f38; --soft: #1f232b; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h3 { margin: 0 0 12px; font-size: 16px; } h4 { margin: 20px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
small { font-size: 12px; } .small { font-size: 13px; } .muted { color: var(--muted); } .pre { white-space: pre-wrap; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
input, select, textarea { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
textarea { resize: vertical; width: 100%; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--primary); }
input[type=color] { padding: 2px; height: 38px; width: 60px; }

/* Botons */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; font: inherit; font-weight: 500; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.block { width: 100%; justify-content: center; padding: 11px; }
.btn.wa { background: #25D366; border-color: #25D366; color: #fff; }
.btn:disabled { opacity: .6; cursor: wait; }
.danger-t { color: var(--red) !important; }
.ok-t { color: var(--green); } .warn-t { color: var(--amber); }
.icon-btn { border: 0; background: none; cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 6px; color: inherit; }
.icon-btn:hover { background: var(--soft); }

/* Estructura */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side); background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex-shrink: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; font-weight: 700; font-size: 17px; }
.brand img { max-height: 34px; max-width: 90px; }
.side nav { flex: 1; overflow-y: auto; padding: 4px 8px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); margin-bottom: 2px; text-decoration: none; }
.side nav a:hover { background: var(--soft); }
.side nav a.active { background: color-mix(in srgb, var(--primary) 12%, transparent); color: var(--primary); font-weight: 600; }
.side .ic { width: 22px; text-align: center; }
.side-foot { padding: 14px 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.who { font-weight: 600; } .who small { display: block; color: var(--muted); font-weight: 400; }
.link { font-size: 13px; }
main { flex: 1; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; padding: 14px 24px; position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px); z-index: 10; flex-wrap: wrap; }
.top h2 { margin: 0; font-size: 20px; flex: 1; min-width: 150px; }
#page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.menu-btn { display: none; font-size: 22px; }
.view { padding: 0 24px 40px; }
.side-back { display: none; }
@media (max-width: 860px) {
  .side { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.2); }
  .shell.open .side { transform: none; }
  .shell.open .side-back { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 40; }
  .menu-btn { display: inline-block; }
  .top { padding: 10px 16px; } .view { padding: 0 16px 40px; }
}

/* Targetes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.card.empty { text-align: center; color: var(--muted); padding: 40px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.cols > .card { margin: 0; }
.cols > .wide { grid-column: span 2; }
@media (max-width: 760px) { .cols { grid-template-columns: 1fr; } .cols > .wide { grid-column: auto; } }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat b { display: block; font-size: 24px; } .stat span { color: var(--muted); font-size: 13px; }
.alert { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.alert.info { background: color-mix(in srgb, var(--primary) 8%, var(--card)); color: var(--text); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
@media (prefers-color-scheme: dark) { .alert { background: #3a2d0a; color: #fcd34d; border-color: #78350f; } }

/* Llistes i taules */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); padding: 8px 0; }
.list li:last-child { border-bottom: 0; }
.list li > a { display: flex; flex: 1; justify-content: space-between; gap: 10px; color: inherit; text-decoration: none; }
.list li > a:hover { color: var(--primary); }
.list li div:first-child { flex: 1; min-width: 0; }
.list small { display: block; color: var(--muted); }
.list .r { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table.click tbody tr { cursor: pointer; } .table.click tbody tr:hover { background: var(--soft); }
.table tr.dim { opacity: .55; }
.table .actions { white-space: nowrap; text-align: right; } .table .actions > * { margin-left: 4px; }
.table .r, td.r { text-align: right; }
.search { width: 100%; margin-bottom: 12px; }
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0 0 12px; }
.dl dt { color: var(--muted); } .dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: 14px; max-height: 400px; overflow-y: auto; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); }
.timeline small { display: block; color: var(--muted); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; vertical-align: middle; }
pre.box { background: var(--soft); border: 1px solid var(--line); border-radius: 8px; padding: 12px; white-space: pre-wrap; font: 13px/1.5 ui-monospace, Menlo, monospace; overflow-x: auto; }

/* Xips d'estat */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: var(--soft); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; text-decoration: none !important; }
.chip.green { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.chip.amber { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.chip.red { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.chip.blue { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.chip.custom { background: color-mix(in srgb, var(--c) 14%, var(--card)); color: var(--c); border-color: color-mix(in srgb, var(--c) 35%, transparent); }
.chip.var { cursor: pointer; font-family: ui-monospace, monospace; font-weight: 400; margin: 2px; }
@media (prefers-color-scheme: dark) { .chip.green, .chip.amber, .chip.red, .chip.blue { background: transparent; } }

/* Formularis */
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full, .check.full, .grid-form > .full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; align-self: end; padding: 8px 0; }
.row { display: flex; align-items: center; } .row.gap { gap: 10px; } .row.wrap { flex-wrap: wrap; } .row.end { justify-content: flex-end; gap: 10px; margin-top: 10px; } .row.between { justify-content: space-between; }
.grow { flex: 1; } .w60 { width: 64px; } .w70 { width: 76px; } .w90 { width: 96px; } .w120 { width: 120px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--card); padding: 7px 14px; cursor: pointer; font: inherit; color: inherit; }
.seg button.on { background: var(--primary); color: #fff; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 12px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 9px 14px; white-space: nowrap; color: var(--muted); border-bottom: 2px solid transparent; text-decoration: none; }
.tabs a.on { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.switch { position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d1d5db; border-radius: 99px; cursor: pointer; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--primary); } .switch input:checked + span::before { transform: translateX(18px); }

/* Desplegable */
.dropdown { position: relative; }
.dropdown .menu { display: none; position: absolute; right: 0; top: calc(100% + 4px); background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); min-width: 220px; z-index: 30; padding: 4px; }
.dropdown:focus-within .menu, .dropdown:hover .menu { display: block; }
.dropdown .menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; border-radius: 6px; cursor: pointer; font: inherit; color: inherit; }
.dropdown .menu button:hover { background: var(--soft); }

/* Modals */
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 4vh 12px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 25px 60px rgba(0,0,0,.3); display: flex; flex-direction: column; max-height: 92vh; }
.modal.large { max-width: 880px; } .modal.xl { max-width: 1000px; }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; flex: 1; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.doc-frame { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

/* Avisos */
#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: 92vw; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); transition: opacity .4s; }
.toast.bad { background: var(--red); } .toast.warn { background: var(--amber); } .toast.out { opacity: 0; }

/* Accés */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; padding: 28px; }
.login-card h1 { margin: 0 0 6px; text-align: center; font-size: 22px; }
.login-mark { width: 56px; height: 56px; border-radius: 14px; background: var(--primary); color: #fff; font-size: 28px; font-weight: 700; display: flex; align-items: center; justify-content: center; margin: 0 auto; }
.login-logo { max-height: 70px; max-width: 200px; margin: 0 auto; }
.err { color: var(--red); margin: 0; text-align: center; }

/* Calendari */
.cal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.cal-head h3 { margin: 0; min-width: 170px; text-align: center; }
.legend { margin-left: auto; display: flex; gap: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.cal-grid .wd { font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; }
.day { min-height: 108px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.day:hover { background: var(--soft); }
.day.other { background: color-mix(in srgb, var(--bg) 60%, transparent); } .day.other .dn { color: var(--muted); opacity: .6; }
.day .dn { font-size: 12px; font-weight: 600; }
.day.today .dn { background: var(--primary); color: #fff; border-radius: 99px; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; }
.ev { display: block; font-size: 12px; padding: 2px 5px; border-radius: 5px; background: color-mix(in srgb, var(--c) 16%, var(--card)); border-left: 3px solid var(--s); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none !important; }
.ev span { font-weight: 600; } .ev em { font-style: normal; color: var(--muted); }
@media (max-width: 700px) { .day { min-height: 64px; } .ev { font-size: 10px; padding: 1px 3px; } .ev span { display: none; } .legend { display: none; } }

/* Formulari d'activitat */
.client-picker { position: relative; }
.search-field { position: relative; margin-bottom: 8px; }
.suggest { position: absolute; top: 100%; left: 0; right: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15); z-index: 20; max-height: 280px; overflow-y: auto; }
.suggest button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 12px; cursor: pointer; font: inherit; color: inherit; border-bottom: 1px solid var(--line); }
.suggest button:hover { background: var(--soft); } .suggest small { display: block; color: var(--muted); } .pad { padding: 10px; }
.client-state { margin-bottom: 10px; font-size: 14px; }
.ap { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: var(--soft); }
.ap-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ap-head label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.ap-workers { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.ap-workers > select { flex: 1; min-width: 220px; }
.wchip { display: inline-flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 3px 4px 3px 10px; font-size: 14px; }
.wchip select { padding: 2px 4px; font-size: 12px; }
.wchip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.ap-view { margin-bottom: 14px; } .ap-title { margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.upload { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }

/* Documents */
.lines-ed td { padding: 4px; vertical-align: top; } .lines-ed textarea { min-width: 220px; }
.lines-ed input { width: 100%; }
.totals { margin: 12px 0 18px auto; max-width: 320px; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .big { font-size: 18px; border-top: 2px solid var(--line); padding-top: 6px; margin-top: 4px; }
.tpl-ed { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.tpl-ed .tpl-code[hidden] + .doc-frame { grid-column: 1 / -1; }
.tpl-code textarea { height: 70vh; font: 12px/1.4 ui-monospace, Menlo, monospace; white-space: pre; }
@media (max-width: 900px) { .tpl-ed { grid-template-columns: 1fr; } }
.logo-prev { max-height: 60px; max-width: 200px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }

/* Automatismes */
.auto { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.auto:last-child { border-bottom: 0; }
.auto small { display: block; color: var(--muted); }
.auto.off b { opacity: .5; }
.vars { margin-top: 10px; }

/* Portal treballador */
.jobs { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.job { margin: 0; border-left: 4px solid var(--line); }
.job.confirmat { border-left-color: var(--green); } .job.rebutjat { border-left-color: var(--red); opacity: .8; }
.job.enviat, .job.rebut, .job.pendent { border-left-color: var(--amber); }
.job h3 { margin: 8px 0; }
.respond { margin-top: 12px; }
.respond input { flex-basis: 100%; }
.lines-ed .amt { white-space: nowrap; }
.weekly input[type=time] { width: 120px; }
details summary { cursor: pointer; margin: 16px 0; font-weight: 600; }
