:root {
  --brand: #335525; /* Noti - Pantone */
  --brand-dark: #2a461f;
  --brand-light: #3f6a33;
  --brand-accent: #79a86c;
  --brand-soft: rgba(51, 85, 37, 0.08);
  --surface: #f6f7f9;
  --surface-strong: #ffffff;
  --surface-muted: #edf0f5;
  --border: rgba(15, 23, 42, 0.12);
  --text-default: #0f172a;
  --text-muted: #475569;
  --shadow-soft: 0 20px 45px rgba(15, 23, 42, 0.15);
  --shadow-strong: 0 10px 20px rgba(15, 23, 42, 0.25);

  --radius-card: 18px;
  --radius-control: 12px;
  --radius-pill: 999px;
  --transition-fast: 160ms ease;

  --brand-grad-1: rgba(51, 85, 37, 0.14);
  --brand-grad-2: rgba(51, 85, 37, 0.10);
  --brand-ring: rgba(51, 85, 37, 0.15);
  --brand-ring-strong: rgba(51, 85, 37, 0.35);

  --brand-avatar-1: rgba(51, 85, 37, 0.55);
  --brand-avatar-2: rgba(120, 160, 90, 0.25);

  /* Menu (top bar) tokens */
  --menu-bg: rgba(255, 255, 255, 0.92);
  --menu-bg-compact: rgba(255, 255, 255, 0.86);
  --menu-text: var(--text-default);
  --menu-subtext: rgba(15, 23, 42, 0.65);
  --menu-shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
  --menu-shadow-compact: 0 4px 12px rgba(15, 23, 42, 0.10);
  --menu-border: 1px solid rgba(15, 23, 42, 0.08);
  --menu-border-compact: 1px solid rgba(15, 23, 42, 0.10);
  --menu-glow: linear-gradient(180deg, rgba(51, 85, 37, 0.15), rgba(51, 85, 37, 0));
  --menu-pill-bg: rgba(51, 85, 37, 0.08);
  --menu-pill-border: 1px solid rgba(51, 85, 37, 0.20);
  --menu-list-border: 1px solid rgba(15, 23, 42, 0.12);
  --menu-list-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);

  /* Layering tokens (avoid magic numbers spread across CSS) */
  --z-menu: 10000;
  --z-widget: 15000;
  --z-widget-modal: 16000;
  --z-bootstrap-backdrop: 19990;
  --z-bootstrap-modal: 20000;
  --z-pipeline-modal: 20010;
  --z-noti-modal: 20020;
}

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

body {
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  background: var(--surface);
  color: var(--text-default);
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body.no-scroll {
  overflow: hidden !important;
}

html,
body {
  width: 100%;
  overflow-x: hidden;
}

.is-hidden,
.is-hidden-role,
.is-hidden-feature {
  display: none !important;
}

:where(button, input, select, textarea) {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--brand-ring-strong);
}

