/* ===========================================================================
   CardioSim by Francisco Silva — DESIGN SYSTEM
   Fase 0 · Fundações visuais
   ---------------------------------------------------------------------------
   Estética: clínico escuro premium (grafite/preto + acentos néon clínicos).
   Tipografia: Geist (Sans + Mono), incorporada localmente (offline).
   Todos os tokens são variáveis CSS para coerência total entre páginas.
   =========================================================================== */

/* ---------- Tipografia incorporada (offline, sem CDN) ---------- */
@font-face {
  font-family: 'Geist';
  src: url('../fonts/Geist-Variable.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('../fonts/GeistMono-Variable.woff2') format('woff2-variations');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ===========================================================================
   TOKENS
   =========================================================================== */
:root {
  /* — Fundos (profundidade em camadas) — */
  --bg-base:     #070A0F;   /* fundo da aplicação */
  --bg-sunken:   #05070B;   /* poços profundos: canvas do monitor */
  --surface-1:   #0E131B;   /* cartões e painéis */
  --surface-2:   #141A24;   /* elementos elevados, campos */
  --surface-3:   #1B2330;   /* hover / ativo */
  --surface-4:   #232D3C;   /* realce subtil */

  /* — Linhas e contornos — */
  --line:        #1C242F;
  --line-strong: #2A3441;
  --hairline:    rgba(255,255,255,0.06);

  /* — Texto — */
  --text-hi:     #ECF1F8;   /* títulos, valores */
  --text-mid:    #9AA7B8;   /* corpo */
  --text-lo:     #5E6C7E;   /* rótulos secundários */
  --text-faint:  #3C4754;   /* placeholders, desativado */

  /* — Acento de assinatura (néon clínico) — */
  --accent:        #00E6A0;
  --accent-press:  #00C98C;
  --accent-soft:   rgba(0,230,160,0.12);
  --accent-line:   rgba(0,230,160,0.40);
  --accent-2:      #2BD7F5;
  --accent-2-soft: rgba(43,215,245,0.12);

  /* — Cores convencionais de monitor (curvas/valores) — */
  --ecg:   #3DF58A;   /* ECG verde */
  --pa:    #FF5C66;   /* pressão arterial vermelho */
  --spo2:  #2FD4F5;   /* SpO2 ciano */
  --co2:   #F5D33D;   /* EtCO2 amarelo */
  --temp:  #B79BFF;   /* temperatura lilás */
  --resp:  #E8EEF6;   /* respiração branco */

  /* — Estado / alarme — */
  --ok:        #2BE5A6;
  --warn:      #FFB13C;
  --warn-soft: rgba(255,177,60,0.12);
  --crit:      #FF4D5E;
  --crit-soft: rgba(255,77,94,0.14);

  /* — Raios — */
  --r-xs: 6px;
  --r-sm: 9px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-pill: 999px;

  /* — Sombras e brilhos — */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.40);
  --shadow-md: 0 8px 28px rgba(0,0,0,0.38);
  --shadow-lg: 0 22px 60px rgba(0,0,0,0.55);
  --glow-accent: 0 0 0 1px var(--accent-line), 0 0 26px rgba(0,230,160,0.22);
  --glow-crit:   0 0 0 1px rgba(255,77,94,0.5), 0 0 26px rgba(255,77,94,0.28);

  /* — Tipografia — */
  --font-sans: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, 'SF Mono', monospace;

  --fs-display: 40px;
  --fs-h1: 28px;
  --fs-h2: 20px;
  --fs-h3: 16px;
  --fs-body: 14px;
  --fs-sm: 13px;
  --fs-xs: 12px;
  --fs-micro: 11px;

  /* — Espaçamento (base 4px) — */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-7: 32px; --sp-8: 48px;

  /* — Movimento — */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --t-fast: 120ms;
  --t: 200ms;
  --t-slow: 320ms;
}

/* ===========================================================================
   RESET E BASE
   =========================================================================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* O atributo HTML [hidden] tem de vencer SEMPRE qualquer display de classe.
   Sem isto, elementos como .vp-fundo (display:flex) ou .rc-editor (display:grid)
   ignoram o atributo hidden e aparecem indevidamente. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  background: var(--bg-base);
  color: var(--text-mid);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.5;
  font-feature-settings: "cv01", "ss01", "tnum";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { color: var(--text-hi); font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; color: inherit; }
::selection { background: var(--accent-soft); color: var(--accent); }

input[type=number] { -moz-appearance: textfield; appearance: textfield; }
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Scrollbar discreta */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: var(--r-pill); border: 3px solid var(--bg-base); }
::-webkit-scrollbar-thumb:hover { background: var(--surface-4); }

/* ===========================================================================
   UTILITÁRIOS
   =========================================================================== */
.micro {
  font-family: var(--font-mono);
  font-size: var(--fs-micro);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-lo);
}
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tnum { font-variant-numeric: tabular-nums; }
.txt-hi { color: var(--text-hi); }
.txt-mid { color: var(--text-mid); }
.txt-lo { color: var(--text-lo); }

/* ===========================================================================
   MARCA
   =========================================================================== */
