:root {
  --primary: #1a8fe3;
  --primary-dark: #0f6dc0;
  --dark: #0a1230;
  --ink: #1c2430;
  --muted: #7a8699;
  --line: #e4e9f2;
  --bg: #eef2f7;
  --card: #ffffff;
  --danger: #e2445c;
  --ok: #2bb673;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(10, 18, 48, .10);
  --shadow-sm: 0 2px 10px rgba(10, 18, 48, .06);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(26, 143, 227, .10), transparent 60%),
    radial-gradient(1000px 500px at -10% 10%, rgba(15, 109, 192, .08), transparent 55%),
    var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- Topbar (quando logado) ---------- */
.topbar {
  background: rgba(255, 255, 255, .85);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.topbar .brand-mini { font-weight: 700; color: var(--dark); font-size: 15px; }
.topbar .spacer { flex: 1; }
.topbar a.navlink {
  font-size: 14px;
  color: var(--ink);
  padding: 7px 12px;
  border-radius: 8px;
}
.topbar a.navlink:hover { background: var(--bg); text-decoration: none; }
.topbar a.navlink.active { background: var(--primary); color: #fff; }
.topbar .user-chip:hover { color: var(--primary); text-decoration: none; }
.topbar .user-chip {
  font-size: 13px;
  color: var(--muted);
  background: var(--bg);
  padding: 6px 12px;
  border-radius: 999px;
}

/* ---------- Header banner ---------- */
.hero {
  background: linear-gradient(120deg, var(--dark) 0%, #12224a 55%, var(--primary) 130%);
  border-radius: var(--radius);
  padding: 30px 34px;
  color: #fff;
  margin: 28px 0 22px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 22px;
  position: relative;
  overflow: hidden;
}
.hero::after {
  content: "";
  position: absolute;
  right: -60px; top: -60px;
  width: 260px; height: 260px;
  background: radial-gradient(circle, rgba(255,255,255,.18), transparent 70%);
  border-radius: 50%;
}
.hero img.logo { max-height: 44px; max-width: 200px; width: auto; height: auto; flex-shrink: 0; display: block; position: relative; z-index: 1; }
.hero .hero-txt { position: relative; z-index: 1; }
.hero h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: .3px; }
.hero p { margin: 6px 0 0; color: rgba(255,255,255,.82); font-size: 14px; }

/* ---------- Card ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 32px;
  margin-bottom: 24px;
}
.card h2.section-title {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--dark);
  margin: 0 0 22px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--line);
}
.subsection {
  margin: 30px 0 16px;
  font-size: 17px;
  font-weight: 700;
  color: var(--dark);
}
.subsection-note { color: var(--muted); font-size: 13px; margin: -8px 0 18px; }

.callout {
  background: linear-gradient(120deg, rgba(26,143,227,.10), rgba(26,143,227,.04));
  border: 1px solid rgba(26,143,227,.25);
  border-left: 4px solid var(--primary);
  border-radius: 10px;
  padding: 14px 18px;
  font-weight: 600;
  color: var(--dark);
  margin: 24px 0;
  font-size: 15px;
}

/* ---------- Form ---------- */
.field { margin-bottom: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 18px; }

label.flabel {
  display: block;
  font-weight: 600;
  font-size: 14px;
  color: var(--dark);
  margin-bottom: 7px;
}
label.flabel .req { color: var(--danger); margin-left: 3px; }

.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font-size: 15px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,143,227,.15);
}
input::placeholder, textarea::placeholder { color: #aeb7c4; }
textarea { min-height: 92px; resize: vertical; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%237a8699' stroke-width='2.5'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}

/* Range slider */
.range-wrap { display: flex; align-items: center; gap: 16px; }
input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--primary);
  border: 3px solid #fff;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 22px; height: 22px; border: 3px solid #fff;
  border-radius: 50%; background: var(--primary); cursor: pointer;
}
.range-value {
  min-width: 44px;
  text-align: center;
  font-weight: 700;
  color: var(--primary);
  background: rgba(26,143,227,.10);
  border-radius: 8px;
  padding: 5px 10px;
}