:root {
  --page-gradient: linear-gradient(180deg, #111727 0%, #0f172a 35%, #09101c 100%);
  --card-glow: 0 24px 60px rgba(15, 23, 42, 0.35);
  --page-gutter: clamp(12px, 2.8vw, 32px);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

main.page-content {
  width: calc(100% - (var(--page-gutter) * 2));
  max-width: 100%;
  margin: 0 auto;
  padding: clamp(20px, 3vw, 32px) 0 calc(48px + var(--safe-bottom));
  min-width: 0;
}

@media (max-width: 520px) {
  main.page-content { padding: 16px 12px 40px; }
  .page-header { padding-bottom: 12px; }
  .card-body { padding: 12px; }
  .section-title, .page-title { font-size: 18px; }
}

@media (max-width: 420px) {
  :root { --radius-card: 14px; --radius-control: 10px; }
  .card-body { padding: 10px; }
}

@media (max-width: 360px) {
  body { font-size: 14px; }
}

/* Skip link for keyboard users */
.skip-link {
  position: absolute;
  left: -999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.skip-link:focus {
  left: 12px;
  top: 12px;
  width: auto;
  height: auto;
  padding: 8px 12px;
  background: var(--brand);
  color: #fff;
  border-radius: 6px;
  z-index: 9999;
  text-decoration: none;
}

/* High-contrast focus outlines for accessibility */
:where(a, button, input, select, textarea):focus {
  outline: 3px solid var(--brand-ring-strong);
  outline-offset: 2px;
}

/* ============================================================
   Form validation (global)
   - Per-field error message + subtle red highlight
============================================================ */

.noti-field-error {
  display: none;
  margin-top: -10px;
  margin-bottom: 14px;
  font-size: 12px;
  font-weight: 800;
  color: #b91c1c;
}

.noti-field-error.is-visible {
  display: block;
}

:where(input, select, textarea).noti-input-error {
  border-color: rgba(220, 38, 38, 0.65) !important;
  background: rgba(220, 38, 38, 0.06) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.14) !important;
}

.noti-btn-loading {
  opacity: 0.85;
  cursor: progress !important;
}

.page-header {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.card.table-card,
.card {
  background: var(--surface-strong);
  border-radius: var(--radius-card);
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: var(--shadow-soft);
}

.card-body {
  padding: clamp(14px, 2.6vw, 24px);
  min-width: 0;
}

.section-title,
.page-title {
  color: var(--text-default);
  margin: 0;
  font-weight: 600;
}

.text-muted {
  color: var(--text-muted);
}

a {
  color: var(--brand);
}

a:hover {
  color: var(--brand-dark);
}

/* Bootstrap overrides (pages that import Bootstrap) */
:root {
  --bs-primary: var(--brand);
  --bs-primary-rgb: 51, 85, 37;
  --bs-link-color: var(--brand);
  --bs-link-hover-color: var(--brand-dark);
}

.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-dark);
  --bs-btn-hover-border-color: var(--brand-dark);
  --bs-btn-active-bg: var(--brand-dark);
  --bs-btn-active-border-color: var(--brand-dark);
  --bs-btn-focus-shadow-rgb: 51, 85, 37;
}

.btn-outline-primary {
  --bs-btn-color: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand);
  --bs-btn-hover-border-color: var(--brand);
  --bs-btn-active-bg: var(--brand-dark);
  --bs-btn-active-border-color: var(--brand-dark);
  --bs-btn-focus-shadow-rgb: 51, 85, 37;
}

.form-control:focus,
.form-select:focus {
  border-color: rgba(51, 85, 37, 0.55);
  box-shadow: 0 0 0 0.25rem rgba(51, 85, 37, 0.15);
}

.form-check-input:checked {
  background-color: var(--brand);
  border-color: var(--brand);
}

/* Default polish (Bootstrap + custom UIs) */
.btn,
.form-control,
.form-select,
.input-group-text,
.modal-content {
  border-radius: var(--radius-control);
}

.btn {
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}

.btn:focus-visible,
:where(button, [role="button"]):focus-visible,
:where(a, input, select, textarea):focus-visible {
  outline: none;
  box-shadow: 0 0 0 0.25rem var(--brand-ring-strong);
}

.badge {
  border-radius: var(--radius-pill);
}

.table > :not(caption) > * > * {
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
}

/* ============================================================
   Modals (Bootstrap + Noti custom)
============================================================ */

:root {
  --modal-overlay: rgba(15, 23, 42, 0.55);
  --modal-bg: rgba(255, 255, 255, 0.96);
  --modal-border: rgba(15, 23, 42, 0.12);
  --modal-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
  --modal-radius: 18px;
  --modal-header-bg: rgba(255, 255, 255, 0.78);
  --modal-header-border: rgba(51, 85, 37, 0.16);
}

