/* =========================================================
   SOS Buddy · base.css
   Cores, fontes, componentes reutilizáveis (botões, cartões,
   campos, selos, janelas, avisos). Usado por todas as páginas.
   ========================================================= */

:root {
  /* Paleta oficial do projeto */
  --navy: #142B4A;
  --blue: #3478F6;
  --blue-ink: #2F6CE0;     /* azul dos botões: mais contraste com texto branco */
  --blue-dark: #1F4FB0;
  --sky: #EAF2FF;
  --white: #FFFFFF;
  --green: #37B879;
  --red: #E74C3C;
  --yellow: #F5B841;

  /* Estados (fundo + texto legível) */
  --ok-bg: #E3F6EC;   --ok-ink: #1D7A4C;
  --warn-bg: #FFF4D6; --warn-ink: #8A5A00;
  --off-bg: #FDECEA;  --off-ink: #B03A2E;
  --danger: #C0392B;
  --danger-line: #F3C4BE;

  /* Superfícies */
  --bg: #F4F7FC;
  --surface: #FFFFFF;
  --surface-2: #F4F7FC;
  --text: #142B4A;
  --text-2: #44546C;
  --muted: #55657D;
  --line: #E3EAF5;
  --field: #DCE6F5;

  --shadow: 0 1px 2px rgba(20, 43, 74, .06);
  --shadow-lg: 0 12px 28px rgba(20, 43, 74, .10);
  --shadow-xl: 0 30px 80px rgba(20, 43, 74, .25);

  --r-lg: 20px;
  --r: 16px;
  --r-sm: 12px;

  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --display: "Nunito", "Trebuchet MS", system-ui, sans-serif;
}

