/* BraSCORE - sistema de design.
   Paleta alinhada ao logotipo (indigo -> azul -> teal -> verde).
   Componentes utilitarios, sem dependencia de framework externo.
*/

:root {
  /* Cores da marca */
  --bs-indigo:  #312783;
  --bs-blue:    #1F60D6;
  --bs-teal:    #15A8A0;
  --bs-green:   #23B36B;

  /* Estados */
  --bs-primary: #1F60D6;
  --bs-accent:  #23B36B;
  --bs-warn:    #F59E0B;
  --bs-error:   #DC2626;
  --bs-success: #15803D;

  /* Superficies */
  --bs-bg:      #F4F7FB;
  --bs-card:    #FFFFFF;
  --bs-border:  #E5E7EB;
  --bs-divider: #EEF2F7;

  /* Texto */
  --bs-text:    #0F172A;
  --bs-muted:   #64748B;
  --bs-soft:    #94A3B8;

  /* Sombra */
  --bs-shadow-sm: 0 1px 2px rgba(15,23,42,.04), 0 1px 3px rgba(15,23,42,.06);
  --bs-shadow-md: 0 2px 6px rgba(15,23,42,.06), 0 6px 16px rgba(15,23,42,.08);

  /* Raios */
  --bs-r-sm: 8px;
  --bs-r-md: 12px;
  --bs-r-lg: 16px;
  --bs-r-pill: 999px;

  /* Gradiente da marca */
  --bs-gradient: linear-gradient(135deg, #312783 0%, #1F60D6 45%, #15A8A0 80%, #23B36B 100%);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  background: var(--bs-bg);
  color: var(--bs-text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--bs-primary); text-decoration: none; transition: color .15s ease; }
a:hover { color: var(--bs-indigo); text-decoration: underline; }

h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; margin: 0 0 6px; color: var(--bs-text); }
h2 { font-size: 1.15rem; font-weight: 600; letter-spacing: -.01em; margin: 0 0 10px; color: var(--bs-text); }
h3 { font-size: .95rem; font-weight: 600; margin: 0 0 6px; color: var(--bs-text); }

p { margin: 0 0 10px; }

/* -------------------------------------------------------------------
   Topbar
   ------------------------------------------------------------------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 28px;
  background: var(--bs-gradient);
  color: #fff;
  box-shadow: 0 2px 8px rgba(15,23,42,.08);
  position: sticky;
  top: 0;
  z-index: 50;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
}
.brand:hover { text-decoration: none; color: #fff; }
.logo-mark {
  width: 38px;
  height: 38px;
  background: #fff;
  border-radius: 10px;
  padding: 4px;
  display: block;
  box-shadow: 0 1px 3px rgba(15,23,42,.18);
}
.logo-text {
  font-weight: 700;
  letter-spacing: .3px;
  font-size: 1.1rem;
}

.nav { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.nav a {
  color: rgba(255,255,255,.86);
  font-size: .88rem;
  padding: 7px 11px;
  border-radius: var(--bs-r-sm);
  transition: background .15s ease, color .15s ease;
}
.nav a:hover {
  color: #fff;
  background: rgba(255,255,255,.12);
  text-decoration: none;
}
.nav .who {
  color: rgba(255,255,255,.7);
  font-size: .78rem;
  padding: 0 8px;
  border-left: 1px solid rgba(255,255,255,.22);
  margin-left: 4px;
}

/* Sino de notificacoes */
.bell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 9px;
  border-radius: var(--bs-r-sm);
  background: rgba(255,255,255,.1);
  transition: background .15s ease;
}
.bell:hover { background: rgba(255,255,255,.18); text-decoration: none; }
.bell-icon { font-size: 1rem; color: #fff; }
.bell-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  background: var(--bs-error);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  border-radius: var(--bs-r-pill);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 2px var(--bs-blue);
}

/* -------------------------------------------------------------------
   Layout
   ------------------------------------------------------------------- */

