:root {
  --ink: #17313b;
  --muted: #667882;
  --line: #d8e6e8;
  --page: #eef7f5;
  --panel: #ffffff;
  --teal: #0f8f8c;
  --mint: #4fc7a5;
  --blue: #2367a7;
  --amber: #f5b94c;
  --rose: #df6a68;
  --shadow: 0 18px 44px rgba(21, 63, 74, 0.13);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  background: var(--page);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

body.auth-loading,
body.logged-out {
  display: block;
}

body.auth-loading .sidebar,
body.auth-loading .shell,
body.logged-out .sidebar,
body.logged-out .shell {
  display: none;
}

body.logged-in .login-screen {
  display: none;
}

body.logged-in #login-form {
  display: none;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 520px);
  background:
    linear-gradient(135deg, rgba(15, 143, 140, 0.94), rgba(35, 103, 167, 0.9)),
    #0f8f8c;
}

.login-visual {
  color: #fff;
  padding: clamp(32px, 7vw, 92px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
}

.login-logo {
  width: min(260px, 72vw);
  height: auto;
  filter: drop-shadow(0 12px 22px rgba(23, 49, 59, 0.18));
}

.login-visual h1 {
  font-size: clamp(2.25rem, 5vw, 4.8rem);
  line-height: 1;
}

.login-visual p {
  max-width: 640px;
  margin: 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 1.08rem;
  line-height: 1.7;
}

.login-highlights {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.login-highlights span {
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.12);
  font-weight: 700;
}

.login-card {
  align-self: center;
  margin: 32px;
  padding: 28px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(23, 49, 59, 0.26);
  display: grid;
  gap: 16px;
}

.login-card h2 {
  font-size: 1.45rem;
}

.link-button {
  background: none;
  border: none;
  box-shadow: none;
  color: #075a57;
  font-weight: 600;
  text-decoration: underline;
  padding: 0;
  cursor: pointer;
}

button,
input,
textarea,
select {
  font: inherit;
}

.sidebar {
  min-height: 100vh;
  padding: 24px;
  background: #ffffff;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-logo {
  width: 148px;
  height: auto;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.eyebrow,
.facility span,
.panel-title span,
.metric span,
.session-chip {
  color: var(--muted);
  font-size: 0.82rem;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 12px 14px;
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  background: #e3f3ef;
  color: #086a68;
}

.facility {
  margin-top: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fcfb;
}

.facility strong {
  display: block;
  margin-top: 5px;
  line-height: 1.35;
}

.shell {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.5rem, 2.6vw, 2.25rem);
}

h2 {
  font-size: 1.05rem;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.top-actions select {
  width: min(260px, 32vw);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 143, 140, 0.14);
}

button[type="submit"],
#refresh-button,
#help-button,
#logout-button,
#forgot-password-button,
#auth-forgot-password-button {
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  color: #fff;
  background: var(--teal);
  cursor: pointer;
  font-weight: 700;
}

#refresh-button {
  background: var(--blue);
}

#help-button {
  background: #ffffff;
  color: var(--blue);
  border: 1px solid var(--line);
}

#logout-button {
  background: #fff3f2;
  color: #b94644;
  border: 1px solid rgba(223, 106, 104, 0.32);
}

#forgot-password-button,
#auth-forgot-password-button {
  background: #eef7f5;
  color: var(--teal);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel,
.module-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
  min-height: 112px;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 2rem;
}

.metric.urgent {
  border-color: rgba(223, 106, 104, 0.35);
}

.metric.urgent strong {
  color: #b94644;
}

.work-grid,
.split,
.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(360px, 1.4fr);
  gap: 18px;
  align-items: start;
}