.marca { display: inline-flex; align-items: center; gap: var(--sp-3); }
.marca-sinal {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 14px 1px rgba(0,230,160,0.6);
  animation: bpm 2.4s var(--ease) infinite;
}
.marca-nome {
  font-size: var(--fs-h2); font-weight: 600; letter-spacing: 0.18em; color: var(--text-hi);
}
.marca-nome em { color: var(--accent); font-style: normal; }
.marca-autor {
  font-family: var(--font-mono); font-size: var(--fs-micro);
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--text-lo);
}
@keyframes bpm { 0%,100% { transform: scale(1); opacity: 1; } 18% { transform: scale(1.5); opacity: 0.7; } 36% { transform: scale(1); opacity: 1; } }

/* ===========================================================================
   BOTÕES
   =========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 44px; padding: 0 var(--sp-5);
  border-radius: var(--r-md);
  font-size: var(--fs-body); font-weight: 500; letter-spacing: 0.01em;
  white-space: nowrap;
  transition: background var(--t-fast) var(--ease), border-color var(--t-fast), transform var(--t-fast), box-shadow var(--t);
  border: 1px solid transparent;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

.btn-primario { background: var(--accent); color: #04140E; font-weight: 600; }
.btn-primario:hover { background: var(--accent-press); box-shadow: 0 0 24px rgba(0,230,160,0.28); }

.btn-secundario { background: var(--surface-2); color: var(--text-hi); border-color: var(--line-strong); }
.btn-secundario:hover { background: var(--surface-3); border-color: var(--surface-4); }

.btn-fantasma { background: transparent; color: var(--text-mid); border-color: var(--line); }
.btn-fantasma:hover { background: var(--surface-2); color: var(--text-hi); }

.btn-perigo { background: var(--crit); color: #240A0C; font-weight: 600; }
.btn-perigo:hover { background: #ff6470; box-shadow: 0 0 24px rgba(255,77,94,0.3); }

.btn-aviso { background: var(--warn); color: #211400; font-weight: 600; }
.btn-aviso:hover { background: #ffc05e; }

.btn-sm { height: 34px; padding: 0 var(--sp-3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-lg { height: 52px; padding: 0 var(--sp-6); font-size: var(--fs-h3); }
.btn[disabled] { opacity: 0.4; pointer-events: none; }

/* ===========================================================================
   CAMPOS DE FORMULÁRIO
   =========================================================================== */
.campo { display: flex; flex-direction: column; gap: var(--sp-2); }
.campo-rotulo {
  font-family: var(--font-mono); font-size: var(--fs-micro);
  letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-lo);
}
.input, .select, .textarea {
  height: 44px; padding: 0 var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  color: var(--text-hi); font-size: var(--fs-body);
  transition: border-color var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
  width: 100%;
}
.textarea { height: auto; padding: var(--sp-3) var(--sp-4); resize: vertical; min-height: 88px; }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--surface-4); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface-1);
}
.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='%235E6C7E' stroke-width='2.5'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right var(--sp-4) center;
  padding-right: var(--sp-7);
  cursor: pointer;
}

/* ===========================================================================
   INTERRUPTOR (switch)
   =========================================================================== */
.switch { position: relative; display: inline-block; width: 48px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .trilho {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--surface-3); border: 1px solid var(--line-strong);
  border-radius: var(--r-pill); transition: all var(--t) var(--ease);
}
.switch .trilho::before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: var(--text-lo); border-radius: 50%; transition: all var(--t) var(--ease);
}
.switch input:checked + .trilho { background: var(--accent-soft); border-color: var(--accent-line); }
.switch input:checked + .trilho::before { transform: translateX(20px); background: var(--accent); box-shadow: 0 0 12px rgba(0,230,160,0.6); }

/* ===========================================================================
   CONTROLO SEGMENTADO
   =========================================================================== */
.segmentado {
  display: inline-flex; padding: 4px; gap: 4px;
  background: var(--surface-1); border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.segmentado button {
  height: 34px; padding: 0 var(--sp-4);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-lo);
  transition: all var(--t-fast) var(--ease);
}
.segmentado button:hover { color: var(--text-hi); }
.segmentado button.ativo { background: var(--surface-3); color: var(--text-hi); box-shadow: var(--shadow-sm); }

/* ===========================================================================
   SLIDER (range)
   =========================================================================== */
.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: var(--r-pill); background: var(--surface-3); outline: none; }
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 3px solid var(--bg-base);
  box-shadow: 0 0 10px rgba(0,230,160,0.5);
}
.slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: var(--accent);
  cursor: pointer; border: 3px solid var(--bg-base);
}

/* ===========================================================================
   CARTÕES E PAINÉIS
   =========================================================================== */