@keyframes notiModalFadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes notiModalPop {
  from {
    transform: translateY(10px) scale(0.99);
    opacity: 0.75;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

/* Custom modal used by some pages (non-Bootstrap) */
.noti-modal {
  position: fixed;
  inset: 0;
  display: none;
  background: var(--modal-overlay);
  padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
  z-index: var(--z-pipeline-modal);
  overflow: auto;
  backdrop-filter: blur(2px);
}

.noti-modal.is-open {
  display: block;
  animation: notiModalFadeIn 160ms ease-out;
}

.noti-modal-content {
  max-width: 920px;
  margin: 0 auto;
  background:
    radial-gradient(820px 260px at 18% 0%, var(--brand-grad-1), transparent 62%),
    radial-gradient(720px 240px at 86% 10%, rgba(121, 168, 108, 0.14), transparent 60%),
    var(--modal-bg);
  border: 1px solid var(--modal-border);
  border-radius: var(--modal-radius);
  box-shadow: var(--modal-shadow);
  padding: 18px;
  backdrop-filter: blur(12px);
  max-height: calc(100vh - 36px);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  overscroll-behavior: contain;
  animation: notiModalPop 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.noti-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: -18px -18px 14px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--modal-header-bg);
  backdrop-filter: blur(14px);
  padding: 14px 18px 12px;
  border-bottom: 1px solid var(--modal-header-border);
}

.noti-modal-title {
  font-weight: 900;
  color: var(--text-default);
  font-size: 18px;
  letter-spacing: -0.02em;
}

.noti-modal-subtitle {
  color: rgba(15, 23, 42, 0.65);
  font-size: 12px;
  font-weight: 700;
}

.noti-modal-close {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.noti-modal-close i {
  font-size: 16px;
}

/* Unified "X" close button (used by pipeline + NotiComponents-created Bootstrap modals) */
.noti-close {
  --noti-close-size: 36px;
  width: var(--noti-close-size);
  height: var(--noti-close-size);
  padding: 0;
  margin: 0;
  border-radius: 999px;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.95) 0%,
    rgba(248, 249, 250, 0.95) 100%
  );
  border: 2px solid rgba(25, 135, 84, 0.2);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  opacity: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative; /* pseudo X */
  color: transparent; /* X drawn with pseudo elements */
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  appearance: none;
  -webkit-appearance: none;
}

.noti-close:hover {
  background: linear-gradient(135deg, #198754 0%, #146c43 100%);
  border-color: #198754;
  transform: scale(1.08) rotate(90deg);
  box-shadow: 0 4px 12px rgba(25, 135, 84, 0.25);
}

.noti-close:active {
  transform: scale(0.95) rotate(90deg);
  box-shadow: 0 2px 6px rgba(25, 135, 84, 0.3);
}

.noti-close::before,
.noti-close::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 2px;
  background-color: #198754;
  border-radius: 1px;
  transition: background-color 0.25s ease;
}

.noti-close::before { transform: rotate(45deg); }
.noti-close::after { transform: rotate(-45deg); }

.noti-close:hover::before,
.noti-close:hover::after {
  background-color: #ffffff;
}

.noti-close:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(25, 135, 84, 0.25), 0 4px 12px rgba(25, 135, 84, 0.15);
}

.noti-close span {
  display: none;
}

@media (max-width: 640px) {
  .noti-modal-content {
    padding: 12px;
  }
  .noti-modal-header {
    margin: -12px -12px 10px;
    padding: 12px 12px 10px;
  }
}

/* Bootstrap modal: skin to match Noti modal */
.modal-backdrop.show {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 1;
  background: var(--modal-overlay);
  backdrop-filter: blur(2px);
}

.modal.show .modal-dialog {
  animation: notiModalPop 180ms cubic-bezier(0.22, 1, 0.36, 1);
  transform: none;
  box-sizing: border-box;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: var(--z-bootstrap-modal);
  overflow: hidden;
  outline: 0;
  display: none;
  box-sizing: border-box;
}