.admin-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.panel {
  padding: 18px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.compact-title {
  margin-bottom: 10px;
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline div {
  display: grid;
  gap: 4px;
  padding: 14px;
  border-left: 4px solid var(--mint);
  background: #f7fbfb;
  border-radius: 6px;
}

.timeline span {
  color: var(--muted);
}

.check-list,
.requirement-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.check-list li,
.requirement-row {
  padding: 12px;
  background: #f8fcfb;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.form-panel {
  display: grid;
  gap: 13px;
}

.format-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.format-row button {
  border: 1px solid rgba(14, 116, 111, 0.22);
  border-radius: 8px;
  padding: 10px;
  background: #effaf7;
  color: #075a57;
  cursor: pointer;
  font-weight: 800;
}

.format-row button:hover {
  border-color: var(--teal);
  background: #dff3ee;
}

.merge-box {
  display: grid;
  gap: 12px;
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fcfb;
}

.attachment-wrap {
  margin-top: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.two-cols,
.three-cols {
  display: grid;
  gap: 12px;
}

.two-cols {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.three-cols {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.table-wrap {
  overflow: auto;
}

.filter-row {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(220px, 1.2fr);
  gap: 12px;
  margin-bottom: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 620px;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
}

.module-card {
  padding: 16px;
  display: grid;
  gap: 10px;
  min-height: 162px;
}

.module-card h3 {
  margin: 0;
  font-size: 1rem;
}

.module-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.pill {
  width: fit-content;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 0.75rem;
  color: #075a57;
  background: #dff3ee;
}

.session-chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 12px;
  background: #fff;
  white-space: nowrap;
}

.queue {
  display: grid;
  gap: 10px;
}

.queue-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fcfb;
}

.queue-item strong {
  display: block;
}

.status-chip {
  display: inline-block;
  border-radius: 999px;
  padding: 5px 9px;
  color: #075a57;
  background: #dff3ee;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-chip.cancelado,
.status-chip.faltou {
  color: #9f2f2d;
  background: #ffe1e0;
}

.status-chip.lgpd-ok {
  color: #245f30;
  background: #dff4df;
}

.status-chip.lgpd-revoked {
  color: #9f2f2d;
  background: #ffe1e0;
}

.status-chip.lgpd-anon {
  color: #475569;
  background: #e2e8f0;
}

.status-chip.lgpd-none {
  color: #644705;
  background: #fff1c7;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.status-chip.atendido {
  color: #245f30;
  background: #dff4df;
}

.status-chip.confirmado {
  color: #174d85;
  background: #e0edfb;
}

.status-chip.chamado {
  color: #644705;
  background: #fff1c7;
}

.status-chip.encaminhado_acolhimento,
.status-chip.em_acolhimento,
.status-chip.classificado,
.status-chip.encaminhado_atendimento {
  color: #075a57;
  background: #dff3ee;
}

.queue-item small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.record-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.record-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fcfb;
}

.record-item div {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}

.record-item span,
.record-item small {
  color: var(--muted);
}

.record-item p {
  margin: 0 0 10px;
  line-height: 1.5;
}

.result-input {
  min-width: 260px;
  resize: vertical;
}

.danger-text {
  color: #9f2f2d;
  font-weight: 800;
}

.permission-grid {
  display: grid;
  gap: 10px;
  max-height: 520px;
  overflow: auto;
  padding-right: 4px;
}

.permission-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fcfb;
}

.permission-group legend {
  padding: 0 5px;
  color: var(--ink);
  font-weight: 800;
}

.permission-check {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: start;
  gap: 9px;
  padding: 7px 0;
  color: var(--ink);
  font-weight: 700;
}

.permission-check input {
  width: auto;
  margin-top: 3px;
}

.permission-check span {
  display: grid;
  gap: 2px;
}

.permission-check small {
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
}

.status-chip.resultado_recebido {
  color: #245f30;
  background: #dff4df;
}

.status-chip.em_analise,
.status-chip.autorizado,
.status-chip.agendado,
.status-chip.realizado {
  color: #174d85;
  background: #e0edfb;
}

.status-chip.solicitado,
.status-chip.coletado,
.status-chip.processando {
  color: #644705;
  background: #fff1c7;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 700;
}

.mini-button:hover {
  border-color: var(--teal);
  color: #075a57;
}

.mini-button.danger:hover {
  border-color: var(--rose);
  color: #9f2f2d;
}

.risk {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 999px;
  margin-right: 8px;
  vertical-align: middle;
}

.risk.vermelho { background: #d64045; }
.risk.laranja { background: #f18701; }
.risk.amarelo { background: var(--amber); }
.risk.verde { background: #30a46c; }
.risk.azul { background: #2878c8; }

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100vw - 44px));
  background: var(--ink);
  color: #fff;
  padding: 12px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.help-panel {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 24px;
  background: rgba(23, 49, 59, 0.28);
}

.help-panel.open {
  display: flex;
}

.help-content {
  width: min(460px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.help-content p {
  color: var(--muted);
  line-height: 1.55;
}

.help-content ul {
  margin: 14px 0 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
}

#help-close {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 9px 12px;
  cursor: pointer;
}

@media (max-width: 980px) {
  body {
    grid-template-columns: 1fr;
  }

  .login-screen {
    grid-template-columns: 1fr;
  }

  .login-card {
    align-self: start;
    margin-top: 0;
  }

  .sidebar {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-item {
    text-align: center;
  }

  .facility {
    display: none;
  }

  .metric-grid,
  .work-grid,
  .split,
  .admin-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .shell,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .top-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions select {
    width: 100%;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-cols,
  .three-cols,
  .filter-row {
    grid-template-columns: 1fr;
  }
}
