/* ============================================================
   CareTecMed Gestão V7 — Redesign
   Paleta baseada no logo (coração navy + engrenagem preta):
     Navy principal:   #000090 (coração do logo)
     Navy escuro:      #00006B (sidebar / fundos)
     Navy claro:       #1A1AB8 (hovers / destaques)
     Azul destaque:    #003DA5 (cabeçalhos)
     Ciano/Acento:     #00C2CB (item ativo, badges)
     Preto:            #000000 (texto do logo, engrenagem)
     Branco:           #FFFFFF
     Cinza fundo:      #F0F2F5 (área de conteúdo)
     Cinza borda:      #E1E5EA
     Cinza texto:      #6B7280
   ============================================================ */

:root {
  --navy: #000090;
  --navy-dark: #00006B;
  --navy-light: #1A1AB8;
  --azul-head: #003DA5;
  --cyan: #00C2CB;
  --cyan-dark: #00A0A8;
  --black: #000000;
  --white: #FFFFFF;
  --bg: #F0F2F5;
  --border: #E1E5EA;
  --text: #1A1A2E;
  --text-muted: #6B7280;
  --green: #0A8D3C;
  --red: #C81E1E;
  --amber: #B97800;
  --sidebar-w: 260px;
}

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

body {
  background: var(--bg);
  font-family: 'Segoe UI', system-ui, Arial, sans-serif;
  color: var(--text);
  font-size: 14px;
}

/* ===================== SIDEBAR ===================== */
aside {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--navy-dark) 0%, var(--navy) 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  z-index: 30;
  box-shadow: 2px 0 12px rgba(0,0,0,0.18);
}