/* Bootstrap modal uses inline display:block; force flex layout only when shown */
.modal.show {
  display: flex !important;
  align-items: center;
  justify-content: center;
}

.modal-content {
  position: relative;
  display: flex;
  flex-direction: column;
  pointer-events: auto;
  border-radius: var(--modal-radius);
  background:
    radial-gradient(820px 260px at 18% 0%, var(--brand-grad-1), transparent 62%),
    radial-gradient(720px 240px at 86% 10%, rgba(121, 168, 108, 0.14), transparent 60%),
    var(--modal-bg);
  border: 1px solid var(--modal-border);
  box-shadow: var(--modal-shadow);
  backdrop-filter: blur(12px);
  max-height: calc(100vh - 80px);
  max-height: calc(100dvh - 80px);
  overflow: hidden;
  box-sizing: border-box;
}

.modal-body {
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  padding: 1rem;
  box-sizing: border-box;
}

.modal-header {
  background: var(--modal-header-bg);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--modal-header-border);
  position: sticky;
  top: 0;
  z-index: 2;
  flex-shrink: 0;
  box-sizing: border-box;
}

.modal-title {
  font-weight: 900;
  letter-spacing: -0.02em;
}

.modal-footer {
  border-top: 1px solid rgba(15, 23, 42, 0.10);
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  background: inherit;
  z-index: 2;
  box-sizing: border-box;
}

.btn-close {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  opacity: 0.9;
  box-shadow: none;
}

.btn-close:hover {
  opacity: 1;
}

/* ============================================================
   Responsive defaults (global)
============================================================ */

:where(img, video, canvas) {
  max-width: 100%;
  height: auto;
}

/* Avoid layout overflow with long text/IDs */
:where(.page-content, .card, .card-body) {
  overflow-wrap: anywhere;
}

