/* ============================================================================
   Yaaleh page archetypes — shared, token-driven CSS that used to be duplicated
   inline in every page's <style> block. Desktop styling; mobile/native overrides
   live in mobile-app.css / mobile-native.css (loaded after this).
   ============================================================================ */

/* ===== Hub / landing pages (Home + module hubs) ===== */

/* Page header (module hubs, list/detail headers) */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 2rem 2rem 1.25rem;
  border-bottom: 1px solid var(--border-neutral-primary);
  margin-bottom: 0;
  background: var(--color-grey-10);
}

.page-header__main {
  min-width: 0;
}

.page-header h4 {
  font-family: var(--font-family-heading);
  font-weight: 700;
  color: var(--color-ink-900);
  margin-bottom: 4px;
  font-size: 1.35rem;
}

.page-header p {
  color: var(--color-grey-80);
  font-size: 0.9rem;
  margin: 0;
}

.page-header__actions {
  flex-shrink: 0;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Home hero */
.home-hero {
  background: linear-gradient(135deg, #06001b 0%, var(--color-brand-80) 55%, var(--color-brand-70) 100%);
  padding: 3rem 2.5rem 2.5rem;
  color: var(--color-white);
  position: relative;
  overflow: hidden;
}

.home-hero::before {
  content: '';
  position: absolute;
  top: -40%;
  right: -8%;
  width: 520px;
  height: 520px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 50%;
  pointer-events: none;
}

.home-hero::after {
  content: '';
  position: absolute;
  bottom: -55%;
  right: 12%;
  width: 360px;
  height: 360px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 50%;
  pointer-events: none;
}

.home-role-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--border-radius-pill);
  padding: 3px 12px;
  font-size: 0.8rem;
  font-weight: 500;
}

.home-hero h1 {
  font-family: var(--font-family-heading);
  font-size: 2rem;
  font-weight: 700;
  margin: 10px 0 4px;
  position: relative;
}

.home-hero .hero-sub {
  opacity: 0.75;
  font-size: 0.93rem;
  position: relative;
}

.home-hero .hero-date {
  opacity: 0.6;
  font-size: 0.85rem;
  margin-top: 2px;
  position: relative;
}

/* Section caption */
.section-label {
  font-family: var(--font-family-heading);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-grey-70);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.9rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--border-neutral-primary);
}

/* Nav cards (hub module cards) */
.nav-card {
  display: flex;
  flex-direction: column;
  background: var(--color-white);
  border: 1px solid var(--border-neutral-primary);
  border-radius: var(--border-radius-lg);
  padding: 22px 20px 18px;
  text-decoration: none;
  color: inherit;
  height: 100%;
  transition: box-shadow 0.18s, transform 0.18s, border-color 0.18s;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.nav-card:hover {
  box-shadow: 0 8px 24px rgba(0, 119, 212, 0.14);
  transform: translateY(-3px);
  border-color: var(--color-brand-70);
  color: inherit;
  text-decoration: none;
}

.nav-card-icon {
  width: 46px;
  height: 46px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.nav-card h5 {
  font-family: var(--font-family-heading);
  font-weight: 600;
  font-size: 0.97rem;
  margin: 0 0 6px;
  color: var(--color-ink-900);
}

.nav-card p {
  font-size: 0.82rem;
  color: var(--color-grey-80);
  margin: 0;
  line-height: 1.55;
  flex-grow: 1;
}

.nav-card-arrow {
  margin-top: 14px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--color-brand-70);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* Info tiles (Home "module" summary) */
.info-tile {
  background: var(--color-grey-10);
  border: 1px solid var(--border-neutral-primary);
  border-radius: var(--border-radius);
  padding: 20px;
  height: 100%;
}

.info-tile .tile-icon {
  font-size: 1.6rem;
  margin-bottom: 10px;
  display: block;
}

.info-tile h6 {
  font-family: var(--font-family-heading);
  font-weight: 600;
  font-size: 0.93rem;
  margin-bottom: 6px;
  color: var(--color-ink-900);
}

.info-tile p {
  font-size: 0.82rem;
  color: var(--color-grey-80);
  margin: 0;
  line-height: 1.55;
}

/* Shortcut chips */
.shortcut-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-white);
  border: 1px solid var(--border-neutral-primary);
  border-radius: var(--border-radius-sm);
  padding: 8px 14px;
  font-size: 0.83rem;
  font-weight: 500;
  color: var(--color-grey-100);
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  cursor: pointer;
}

