:root {
  --navy: #1e3a5f;
  --navy-dark: #142943;
  --red: #e63946;
  --green: #16845b;
  --yellow: #f2b134;
  --ink: #17212b;
  --muted: #617182;
  --line: #dce3ea;
  --surface: #fff;
  --bg: #f5f7fa;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(135deg, #142943, #1e3a5f 55%, #e63946); }
.login-card { width: min(430px, 100%); background: rgba(255,255,255,.98); border-radius: 20px; padding: 34px; box-shadow: 0 24px 70px rgba(0,0,0,.22); }
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; font-size: 1.25rem; color: var(--navy); }
.brand img { width: 48px; height: 48px; border-radius: 12px; }
.login-card h1 { margin: 28px 0 7px; font-size: 1.7rem; }
.muted { color: var(--muted); }
.form-row { margin: 16px 0; }
.form-row label { display: block; margin-bottom: 7px; font-weight: 700; font-size: .9rem; }
.form-row input, .form-row select, .form-row textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 12px 13px; background: #fff; }
.form-row textarea { min-height: 90px; resize: vertical; }
.btn { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 750; }
.btn-primary { color: #fff; background: var(--red); }
.btn-primary:hover { background: #c92e3b; }
.btn-secondary { color: var(--navy); background: #e8eef5; }
.btn-quiet { background: transparent; color: var(--muted); }
.btn-block { width: 100%; }
.error { color: #a51d2a; background: #fff0f1; border-radius: 9px; padding: 10px 12px; margin: 12px 0; }
.notice { color: #176844; background: #ecfaf3; border-radius: 9px; padding: 10px 12px; margin: 12px 0; }

.app-shell { min-height: 100vh; }
.topbar { height: 68px; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; background: var(--navy); color: #fff; }
.topbar .brand { color: #fff; }
.topbar .brand img { width: 38px; height: 38px; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.top-actions .btn-quiet { color: #dbe7f1; }
.workspace { max-width: 1440px; margin: 0 auto; padding: 28px 24px 48px; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 22px; }
.page-heading h1 { margin: 0 0 5px; font-size: clamp(1.45rem, 3vw, 2.1rem); }
.page-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card, .panel, .event-card { background: var(--surface); border: 1px solid var(--line); border-radius: 15px; padding: 18px; box-shadow: 0 4px 16px rgba(24,45,67,.04); }
.stat-card strong { display: block; font-size: 1.85rem; color: var(--navy); }
.stat-card span { color: var(--muted); font-size: .9rem; }
.events-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; margin-top: 22px; }
.event-card { display: flex; flex-direction: column; gap: 11px; }
.event-card h3 { margin: 0; color: var(--navy); }
.event-meta { color: var(--muted); font-size: .9rem; }
.event-badges { display: flex; gap: 7px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; font-size: .76rem; font-weight: 750; background: #e8eef5; color: var(--navy); }
.badge-live { background: #e7f8ef; color: #126541; }
.badge-red { background: #ffeaec; color: #ad2430; }
.badge-yellow { background: #fff6dc; color: #8b6500; }
.badge-green { background: #e8f8ed; color: #14733f; }
.badge-grey { background: #edf0f2; color: #687581; }
.empty { color: var(--muted); text-align: center; padding: 40px 15px; }

.event-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; }
.map-panel { min-height: 560px; padding: 0; overflow: hidden; }
#event-map { height: 560px; width: 100%; }
.side-stack { display: grid; gap: 18px; align-content: start; }
.panel h2, .panel h3 { margin: 0 0 14px; color: var(--navy); }
.summary-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.summary-item { border: 1px solid var(--line); border-radius: 11px; padding: 12px; }
.summary-item strong { display: block; font-size: 1.5rem; }
.summary-item span { font-size: .78rem; color: var(--muted); }
.list { display: grid; gap: 9px; }
.list-item { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--line); padding: 8px 0; }
.list-item:last-child { border-bottom: 0; }
.list-item strong { color: var(--navy); }
.occ-list { max-height: 280px; overflow: auto; }
.offline-bar { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 14px; background: #fff3cd; color: #6e5200; text-align: center; font-size: .82rem; z-index: 2000; }
.online-bar { background: #e8f8ed; color: #16633c; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,41,67,.58); display: grid; place-items: center; padding: 20px; z-index: 1000; }
.modal { width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: #fff; border-radius: 16px; padding: 22px; }
.modal-heading { display: flex; justify-content: space-between; gap: 15px; align-items: center; }
.modal-heading h2 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

@media (max-width: 900px) {
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .event-layout { grid-template-columns: 1fr; }
  .map-panel, #event-map { min-height: 390px; height: 390px; }
}
@media (max-width: 560px) {
  .topbar { padding: 0 14px; }
  .topbar .brand span { display: none; }
  .workspace { padding: 20px 14px 42px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .cards { gap: 9px; }
  .stat-card { padding: 13px; }
  .stat-card strong { font-size: 1.5rem; }
  .login-card { padding: 25px 20px; }
}

/* ------------------------------------------------------------------ */
/* Formulários auxiliares                                              */
/* ------------------------------------------------------------------ */
.check-row { display: flex; gap: 9px; align-items: center; margin: 14px 0; font-size: .92rem; }
.gps-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }

/* ------------------------------------------------------------------ */
/* Gestão de equipas                                                   */
/* ------------------------------------------------------------------ */
.team-form, .member-form { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.team-form input, .member-form input { flex: 2 1 160px; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; }
.team-form select, .member-form select { flex: 1 1 130px; border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; background: #fff; }
.team-box { border: 1px solid var(--line); border-radius: 12px; padding: 13px; margin: 11px 0; }
.team-head { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.team-head .team-actions { margin-left: auto; display: flex; gap: 5px; flex-wrap: wrap; }
.team-members { margin: 10px 0; display: grid; gap: 6px; }
.member-row { display: flex; justify-content: space-between; align-items: center; gap: 9px; border-bottom: 1px dashed var(--line); padding-bottom: 5px; }

/* ------------------------------------------------------------------ */
/* Relatório                                                           */
/* ------------------------------------------------------------------ */
.report { max-width: 980px; margin: 0 auto; }
.report-header { text-align: center; margin-bottom: 26px; }
.report-header .brand { justify-content: center; margin-bottom: 15px; }
.report-header h1 { margin: 0 0 7px; }
.report-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin: 16px 0; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; }
.bar-col .bar { width: 78%; background: var(--red); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar-col small { font-size: .66rem; color: var(--muted); line-height: 1.1; }

@media (max-width: 700px) {
  .report-grid { grid-template-columns: 1fr; }
}

/* Impressão do relatório */
@media print {
  body { background: #fff; }
  .topbar, .no-print, .offline-bar, #modal-root { display: none !important; }
  .workspace { padding: 0; max-width: 100%; }
  .panel, .stat-card { box-shadow: none; break-inside: avoid; }
  .report { max-width: 100%; }
}