/* Utility: horizontal scroller for wide tables/grids */
.table-scroller {
  width: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Bootstrap helper: smooth horizontal scroll on mobile */
.table-responsive {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Mobile: Indicador visual de scroll horizontal em tabelas */
@media (max-width: 768px) {
  .table-scroller,
  .table-responsive {
    position: relative;
    background:
      linear-gradient(90deg, white 30%, rgba(255,255,255,0)),
      linear-gradient(-90deg, white 30%, rgba(255,255,255,0)),
      linear-gradient(90deg, rgba(15, 23, 42, 0.08), rgba(15, 23, 42, 0)),
      linear-gradient(-90deg, rgba(15, 23, 42, 0.08), rgba(15, 23, 42, 0));
    background-color: white;
    background-attachment: local, local, scroll, scroll;
    background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
    background-position: left center, right center, left center, right center;
    background-repeat: no-repeat;
  }
}

@media (max-width: 900px) {
  main.page-content {
    padding-bottom: 32px;
  }

  .page-header {
    padding-bottom: 14px;
    margin-bottom: 18px;
  }
}

@media (max-width: 520px) {
  main.page-content {
    width: calc(100% - 24px);
  }
}

/* ============================================================
   Mobile ergonomics (global)
   - Prevent iOS Safari auto-zoom on input focus (>= 16px)
   - Slightly larger tap targets
============================================================ */

@media (max-width: 520px) {
  :where(
    input[type="text"],
    input[type="search"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="url"],
    input[type="number"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="time"],
    select,
    textarea
  ) {
    font-size: 16px !important;
  }

  :where(button, .btn, [role="button"]) {
    min-height: 40px;
  }

  :where(button, .btn) {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  .page-title {
    font-size: 22px;
  }

  /* Bootstrap modals: better on phones */
  .modal-dialog {
    position: relative;
    width: auto;
    margin: auto;
    pointer-events: none;
    box-sizing: border-box;
  }

  /* Modal sizes */
  .modal-sm .modal-dialog {
    max-width: 400px;
  }

  .modal-md .modal-dialog {
    max-width: 600px;
  }

  .modal-lg .modal-dialog {
    max-width: 900px;
  }

  .modal-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    box-sizing: border-box;
  }

  .modal-footer .btn {
    width: 100%;
    box-sizing: border-box;
  }
}

/* Mobile: Max-height em modais para viewports baixos (previne overflow) */
@media (max-width: 520px) and (max-height: 700px) {
  .modal-content,
  .noti-modal-content {
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
  }

  .modal-body,
  .noti-modal-body {
    padding: 1rem;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    box-sizing: border-box;
  }
}

/* Altura muito baixa (landscape mobile ou telas pequenas) */
@media (max-width: 768px) and (max-height: 500px) {
  .modal-content,
  .noti-modal-content {
    max-height: 90vh;
    box-sizing: border-box;
  }

  .modal-header,
  .noti-modal-header {
    padding: 8px 12px;
    box-sizing: border-box;
  }

  .modal-footer,
  .noti-modal-footer {
    padding: 8px 12px;
    box-sizing: border-box;
  }
}

/* Common page layouts (Bootstrap-like pages + custom dashboards) */
@media (max-width: 680px) {
  .page-header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
  }

  .page-actions {
    width: 100% !important;
    min-width: 0 !important;
    justify-content: flex-start !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .page-actions > * {
    flex: 0 0 auto;
  }

  .filters-row {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .filters-row > * {
    width: 100% !important;
    min-width: 0 !important;
  }

  .filters-meta {
    flex-direction: column;
    align-items: flex-start;
  }

  .table-footer {
    flex-direction: column;
    align-items: stretch;
  }
}

  /* Global small-screen defaults: unify tokens and behaviors across pages */
  @media (max-width: 520px) {
    :root {
      --radius-card: 14px;
      --radius-control: 10px;
      --page-gutter: 12px;
    }

    /* Make primary controls full-width where appropriate */
    :where(.btn, button, .master-btn, .inicio-btn, .pipeline-btn) {
      width: 100%;
      display: block;
      box-sizing: border-box;
    }

    /* Inputs & selects should expand to container width */
    :where(input, select, textarea, .master-input, .pipeline-input, .form-control) {
      width: 100% !important;
      min-width: 0 !important;
      box-sizing: border-box;
    }

    /* Tables and wide grids get a consistent scroller */
    table, .table, .table-responsive, .table-scroller {
      width: 100% !important;
      overflow: auto !important;
      -webkit-overflow-scrolling: touch !important;
      overscroll-behavior: contain !important;
    }

    /* Reduce inner paddings on very small screens to maximize content */
    .card-body, .page-header, .filters-card, .table-card {
      padding: 10px !important;
    }
  }

  @media (max-width: 420px) {
    :root { --radius-card: 12px; --radius-control: 8px; }
    main.page-content { padding-left: 12px; padding-right: 12px; }
  }

  @media (max-width: 360px) {
    body { font-size: 14px; }
  }

/* ============================================================
   Utility: Esconder colunas não-essenciais em tabelas mobile
   Uso: <th class="d-none d-md-table-cell">Coluna Secundária</th>
============================================================ */

/* Desktop: mostrar todas as colunas */
@media (min-width: 769px) {
  .d-md-table-cell {
    display: table-cell !important;
  }
}

/* Mobile: esconder colunas marcadas */
@media (max-width: 768px) {
  .d-none.d-md-table-cell {
    display: none !important;
  }
}

/* Alternativa: classes específicas para viewports */
@media (max-width: 640px) {
  .hide-sm {
    display: none !important;
  }
}

@media (max-width: 520px) {
  .hide-xs {
    display: none !important;
  }
}

/* Sticky header para tabelas longas */
@media (min-width: 520px) {
  .sticky-head th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--surface-strong);
    box-shadow: 0 2px 4px rgba(15, 23, 42, 0.08);
  }
}
