/* frontend/css/styles.css
 * High-contrast, WCAG 2.1 AA compliant stylesheet for SESAU Campo Grande/MS
 * 6-Level SIAPS + e-SUS PEC Analytical Platform.
 */

:root {
  --bg-page: #0b1120;
  --bg-surface: #111827;
  --bg-card: #1e293b;
  --bg-card-hover: #26354d;
  --border-subtle: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --brand-primary: #0ea5e9;
  --brand-accent: #10b981;
  --color-otimo: #10b981;
  --color-bom: #38bdf8;
  --color-suficiente: #f59e0b;
  --color-regular: #ef4444;
  --color-trap: #f43f5e;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

.hidden {
  display: none !important;
}

/* Header */
.top-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.9rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-badge {
  background: linear-gradient(135deg, #0284c7, #059669);
  color: #ffffff;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.header-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.search-box {
  position: relative;
  display: flex;
  gap: 0.35rem;
}

.search-box input {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  width: 280px;
  font-size: 0.85rem;
}

.search-box input:focus,
.period-selector select:focus,
.btn:focus {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

.search-dropdown {
  position: absolute;
  top: 110%;
  left: 0;
  width: 420px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--brand-primary);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.65);
  z-index: 100;
  padding: 0.5rem;
}

.search-item {
  display: block;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
}

.search-item:hover {
  background: var(--bg-card-hover);
}

.period-selector {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.period-selector select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 0.42rem 0.6rem;
  border-radius: 6px;
  font-size: 0.82rem;
}

/* Buttons */
.btn {
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, transform 0.1s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-primary {
  background: var(--brand-primary);
  color: #082f49;
}

.btn-primary:hover {
  background: #38bdf8;
}

.btn-accent {
  background: var(--brand-accent);
  color: #022c22;
}

.btn-accent:hover {
  background: #34d399;
}

.btn-outline {
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.btn-outline:hover {
  background: var(--bg-card);
  border-color: var(--brand-primary);
}

/* 6-Level Hierarchy Bar */
.hierarchy-nav {
  background: #0f172a;
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.65rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.breadcrumb-trail {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  list-style: none;
}

.breadcrumb-step {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.84rem;
}

.breadcrumb-pill {
  padding: 0.28rem 0.65rem;
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
}

.breadcrumb-pill.active {
  background: rgba(14, 165, 233, 0.2);
  color: #38bdf8;
  border-color: #0ea5e9;
}

.level-badges-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.level-tag {
  font-size: 0.74rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  border: 1px solid transparent;
}

.level-tag.current {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: #10b981;
  font-weight: 700;
}

/* Main Workspace */
.main-workspace {
  flex: 1;
  padding: 1.25rem 1.5rem;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Alert Banners */
.alert-banner {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid #ef4444;
  border-left: 5px solid #ef4444;
  border-radius: 8px;
  padding: 0.85rem 1.1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.alert-banner-title {
  font-weight: 700;
  color: #fca5a5;
  font-size: 0.92rem;
}

.alert-banner-desc {
  font-size: 0.83rem;
  color: var(--text-secondary);
}

/* Grid & Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 1rem 1.15rem;
}

.card-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.card-value {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-primary);
}

.card-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.card-danger {
  border-color: rgba(239, 68, 68, 0.65);
  background: linear-gradient(180deg, rgba(239, 68, 68, 0.12), var(--bg-card));
}

.card-success {
  border-color: rgba(16, 185, 129, 0.65);
  background: linear-gradient(180deg, rgba(16, 185, 129, 0.12), var(--bg-card));
}

.two-col-layout {
  display: grid;
  grid-template-columns: 1.05fr 1.35fr;
  gap: 1.15rem;
}

@media (max-width: 1100px) {
  .two-col-layout {
    grid-template-columns: 1fr;
  }
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.section-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Concept Badges */
.badge {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-otimo {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid #10b981;
}

.badge-bom {
  background: rgba(56, 189, 248, 0.2);
  color: #7dd3fc;
  border: 1px solid #0ea5e9;
}

.badge-suficiente {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
  border: 1px solid #f59e0b;
}

.badge-regular {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid #ef4444;
}

.badge-25x {
  background: rgba(244, 63, 94, 0.25);
  color: #fda4af;
  border: 1px solid #f43f5e;
  font-weight: 800;
}

/* 3-Color Traffic Light Semáforo */
.semaforo-meta {
  background: rgba(16, 185, 129, 0.22);
  color: #34d399;
  border: 1px solid #10b981;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.semaforo-atencao {
  background: rgba(245, 158, 11, 0.22);
  color: #fcd34d;
  border: 1px solid #f59e0b;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.semaforo-risco {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  border: 1px solid #ef4444;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.semaforo-container {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-top: 0.35rem;
  padding: 0.4rem 0.55rem;
  background: rgba(15, 23, 42, 0.6);
  border-radius: 6px;
  border: 1px solid rgba(51, 65, 85, 0.5);
}

.semaforo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.semaforo-quota {
  font-size: 0.74rem;
  color: #e2e8f0;
  line-height: 1.3;
}

.semaforo-quota-strong {
  font-weight: 700;
  color: #38bdf8;
}

/* Discrete "? Onde clicar no PEC" Button & Helper */
.btn-pec-helper {
  background: rgba(14, 165, 233, 0.12);
  color: #38bdf8;
  border: 1px solid #0284c7;
  border-radius: 6px;
  padding: 0.22rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-pec-helper:hover {
  background: rgba(14, 165, 233, 0.25);
  color: #f0f9ff;
  border-color: #38bdf8;
  transform: translateY(-1px);
}

.btn-pec-helper:active {
  transform: translateY(0);
}

.pec-practice-item {
  margin-bottom: 0.35rem;
  padding: 0.32rem 0.5rem;
  background: #0f172a;
  border-left: 3px solid #38bdf8;
  border-radius: 4px;
  font-size: 0.76rem;
}

.pec-practice-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.pec-practice-text {
  color: #f8fafc;
}

.pec-practice-actions {
  margin-top: 0.3rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.modal-medium {
  max-width: 680px;
}

.pec-helper-content, .indicator-glossary-content {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.pec-helper-indicator-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid #334155;
}

.pec-helper-card {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
}

.pec-helper-field-title {
  font-size: 0.74rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.25rem;
}

.pec-helper-field-desc {
  font-size: 0.82rem;
  color: #f1f5f9;
  line-height: 1.4;
}

.pec-helper-path-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #020617;
  border: 1px solid #334155;
  border-radius: 6px;
  padding: 0.45rem 0.65rem;
  margin-top: 0.25rem;
}

.pec-path-icon {
  font-size: 0.95rem;
}

.pec-path-code {
  color: #34d399;
  font-weight: 700;
  font-size: 0.82rem;
}

.pec-helper-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

@media (max-width: 640px) {
  .pec-helper-grid {
    grid-template-columns: 1fr;
  }
}

.pec-code-highlight {
  background: #020617;
  color: #38bdf8;
  font-size: 0.88rem;
  font-weight: 700;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  border: 1px solid #1e293b;
}

.btn-copy-code {
  padding: 0.22rem 0.5rem;
  font-size: 0.73rem;
  border-radius: 4px;
}

/* 1-Click Tooltip Glossary */
.indicator-glossary-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.45rem;
  background: rgba(56, 189, 248, 0.15);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.indicator-glossary-badge:hover {
  background: rgba(56, 189, 248, 0.3);
  color: #ffffff;
  border-color: #38bdf8;
  box-shadow: 0 0 8px rgba(14, 165, 233, 0.35);
}

.indicator-glossary-badge::before {
  content: "ⓘ";
  font-size: 0.72rem;
  font-weight: 800;
  opacity: 0.85;
}

.indicator-tooltip {
  position: relative;
  display: inline-block;
}

/* Data Tables */
.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.data-table th,
.data-table td {
  padding: 0.65rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table th {
  background: rgba(15, 23, 42, 0.7);
  color: var(--text-secondary);
  font-weight: 700;
  font-size: 0.76rem;
  text-transform: uppercase;
}

.data-table tbody tr:hover {
  background: var(--bg-card-hover);
}

/* Radial Gauges Grid */
.gauges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
}

.gauge-card {
  background: #152033;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.gauge-card.trap-warning {
  border-color: #f43f5e;
  box-shadow: 0 0 0 1px rgba(244, 63, 94, 0.35);
}

/* Interactive SVG Map */
.svg-map-container {
  width: 100%;
  background: #0f172a;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.district-node {
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.district-node:hover {
  opacity: 0.9;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1.25rem;
  z-index: 200;
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-large {
  max-width: 980px;
}

.modal-copilot {
  max-width: 460px;
  border-color: var(--brand-primary);
}

.modal-header {
  padding: 0.9rem 1.25rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 1rem;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.app-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  padding: 0.75rem 1.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
}

/* ==========================================================================
   Operational Workflows: Inverted Ceiling Alerts & Live Check-in (M1 / R3)
   ========================================================================== */
.alert-ceiling-warning {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid #f59e0b;
  border-left: 4px solid #f59e0b;
  color: #fef3c7;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.alert-ceiling-critical {
  background: rgba(239, 68, 68, 0.18);
  border: 1px solid #ef4444;
  border-left: 4px solid #ef4444;
  color: #fee2e2;
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
  0%, 100% { border-color: #ef4444; }
  50% { border-color: #f87171; }
}

.badge-ceiling-trap {
  background: #7f1d1d;
  color: #fca5a5;
  border: 1px solid #ef4444;
  font-weight: 700;
}

.btn-checkin-registered {
  background: #065f46 !important;
  color: #34d399 !important;
  border: 1px solid #10b981 !important;
  font-weight: 600;
}

/* Printable Nursing Triage Shift Layout */
#triage-print-area {
  display: none;
}

@media print {
  @page {
    size: A4 landscape;
    margin: 8mm 6mm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    font-size: 9pt !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .top-header,
  #hierarchy-nav-container,
  .app-footer,
  .btn,
  button,
  input,
  select,
  .weekly-agenda-toolbar,
  .tabs-nav,
  .modal-backdrop:not(#triage-print-modal),
  #main-workspace,
  .modal-header,
  .modal-card {
    display: none !important;
  }

  #triage-print-area {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .triage-print-header {
    border-bottom: 2px solid #000000;
    padding-bottom: 6px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
  }

  .triage-print-header h1 {
    font-size: 13pt;
    margin: 0 0 4px 0;
    color: #000000;
  }

  .triage-print-header p {
    margin: 2px 0;
    font-size: 8.5pt;
    color: #333333;
  }

  .triage-print-table {
    width: 100% !important;
    border-collapse: collapse !important;
    margin-top: 6px !important;
    page-break-inside: auto !important;
  }

  .triage-print-table th,
  .triage-print-table td {
    border: 1px solid #333333 !important;
    padding: 5px 6px !important;
    color: #000000 !important;
    background: #ffffff !important;
    font-size: 8pt !important;
    page-break-inside: avoid !important;
    vertical-align: middle !important;
  }

  .triage-print-table th {
    background: #f1f5f9 !important;
    font-weight: 700 !important;
    text-align: left !important;
    color: #0f172a !important;
  }

  .triage-print-table .box-input {
    border: 1px dashed #666666;
    padding: 2px 4px;
    display: inline-block;
    min-width: 45px;
    height: 14px;
    margin: 1px 2px;
  }

  .triage-golden-rules {
    margin-top: 8px;
    border: 1px solid #000000;
    padding: 6px 10px;
    font-size: 7.5pt;
    line-height: 1.35;
    background: #f8fafc;
    color: #000000;
  }
}

/* =========================================================================
   M3 & M4: Role-Based Profile Selector, Clinical Views & CSV Importer
   ========================================================================= */

.profile-selector-bar {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 0.22rem;
}

.profile-btn {
  background: transparent;
  color: #cbd5e1;
  border: none;
  border-radius: 7px;
  padding: 0.36rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.profile-btn:hover {
  color: #f8fafc;
  background: rgba(56, 189, 248, 0.14);
}

.profile-btn.active {
  background: linear-gradient(135deg, #0284c7 0%, #0ea5e9 100%);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.35);
}

.profile-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  border: 1px solid #334155;
}

.profile-banner-gestor {
  border-left: 4px solid #38bdf8;
}

.profile-banner-esf {
  border-left: 4px solid #10b981;
}

.profile-banner-esb {
  border-left: 4px solid #f59e0b;
}

.profile-banner-acs {
  border-left: 4px solid #a855f7;
}

.profile-banner-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: #f8fafc;
  margin-bottom: 0.2rem;
}

.profile-banner-sub {
  font-size: 0.82rem;
  color: #cbd5e1;
}

.sim-range-input {
  width: 100%;
  accent-color: #0ea5e9;
  cursor: pointer;
}

.clinical-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.22rem 0.55rem;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 700;
}

.c1-ruler-card {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 10px;
  padding: 1rem;
}

.acs-mobile-card {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 12px;
  padding: 1rem;
  transition: border-color 0.15s ease;
}

.acs-mobile-card:hover {
  border-color: #38bdf8;
}