/* File upload */
.filebox {
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fafbfd;
  transition: border-color .15s, background .15s;
}
.filebox:hover { border-color: var(--primary); background: rgba(26,143,227,.03); }
.filebox { position: relative; cursor: pointer; }
/* escondido visualmente mas acessível por teclado/leitores de ecrã */
.filebox input[type="file"] {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.filebox:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,143,227,.15); }
.filebtn {
  background: var(--dark);
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.filebtn:hover { background: #12224a; }
.filename { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filename.has { color: var(--ok); font-weight: 600; }

/* Turnstile */
.turnstile-wrap { margin: 22px 0; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  padding: 13px 28px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(26,143,227,.30);
  transition: transform .12s, box-shadow .12s, opacity .12s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(26,143,227,.38); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ghost {
  background: #fff; color: var(--ink);
  border: 1.5px solid var(--line); box-shadow: none;
}
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); box-shadow: none; }
.btn-danger { background: linear-gradient(135deg, #e2445c, #c62f47); box-shadow: 0 6px 18px rgba(226,68,92,.3); }
.btn-dark { background: var(--dark); box-shadow: none; }
.btn-dark:hover { background: #12224a; box-shadow: none; }
.btn-sm { padding: 8px 16px; font-size: 13px; }

.form-actions { margin-top: 26px; display: flex; gap: 12px; align-items: center; }

/* Footer */
.site-footer {
  background: linear-gradient(120deg, var(--dark), #12224a 60%, var(--primary) 140%);
  color: #fff;
  border-radius: var(--radius);
  padding: 22px 30px;
  margin: 10px 0 40px;
  font-size: 14px;
  line-height: 1.9;
  box-shadow: var(--shadow);
}
.site-footer .fline { color: rgba(255,255,255,.9); }
.site-footer .fline:first-child { font-weight: 700; letter-spacing: .3px; }

/* Alerts */
.alert {
  border-radius: 10px;
  padding: 14px 18px;
  margin-bottom: 18px;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-success { background: rgba(43,182,115,.12); color: #1c7a4f; border: 1px solid rgba(43,182,115,.35); }
.alert-error   { background: rgba(226,68,92,.10); color: #b32741; border: 1px solid rgba(226,68,92,.30); }
.alert-info    { background: rgba(26,143,227,.10); color: #0f6dc0; border: 1px solid rgba(26,143,227,.30); }

/* Login page */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.auth-head {
  background: linear-gradient(120deg, var(--dark), var(--primary) 140%);
  padding: 34px 30px 26px;
  text-align: center;
}
.auth-head img { max-height: 40px; max-width: 200px; width: auto; height: auto; margin: 0 auto 10px; display: block; }
.auth-head h1 { color: #fff; font-size: 19px; margin: 8px 0 0; }
.auth-head p { color: rgba(255,255,255,.8); font-size: 13px; margin: 4px 0 0; }
.auth-body { padding: 30px 30px 34px; }

/* Success screen */
.success-screen { text-align: center; padding: 20px 10px; }
.success-icon {
  width: 76px; height: 76px; margin: 0 auto 18px;
  border-radius: 50%;
  background: rgba(43,182,115,.12);
  display: flex; align-items: center; justify-content: center;
}
.success-screen h2 { color: var(--dark); margin: 0 0 8px; }
.success-screen p { color: var(--muted); max-width: 440px; margin: 0 auto 22px; }

/* Admin tables */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.table th {
  text-align: left;
  padding: 12px 14px;
  background: var(--bg);
  color: var(--dark);
  font-weight: 700;
  border-bottom: 2px solid var(--line);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:hover td { background: #fafbfd; }
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-ok { background: rgba(43,182,115,.14); color: #1c7a4f; }
.badge-warn { background: rgba(226,161,68,.16); color: #a86a13; }

/* Admin tabs */
.tabs { display: flex; gap: 6px; margin-bottom: 22px; flex-wrap: wrap; border-bottom: 2px solid var(--line); }
.tabs a {
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }

.help-block { font-size: 13px; color: var(--muted); margin: 4px 0 14px; }

.row-flex { display: flex; gap: 10px; align-items: center; }
.chip-list { display: flex; flex-direction: column; gap: 8px; }
.chip-row { display: flex; gap: 8px; }
.chip-row input { flex: 1; }

/* Responsive */
@media (max-width: 680px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hero { flex-direction: column; text-align: center; padding: 24px; }
  .hero img.logo { max-width: 160px; margin: 0 auto; }
  .card { padding: 22px 18px; }
  .topbar-inner { flex-wrap: wrap; }
}

/* ---------- Validação e feedback ---------- */
.alert-list { margin: 6px 0 0; padding-left: 18px; font-weight: 500; }
.alert-list li { margin: 2px 0; }
input.invalid, select.invalid, textarea.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(226, 68, 92, .12);
}
.filebox.invalid { border-color: var(--danger); background: rgba(226, 68, 92, .04); }
.filename.bad { color: var(--danger); font-weight: 600; white-space: normal; }
.draft-note { align-items: center; justify-content: space-between; flex-wrap: wrap; }
.draft-note[hidden], #clientErrors[hidden] { display: none; }
.filebox { min-width: 0; }
.filename { min-width: 0; }
@media (max-width: 680px) {
  .filebox { flex-wrap: wrap; }
  .form-actions { flex-direction: column; align-items: stretch; }
  .form-actions .btn { width: 100%; }
}

/* ---------- Backoffice ---------- */
.badge-err { background: rgba(226,68,92,.12); color: #b32741; }
.check-row { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.doc-row { justify-content: space-between; gap: 12px; border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; }
.sub-footer { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.btn:focus-visible, a:focus-visible, select:focus-visible { outline: 3px solid rgba(26,143,227,.45); outline-offset: 2px; }
@media (max-width: 680px) {
  .doc-row { flex-wrap: wrap; }
  .table td, .table th { padding: 10px; }
  .topbar .brand-mini { width: 100%; }
  .topbar-inner { gap: 4px 6px; padding: 8px 12px; }
  .topbar .spacer { display: none; }
  .topbar a.navlink { padding: 6px 9px; font-size: 13px; }
  .topbar .user-chip { padding: 5px 10px; font-size: 12px; margin-left: auto; }
  /* abas: uma linha que desliza na horizontal */
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; gap: 0; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { white-space: nowrap; padding: 10px 12px; font-size: 13px; }
  /* tabelas empilhadas em cartões */
  .table.stack thead { display: none; }
  .table.stack, .table.stack tbody, .table.stack tr, .table.stack td { display: block; width: 100%; }
  .table.stack tr { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
  .table.stack td { border: 0; padding: 4px 0; }
  .table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-bottom: 2px; }
  .table.stack tr:hover td { background: transparent; }
  .table.stack input[type="password"] { max-width: none !important; flex: 1; }
}