.sidebar-brand {
  padding: 20px 22px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.10);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-brand img { height: 48px; width: auto; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

aside button.nav-btn {
  background: transparent;
  border: 0;
  color: rgba(255,255,255,0.75);
  text-align: left;
  padding: 12px 22px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all 0.15s;
  width: 100%;
  font-family: inherit;
}
aside button.nav-btn:hover {
  background: rgba(255,255,255,0.07);
  color: #fff;
}
aside button.nav-btn.active {
  background: rgba(0,194,203,0.15);
  color: var(--cyan);
  border-left: 3px solid var(--cyan);
  padding-left: 19px;
  font-weight: 600;
}
aside button.nav-btn .nav-icon { font-size: 18px; width: 24px; text-align: center; }

.sidebar-bottom {
  border-top: 1px solid rgba(255,255,255,0.10);
  padding: 8px 0;
}
.nav-logout { color: rgba(255,180,180,0.8) !important; }
.nav-logout:hover { background: rgba(200,30,30,0.2) !important; color: #ffcccc !important; }

/* ===================== MAIN AREA ===================== */
.app {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

header {
  background: #fff;
  padding: 16px 30px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.header-left { display: flex; align-items: center; gap: 16px; }
.mobile-toggle { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--navy); }
header h1 { font-size: 22px; font-weight: 700; color: var(--azul-head); }
header p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.header-right {
  display: flex;
  align-items: center;
  gap: 18px;
}
.header-date {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.header-bell {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.15s;
}
.header-bell:hover { background: var(--navy); color: #fff; border-color: var(--navy); }
.bell-badge {
  position: absolute;
  top: -4px; right: -4px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 50%;
  width: 18px; height: 18px;
  display: flex; align-items: center; justify-content: center;
}
.header-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.header-user .avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
}
.header-user .user-info { display: flex; flex-direction: column; line-height: 1.3; }
.header-user .user-info b { font-size: 14px; color: var(--text); }
.header-user .user-info span { font-size: 11px; color: var(--text-muted); }

section { padding: 24px 30px; }
.hidden { display: none; }

/* ===================== DASHBOARD CARDS ===================== */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.card {
  background: #fff;
  padding: 22px;
  border-radius: 14px;
  border: 1px solid var(--border);
  display: flex;
  align-items: flex-start;
  gap: 16px;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.2s;
}
.card:hover { box-shadow: 0 6px 24px rgba(0,0,144,0.10); transform: translateY(-2px); }
.card-icon-box {
  width: 50px; height: 50px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.icon-blue { background: #E8EAF6; }
.icon-amber { background: #FFF3D7; }
.icon-cyan { background: #D7F7F9; }
.icon-green { background: #E6F4EA; }
.icon-navy { background: #D7D7EE; }
.icon-red { background: #FEE4E2; }

.card .card-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
}
.card .card-value {
  font-size: 34px;
  font-weight: 800;
  color: var(--navy-dark);
  margin-top: 4px;
  line-height: 1;
}
.card .card-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ===================== DASHBOARD GRID ===================== */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1.3fr;
  gap: 18px;
  margin-top: 20px;
}
.chart-panel, .list-panel { display: flex; flex-direction: column; }

.panel {
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--border);
  overflow: hidden;
}
.panel-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.panel-head h3 { font-size: 15px; font-weight: 700; color: var(--navy-dark); }
.panel-total { font-size: 12px; color: var(--text-muted); font-weight: 600; }

.donut-wrap {
  position: relative;
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.donut-center {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}
.donut-num { font-size: 30px; font-weight: 800; color: var(--navy-dark); line-height: 1; }
.donut-lbl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; margin-top: 2px; }

.chart-legend {
  padding: 4px 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.legend-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}
.legend-item .legend-left { display: flex; align-items: center; gap: 8px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.legend-item .legend-pct { font-weight: 700; color: var(--text-muted); }

/* OS recent list */
.os-list { padding: 8px 20px; flex: 1; }
.os-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.os-item:last-child { border-bottom: 0; }
.os-item .os-info { display: flex; flex-direction: column; gap: 2px; }
.os-item .os-num { font-weight: 700; font-size: 13px; color: var(--navy-dark); }
.os-item .os-equip { font-size: 13px; color: var(--text); }
.os-item .os-date { font-size: 11px; color: var(--text-muted); }
.os-item .os-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }

.ver-todas {
  display: block;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--navy);
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  transition: background 0.15s;
}
.ver-todas:hover { background: var(--bg); }

/* ===================== TOOLBAR ===================== */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.toolbar h2 { font-size: 18px; color: var(--azul-head); }
.toolbar p { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.toolbar > div:first-child { margin-right: auto; }

/* ===================== BUTTONS ===================== */
button, .btn {
  background: var(--navy);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s;
  font-family: inherit;
}
button:hover { background: var(--navy-light); }
button.btn-cyan { background: var(--cyan); color: var(--navy-dark); }
button.btn-cyan:hover { background: var(--cyan-dark); }
button.btn-sm { padding: 6px 12px; font-size: 12px; border-radius: 6px; }
button.btn-danger { background: var(--red); }
button.btn-danger:hover { background: #a01818; }
button.btn-ghost {
  background: transparent;
  color: var(--navy);
  border: 1px solid var(--border);
}
button.btn-ghost:hover { background: var(--bg); border-color: var(--navy); }
.btn-filter {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-filter:hover { background: var(--bg); color: var(--navy); border-color: var(--navy); }

/* ===================== INPUTS ===================== */
input, select, textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(0,0,144,0.1);
}
.toolbar input { width: 300px; }
.toolbar select { width: auto; }

/* ===================== TABLES ===================== */
.panel table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 18px; border-bottom: 1px solid var(--border); }
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  font-weight: 700;
  background: #FAFBFC;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #F8F9FB; }
td small { color: var(--text-muted); }
td b { color: var(--navy-dark); }

/* Status badges */
.badge {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}
.badge-green { background: #E6F4EA; color: var(--green); }
.badge-red { background: #FEE4E2; color: var(--red); }
.badge-amber { background: #FEF3D7; color: var(--amber); }
.badge-navy { background: #E8E8F5; color: var(--navy); }
.badge-cyan { background: #D7F7F9; color: var(--cyan-dark); }

/* ===================== PAGINATION ===================== */
.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  color: var(--text-muted);
  font-size: 13px;
}
.pager-btns { display: flex; align-items: center; gap: 6px; }
.pager-btn {
  min-width: 34px; height: 34px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.pager-btn:hover { border-color: var(--navy); color: var(--navy); }
.pager-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.pager-dots { padding: 0 4px; color: var(--text-muted); }

/* ===================== RELATÓRIOS ===================== */
.relatorio-list { padding: 8px 20px; }
.rel-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.rel-item:last-child { border-bottom: 0; }
.rel-item .rel-icon { font-size: 28px; }
.rel-item > div { flex: 1; }
.rel-item b { font-size: 14px; color: var(--navy-dark); }

/* ===================== CONFIGURAÇÕES ===================== */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
.config-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.config-card h3 { font-size: 16px; color: var(--navy-dark); }
.config-card p { font-size: 13px; color: var(--text-muted); flex: 1; }
.config-card button { align-self: flex-start; }

/* ===================== MODAL ===================== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 60;
}
.modal.hidden { display: none; }
.modalbox {
  background: #fff;
  border-radius: 14px;
  padding: 28px;
  width: 95%; max-width: 900px;
  max-height: 90vh; overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modalbox h2 {
  font-size: 20px;
  color: var(--navy-dark);
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}
.close {
  float: right;
  background: transparent;
  color: var(--text-muted);
  font-size: 26px;
  border: 0;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.close:hover { color: var(--red); background: transparent; }

/* ===================== FORM GRID ===================== */
.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.grid label, label {
  display: flex; flex-direction: column; gap: 5px;
  font-size: 13px; font-weight: 600; color: var(--text);
  margin-bottom: 8px;
}
.actions {
  margin-top: 22px;
  display: flex; gap: 10px;
  justify-content: flex-end;
}

/* ===================== TOAST ===================== */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--navy-dark); color: #fff;
  padding: 14px 22px; border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  z-index: 100; max-width: 380px;
  font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.toast.ok { background: var(--green); }
.toast.err { background: var(--red); }
.toast.warn { background: var(--amber); }

/* ===================== LOGIN PAGE (split-screen) ===================== */
.login-body {
  min-height: 100vh;
  display: flex;
  margin: 0;
  font-family: 'Segoe UI', system-ui, Arial, sans-serif;
}
.login-left {
  flex: 1;
  background: linear-gradient(160deg, var(--navy-dark) 0%, var(--navy) 50%, var(--navy-light) 100%);
  color: #fff;
  padding: 56px 56px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.login-left::after {
  content: '';
  position: absolute;
  right: -80px; bottom: -80px;
  width: 380px; height: 380px;
  border-radius: 50%;
  background: rgba(0,194,203,0.08);
}
.login-left::before {
  content: '';
  position: absolute;
  left: -60px; top: -60px;
  width: 280px; height: 280px;
  border-radius: 50%;
  background: rgba(255,255,255,0.04);
}
.login-left .login-logo { height: 150px; width: auto; margin-bottom: 44px; position: relative; z-index: 1; }
.login-left h1 {
  font-size: 32px; font-weight: 800; line-height: 1.3;
  margin-bottom: 18px; max-width: 480px;
  position: relative; z-index: 1;
}
.login-left p {
  font-size: 15px; color: rgba(255,255,255,0.78);
  line-height: 1.7; max-width: 460px;
  position: relative; z-index: 1;
}
.login-left .login-footer {
  margin-top: auto;
  font-size: 12px; color: rgba(255,255,255,0.45);
  padding-top: 30px;
  position: relative; z-index: 1;
}
.login-left .login-feature {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 22px; font-size: 13px; color: rgba(255,255,255,0.65);
  position: relative; z-index: 1;
}

.login-right {
  flex: 1;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.08);
  border: 1px solid var(--border);
}
.login-card h2 {
  font-size: 26px; color: var(--navy-dark);
  margin-bottom: 6px; font-weight: 800;
}
.login-card .form-subtitle {
  font-size: 14px; color: var(--text-muted);
  margin-bottom: 28px;
}
.login-form label {
  font-size: 13px; font-weight: 600; color: var(--text);
  margin-bottom: 5px; display: block;
}
.login-form .field-group { margin-bottom: 18px; }
.login-form input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
}
.login-form input:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(0,0,144,0.1);
}
.field-remember { margin-bottom: 20px; }
.checkbox-label {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  font-size: 13px !important;
  font-weight: 400 !important;
  cursor: pointer;
}
.checkbox-label input { width: 16px; height: 16px; cursor: pointer; }
.login-form button {
  width: 100%;
  background: var(--navy);
  color: #fff;
  padding: 13px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  margin-top: 4px;
}
.login-form button:hover { background: var(--navy-light); }
.login-error {
  margin-top: 16px;
  padding: 12px 16px;
  background: #FEE4E2;
  border-radius: 8px;
  color: var(--red);
  font-size: 13px;
  text-align: center;
}
.login-help {
  margin-top: 20px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
.login-right-footer {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ===================== RESPONSIVE ===================== */
/* ============================================================
   NOVOS ELEMENTOS — Seletor de Unidade, Submenu, Cadastros
   ============================================================ */

/* ---- Seletor de unidade ativa (sidebar) ---- */
.sidebar-unit {
  margin: 4px 14px 14px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 10px;
}
.sidebar-unit > label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--cyan);
  margin-bottom: 6px;
}
.unit-select-wrap select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid rgba(255,255,255,0.12);
  background: #0a0a4a;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2300C2CB' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 28px;
}
.unit-select-wrap select:hover { border-color: var(--cyan); }
.unit-select-wrap select:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(0,194,203,0.25); }
.unit-badge {
  margin-top: 6px;
  font-size: 11px;
  color: rgba(255,255,255,0.55);
  font-weight: 600;
}
.unit-badge::before {
  content: "● ";
  color: var(--cyan);
}

/* ---- Submenu expansível (Cadastros) ---- */
.nav-parent {
  justify-content: flex-start;
}
.nav-chevron {
  margin-left: auto;
  font-size: 12px;
  color: rgba(255,255,255,0.45);
  transition: transform .2s ease;
}
.nav-parent.open .nav-chevron {
  transform: rotate(180deg);
  color: var(--cyan);
}
.nav-submenu {
  overflow: hidden;
  max-height: 500px;
  transition: max-height .25s ease;
}
.nav-submenu.hidden {
  max-height: 0;
  display: block !important;
  overflow: hidden;
}
.nav-sub {
  padding-left: 40px !important;
  font-size: 13px !important;
  opacity: .88;
  background: rgba(0,0,0,0.15);
  border-left: none !important;
  position: relative;
}
.nav-sub::before {
  content: "";
  position: absolute;
  left: 24px; top: 50%;
  width: 8px; height: 1px;
  background: rgba(255,255,255,0.20);
}
.nav-sub:hover {
  background: rgba(0,0,0,0.30);
  opacity: 1;
}
.nav-sub.active {
  background: rgba(0,194,203,0.10);
  opacity: 1;
}
.nav-sub .nav-icon { font-size: 14px; }

/* ---- Badge de unidade ativa no header ---- */
.header-unit-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 14px;
  background: linear-gradient(135deg, #eef4ff, #e0f7f8);
  border: 1px solid var(--cyan);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  color: var(--navy-dark);
  white-space: nowrap;
}
.header-unit-badge::before {
  content: "🏥";
  font-size: 14px;
}
.header-unit-badge small {
  font-weight: 600;
  color: var(--azul-head);
  font-size: 11px;
}

/* ---- Painel de permissões por unidade ---- */
.perm-panel {
  margin-top: 18px;
  padding: 18px 20px;
  background: #f7f9ff;
  border: 1px solid #dde3f0;
  border-radius: 12px;
}
.perm-panel h4 {
  margin: 0 0 4px;
  font-size: 15px;
  color: var(--navy);
}
.perm-panel .perm-sub {
  font-size: 12px;
  color: #667;
  margin-bottom: 14px;
}
.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
}
.perm-unit-card {
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #dde3f0;
  border-radius: 10px;
  transition: box-shadow .15s;
}
.perm-unit-card:hover { box-shadow: 0 2px 10px rgba(0,0,144,0.08); }
.perm-unit-card .perm-unit-name {
  font-weight: 700;
  font-size: 13px;
  color: var(--navy);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 5px;
}
.perm-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.perm-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 15px;
  cursor: pointer;
  user-select: none;
  border: 1px solid #ccc;
  background: #f0f0f5;
  color: #888;
  transition: all .15s;
}
.perm-chip.on {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}
.perm-chip:hover { transform: translateY(-1px); }

/* ---- Form fields for equipment modal (selects) ---- */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid-2 .form-field.full { grid-column: span 2; }

/* ---- Campos de formulário genéricos (CRUD modals) ---- */
.form-field {
  display: flex;
  flex-direction: column;
  margin-bottom: 14px;
}
.form-field.full { grid-column: span 2; }
.form-field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--navy-dark);
  margin-bottom: 5px;
  letter-spacing: .02em;
}
.form-field label .req { color: #C81E1E; }
.form-field input,
.form-field select,
.form-field textarea {
  padding: 9px 11px;
  border: 1px solid #cdd5e5;
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(0,0,144,0.10);
}
.form-field textarea { resize: vertical; min-height: 70px; }
.form-field input[readonly] { background: #f0f0f5; color: #777; }

/* ---- Sub-painel de setores dentro do modal de unidade ---- */
.setor-list-box {
  margin-top: 6px;
  border: 1px solid #dde3f0;
  border-radius: 9px;
  padding: 12px 14px;
  background: #f7f9ff;
}
.setor-list-box h5 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: 6px;
}
.setor-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.setor-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: #fff;
  border: 1px solid #c5cde0;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--navy-dark);
}
.setor-chip .setor-x {
  cursor: pointer;
  color: #C81E1E;
  font-weight: 800;
  font-size: 14px;
  line-height: 1;
}
.setor-chip .setor-x:hover { color: #a01515; }
.setor-add-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.setor-add-row input {
  flex: 1;
  padding: 7px 10px;
  border: 1px solid #c5cde0;
  border-radius: 7px;
  font-size: 13px;
}
.setor-add-row button {
  padding: 7px 14px;
  font-size: 13px;
}

/* ---- Toggle switch para ativar/desativar ---- */
.toggle-sw {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.toggle-sw .sw-track {
  width: 40px; height: 22px;
  border-radius: 12px;
  background: #ccc;
  position: relative;
  transition: background .2s;
}
.toggle-sw .sw-track::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle-sw.on .sw-track { background: var(--navy); }
.toggle-sw.on .sw-track::after { transform: translateX(18px); }
.toggle-sw .sw-label { font-size: 13px; font-weight: 700; color: var(--text); }

@media (max-width: 1200px) {
  .dash-grid { grid-template-columns: 1fr 1fr; }
  .list-panel { grid-column: span 2; }
}
@media (max-width: 900px) {
  :root { --sidebar-w: 64px; }
  aside { width: 64px; }
  aside .sidebar-brand img { height: 30px; }
  aside .sidebar-nav span,
  aside button.nav-btn span:not(.nav-icon),
  aside .nav-logout span:not(.nav-icon) { display: none; }
  aside button.nav-btn { justify-content: center; padding: 14px; }
  aside button.nav-btn.active { border-left: 0; padding-left: 14px; }
  .app { margin-left: 64px; }
  .mobile-toggle { display: block; }
  .cards { grid-template-columns: 1fr 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .list-panel { grid-column: span 1; }
  .toolbar { flex-wrap: wrap; }
  .toolbar > div:first-child { width: 100%; }
  .toolbar input { width: 100%; }
  .grid { grid-template-columns: 1fr; }
  .login-left { display: none; }
  .login-right { flex: 1; }
  .header-date { display: none; }
}
@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr; }
  .header-user .user-info { display: none; }
}

/* ===== Notificações (modal config) ===== */
.notif-list { display:flex; flex-direction:column; gap:10px; }
.notif-row {
  display:flex; align-items:center; justify-content:space-between;
  padding:14px 16px; border:1px solid #e0e6f0; border-radius:10px;
  background:#f8faff; gap:16px;
}
.notif-row:hover { border-color: var(--cyan); }
.notif-info { flex:1; }
.notif-info b { font-size:14px; color:var(--navy-dark); display:block; margin-bottom:2px; }
.notif-info small { color:#667; font-size:12px; }

/* ===== Relatórios gerados ===== */
.rel-item { display:flex; align-items:center; gap:14px; padding:14px 0; border-bottom:1px solid #eee; }
.rel-item:last-child { border-bottom:0; }
.rel-item .rel-icon { font-size:24px; }
.rel-item div:nth-child(2) { flex:1; }
.rel-item b { color:var(--navy-dark); }
.rel-item small { color:#667; }

/* ============================================================
   OS - Busca de equipamento (autocomplete do banco)
   ============================================================ */
.os-equip-busca-wrap { position: relative; }
.os-equip-resultados {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1000;
  max-height: 240px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #c5d0e0;
  border-top: none;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 8px 20px rgba(0,0,40,0.15);
}
.os-equip-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #eef2f8;
  color: #1a2744;
}
.os-equip-item:hover, .os-equip-item.active {
  background: #eaf1ff;
  color: #000090;
}
.os-equip-item:last-child { border-bottom: none; }


/* ============================================================
   CareTecMed 8.1 — Utilizadores, permissões e confirmação
   ============================================================ */
.confirm-overlay{position:fixed;inset:0;z-index:99999;background:rgba(5,15,38,.58);backdrop-filter:blur(5px);display:flex;align-items:center;justify-content:center;padding:22px}
.confirm-overlay.hidden{display:none}
.confirm-card{width:min(460px,100%);background:#fff;border-radius:20px;padding:34px;box-shadow:0 28px 80px rgba(2,12,35,.35);text-align:center;animation:confirmIn .18s ease-out}
@keyframes confirmIn{from{opacity:0;transform:translateY(10px) scale(.98)}to{opacity:1;transform:none}}
.confirm-icon{width:68px;height:68px;margin:0 auto 18px;border-radius:20px;background:#fff0f0;color:#b42318;display:grid;place-items:center;font-size:32px}
.confirm-card h2{margin:0 0 9px;color:#102a56;font-size:23px}.confirm-card p{margin:0;color:#60708d;line-height:1.55}
.confirm-actions{display:flex;gap:10px;justify-content:center;margin-top:26px;flex-wrap:wrap}.confirm-actions button{min-height:44px;padding:0 18px}
.btn-danger-solid{border:0;border-radius:9px;background:#b42318;color:#fff;font-weight:700;cursor:pointer}.btn-danger-solid:hover{background:#8f1b13}
.user-actions{min-width:310px;white-space:nowrap}.btn-warning{background:#fff7e6!important;color:#9a5b00!important;border-color:#f2cf8c!important}
.perm-panel{margin-top:18px;border:1px solid #dbe3f0;border-radius:15px;background:#f8faff;padding:22px;box-shadow:0 8px 26px rgba(18,45,88,.07)}
.perm-toolbar{grid-column:1/-1;display:flex;align-items:center;justify-content:space-between;gap:14px;background:#fff;border:1px solid #dce4f1;border-radius:12px;padding:15px 17px}.perm-toolbar small{display:block;color:#6b7890;margin-top:3px}
.perm-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(330px,1fr));gap:14px}
.perm-unit-card{background:#fff;border:1px solid #dce4f1;border-radius:13px;padding:16px}.perm-unit-head{display:flex;justify-content:space-between;gap:12px;align-items:center;padding-bottom:12px;border-bottom:1px solid #edf1f7}.perm-unit-head span{font-size:12px;color:#68758d}
.perm-checks-grid{display:grid;grid-template-columns:1fr 1fr;gap:10px 14px;padding-top:14px}.perm-checks-grid label{font-size:13px;color:#34435f;display:flex;align-items:center;gap:7px}.perm-checks-grid input,.perm-unit-head input{width:17px;height:17px;accent-color:#073ca4}
@media(max-width:760px){.perm-grid{grid-template-columns:1fr}.perm-checks-grid{grid-template-columns:1fr}.perm-toolbar{align-items:flex-start;flex-direction:column}.confirm-actions{flex-direction:column-reverse}.confirm-actions button{width:100%}.user-actions{min-width:240px}}


/* ===== Correção do logo oficial CareTecMed 8.1.2 ===== */
.login-left .login-logo {
  display: block;
  width: min(520px, 82%);
  height: auto;
  max-height: 220px;
  object-fit: contain;
  background: #fff;
  border-radius: 18px;
  padding: 10px 18px;
  box-sizing: border-box;
}

.sidebar-brand {
  min-height: 70px;
}

.sidebar-brand img {
  display: block;
  width: 54px;
  height: 54px;
  object-fit: contain;
  object-position: center;
  background: #fff;
  border-radius: 12px;
  padding: 4px;
  box-sizing: border-box;
}

@media (max-width: 760px) {
  .login-left .login-logo {
    width: min(420px, 90%);
    max-height: 180px;
  }
}


/* ===== Nome ao lado do logo na barra lateral ===== */
.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  line-height: 1;
}

.sidebar-brand-text strong {
  color: #ffffff;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.3px;
  white-space: nowrap;
}

.sidebar-brand-text span {
  margin-top: 7px;
  color: #9ea8ff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 3px;
  white-space: nowrap;
}

@media (max-width: 900px) {
  .sidebar-brand {
    justify-content: center;
    padding-left: 5px;
    padding-right: 5px;
  }

  .sidebar-brand-text {
    display: none;
  }
}

/* ============================================================
   CareTecMed Mobile 9.0 — experiência responsiva para telemóvel
   ============================================================ */
.mobile-sidebar-backdrop { display:none; }

@media (max-width: 900px) {
  :root { --sidebar-w: 280px; }

  html, body { width:100%; max-width:100%; overflow-x:hidden; }
  body.mobile-menu-open { overflow:hidden; }

  aside {
    width:min(86vw, 300px);
    transform:translateX(-105%);
    transition:transform .24s ease;
    z-index:1002;
    box-shadow:8px 0 32px rgba(0,0,0,.28);
  }
  aside.open { transform:translateX(0); }
  aside .sidebar-brand { justify-content:flex-start; padding:14px 18px; min-height:74px; }
  aside .sidebar-brand img { width:48px; height:48px; }
  aside .sidebar-brand-text { display:flex; }
  aside .sidebar-nav span,
  aside button.nav-btn span:not(.nav-icon),
  aside .nav-logout span:not(.nav-icon) { display:inline; }
  aside button.nav-btn,
  aside button.nav-btn.active { justify-content:flex-start; padding:13px 18px; min-height:48px; }
  aside button.nav-btn.active { padding-left:15px; border-left:3px solid var(--cyan); }
  aside button.nav-btn .nav-icon { flex:0 0 28px; }
  .sidebar-unit { display:block; }

  .mobile-sidebar-backdrop {
    position:fixed; inset:0; z-index:1001;
    background:rgba(2,6,23,.55); backdrop-filter:blur(2px);
  }
  body.mobile-menu-open .mobile-sidebar-backdrop { display:block; }

  .app { margin-left:0; width:100%; min-width:0; }
  header { padding:10px 14px; gap:10px; min-height:64px; }
  .header-left { gap:10px; min-width:0; flex:1; }
  .mobile-toggle {
    display:grid; place-items:center; flex:0 0 44px; width:44px; height:44px;
    border:1px solid var(--border); border-radius:11px; background:#fff;
    font-size:24px; line-height:1; box-shadow:0 2px 8px rgba(0,0,0,.06);
  }
  header h1 { font-size:18px; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:52vw; }
  header p { display:none; }
  .header-right { gap:8px; flex:0 0 auto; }
  .header-unit-badge, .header-date { display:none !important; }
  .header-user .avatar { width:38px; height:38px; }
  .header-user .user-info { display:none; }

  section { padding:14px 12px 28px; min-width:0; }
  .cards { grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
  .card { padding:14px 12px; gap:10px; border-radius:12px; min-width:0; }
  .card-icon-box { width:40px; height:40px; font-size:20px; border-radius:10px; }
  .card .card-label { font-size:10px; letter-spacing:.45px; }
  .card .card-value { font-size:27px; }
  .card .card-sub { font-size:10px; }

  .dash-grid, .grid, .form-grid, .filters-grid, .relatorios-grid { grid-template-columns:1fr !important; }
  .panel, .modal-content, .form-card { border-radius:12px; }
  .panel-head { padding:13px 14px; gap:8px; }
  .panel-head h3 { font-size:14px; }

  .toolbar, .filters, .filter-row, .actions-row {
    display:flex; flex-direction:column; align-items:stretch !important; gap:9px !important;
  }
  .toolbar > *, .filters > *, .filter-row > *, .actions-row > * { width:100% !important; max-width:none !important; }
  .toolbar button, .filters button, .actions-row button { min-height:44px; }

  input, select, textarea, button { font-size:16px; }
  input, select, textarea { min-height:44px; width:100%; max-width:100%; }
  textarea { min-height:105px; }
  label { line-height:1.35; }

  .table-wrap, .table-responsive, .overflow-auto {
    width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch;
    border-radius:10px;
  }
  table { min-width:760px; }
  table th, table td { padding:10px 9px; font-size:12px; }
  .docs-preventivas-table { min-width:1200px; }

  .modal, [class*="modal-overlay"], .doc-preview-overlay { padding:8px !important; align-items:flex-end !important; }
  .modal-content, .modal-card, .doc-preview-card {
    width:100% !important; max-width:none !important; max-height:94vh !important;
    border-radius:18px 18px 0 0 !important; overflow:auto !important;
  }
  .modal-header, .modal-head { position:sticky; top:0; z-index:3; background:#fff; }
  .modal-footer, .modal-actions {
    position:sticky; bottom:0; z-index:3; background:#fff;
    display:flex; flex-direction:column-reverse; gap:8px; padding-bottom:max(12px, env(safe-area-inset-bottom));
  }
  .modal-footer button, .modal-actions button { width:100%; min-height:46px; }

  .btn, button { touch-action:manipulation; }
  .btn-sm { min-height:38px; padding:8px 10px; }
  .user-actions { min-width:210px; white-space:normal; }

  .notif-row, .rel-item { align-items:flex-start; }
  .setor-add-row { flex-direction:column; }
  .setor-add-row button { width:100%; min-height:44px; }

  .confirm-overlay { padding:12px; align-items:flex-end; }
  .confirm-card { border-radius:18px 18px 0 0; padding:24px 18px max(20px,env(safe-area-inset-bottom)); }
}

@media (max-width: 560px) {
  .cards { grid-template-columns:1fr; }
  .card { align-items:center; }
  .card .card-value { font-size:30px; }
  header h1 { max-width:48vw; }
  section { padding-left:10px; padding-right:10px; }
  .panel-head { flex-wrap:wrap; }
  .caretec-loading-card { padding:24px 18px; }
  .caretec-loading-title { font-size:20px; }
}

@media (display-mode: standalone) {
  header { padding-top:max(10px, env(safe-area-inset-top)); }
  aside { padding-top:env(safe-area-inset-top); }
}

/* ============================================================
   CareTecMed Mobile 9.1 — menus e conteúdo sem cortes
   ============================================================ */
@media (max-width: 900px) {
  /* Menu lateral: textos longos ficam legíveis e a área central rola. */
  aside {
    max-width: calc(100vw - 44px);
    height: 100dvh;
    overflow: hidden;
  }
  aside .sidebar-brand,
  aside .sidebar-unit,
  aside .sidebar-bottom { flex: 0 0 auto; }
  aside .sidebar-nav {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding-bottom: 12px;
    scrollbar-width: thin;
  }
  aside button.nav-btn,
  aside button.nav-btn.active {
    width: 100%;
    min-width: 0;
    height: auto;
    line-height: 1.3;
  }
  aside button.nav-btn span:not(.nav-icon):not(.nav-chevron) {
    display: block;
    min-width: 0;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  aside .nav-chevron { margin-left: auto; flex: 0 0 auto; }
  aside .nav-sub { padding-left: 34px !important; }

  /* Cabeçalho: título usa o espaço disponível sem empurrar os botões. */
  header { width: 100%; min-width: 0; }
  .header-left,
  .header-left > div { min-width: 0; }
  header h1 {
    max-width: none;
    min-width: 0;
    white-space: normal;
    line-height: 1.15;
    overflow: visible;
    text-overflow: clip;
  }

  /* Painéis e tabelas: rolagem horizontal dentro do cartão, nunca na página. */
  section, .panel, .panel-body, .content, .page-content { max-width: 100%; min-width: 0; }
  .panel { overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  .panel > table,
  .panel > div > table { width: max-content; min-width: 720px; }
  .panel table th,
  .panel table td {
    white-space: normal;
    overflow-wrap: break-word;
    vertical-align: middle;
  }
  .panel-head,
  .toolbar { min-width: 100%; }

  /* Formulários e filtros não mantêm colunas ou larguras do computador. */
  .form-grid-2 { grid-template-columns: 1fr !important; }
  .form-grid-2 .form-field.full,
  .form-field.full { grid-column: 1 !important; }
  .config-grid,
  .perm-grid { grid-template-columns: minmax(0, 1fr) !important; }
  .perm-unit-card,
  .perm-toolbar { min-width: 0; }
  .pager { flex-wrap: wrap; gap: 10px; }
  .pager-btns { max-width: 100%; overflow-x: auto; padding-bottom: 3px; }

  /* Modais usam a largura visível e permitem ler todo o conteúdo. */
  .modalbox,
  .modal-content,
  .modal-card,
  .doc-preview-card {
    max-width: 100% !important;
    min-width: 0 !important;
  }
  .modalbox { max-height: 94dvh; overflow-y: auto; }
}

@media (max-width: 560px) {
  aside { width: min(90vw, 320px); max-width: calc(100vw - 28px); }
  aside button.nav-btn,
  aside button.nav-btn.active { padding-top: 12px; padding-bottom: 12px; }
  header { padding-left: 10px; padding-right: 10px; }
  header h1 { font-size: 16px; }
  .header-right { gap: 4px; }
  section { padding: 10px 8px 24px; }
  .panel { border-radius: 10px; }
  .toolbar { padding: 12px !important; }
  .toolbar h2 { font-size: 16px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
}