.container {
  max-width: 1200px;
  margin: 28px auto;
  padding: 0 24px;
}

.page-header { margin: 6px 0 20px; }
.page-header .subtitle {
  color: var(--bs-muted);
  font-size: .9rem;
  max-width: 780px;
  margin-top: 4px;
}
.page-header .actions-bar,
.page-header .actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card {
  background: var(--bs-card);
  border-radius: var(--bs-r-md);
  padding: 22px 24px;
  box-shadow: var(--bs-shadow-sm);
  border: 1px solid var(--bs-border);
  margin-bottom: 18px;
  transition: box-shadow .2s ease;
}
.card:hover { box-shadow: var(--bs-shadow-md); }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
  flex-wrap: wrap;
}
.card.center { max-width: 480px; margin: 60px auto; }

.muted { color: var(--bs-muted); font-size: .88rem; }

/* -------------------------------------------------------------------
   Login
   ------------------------------------------------------------------- */

.login-card { max-width: 440px; margin: 60px auto; }
.login-hero { text-align: center; margin-bottom: 22px; }
.login-logo { width: 90px; height: 90px; margin: 0 auto 14px; display: block; }
.login-hero h1 { font-size: 1.5rem; }
.login-hero p { color: var(--bs-muted); font-size: .85rem; }

/* -------------------------------------------------------------------
   Forms
   ------------------------------------------------------------------- */

form label {
  display: block;
  margin: 12px 0;
  font-size: .82rem;
  color: var(--bs-text);
  font-weight: 500;
}
form label.inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 16px;
  font-weight: 400;
}
form label small {
  display: block;
  color: var(--bs-muted);
  font-weight: 400;
  margin-top: 3px;
  font-size: .75rem;
}

form input,
form select,
form textarea {
  display: block;
  width: 100%;
  padding: 9px 12px;
  margin-top: 4px;
  border-radius: var(--bs-r-sm);
  border: 1px solid var(--bs-border);
  background: #fff;
  font-size: .92rem;
  color: var(--bs-text);
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}
form input:focus,
form select:focus,
form textarea:focus {
  outline: none;
  border-color: var(--bs-primary);
  box-shadow: 0 0 0 3px rgba(31,96,214,.15);
}
form input[type=checkbox] {
  width: auto;
  display: inline-block;
  margin: 0;
}
form textarea { resize: vertical; min-height: 70px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
}
.form-grid label.full { grid-column: 1 / -1; }
.form-actions {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* -------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------- */

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #fff;
  color: var(--bs-text);
  padding: 8px 14px;
  border-radius: var(--bs-r-sm);
  border: 1px solid var(--bs-border);
  cursor: pointer;
  font-size: .88rem;
  font-weight: 500;
  text-decoration: none;
  font-family: inherit;
  transition: background .15s ease, border-color .15s ease, transform .05s ease, box-shadow .15s ease;
  box-shadow: 0 1px 2px rgba(15,23,42,.04);
}
button:hover,
.btn:hover {
  background: #F8FAFC;
  border-color: #CBD5E1;
  text-decoration: none;
  color: var(--bs-text);
}
button:active,
.btn:active { transform: translateY(1px); }
button:disabled,
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn.primary {
  background: var(--bs-primary);
  border-color: var(--bs-primary);
  color: #fff;
}
.btn.primary:hover {
  background: #1A52BB;
  border-color: #1A52BB;
  color: #fff;
}