.cartao {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
}
.cartao-elevado { box-shadow: var(--shadow-md); }
.painel {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.painel-cabecalho {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
}

/* ===========================================================================
   BADGES / CHIPS / ESTADO
   =========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 var(--sp-3);
  border-radius: var(--r-pill);
  font-family: var(--font-mono); font-size: var(--fs-micro);
  letter-spacing: 0.1em; text-transform: uppercase;
  background: var(--surface-2); color: var(--text-mid); border: 1px solid var(--line-strong);
}
.badge-ok   { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.badge-aviso{ background: var(--warn-soft); color: var(--warn); border-color: rgba(255,177,60,0.4); }
.badge-crit { background: var(--crit-soft); color: var(--crit); border-color: rgba(255,77,94,0.5); }

.ponto { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.ponto-ok   { background: var(--ok); box-shadow: 0 0 8px rgba(43,229,166,0.7); }
.ponto-aviso{ background: var(--warn); }
.ponto-crit { background: var(--crit); box-shadow: 0 0 8px rgba(255,77,94,0.7); animation: pisca 1s steps(1) infinite; }
.ponto-off  { background: var(--text-faint); }
@keyframes pisca { 50% { opacity: 0.25; } }

/* ===========================================================================
   SEPARADORES (tabs)
   =========================================================================== */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); }
.tab {
  position: relative; padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm); font-weight: 500; color: var(--text-lo);
  border-bottom: 2px solid transparent; transition: color var(--t-fast);
}
.tab:hover { color: var(--text-hi); }
.tab.ativo { color: var(--accent); border-bottom-color: var(--accent); }

/* ===========================================================================
   AZULEJO DE SINAL VITAL (valor numérico estilo monitor)
   =========================================================================== */
.vital {
  position: relative; padding: var(--sp-4);
  background: var(--surface-1); border: 1px solid var(--line);
  border-radius: var(--r-md); overflow: hidden;
}
.vital::before { content: ""; position: absolute; left: 0; top: var(--sp-3); bottom: var(--sp-3); width: 3px; border-radius: 0 2px 2px 0; }
.vital-rotulo { display: flex; align-items: baseline; gap: 6px; font-family: var(--font-mono); font-size: var(--fs-micro); letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-lo); }
.vital-valor { font-family: var(--font-mono); font-weight: 600; font-size: 44px; line-height: 1; font-variant-numeric: tabular-nums; margin-top: 4px; }
.vital-fc::before    { background: var(--ecg); }   .vital-fc .vital-valor    { color: var(--ecg); }
.vital-pa::before    { background: var(--pa); }    .vital-pa .vital-valor    { color: var(--pa); }
.vital-spo2::before  { background: var(--spo2); }  .vital-spo2 .vital-valor  { color: var(--spo2); }
.vital-co2::before   { background: var(--co2); }   .vital-co2 .vital-valor   { color: var(--co2); }
.vital-temp::before  { background: var(--temp); }  .vital-temp .vital-valor  { color: var(--temp); }

/* ===========================================================================
   GRELHA DE ECG (fundo do monitor)
   =========================================================================== */
.grelha-ecg {
  background-color: var(--bg-sunken);
  background-image:
    linear-gradient(rgba(255,90,96,0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,90,96,0.07) 1px, transparent 1px),
    linear-gradient(rgba(255,90,96,0.16) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,90,96,0.16) 1px, transparent 1px);
  background-size: 8px 8px, 8px 8px, 40px 40px, 40px 40px;
}

/* ===========================================================================
   AVISO RODAR DISPOSITIVO
   =========================================================================== */
.aviso-rodar { display: none; }
@media (max-width: 920px) and (orientation: portrait) {
  .so-horizontal { display: none !important; }
  .aviso-rodar {
    display: flex; position: fixed; inset: 0; z-index: 999;
    flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-5);
    background: var(--bg-base); text-align: center; padding: var(--sp-6);
  }
}

/* ===========================================================================
   FASE 5E — Alarmes visuais (valores fora de referência piscam)
   =========================================================================== */
@keyframes alarmePisca {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.25; }
}
@keyframes alarmePiscaFundo {
  0%, 100% { background: var(--surface-2); }
  50%      { background: rgba(245,160,61,0.18); }
}
@keyframes alarmePiscaFundoGrave {
  0%, 100% { background: var(--surface-2); }
  50%      { background: rgba(255,92,102,0.22); }
}
/* Nível 1 (ligeiro) — âmbar */
.alarme-1 .valor, .alarme-1 .fm-valor { color: #F5A03D !important; animation: alarmePisca 1s ease-in-out infinite; }
.alarme-1 { animation: alarmePiscaFundo 1s ease-in-out infinite; }
/* Nível 2 (grave) — vermelho, mais rápido */
.alarme-2 .valor, .alarme-2 .fm-valor { color: #FF5C66 !important; animation: alarmePisca 0.6s ease-in-out infinite; }
.alarme-2 { animation: alarmePiscaFundoGrave 0.6s ease-in-out infinite; }

/* Indicador de alarme global no topo */
.alarme-banner {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: var(--r-pill);
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.16em;
  text-transform: uppercase; font-weight: 600;
}
.alarme-banner.nivel-1 { background: rgba(245,160,61,0.14); color: #F5A03D; border: 1px solid rgba(245,160,61,0.4); }
.alarme-banner.nivel-2 { background: rgba(255,92,102,0.16); color: #FF5C66; border: 1px solid rgba(255,92,102,0.5); animation: alarmePisca 0.8s ease-in-out infinite; }