.shortcut-chip:hover {
  background: var(--color-brand-10);
  border-color: var(--color-brand-70);
  color: var(--color-brand-90);
  text-decoration: none;
}

.shortcut-chip i {
  color: var(--color-brand-70);
  font-size: 0.95rem;
}

/* ===== List / index pages (ListPageShell) — part of the main, not a floating card ===== */
.list-page {
  width: 100%;
  /* Use (nearly) the full main width on desktop — only a slim gutter so the table breathes. */
  padding: 20px 16px 32px;
}

.list-page__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.list-page__title {
  margin: 0;
  font-family: var(--font-family-heading);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-ink-900);
}

.list-page__toolbar {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.list-page__toolbar .list-search {
  width: 340px;
  max-width: 100%;
}

.list-search__suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  max-height: 300px;
  overflow-y: auto;
  z-index: 1050;
}

/* The DS table sits directly on the page as the data surface (the .ds-table-wrap border/radius is
   the table's natural frame — not a modal card). Pagination/feedback flow below it on the page. */
.list-page .ds-table-wrap {
  box-shadow: var(--card-shadow);
  /* Let in-row dropdowns (status pill, actions menu) escape the wrap instead of being clipped.
     The list tables fit the full main width on desktop, so the wrap doesn't need to scroll. */
  overflow: visible;
}

/* Bootstrap's `.table{margin-bottom:1rem}` left a phantom empty strip below the table inside the
   wrap. Out-specify it to zero. Also use
   `border-collapse:separate` so the table's own corners can be rounded to match the wrap (the wrap
   runs `overflow:visible` to free in-row dropdowns, so it no longer clips the square table corners). */
.list-page table.ds-table {
  margin: 0;
  border-collapse: separate;
  border-spacing: 0;
  /* The wrap behind already provides the rounded white surface; the table's own white bg had square
     corners that poked out behind the rounded header cells. Drop it and round the table too. */
  background: transparent;
  border-radius: var(--border-radius);
}
.list-page table.ds-table thead tr:first-child th:first-child {
  border-top-left-radius: var(--border-radius);
}
.list-page table.ds-table thead tr:first-child th:last-child {
  border-top-right-radius: var(--border-radius);
}
.list-page table.ds-table tbody tr:last-child td:first-child {
  border-bottom-left-radius: var(--border-radius);
}
.list-page table.ds-table tbody tr:last-child td:last-child {
  border-bottom-right-radius: var(--border-radius);
}

/* Keep row-action icons (edit/delete) side by side — the narrow actions column was wrapping them
   into a stack and inflating the row height. */
.list-page table.ds-table td:last-child .d-flex {
  flex-wrap: nowrap !important;
}

.list-page table.ds-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.list-page table.ds-table th.sortable:hover {
  background: var(--color-grey-40);
}

.list-page .ds-pagination {
  margin-top: 18px;
}

.list-page__feedback {
  padding: 40px 16px;
  text-align: center;
  color: var(--color-grey-80);
}

/* Mobile: the article is edge-to-edge; the list page owns one consistent 14px gutter (toolbar + cards
   aligned). The Dashboard aging stays full-bleed (its container is zeroed separately). */
