/* ═══════════════════════════════════════════════════════════════════════════
   fama-table.css  —  Standard card + table pattern for FAMA pages
   ───────────────────────────────────────────────────────────────────────────
   Usage
   ─────
     <link rel="stylesheet" href="{{ url_for('static', filename='css/fama-table.css') }}">

   HTML skeleton
   ─────────────
     <div class="ft-card">
       <div class="ft-card-header">
         <div>
           <div class="ft-card-title"><i class="..."></i> Title</div>
           <div class="ft-card-subtitle">Subtitle</div>
         </div>
         <div class="ft-card-actions">
           <a href="..." class="btn btn-primary btn-sm">...</a>
         </div>
       </div>
       <div class="ft-table-area">
         <table class="ft-table table" data-toggle="table" ...>
           <thead><tr>
             <th>Label</th>
             <th class="ft-num">Value (R$)</th>
             <th class="ft-num ft-total">Total (R$)</th>
             <th class="text-center" style="width:90px;">Options</th>
           </tr></thead>
           <tbody>...</tbody>
           <tfoot class="ft-tfoot"><tr>...</tr></tfoot>
         </table>
       </div>
     </div>

   Required JS (bootstrap-table pages)  — paste in {% block scripts %}
   ───────────────────────────────────────────────────────────────────
   Note: FAMA loads bootstrap-table twice (v1.12 CSS + v1.22 JS).
   The event-driven pattern below runs after both initialisations and:
   - groups container + pagination inside a single framed box
   - forces white header via setProperty (theme CSS overrides !important)

     (function(){
       var $card=$('.ft-card'),$area=$card.find('.ft-table-area');
       var $table=$card.find('.ft-table'),applied=false;
       function applyLayout(){
         if(applied)return; applied=true;
         $card.find('.fixed-table-toolbar')
              .css({'padding-left':'1.25rem','padding-right':'1.25rem'});
         var $c=$card.find('.fixed-table-container');
         var $p=$('.fixed-table-pagination').first();
         if($c.length&&!$c.parent().hasClass('ft-table-wrap')){
           var $w=$('<div class="ft-table-wrap"></div>').css({margin:'0 1.25rem'});
           $c.before($w); $w.append($c);
           $c.css({border:'1px solid #e2e8f0',borderRadius:'8px'});
         }
         $card.find('thead th').each(function(){
           this.style.setProperty('background','#ffffff','important');
           this.style.setProperty('color','#475569','important');
           this.style.setProperty('border-top','none','important');
           this.style.setProperty('border-bottom','2px solid #e2e8f0','important');
         });
       }
       $table.on('all.bs.table post-body.bs.table',function(){applied=false;applyLayout();});
       $(function(){setTimeout(applyLayout,0);});
     })();

   Classes
   ───────
   .ft-card                  Outer wrapper card (with lateral margin)
   .ft-card-header           Card header row  (title left, actions right)
   .ft-card-title            H tag inside .ft-card-header
   .ft-card-subtitle         Muted subtitle below title
   .ft-card-actions          Button group inside .ft-card-header (right side)
   .ft-table-area            Wrapper for bootstrap-table generated DOM
   .ft-table                 The <table> element
   .ft-num                   Right-aligned numeric cell
   .ft-total                 Highlighted total cell / column (blue)
   .ft-badge                 Small pill badge
   .ft-badge-{color}         Colour variants: blue (default), green, red, amber, gray, teal
   .ft-empty                 Full-width empty-state block (no data)
   .ft-tfoot                 <tfoot> totals row style
   .ft-actions               Cell wrapping edit/delete buttons
═══════════════════════════════════════════════════════════════════════════ */

/* ── Card ──────────────────────────────────────────────────────────────── */
.ft-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, .06);
  /* overflow: hidden removed — was clipping the rows-per-page dropdown in pagination */
  margin: 0 .75rem 1.25rem;
}

/* Clip border-radius on the card header/footer only, not the whole card */
.ft-card-header:first-child {
  border-radius: 10px 10px 0 0;
}
.ft-card > *:last-child {
  border-radius: 0 0 10px 10px;
}

.ft-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .85rem 1.25rem;
  border-bottom: 1px solid #f0f4f8;
  background: #fff;
  gap: 1rem;
}