/* Tema escuro (Configurações > Preferências) */
:root[data-theme="dark"] {
  --sky: #1C3355;
  --ok-bg: #133A2A;   --ok-ink: #7FE0AE;
  --warn-bg: #3A2E10; --warn-ink: #F5CD72;
  --off-bg: #3E1C1A;  --off-ink: #FFA59B;
  --danger-line: #6B2B26;
  --bg: #0E1B2E;
  --surface: #16263D;
  --surface-2: #1B2E49;
  --text: #E8EEF7;
  --text-2: #C3CFDF;
  --muted: #A9B7CB;
  --line: #24395A;
  --field: #2E4669;
  --blue-dark: #9EC0FF;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, .35);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--display); line-height: 1.15; margin: 0; }
p { margin: 0; }
img { max-width: 100%; display: block; }
a { color: var(--blue-ink); }
a:hover { color: var(--blue-dark); }
button, input, select, textarea { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

/* Faixa de aviso: o projeto é uma demonstração */
.demo-strip {
  background: #FFF4D6;
  color: #6B4A00;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  padding: 8px 16px;
}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  border-radius: var(--r-sm); border: 1.5px solid transparent;
  font-weight: 600; font-size: 15px; line-height: 1.2;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s ease, transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { flex: 0 0 auto; }

.btn-primary { background: var(--blue-ink); color: #FFFFFF; }
.btn-primary:hover { background: #2559C4; color: #FFFFFF; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--field); }
.btn-ghost:hover { border-color: #B8CBEA; color: var(--text); }
.btn-soft { background: var(--sky); color: var(--blue-dark); }
.btn-soft:hover { color: var(--blue-dark); filter: brightness(.97); }
.btn-danger { background: var(--danger); color: #FFFFFF; }
.btn-danger:hover { background: #A93226; color: #FFFFFF; }
.btn-danger-ghost { background: var(--surface); color: var(--off-ink); border-color: var(--danger-line); }
.btn-danger-ghost:hover { background: var(--off-bg); color: var(--off-ink); }
.btn-link { background: none; border: 0; color: var(--blue-ink); padding: 0 6px; min-height: 40px; }
.btn-lg { min-height: 52px; padding: 0 26px; font-size: 16px; border-radius: 14px; font-weight: 700; }
.btn-block { width: 100%; }
.btn-icon { width: 44px; padding: 0; }

/* ---------- Cartões ---------- */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card-title { font-size: 19px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.lift { transition: transform .2s ease, box-shadow .2s ease; }
.lift:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

/* ---------- Selos de estado ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 700; line-height: 1;
  padding: 6px 10px; border-radius: 999px; white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; }
.badge-ok { background: var(--ok-bg); color: var(--ok-ink); }      .badge-ok .dot { background: var(--green); }
.badge-warn { background: var(--warn-bg); color: var(--warn-ink); } .badge-warn .dot { background: var(--yellow); }
.badge-off { background: var(--off-bg); color: var(--off-ink); }   .badge-off .dot { background: var(--red); }
.badge-info { background: var(--sky); color: var(--blue-dark); }    .badge-info .dot { background: var(--blue); }
.badge-muted { background: var(--surface-2); color: var(--muted); } .badge-muted .dot { background: var(--muted); }

/* ---------- Avatares ---------- */
.avatar {
  flex: 0 0 auto;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-family: var(--display); font-weight: 900; color: #142B4A;
  overflow: hidden; background: #DDEBFF;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Campos de formulário ---------- */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 600; min-width: 0; }
.input {
  width: 100%;
  min-height: 46px;
  border: 1.5px solid var(--field);
  border-radius: var(--r-sm);
  padding: 11px 14px;
  background: var(--surface);
  color: var(--text);
  font-weight: 400; font-size: 15px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(52, 120, 246, .2); }
.input[readonly] { background: var(--surface-2); color: var(--muted); }
textarea.input { resize: vertical; min-height: 90px; }
.input.invalid { border-color: var(--red); }
.field-error { color: var(--off-ink); font-size: 13px; font-weight: 500; }
.field-hint { color: var(--muted); font-size: 13px; font-weight: 400; }
.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; font-weight: 500; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--blue-ink); flex: 0 0 auto; }

/* Interruptor liga/desliga */
.switch {
  flex: 0 0 auto;
  width: 52px; height: 30px; padding: 3px;
  border: 0; border-radius: 15px;
  background: #C4CFDF; cursor: pointer;
  transition: background .2s ease;
}
.switch::after {
  content: ""; display: block; width: 24px; height: 24px; border-radius: 50%;
  background: #FFFFFF; box-shadow: 0 1px 3px rgba(20, 43, 74, .3);
  transition: transform .2s ease;
}
.switch[aria-checked="true"] { background: var(--blue-ink); }
.switch[aria-checked="true"]::after { transform: translateX(22px); }

/* Escolha de avatar */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch {
  width: 38px; height: 38px; border-radius: 50%;
  border: 3px solid var(--surface); box-shadow: 0 0 0 1.5px var(--field);
  cursor: pointer;
}
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--blue-ink); }

/* ---------- Janelas (modal) ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 43, 74, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 48px 16px; overflow-y: auto;
  animation: fade .2s ease;
}
.modal {
  width: 640px; max-width: 100%;
  background: var(--surface); color: var(--text);
  border-radius: 24px; padding: 28px;
  box-shadow: var(--shadow-xl);
  animation: pop .28s cubic-bezier(.2, .9, .3, 1.2);
}
.modal-sm { width: 440px; margin-top: 10vh; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.modal-head h2 { font-size: 24px; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; margin-top: 22px; }
.modal-close {
  width: 40px; height: 40px; border-radius: 10px; border: 0;
  background: var(--surface-2); color: var(--text); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}

.confirm { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; }
.confirm h2 { font-size: 22px; }
.confirm p { color: var(--text-2); }
.confirm .row { display: flex; gap: 10px; width: 100%; margin-top: 8px; }
.confirm .row .btn { flex: 1 1 0; }
.confirm-icon {
  width: 56px; height: 56px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--warn-bg); color: var(--warn-ink);
}
.confirm-icon.danger { background: var(--off-bg); color: var(--off-ink); }

/* Passo a passo de instalação no iPhone */
.ios-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.ios-steps li { display: flex; gap: 12px; align-items: flex-start; font-size: 15px; line-height: 1.5; }
.ios-steps li svg { vertical-align: -3px; color: var(--blue-ink); }
.ios-steps .n { flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%; background: var(--sky); color: var(--blue-dark); font-weight: 800; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- Avisos (toast) ---------- */
.toast-stack {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  max-width: 360px;
  background: #142B4A; color: #FFFFFF;
  border-radius: 14px; padding: 13px 16px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 16px 40px rgba(20, 43, 74, .25);
  font-size: 14px; font-weight: 500;
  animation: pop .3s cubic-bezier(.2, .9, .3, 1.2);
}
.toast .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; background: var(--blue); }
.toast.ok .dot { background: var(--green); }
.toast.warn .dot { background: var(--yellow); }
.toast.error .dot, .toast.sos .dot { background: var(--red); }
.toast.leaving { opacity: 0; transform: translateY(8px); transition: all .25s ease; }

/* ---------- Animações ---------- */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: scale(.94); } to { opacity: 1; transform: scale(1); } }
@keyframes pulse-red {
  0% { box-shadow: 0 0 0 0 rgba(231, 76, 60, .5); }
  70% { box-shadow: 0 0 0 20px rgba(231, 76, 60, 0); }
  100% { box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}
@keyframes spin { to { transform: rotate(360deg); } }
.pulse { animation: pulse-red 2.2s ease-out infinite; border-radius: 50%; }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid #C9D8F2; border-top-color: var(--blue-ink);
  animation: spin 1s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media (max-width: 560px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .modal { padding: 22px; border-radius: 20px; }
  .modal-backdrop { padding: 16px; }
  .toast-stack { left: 16px; right: 16px; bottom: 88px; align-items: stretch; }
  .toast { max-width: none; }
}