.btn.ok,
.btn.success {
  background: var(--bs-success);
  border-color: var(--bs-success);
  color: #fff;
}
.btn.ok:hover { background: #126633; border-color: #126633; color: #fff; }

.btn.warning {
  background: var(--bs-warn);
  border-color: var(--bs-warn);
  color: #fff;
}
.btn.warning:hover { background: #D87A07; border-color: #D87A07; color: #fff; }

.btn.danger {
  background: var(--bs-error);
  border-color: var(--bs-error);
  color: #fff;
}

.btn.small { font-size: .78rem; padding: 5px 10px; }

/* -------------------------------------------------------------------
   Tables
   ------------------------------------------------------------------- */

table,
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 6px;
  background: var(--bs-card);
  border-radius: var(--bs-r-md);
  overflow: hidden;
  font-size: .88rem;
}
th, td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--bs-divider);
  vertical-align: middle;
}
th {
  background: #F8FAFC;
  color: var(--bs-muted);
  font-weight: 600;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
tbody tr {
  transition: background .12s ease;
}
tbody tr:hover { background: #FAFBFD; }
tbody tr:last-child td { border-bottom: none; }

/* -------------------------------------------------------------------
   Filtros
   ------------------------------------------------------------------- */

.filters,
.filters-bar,
.filters-panel {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: #F8FAFC;
  border-radius: var(--bs-r-md);
  border: 1px solid var(--bs-border);
}
.filters select,
.filters input,
.filters-bar select,
.filters-bar input,
.filters-panel select,
.filters-panel input {
  padding: 7px 10px;
  border-radius: var(--bs-r-sm);
  border: 1px solid var(--bs-border);
  min-width: 160px;
  background: #fff;
  font-size: .85rem;
}

/* -------------------------------------------------------------------
   Badges, pills, alertas
   ------------------------------------------------------------------- */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--bs-r-pill);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
}
.badge.ok    { background: #DCFCE7; color: #166534; }
.badge.warn  { background: #FEF3C7; color: #92400E; }
.badge.err   { background: #FEE2E2; color: #991B1B; }
.badge.info  { background: #DBEAFE; color: #1E40AF; }

.alert {
  padding: 11px 14px;
  border-radius: var(--bs-r-sm);
  font-size: .88rem;
  margin-top: 12px;
  border: 1px solid transparent;
}
.alert.success { background: #ECFDF5; color: #166534; border-color: #BBF7D0; }
.alert.error   { background: #FEF2F2; color: #991B1B; border-color: #FECACA; }
.alert.warning { background: #FFFBEB; color: #92400E; border-color: #FDE68A; }

/* Pílulas de stage (auditoria) */
.stage { display: inline-block; padding: 3px 10px; border-radius: var(--bs-r-pill); font-size: .72rem; font-weight: 500; }
.stage-aberto             { background: #F1F5F9; color: #475569; }
.stage-revisado_coletador { background: #E0E7FF; color: #3730A3; }
.stage-revisado_centro    { background: #DBEAFE; color: #1E40AF; }
.stage-auditado_global    { background: #DCFCE7; color: #15803D; }
.stage-devolvido_coletador{ background: #FEF3C7; color: #92400E; }

/* -------------------------------------------------------------------
   Cards de KPI / stat
   ------------------------------------------------------------------- */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-bottom: 6px;
}
.stat-card {
  padding: 16px 18px;
  background: #fff;
  border-radius: var(--bs-r-md);
  border: 1px solid var(--bs-border);
  box-shadow: var(--bs-shadow-sm);
}
.stat-card.warn { background: #FFFBEB; border-color: #FDE68A; }
.stat-card.ok   { background: #F0FDF4; border-color: #BBF7D0; }
.stat-card h3 {
  font-size: .75rem;
  margin: 0 0 6px;
  color: var(--bs-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.stat-big {
  font-size: 1.9rem;
  font-weight: 700;
  margin: 0;
  color: var(--bs-text);
  line-height: 1.1;
  letter-spacing: -.02em;
}

/* -------------------------------------------------------------------
   Cards de telas (patient_detail)
   ------------------------------------------------------------------- */

.screens-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.screen-card {
  display: block;
  padding: 16px 18px;
  border: 1px solid var(--bs-border);
  border-radius: var(--bs-r-md);
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition: transform .12s ease, box-shadow .18s ease, border-color .15s ease;
}
.screen-card:hover {
  transform: translateY(-2px);
  text-decoration: none;
  box-shadow: var(--bs-shadow-md);
  border-color: #CBD5E1;
}
.screen-card.concluido { border-color: #BBF7D0; background: #F0FDF4; }
.screen-card-head {
  display: flex;
  justify-content: space-between;
  font-size: .72rem;
  color: var(--bs-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.screen-card-status { font-weight: 600; }
.screen-card.concluido .screen-card-status { color: var(--bs-success); }
.screen-card h3 { margin: 10px 0 12px; font-size: 1rem; }

/* Barra de progresso */
.bar {
  height: 6px;
  background: #EEF2F7;
  border-radius: var(--bs-r-pill);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--bs-gradient);
  border-radius: var(--bs-r-pill);
  transition: width .3s ease;
}
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-row .pct {
  font-size: .76rem;
  color: var(--bs-muted);
  min-width: 38px;
  text-align: right;
}
.bar-row .bar { flex: 1; min-width: 120px; }

/* -------------------------------------------------------------------
   Auditoria / lista de pacientes
   ------------------------------------------------------------------- */

.list-header h1 { margin: 0 0 4px; }
.list-header .muted { margin: 0 0 14px; }
.alert-pill {
  display: inline-block;
  min-width: 26px;
  padding: 2px 8px;
  background: #FEF3C7;
  color: #92400E;
  border-radius: var(--bs-r-pill);
  font-size: .78rem;
  font-weight: 600;
  text-align: center;
}
.dot-ok { color: var(--bs-success); font-weight: 700; }

/* Tela genérica de formulario clinico */
.screen-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.screen-field.required > input,
.screen-field.required > select {
  border-color: var(--bs-primary);
}
.screen-field.custom { background: #FAFBFD; padding: 8px 10px; border-radius: var(--bs-r-sm); }
.section-sep {
  grid-column: 1 / -1;
  margin: 12px 0 4px;
  padding-top: 10px;
  border-top: 1px dashed var(--bs-border);
  font-size: .92rem;
  color: var(--bs-muted);
  font-weight: 600;
}

/* -------------------------------------------------------------------
   Modal
   ------------------------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}
/* CSS author override do atributo [hidden]: como .modal define display:flex,
   precisamos garantir que [hidden] de fato esconda o elemento. */
.modal[hidden] { display: none !important; }
.modal-content {
  background: #fff;
  border-radius: var(--bs-r-lg);
  padding: 24px;
  max-width: 520px;
  width: 92%;
  box-shadow: 0 12px 40px rgba(15,23,42,.25);
}
.modal-content h2 { margin-top: 0; }
.modal-content textarea {
  width: 100%;
  padding: 11px;
  border-radius: var(--bs-r-sm);
  border: 1px solid var(--bs-border);
  margin-top: 10px;
}

/* -------------------------------------------------------------------
   Chips de fatores (padrao reutilizado em Fatores de risco, Estado
   cardiaco, CEC, Pos-op, Seguimento 30d)
   ------------------------------------------------------------------- */

.factors-chips { display: flex; flex-direction: column; gap: 10px; min-height: 60px; }
.empty-msg { padding: 16px; text-align: center; background: #FAFBFD;
             border: 1px dashed var(--bs-border); border-radius: var(--bs-r-md);
             color: var(--bs-muted); }
.factor-chip { background: #F0FDF4; border: 1px solid #BBF7D0;
               border-radius: var(--bs-r-md); padding: 12px 14px;
               box-shadow: var(--bs-shadow-sm); }
.factor-chip .chip-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.factor-chip .chip-detail { margin-top: 6px; font-size: .82rem; color: var(--bs-muted); }
.chip-action { margin-left: auto; background: transparent; border: none;
               color: var(--bs-primary); cursor: pointer; font-size: .8rem;
               padding: 4px 10px; border-radius: 6px; font-weight: 600;
               transition: background .15s ease; }
.chip-action.danger { color: var(--bs-error); }
.chip-action:hover { background: rgba(31,96,214,.08); }
.chip-action.danger:hover { background: rgba(220,38,38,.08); }

.modal-wide .modal-content { max-width: 720px; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
               gap: 10px; margin: 14px 0; max-height: 55vh; overflow-y: auto;
               padding: 4px; }
.picker-item { text-align: left; padding: 12px 14px; border: 1px solid var(--bs-border);
               border-radius: var(--bs-r-md); background: #fff; cursor: pointer;
               display: flex; flex-direction: column; gap: 4px;
               transition: all .12s ease; }
.picker-item:hover { border-color: var(--bs-primary); background: #EFF6FF;
                     transform: translateY(-1px); box-shadow: var(--bs-shadow-sm); }
.picker-item.compound { border-left: 3px solid var(--bs-accent); }
.picker-label { font-weight: 600; color: var(--bs-text); }

/* -------------------------------------------------------------------
   Choice grid (radio/checkbox em cards) reutilizado em Tela 6 (CEC),
   Tela 7 (Pos-op transfusoes), Tela 9 (Tipo de seguimento)
   ------------------------------------------------------------------- */

.cec-choice { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
              gap: 10px; }
.proc-chip { display: flex; align-items: center; gap: 8px; padding: 12px 14px;
             border: 1px solid var(--bs-border); border-radius: var(--bs-r-md);
             background: #fff; cursor: pointer; transition: all .15s ease; }
.proc-chip:hover { border-color: var(--bs-primary); }
.proc-chip:has(input:checked) { border-color: var(--bs-primary); background: #EFF6FF;
                                box-shadow: 0 0 0 2px rgba(31,96,214,.15); }

.req { color: var(--bs-error); font-weight: 700; }

/* -------------------------------------------------------------------
   Indicador de progresso de telas (badge no canto superior da pagina)
   ------------------------------------------------------------------- */

.screen-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: var(--bs-r-pill);
  background: var(--bs-gradient); color: #fff;
  font-size: .78rem; font-weight: 600; letter-spacing: .03em;
  box-shadow: var(--bs-shadow-sm); margin-bottom: 10px;
}
.screen-pill::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: rgba(255,255,255,.85);
}

/* Variavel STS exibida em codigo */
.var-code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: .76rem; color: var(--bs-muted); background: #F1F5F9;
  border-radius: 4px; padding: 1px 6px; margin-left: 4px;
}

/* -------------------------------------------------------------------
   Footer
   ------------------------------------------------------------------- */

.footer {
  text-align: center;
  padding: 26px 20px;
  color: var(--bs-soft);
  font-size: .78rem;
  border-top: 1px solid var(--bs-divider);
  background: #fff;
  margin-top: 30px;
}
.footer small { display: block; max-width: 760px; margin: 12px auto 0; line-height: 1.5; }
.sponsors { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; justify-content: center; }
.sponsors-label { font-size: .72rem; color: var(--bs-muted); text-transform: uppercase; letter-spacing: .05em; }
.sponsors img { height: 36px; width: auto; opacity: .8; transition: opacity .15s ease; }
.sponsors a:hover img { opacity: 1; }

/* -------------------------------------------------------------------
   Acessibilidade e responsivo
   ------------------------------------------------------------------- */

@media (max-width: 820px) {
  .topbar { padding: 10px 16px; gap: 8px; flex-wrap: wrap; }
  .nav { width: 100%; justify-content: flex-start; }
  .nav .who { display: none; }
  .container { padding: 0 16px; margin: 18px auto; }
  .card { padding: 18px 16px; }
  h1 { font-size: 1.35rem; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .stats-row { grid-template-columns: 1fr; }
}

/* Focus visivel para acessibilidade */
:focus-visible {
  outline: 2px solid var(--bs-primary);
  outline-offset: 2px;
  border-radius: var(--bs-r-sm);
}

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E1; border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }
