:root {
  --bg: #f5f7fa; --panel: #ffffff; --ink: #1f2937; --muted: #6b7280; --line: #e4e8ee;
  --accent: #2f62b8; --accent-ink: #fff; --soft: #edf2fb; --soft-2: #f3f6fb; --teal: #3a9e96;
  --warn: #9a5b13; --warn-bg: #fdf4e7; --bad: #c2483d; --bad-bg: #fdecea; --ok: #1f7a55; --ok-bg: #e7f5ee;
  --shadow: 0 1px 2px rgba(31, 41, 55, .05), 0 2px 8px rgba(31, 41, 55, .04);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 15px; margin: 0; }
.muted { color: var(--muted); } .small { font-size: 12px; }
[hidden] { display: none !important; }
.sp { flex: 1; }

.appbar { display: flex; align-items: center; gap: 22px; height: 54px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1000; }
.app-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.app-logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; }
.tabs { display: flex; align-self: stretch; gap: 2px; overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 0 12px; cursor: pointer; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }

.wrap { max-width: 1200px; margin: 0 auto; padding: 22px 16px 48px; }
.wrap.narrow { max-width: 900px; }
.bar-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.bar-head p { margin: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 13px; cursor: pointer; font-weight: 600; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover:not(:disabled) { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.ghost { background: transparent; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font-weight: 600; padding: 0; }
input[type=text], input[type=number], input[type=date], select { border: 1px solid var(--line); background: var(--soft-2); border-radius: 7px; padding: 6px 9px; min-width: 0; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; }

.drop { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 30px; margin: 16px 0; border: 1.5px dashed var(--line); border-radius: 14px; background: var(--panel); cursor: pointer; color: var(--muted); }
.drop b { color: var(--accent); font-size: 16px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--soft-2); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 14px 0; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.kpi b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi.warn b { color: var(--warn); } .kpi.bad b { color: var(--bad); }
.progress { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 10px 0 4px; }
.progress span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 7px 9px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--soft-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: auto; }
.badge { font-size: 11px; padding: 2px 7px; border-radius: 999px; background: var(--soft-2); color: var(--muted); white-space: nowrap; font-weight: 600; }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.bad { background: var(--bad-bg); color: var(--bad); }

/* Planeamento */
.plan-grid { display: grid; grid-template-columns: 240px minmax(0, 1fr) 420px; height: calc(100vh - 54px); }
.plan-grid > * { min-height: 0; overflow-y: auto; }
.people { background: var(--panel); border-right: 1px solid var(--line); padding: 10px; }
.people button { width: 100%; text-align: left; border: 1px solid transparent; background: none; border-radius: 8px; padding: 8px 10px; cursor: pointer; display: grid; gap: 1px; }
.people button:hover { background: var(--soft-2); }
.people button.on { background: var(--soft); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.people .nm { font-weight: 600; font-size: 13px; }
.people .mt { font-size: 11.5px; color: var(--muted); }
.people h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 12px 6px 6px; }
.plan-main { padding: 16px 18px 40px; }
.phead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.phead h1 { font-size: 20px; }
.settings { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
.settings label.chk { display: flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 500; color: var(--ink); }
.zone { margin-bottom: 18px; }
.zhead { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; flex-wrap: wrap; }
.zhead h2 { font-size: 14px; }
.zhead .tag { background: var(--teal); color: #fff; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 700; }
.days { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 10px; }
.day { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.day.sel { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
.dhead { padding: 9px 11px; border-bottom: 1px solid var(--line); cursor: pointer; }
.dhead .t { display: flex; justify-content: space-between; gap: 6px; font-weight: 700; }
.dhead .s { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; margin-top: 2px; }
.dhead .km { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 700; }
.dlist { list-style: none; margin: 0; padding: 6px; flex: 1; min-height: 44px; }
.dlist.over { background: var(--soft-2); }
.dlist li { display: grid; grid-template-columns: 20px 1fr auto; gap: 6px; align-items: start; padding: 6px 6px; border-radius: 8px; cursor: grab; background: var(--panel); }
.dlist li:hover { background: var(--soft-2); }
.dlist li.dragging { opacity: .4; }
.dlist li.drop-before { box-shadow: 0 -2px 0 var(--accent); }
.dlist .n { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; margin-top: 1px; }
.dlist .nm { font-weight: 600; font-size: 12.5px; line-height: 1.3; }
.dlist .ad { font-size: 11.5px; color: var(--muted); line-height: 1.3; }
.dlist .leg { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dlist .mv { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 16px; line-height: 1; padding: 0 4px; }
.dlist .mv:hover { color: var(--accent); }
.dfoot { display: flex; gap: 6px; padding: 6px 8px 8px; border-top: 1px dashed var(--line); }
.unloc { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: 12.5px; margin-bottom: 8px; }
.plan-map { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; }
#map { flex: 1; min-height: 300px; }
.map-cap { padding: 8px 12px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); }
.mk { width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: #fff; font: 700 11px/24px Inter, sans-serif; text-align: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.3); }
.mk.home { background: #1f2937; border-radius: 6px; }
.mk.other { background: #9fb3d9; }

/* Colaboradores */
.pcard { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow); }
.prow { display: grid; grid-template-columns: 1.2fr 2fr 0.8fr 1fr auto auto; gap: 8px; align-items: end; }
.zchips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.zchip { display: flex; align-items: center; gap: 6px; background: var(--soft-2); border: 1px solid var(--line); border-radius: 10px; padding: 5px 8px; font-size: 12.5px; }
.zchip input { width: 110px; padding: 3px 6px; }
.zchip select { padding: 3px 6px; font-size: 12px; }

.modal { position: fixed; inset: 0; background: rgba(17, 24, 39, .45); z-index: 3000; display: grid; place-items: center; padding: 16px; }
.mbox { background: var(--panel); border-radius: 14px; padding: 18px; width: 100%; max-width: 460px; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: grid; gap: 12px; }
.mbox h2 { font-size: 16px; }
.mbox .actions { justify-content: flex-end; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 9px; z-index: 4000; max-width: calc(100vw - 32px); }

@media (max-width: 1200px) { .plan-grid { grid-template-columns: 210px minmax(0, 1fr) 340px; } }
@media (max-width: 900px) {
  .plan-grid { grid-template-columns: 1fr; height: auto; }
  .plan-grid > * { overflow: visible; }
  .people { border-right: 0; border-bottom: 1px solid var(--line); max-height: 220px; overflow-y: auto; }
  .plan-map { order: -1; height: 320px; }
  .prow { grid-template-columns: 1fr 1fr; }
}

.totals { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.totals > div { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-width: 120px; }
.totals span { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.totals b { font-size: 18px; font-variant-numeric: tabular-nums; }
.totals .paid { border-color: color-mix(in srgb, var(--teal) 50%, var(--line)); background: color-mix(in srgb, var(--teal) 6%, var(--panel)); }
.totals .paid b, .pd { color: #22756e; }
.dlist .leg.pd, .ret .pd { color: #22756e; font-weight: 600; }
.ret { font-size: 12px; padding: 4px 12px 8px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }

.brand-logo { height: 34px; width: auto; display: block; filter: brightness(1.09) contrast(1.35); mix-blend-mode: multiply; }
.brand-sep { width: 1px; height: 20px; background: var(--line); }

table.confirm td:nth-child(3) { width: 34%; }
table.confirm td:nth-child(3) input { width: 100%; }
table.confirm td.acts { width: 128px; }
table.confirm td.acts .btn { width: 100%; justify-content: center; margin: 2px 0; }
table.confirm td:nth-child(3) input { min-width: 280px; }
.btn.ok { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); color: var(--ok); }
.btn.ok:hover { background: var(--ok-bg); }
.mbox:has(#pickMap) { max-width: 720px; }

/* conta só de consulta: esconde os controlos de edição */
body.ro .dlist .mv, body.ro [data-opt], body.ro [data-planzone], body.ro [data-newday], body.ro [data-delday], body.ro #btnPlanPerson,
body.ro #btnPlanAll, body.ro #btnGeo, body.ro #btnGeoApprox, body.ro #btnApproveAll, body.ro [data-approve], body.ro [data-regeo], body.ro .drop,
body.ro #btnAddPerson, body.ro label:has(#homesFile), body.ro [data-geohome], body.ro [data-newzone], body.ro .settings { display: none !important; }
body.ro .dlist li { cursor: default; }
#userBox .btn { padding: 4px 9px; }