.ft-card-title {
  font-size: .9rem;
  font-weight: 700;
  color: #1e2a3a;
  letter-spacing: .02em;
  margin: 0;
}

.ft-card-subtitle {
  font-size: .75rem;
  color: #8c9ab0;
  margin-top: .1rem;
}

.ft-card-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

/* ── Table ─────────────────────────────────────────────────────────────── */
.ft-table {
  width: 100%;
  margin: 0;
  border-collapse: collapse;
  font-size: .875rem;
}

.ft-table thead th,
.ft-card .fixed-table-header th,
.ft-card .fixed-table-body thead th {
  background: #ffffff !important;
  color: #475569 !important;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
  border: none !important;
  border-bottom: 2px solid #e2e8f0 !important;
  padding: .65rem .85rem;
  vertical-align: middle;
}

.ft-table tbody tr {
  border-bottom: 1px solid #f0f4f8;
  transition: background .1s;
}

.ft-table tbody tr:last-child { border-bottom: none; }

.ft-table tbody tr:hover { background: #f5f8ff; }

.ft-table tbody td {
  padding: .6rem .85rem;
  vertical-align: middle;
  color: #334155;
}

/* ── Numeric cells ─────────────────────────────────────────────────────── */
.ft-num {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ── Total / highlight column ──────────────────────────────────────────── */
.ft-total {
  color: #187fc3 !important;
  font-weight: 700 !important;
}

/* ── Footer (totals row) ───────────────────────────────────────────────── */
.ft-tfoot td {
  padding: .65rem .85rem;
  font-size: .875rem;
  font-weight: 700;
  background: #f8fafc;
  border-top: 2px solid #e2e8f0 !important;
  color: #1e2a3a;
}

/* ── Badges ────────────────────────────────────────────────────────────── */
.ft-badge {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  white-space: nowrap;
  background: #e8f0fe;
  color: #3b5bdb;
}

.ft-badge-blue   { background: #e8f0fe; color: #3b5bdb; }
.ft-badge-green  { background: #dcfce7; color: #15803d; }
.ft-badge-red    { background: #fee2e2; color: #b91c1c; }
.ft-badge-amber  { background: #fef9c3; color: #92400e; }
.ft-badge-gray   { background: #f1f5f9; color: #475569; }
.ft-badge-teal   { background: #ccfbf1; color: #0f766e; }

/* ── Empty state ───────────────────────────────────────────────────────── */
.ft-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: #94a3b8;
}

.ft-empty-icon {
  font-size: 2.5rem;
  margin-bottom: .75rem;
  display: block;
  opacity: .4;
}

.ft-empty-title {
  font-size: 1rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: .4rem;
}

.ft-empty-text {
  font-size: .85rem;
  color: #94a3b8;
}

/* ── Action buttons inside table ───────────────────────────────────────── */
.ft-actions {
  white-space: nowrap;
  text-align: center;
}

.ft-actions .btn {
  padding: .2rem .45rem;
  font-size: .78rem;
  line-height: 1.4;
}

/* ── Table area ─────────────────────────────────────────────────────────── */
.ft-table-area {
  padding: 0;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Bootstrap-table overrides — scoped to .ft-card
   Note: table container inset + border-radius applied via JS (see header)
═══════════════════════════════════════════════════════════════════════════ */

/* Toolbar — flex, everything pushed to the right */
.ft-card .fixed-table-toolbar {
  padding: .75rem 1.25rem .5rem;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  flex-wrap: wrap;
  gap: .4rem;
}

/* Search comes first (visually leftmost of the right group) */
.ft-card .fixed-table-toolbar .search {
  order: 0;
  float: none !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: .5rem;
}

/* Buttons wrapper (div.columns) comes AFTER the search */
.ft-card .fixed-table-toolbar .columns {
  order: 1;
  float: none !important;
}

/* Toolbar buttons (export + columns toggle + view toggle) */
.ft-card .fixed-table-toolbar .btn-group > .btn,
.ft-card .fixed-table-toolbar .columns > .btn,
.ft-card .fixed-table-toolbar .btn {
  background: #f8fafc !important;
  border: 1px solid #e2e8f0 !important;
  color: #475569 !important;
  font-size: .78rem !important;
  height: 32px !important;
  max-height: 32px !important;
  padding: 0 .65rem !important;
  line-height: 30px !important;
  border-radius: 6px !important;
  box-shadow: none !important;
  vertical-align: middle;
  transition: background .12s, border-color .12s;
}

/* btn-group wrapper — keep inline-flex so it doesn't stretch */
.ft-card .fixed-table-toolbar .columns,
.ft-card .fixed-table-toolbar .columns .btn-group {
  display: inline-flex !important;
  align-items: center !important;
  height: 32px !important;
  vertical-align: middle;
}

.ft-card .fixed-table-toolbar .btn:hover {
  background: #f0f4f8 !important;
  border-color: #cbd5e1 !important;
  color: #1e2a3a !important;
}

/* Search wrapper — inline-flex so input + clear sit on same axis */
.ft-card .fixed-table-toolbar .search {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}

/* Search input — override Bootstrap .form-control height */
.ft-card .fixed-table-toolbar .search input,
.ft-card .fixed-table-toolbar .search input.form-control {
  height: 32px !important;
  max-height: 32px !important;
  min-height: 32px !important;
  line-height: 30px !important;
  padding: 0 .75rem !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 6px !important;
  font-size: .78rem !important;
  color: #334155 !important;
  background: #fafafa !important;
  box-shadow: none !important;
  min-width: 200px;
  transition: border-color .15s, background .15s;
}

.ft-card .fixed-table-toolbar .search input:focus,
.ft-card .fixed-table-toolbar .search input.form-control:focus {
  border-color: #6366f1 !important;
  background: #fff !important;
  outline: none !important;
  box-shadow: none !important;
}

/* Clear button */
.ft-card .fixed-table-toolbar .search .btn-default,
.ft-card .fixed-table-toolbar .search .search-clear-button {
  margin-left: .4rem !important;
  height: 32px !important;
  max-height: 32px !important;
  line-height: 30px !important;
  padding: 0 .65rem !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 6px !important;
  font-size: .78rem !important;
  color: #475569 !important;
  background: #f8fafc !important;
  box-shadow: none !important;
}

/* Pagination — position:relative + z-index garante que o dropdown fica
   no primeiro plano acima do fixed-table-container */
.ft-card .fixed-table-pagination {
  padding: .5rem 1.25rem;
  border-top: 1px solid #f0f4f8;
  position: relative;
  z-index: 10;
}

.ft-card .fixed-table-pagination .pagination-detail {
  margin-left: 1.5rem !important;
}

.ft-card .fixed-table-pagination .pagination-info {
  font-size: .78rem;
  color: #8c9ab0;
}

.ft-card .fixed-table-pagination .pagination .page-link {
  font-size: .78rem;
  padding: .25rem .55rem;
  color: #475569;
  border-color: #e2e8f0;
}

.ft-card .fixed-table-pagination .pagination .page-item.active .page-link {
  background: #3f6ad8;
  border-color: #3f6ad8;
  color: #fff;
}

/* Remove double border on outer wrappers */
.ft-card .fixed-table-border {
  border: none !important;
}

/* ═══════════════════════════════════════════════════════════════════════════
   GLOBAL bootstrap-table normalization — applies to ALL tables app-wide
   .ft-card-scoped rules above take precedence via higher specificity.
   These ensure consistent style even on legacy "card" + "omp-filter-card"
   containers that don't use the ft-card pattern.
═══════════════════════════════════════════════════════════════════════════ */

/* ── Global: Table body font & cell style ─────────────────────────────── */
[data-toggle="table"] tbody td {
  font-size: .875rem;
  color: #334155;
  vertical-align: middle;
}

/* ── Global: Table header ─────────────────────────────────────────────── */
[data-toggle="table"] thead th {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #475569;
  white-space: nowrap;
  vertical-align: middle;
}

/* ── Global: Smaller pagination ───────────────────────────────────────── */
.fixed-table-pagination .pagination .page-link {
  font-size: .78rem !important;
  padding: .25rem .55rem !important;
  color: #475569;
  border-color: #e2e8f0;
  line-height: 1.4;
}

.fixed-table-pagination .pagination .page-item.active .page-link,
.fixed-table-pagination .pagination li.active a {
  background-color: #3f6ad8 !important;
  border-color:     #3f6ad8 !important;
  color:            #fff    !important;
}

.fixed-table-pagination .pagination-info,
.fixed-table-pagination .page-list .btn {
  font-size: .78rem !important;
  color: #8c9ab0;
}

.fixed-table-pagination .page-list .btn {
  padding: .25rem .55rem !important;
  border-color: #e2e8f0;
}

/* ── Global: Pagination stacking context + dropdown z-index ──────────── */
.fixed-table-pagination {
  position: relative;
  z-index: 10;
}
.fixed-table-pagination .page-list .dropdown-menu {
  z-index: 1060 !important;
}

/* ── Global: Rows-per-page button — azul consistente com paginação ────── */
.fixed-table-pagination .page-list .btn,
.fixed-table-pagination .page-list .btn-secondary,
.fixed-table-pagination .page-list .btn-default {
  background-color: #3f6ad8 !important;
  border-color:     #3f6ad8 !important;
  color:            #fff    !important;
}
.fixed-table-pagination .page-list .btn:hover,
.fixed-table-pagination .page-list .btn-secondary:hover {
  background-color: #3461c5 !important;
  border-color:     #3461c5 !important;
}
.fixed-table-pagination .page-list .dropdown-menu > li > a {
  font-size: .78rem !important;
  padding: .3rem .75rem;
}

/* ── Global: Toolbar — flex, everything pushed to the right ──────────── */
.fixed-table-toolbar {
  display: flex !important;
  align-items: center !important;
  justify-content: flex-end !important;
  flex-wrap: wrap;
  gap: .4rem;
}

/* Search comes first (visually leftmost of the right group) */
.fixed-table-toolbar .search {
  order: 0;
  float: none !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: .5rem;
}

/* Buttons wrapper (div.columns) comes AFTER the search */
.fixed-table-toolbar .columns {
  order: 1;
  float: none !important;
}

/* ── Global: Toolbar buttons (export, columns, toggle, search clear) ─── */
.fixed-table-toolbar .btn-group > .btn,
.fixed-table-toolbar .columns > .btn,
.fixed-table-toolbar > .btn {
  height: 32px !important;
  max-height: 32px !important;
  line-height: 30px !important;
  vertical-align: middle;
}

.fixed-table-toolbar .columns,
.fixed-table-toolbar .columns .btn-group {
  display: inline-flex !important;
  align-items: center !important;
  height: 32px !important;
  vertical-align: middle;
}

.fixed-table-toolbar .search .btn-default,
.fixed-table-toolbar .search .search-clear-button {
  margin-left: .4rem !important;
  height: 32px !important;
  max-height: 32px !important;
  line-height: 30px !important;
  padding: 0 .65rem !important;
  font-size: .78rem !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 6px !important;
  background: #f8fafc !important;
  color: #475569 !important;
  box-shadow: none !important;
  vertical-align: middle;
  transition: background .12s, border-color .12s;
}

.fixed-table-toolbar .search .btn-default:hover,
.fixed-table-toolbar .search .search-clear-button:hover,
.fixed-table-toolbar .btn-group > .btn:hover,
.fixed-table-toolbar > .btn:hover {
  background: #f0f4f8 !important;
  border-color: #cbd5e1 !important;
  color: #1e2a3a !important;
}

/* ── Global: Search input — override Bootstrap .form-control ──────────── */
.fixed-table-toolbar .search input,
.fixed-table-toolbar .search input.form-control {
  height: 32px !important;
  max-height: 32px !important;
  min-height: 32px !important;
  line-height: 30px !important;
  border: 1px solid #e2e8f0 !important;
  border-radius: 6px !important;
  font-size: .78rem !important;
  padding: 0 .75rem !important;
  color: #334155 !important;
  background: #fafafa !important;
  box-shadow: none !important;
  transition: border-color .15s, background .15s;
}

.fixed-table-toolbar .search input:focus,
.fixed-table-toolbar .search input.form-control:focus {
  border-color: #6366f1 !important;
  background: #fff !important;
  outline: none !important;
  box-shadow: none !important;
}