@media (max-width: 768px) {
  .list-page {
    padding: 4px 14px 20px;
  }
  /* On native the table is carded (cards-mobile) — flatten the desktop wrap frame (white/rounded/
     border/shadow) so the row-cards are the ONLY rounded surfaces. No wrap-card behind the cards. */
  html.yaaleh-maui-app .list-page .ds-table-wrap {
    background: transparent !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
  }
  html.yaaleh-maui-app .list-page table.ds-table {
    border-radius: 0 !important;
  }
  /* Action cell with several buttons (Editar / Permissões / Remover): let the button group drop to
     its own line inside the card instead of overflowing off the right edge. */
  html.yaaleh-maui-app .list-page table.cards-mobile td:last-child {
    flex-wrap: wrap;
    row-gap: 8px;
  }
  .list-page__header {
    margin-bottom: 12px;
  }
  .list-page__title {
    font-size: 1.2rem;
  }
  .list-page__toolbar {
    width: 100%;
  }
  .list-page__toolbar .list-search {
    width: 100%;
    flex: 1 1 100%;
  }
  .list-page__toolbar .ds-btn {
    flex: 1 1 auto;
    justify-content: center;
  }
}

/* ===== Agent association (AgentSync) — chips + per-row multi-select ===== */
.agent-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.agent-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 220px;
  padding: 3px 6px 3px 10px;
  background: var(--color-brand-tint);
  color: var(--color-brand-80);
  border: 1px solid var(--color-brand-20);
  border-radius: 999px;
  font-size: var(--font-size-13);
  font-weight: 600;
  line-height: 1.2;
}
.agent-chip__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--color-brand-70);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.agent-chip__remove:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--color-brand-90);
}

/* The "add agents" column needs room for the multi-select toggle; its menu scrolls internally. */
.agentsync-add-col {
  min-width: 240px;
}
.agentsync-menu {
  min-width: 250px;
  max-height: 240px;
  overflow-y: auto;
}

@media (max-width: 768px) {
  /* On native each user row becomes a card — let the dropdown, chips and menu use the card width. */
  .agentsync-add-col {
    min-width: 0;
  }
  .agentsync-menu {
    min-width: 0;
    width: 100%;
  }
  .agent-chip {
    max-width: 100%;
  }
}

/* ===== Form (create/edit) pages (FormPageShell) — part of the main, single clean surface ===== */
.form-page {
  width: 100%;
  max-width: 100%;
  padding: 20px 16px 40px;
}

.form-page__header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.form-page__back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  margin-top: 2px;
  color: var(--color-grey-90);
  background: var(--color-white);
  border: 1px solid var(--border-neutral-primary);
  border-radius: var(--border-radius-sm);
  text-decoration: none;
  transition: color 0.15s ease, border-color 0.15s ease;
}

.form-page__back:hover {
  color: var(--color-brand-70);
  border-color: var(--color-brand-40);
}

.form-page__title {
  margin: 0;
  font-family: var(--font-family-heading);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-ink-900);
}

.form-page__subtitle {
  margin: 2px 0 0;
  color: var(--color-grey-80);
  font-size: 0.9rem;
}

.form-page__surface {
  padding: 24px;
  background: var(--color-white);
  border: 1px solid var(--border-neutral-primary);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--card-shadow);
}

.form-page__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* Stacked footer actions (a `.d-grid` of buttons inside the form) read as full-width CTAs —
   `.ds-btn`'s inline-flex otherwise collapses them to content width inside the grid cell. */
.form-page .d-grid > .ds-btn,
.form-page .d-grid > .btn {
  width: 100%;
  justify-content: center;
}

/* Light design-system touch on form fields within form pages (no per-input markup change). */
.form-page .form-label {
  font-family: var(--font-family-body);
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--color-ink-900);
  margin-bottom: 4px;
}

.form-page .form-control,
.form-page .form-select {
  border-radius: var(--border-radius);
  border-color: var(--border-neutral-primary);
}

.form-page .form-control:focus,
.form-page .form-select:focus {
  border-color: var(--focus-ring);
  box-shadow: var(--focus-shadow);
}

