:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --border: #e2e8f0;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar-w: 260px;
  --topbar-h: 64px;
  --bottom-nav-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }

.app-shell {
  display: flex;
  min-height: 100dvh;
}

.app-shell[hidden],
.login-view[hidden] {
  display: none !important;
}

/* Sidebar desktop */
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 1.25rem 1rem;
  display: none;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
}

.sidebar.open { display: flex; }

.sidebar__brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.5rem 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.sidebar__brand strong { display: block; font-size: 0.95rem; }
.sidebar__brand small { color: var(--text-muted); font-size: 0.75rem; }

.sidebar__logo {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #fff;
  display: grid;
  place-items: center;
}

.sidebar__logo svg { width: 22px; height: 22px; }

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.nav-link {
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  min-height: 44px;
  display: flex;
  align-items: center;
}

.nav-link:hover { background: #f1f5f9; color: var(--text); }
.nav-link.active { background: #eff6ff; color: var(--primary); }

.sidebar__footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-user {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0 0.25rem;
}

.sidebar-user strong {
  font-size: 0.9rem;
  color: var(--text);
}

.sidebar-user__email,
.sidebar-user__perfil {
  font-size: 0.75rem;
  color: var(--text-muted);
  word-break: break-word;
}

.btn-logout {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 10px 14px;
  min-height: 44px;
  background: #f1f5f9;
  color: #334155;
  font-weight: 700;
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-logout:hover {
  background: #fee2e2;
  color: #b91c1c;
}

.btn-logout--topbar {
  width: auto;
  min-height: 40px;
  padding: 0.5rem 0.875rem;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 35;
}

.sidebar-overlay[hidden] { display: none; }

/* Main */
.main {
  flex: 1;
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
}

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar__title h1 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.2;
}

.topbar__tenant {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.topbar__actions { margin-left: auto; }

.content {
  padding: 1rem;
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.page { display: none; }
.page.active { display: block; }

/* Cards */
.cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  min-height: 88px;
}

.stat-card__label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.stat-card__value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card__value--ok { color: #16a34a; }
.stat-card__value--warn { color: #d97706; }
.stat-card__value--muted { color: var(--text-muted); font-size: 1rem; }

.panel-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.panel--center {
  text-align: center;
  padding: 2.5rem 1.5rem;
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.panel__header h2 {
  margin: 0;
  font-size: 1rem;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.timeline li {
  padding: 0.875rem;
  border-radius: var(--radius-sm);
  background: #f8fafc;
  border: 1px solid var(--border);
}

.timeline strong { display: block; font-size: 0.9rem; }
.timeline span { font-size: 0.8rem; color: var(--text-muted); }

.n8n-status__row {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.n8n-status__row:last-of-type { border-bottom: none; }
.hint { font-size: 0.8rem; color: var(--text-muted); margin: 0.75rem 0 0; }

/* Buttons */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  min-height: 44px;
  transition: transform 0.1s, background 0.15s;
}

.btn:active { transform: scale(0.98); }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); }
.btn--secondary { background: #eff6ff; color: var(--primary); }
.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--sm { min-height: 40px; padding: 0.5rem 0.875rem; font-size: 0.8rem; }

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: #f1f5f9;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}

.icon-btn svg { width: 22px; height: 22px; }

.badge {
  display: inline-block;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  background: #eff6ff;
  color: var(--primary);
}

.badge--muted { background: #f1f5f9; color: var(--text-muted); }
.badge--success { background: #dcfce7; color: #166534; }
.badge--danger { background: #fee2e2; color: #991b1b; }

/* Bottom nav mobile */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  z-index: 30;
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  min-height: 44px;
  padding: 0.35rem 0;
}

.bottom-nav__item svg { width: 22px; height: 22px; }
.bottom-nav__item.active { color: var(--primary); }

/* PWA banner */
.pwa-banner {
  position: fixed;
  left: 0.75rem;
  right: 0.75rem;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 0.75rem);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(15, 23, 42, 0.15);
  padding: 1rem;
  z-index: 50;
  animation: slideUp 0.3s ease;
}

.pwa-banner[hidden] { display: none !important; }

.pwa-banner__content {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.pwa-banner__icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: #eff6ff;
  color: var(--primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.pwa-banner__icon svg { width: 24px; height: 24px; }
.pwa-banner p { margin: 0.25rem 0 0; font-size: 0.85rem; color: var(--text-muted); }
.pwa-banner__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.toast {
  position: fixed;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 60;
  max-width: calc(100% - 2rem);
  text-align: center;
}

.toast[hidden] { display: none; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tablet+ */
@media (min-width: 640px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 768px) {
  .main { padding-bottom: 0; margin-left: 0; }
  .bottom-nav { display: none; }
  .icon-btn#menuToggle { display: none; }
  .btn-logout--topbar { display: none; }
  .sidebar {
    display: flex;
    position: sticky;
    height: 100dvh;
    top: 0;
  }
  .sidebar-overlay { display: none !important; }
  .cards-grid { grid-template-columns: repeat(3, 1fr); }
  .panel-grid { grid-template-columns: 1.2fr 1fr; }
  .pwa-banner { max-width: 420px; left: auto; right: 1.5rem; bottom: 1.5rem; }
}

@media (min-width: 1024px) {
  .cards-grid { grid-template-columns: repeat(5, 1fr); }
  .content { padding: 1.5rem; }
}

/* Standalone PWA */
@media (display-mode: standalone) {
  .pwa-banner { display: none !important; }
}

/* Login */
.login-view {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  padding-bottom: calc(1.25rem + var(--safe-bottom));
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, rgba(37, 99, 235, 0.12), transparent),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.75rem 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.login-card__brand {
  display: flex;
  gap: 0.875rem;
  align-items: flex-start;
  margin-bottom: 1.5rem;
}

.login-card__brand h1 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.3;
}

.login-card__subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--text-muted);
}

.form-field input {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: #f8fafc;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
  background: var(--surface);
}

.login-form__error {
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-sm);
  background: #fef2f2;
  color: #991b1b;
  font-size: 0.85rem;
}

.login-form__error[hidden] { display: none; }

.btn--block { width: 100%; }

.login-card__footer {
  margin: 1.25rem 0 0;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.user-chip {
  display: none;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--primary);
  text-transform: capitalize;
}

.app-loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: grid;
  place-items: center;
  z-index: 100;
}

.app-loading[hidden] { display: none; }

.app-loading__spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (max-width: 767px) {
  .topbar__actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
  }

  .user-chip {
    display: none;
  }

  .btn-logout--topbar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

@media (min-width: 768px) {
  .user-chip { display: inline-block; }
  .topbar__actions { display: flex; align-items: center; gap: 0.5rem; }
}

/* Grupos */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.page-header__title {
  margin: 0;
  font-size: 1.35rem;
}

.page-header__subtitle {
  margin: 0.35rem 0 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  max-width: 36rem;
}

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.filters-bar__search {
  flex: 1 1 100%;
  min-height: 44px;
  padding: 0.65rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: var(--surface);
}

.filters-bar__select {
  flex: 1 1 calc(50% - 0.25rem);
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
  background: var(--surface);
}

.grupos-count,
.entity-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.grupos-error,
.entity-error {
  padding: 0.75rem;
  background: #fef2f2;
  color: #991b1b;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.grupos-error[hidden],
.entity-error[hidden] { display: none; }

.grupos-loading,
.entity-loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.grupos-loading[hidden],
.entity-loading[hidden] { display: none; }

.grupos-cards,
.entity-cards {
  display: grid;
  gap: 0.75rem;
}

.grupos-table-wrap,
.entity-table-wrap {
  display: none;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.grupos-table,
.entity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

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

.grupos-table th,
.entity-table th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.grupos-table tbody tr:hover,
.entity-table tbody tr:hover {
  background: #f8fafc;
}

.cell-mono {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  word-break: break-all;
}

.table-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 768px) {
  .table-actions {
    justify-content: flex-start;
    gap: 8px;
  }
}

.grupo-card,
.entity-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.entity-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.entity-card__header h3 {
  margin: 0;
  font-size: 1rem;
}

.entity-card__desc {
  margin: 0 0 0.5rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.entity-card__meta {
  margin: 0 0 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.entity-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.nav-link--soon {
  opacity: 0.55;
  cursor: default;
  pointer-events: none;
}

.grupo-card__header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.grupo-card__header h3 {
  margin: 0;
  font-size: 1rem;
}

.grupo-card__meta {
  margin: 0 0 0.75rem;
  display: grid;
  gap: 0.35rem;
}

.grupo-card__meta div {
  display: flex;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.grupo-card__meta dt {
  color: var(--text-muted);
  min-width: 5.5rem;
}

.grupo-card__meta dd {
  margin: 0;
  flex: 1;
  word-break: break-word;
}

.grupo-card__actions {
  display: flex;
  gap: 0.5rem;
}

.form-hint {
  margin: 0.35rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.approval-mode-field {
  border: 0;
  padding: 0;
  margin: 0 0 1rem;
}

.approval-mode-field legend {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.radio-option {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  line-height: 1.4;
  cursor: pointer;
}

.radio-option input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.envio-await-approval {
  display: inline-flex;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.filters-bar--period {
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.75rem;
}

.report-tabs {
  display: flex;
  gap: 0.35rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  margin: 1rem 0;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.report-tabs__btn {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}

.report-tabs__btn.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.report-panel {
  margin-top: 0.5rem;
}

.report-panel__toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.form-field textarea {
  width: 100%;
  min-height: 80px;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  resize: vertical;
  background: #f8fafc;
}

.form-field select {
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 0.875rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  background: #f8fafc;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.modal[hidden] { display: none !important; }

body.modal-open { overflow: hidden; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
}

.modal__panel {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100%;
  height: 92dvh;
  max-height: 92dvh;
  overflow: hidden;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.25rem 1.25rem 0;
  box-shadow: 0 -8px 40px rgba(15, 23, 42, 0.15);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.modal__header h2 {
  margin: 0;
  font-size: 1.15rem;
}

.modal__form {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  overflow: hidden;
}

.modal__form-error {
  flex-shrink: 0;
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--danger, #b91c1c);
  background: color-mix(in srgb, var(--danger, #dc2626) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger, #dc2626) 35%, transparent);
  border-radius: var(--radius-sm, 0.375rem);
}

.modal__body-scroll > .modal__form-error {
  position: sticky;
  top: 0;
  z-index: 2;
}

.modal__form-error[hidden] {
  display: none;
}

.modal__body-scroll {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 0.15rem 0.75rem 0;
  scroll-padding-top: 0.5rem;
  scroll-padding-bottom: 1rem;
}

.modal__body-scroll > .form-field,
.modal__body-scroll > .form-row,
.modal__body-scroll > .form-hint,
.modal__body-scroll > .template-vars,
.modal__body-scroll > .preview-panel,
.modal__body-scroll > .btn {
  margin-bottom: 0.875rem;
}

.modal__body-scroll > *:last-child {
  margin-bottom: 0;
}

.field--error-hint {
  outline: 2px solid var(--danger, #dc2626);
  outline-offset: 2px;
}

.modal__actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.5rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 1rem 0 calc(1rem + env(safe-area-inset-bottom, 0px));
  margin-top: 0;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.modal__actions .btn {
  min-width: 7rem;
}

.modal--wide .modal__panel {
  max-width: 640px;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

@media (min-width: 640px) {
  .form-row {
    flex-direction: row;
  }

  .form-row .form-field {
    flex: 1;
  }
}

.template-vars {
  padding: 0.75rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.template-vars__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.template-vars__buttons .btn {
  font-size: 0.75rem;
  padding: 0.25rem 0.5rem;
}

.preview-panel {
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.preview-panel h3 {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
}

.preview-panel__text {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 0.9rem;
  line-height: 1.5;
}

.entity-card__excerpt {
  color: var(--text-muted);
  font-size: 0.85rem;
}

@media (min-width: 640px) {
  .filters-bar__search { flex: 1 1 12rem; }
  .filters-bar__select { flex: 0 1 auto; min-width: 140px; }
}

@media (min-width: 768px) {
  .grupos-cards,
  .entity-cards { display: none; }
  .grupos-table-wrap,
  .entity-table-wrap { display: block; }

  .modal {
    align-items: center;
    padding: 1rem;
  }

  .modal__panel {
    width: 100%;
    height: auto;
    max-width: 480px;
    max-height: 90dvh;
    border-radius: var(--radius);
  }

  .modal--wide .modal__panel {
    max-width: 720px;
  }
}

.detail-list {
  display: grid;
  gap: 0.65rem;
  margin: 0 0 1rem;
}

.detail-list > div {
  display: grid;
  grid-template-columns: minmax(120px, 38%) 1fr;
  gap: 0.5rem;
  align-items: start;
}

.detail-list dt {
  font-weight: 600;
  color: var(--text-muted);
  margin: 0;
}

.detail-list dd {
  margin: 0;
}

.detail-list__subtitle {
  margin: 1rem 0 0.5rem;
  font-size: 0.95rem;
}

.message-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}

.message-excerpt {
  font-style: italic;
}

/* modal__body-scroll — regras principais na seção Modal acima */

.cards-grid--compact {
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.code-block {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  background: var(--surface-elevated, #f4f4f5);
  border: 1px solid var(--border, #e4e4e7);
  border-radius: var(--radius-sm, 6px);
  padding: 0.75rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.tentativa-card {
  border: 1px solid var(--border, #e4e4e7);
  border-radius: var(--radius-sm, 6px);
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
}

.tentativa-card__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.entity-error-inline {
  color: var(--danger, #b91c1c);
  font-size: 0.9rem;
}

.scheduler-panel__hint {
  margin-bottom: 1rem;
}

.scheduler-status-grid {
  margin-bottom: 1rem;
}

.stat-card--wide {
  grid-column: 1 / -1;
}

.stat-card__value--sm {
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.4;
}

.scheduler-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.scheduler-runs-cards {
  display: block;
}

.scheduler-runs-table {
  display: none;
}

.panel__header--row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.pagination-bar {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.integracao-security-hint {
  padding: 0.65rem 0.85rem;
  background: var(--surface-elevated, #f4f4f5);
  border-radius: var(--radius-sm, 6px);
  border-left: 3px solid var(--primary, #2563eb);
  margin-bottom: 1rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0 0;
  cursor: pointer;
  font-size: 0.9rem;
  user-select: none;
}

.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-width: 18px;
  margin: 0;
  accent-color: #2563eb;
  flex-shrink: 0;
}

.checkbox-row span {
  line-height: 1.4;
}

@media (min-width: 768px) {
  .scheduler-runs-cards {
    display: none;
  }

  .scheduler-runs-table {
    display: block;
  }
}

.audit-detail-body {
  max-height: min(70vh, 520px);
  overflow-y: auto;
}

.audit-detail-dl {
  display: grid;
  grid-template-columns: minmax(100px, 140px) 1fr;
  gap: 8px 16px;
  margin: 0 0 16px;
  font-size: 0.9rem;
}

.audit-detail-dl dt {
  font-weight: 600;
  color: var(--text-muted, #64748b);
}

.audit-detail-dl dd {
  margin: 0;
  word-break: break-word;
}

.audit-ua {
  font-size: 0.8rem;
  line-height: 1.35;
}

.audit-json-block {
  margin-top: 12px;
}

.audit-json-block h4 {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-weight: 600;
}

.audit-json-pre {
  margin: 0;
  padding: 12px;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  font-size: 0.78rem;
  line-height: 1.45;
  overflow-x: auto;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
}