@media (max-width: 768px) {
  .form-page {
    padding: 4px 14px 24px;
    max-width: 100%;
  }
  .form-page__surface {
    padding: 16px;
  }
}

/* ===== Dashboard aging — padrão limpo das listas (.data-table): cards brancos,
   cabeçalho sutil, sem os blocos azuis chapados que pesavam a tela. ===== */
.dashboard-aging .accordion-item {
  margin-bottom: 1rem;
  border: 1px solid #e2e8f0;
  border-radius: var(--border-radius-lg);
  background: var(--color-white);
  overflow: hidden;
}

.dashboard-aging .accordion-button {
  background-color: var(--color-white) !important;
  color: #1f2937 !important;
  font-family: var(--font-family-heading);
  font-weight: 700;
  border-radius: 0 !important;
  box-shadow: none !important;
}

.dashboard-aging .accordion-button:not(.collapsed) {
  background-color: #f7fafc !important;
  border-bottom: 1px solid #e2e8f0;
}

.dashboard-aging .accordion-button::after {
  /* chevron escuro sobre o header claro */
  filter: none;
}

/* Cabeçalho da tabela: branco com borda inferior (igual .data-table das listas) */
.dashboard-aging .table {
  margin-bottom: 0;
}

.dashboard-aging .table thead.bg-primary th {
  background-color: var(--color-white) !important;
  color: #2d3748 !important;
  font-weight: 600;
  border: 0 !important;
  border-bottom: 2px solid #e2e8f0 !important;
}

.dashboard-aging .table tbody td {
  color: #4a5568;
  border-color: #f0f4f8;
}

.dashboard-aging .table tbody tr:hover td {
  background: #f7fafc;
}

/* Linha "Total" (antes: tbody azul via style inline) → destaque sutil cinza */
.dashboard-aging .table tbody.fw-bold {
  background-color: #f1f5f9 !important;
  color: #1f2937 !important;
}

.dashboard-aging .table tbody.fw-bold td {
  border-top: 2px solid #e2e8f0;
}

/* Tighten the carded aging "total" card on mobile — the card's own bottom padding + an 11px margin
   read as dead space below TOTAL. (Scoped to Dashboard so other carded tables keep their spacing.) */
.dashboard-aging table.cards-mobile > tbody > tr {
  padding-bottom: 2px !important;
  margin-bottom: 4px !important;
}

/* ===== Single mobile gutter ===== On native the .main-container article owns the one 12px gutter.
   Page-level wrappers inside (PageHeader strip, the page's own .container-fluid.px-4) must NOT re-add
   horizontal padding — that was stacking into a doubled/tripled inset. */
@media (max-width: 768px) {
  /* Article is edge-to-edge (mobile-app.css). Bare-text headers add a small side inset so titles
     don't touch the screen; full-bleed strip bg, inset text. */
  html.yaaleh-maui-app .page-header {
    padding: 0.85rem 14px;
  }
  html.yaaleh-maui-app .container-fluid.px-4 {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  /* Aging on mobile = ONE cohesive card (the .accordion-item is the card: rounded, overflow hidden).
     Kill the round-on-round: the blue header is flush (the item's overflow rounds the top), and the
     aging rows are FLAT inside the card body — not separate rounded cards with their own bg/shadow. */
  html.yaaleh-maui-app .dashboard-aging .accordion-button {
    border-radius: 0 !important;
  }
  html.yaaleh-maui-app .dashboard-aging table.cards-mobile > tbody > tr,
  html.yaaleh-maui-app .dashboard-aging table.cards-mobile > tbody > tr.card-total {
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    margin: 0 !important;
  }
  /* Give the TOTAL line a subtle top divider so it still reads as the summary on the flat body. */
  html.yaaleh-maui-app .dashboard-aging table.cards-mobile > tbody > tr.card-total > td:last-child {
    border-top: 1px solid var(--m-border);
    margin-top: 2px;
    padding-top: 10px;
  }
}
