:root {
  --brand:      #e30613;
  --brand-dark: #c50011;
  --sidebar-w:  220px;
  --nav-h:      52px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: #f4f5f7; color: #222; }

/* ── Brand Wordmark ── */
.brand-wordmark {
  font-family: 'EB Garamond', Garamond, Georgia, serif;
  font-weight: 700; font-size: 2.6rem; color: var(--brand);
  letter-spacing: .12em; line-height: 1; margin-bottom: .15rem;
}
.brand-wordmark-sub {
  font-size: .78rem; font-weight: 600; letter-spacing: .18em;
  text-transform: uppercase; color: #555; margin-bottom: .1rem;
}
.brand-wordmark-nav {
  font-family: 'EB Garamond', Garamond, Georgia, serif;
  font-weight: 700; font-size: 1.15rem; color: #fff;
  letter-spacing: .1em; line-height: 1; vertical-align: middle;
}
.nav-brand-divider {
  color: rgba(255,255,255,.35); margin: 0 .55rem;
  font-weight: 300; font-size: 1rem; vertical-align: middle;
}

/* ── Login ── */
.login-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #e30613 0%, #8b0000 100%);
  display: flex; align-items: center; justify-content: center; z-index: 9999;
}
.login-card {
  background: #fff; border-radius: 14px;
  padding: 2.5rem 2rem; width: 100%; max-width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,.4); text-align: center;
}
.login-brand { margin-bottom: .25rem; }
.login-sub   { font-size: .85rem; color: #888; margin-bottom: 1.5rem; }

/* ── App Shell ── */
#appShell { display: flex; flex-direction: column; height: 100vh; }

/* ── Navbar ── */
.app-nav {
  height: var(--nav-h); background: var(--brand);
  display: flex; align-items: center; padding: 0 1.25rem;
  gap: 1rem; flex-shrink: 0; box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.nav-brand { color: #fff; font-weight: 800; font-size: 1.1rem; letter-spacing: .03em; flex: 1; }
.nav-user  { color: rgba(255,255,255,.85); font-size: .82rem; }

/* ── Body = sidebar + content ── */
.app-body { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w); background: #fff; border-right: 1px solid #e5e7eb;
  overflow-y: auto; flex-shrink: 0; padding: .75rem 0;
}
.sidebar-section { padding: .25rem .75rem; font-size: .65rem; font-weight: 800;
  text-transform: uppercase; letter-spacing: .08em; color: #aaa; margin-top: .75rem; }
.nav-item {
  display: flex; align-items: center; gap: .6rem;
  padding: .5rem 1rem; font-size: .85rem; color: #555; cursor: pointer;
  border-left: 3px solid transparent; transition: all .12s;
}
.nav-item:hover { background: #fef2f2; color: var(--brand); }
.nav-item.active { background: #fef2f2; color: var(--brand); font-weight: 600;
  border-left-color: var(--brand); }
.nav-item i { font-size: 1rem; width: 20px; text-align: center; }

/* ── Page Content ── */
.page-content { flex: 1; overflow-y: auto; padding: 1.5rem; }
.page-title   { font-size: 1.25rem; font-weight: 700; margin-bottom: 1.25rem; color: #1a1a1a; }

/* ── KPI Cards (same pattern as project feedback) ── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .875rem; margin-bottom: 1.5rem; }
.kpi-card {
  background: #fff; border: 1px solid #DEE2E6; border-radius: 12px;
  padding: .9rem 1.1rem .8rem; box-shadow: 0 1px 3px rgba(0,0,0,.06);
  border-top: 3px solid var(--brand-color, #1971C2);
}
.kpi-label {
  font-size: .6rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: #868E96; margin: 0 0 5px;
}
.kpi-value {
  font-size: clamp(.82rem, 1.5vw, 1.2rem); font-weight: 700;
  color: var(--brand-color, #1971C2); line-height: 1.2; margin: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kpi-sub { font-size: .72rem; color: #868E96; margin: 4px 0 0; }

/* ── Tables ── */
.table-wrap { background: #fff; border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.07); overflow: hidden; }
.table-wrap table { width: 100%; border-collapse: collapse; font-size: .83rem; }
.table-wrap thead th {
  background: #f8f9fa; padding: .625rem .875rem; text-align: left;
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: #6c757d; border-bottom: 2px solid #e9ecef;
  white-space: nowrap;
  position: sticky; top: 0; z-index: 2;
  box-shadow: 0 1px 0 #e9ecef;
}
.table-wrap tbody tr { border-bottom: 1px solid #f0f0f0; transition: background .1s; }
.table-wrap tbody tr:hover { background: #fafafa; }
.table-wrap tbody td { padding: .55rem .875rem; vertical-align: middle; }
.table-wrap tbody tr:last-child { border-bottom: none; }

/* ── Badges ── */
.badge-status {
  display: inline-block; padding: .2rem .55rem; border-radius: 20px;
  font-size: .7rem; font-weight: 700; text-transform: capitalize;
}
.badge-pendente    { background: #fff3cd; color: #856404; }
.badge-em_analise  { background: #cff4fc; color: #055160; }
.badge-aprovado    { background: #d1e7dd; color: #0f5132; }
.badge-reprovado   { background: #f8d7da; color: #842029; }
.badge-cancelado   { background: #e9ecef; color: #6c757d; }
.badge-utilizado   { background: #e0cffc; color: #3d1d8e; }

.badge-risco-alto  { background: #f8d7da; color: #842029; }
.badge-risco-medio { background: #fff3cd; color: #856404; }
.badge-risco-baixo { background: #d1e7dd; color: #0f5132; }

/* ── Filters bar ── */
.filters-bar {
  display: flex; align-items: flex-end; gap: .75rem; flex-wrap: wrap;
  background: #fff; padding: .875rem 1rem; border-radius: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.07); margin-bottom: 1rem;
}
.filter-group label { display: block; font-size: .72rem; font-weight: 600; color: #555; margin-bottom: .25rem; }
.filter-group select, .filter-group input { border: 1px solid #ced4da; border-radius: 6px; padding: .3rem .6rem; font-size: .82rem; color: #333; background: #fff; }

/* ── Detail card ── */
.detail-section { background: #fff; border-radius: 10px; padding: 1.25rem; box-shadow: 0 1px 4px rgba(0,0,0,.07); margin-bottom: 1rem; }
.detail-section h6 { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: #888; margin: 0 0 .875rem; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .625rem; }
.detail-field label { font-size: .7rem; color: #888; display: block; margin-bottom: 2px; }
.detail-field span  { font-size: .88rem; font-weight: 600; color: #222; }

/* ── Score bar ── */
.score-bar-wrap { background: #f0f0f0; border-radius: 20px; height: 10px; overflow: hidden; margin-top: 4px; }
.score-bar { height: 100%; border-radius: 20px; transition: width .4s ease; }

/* ── Charts ── */
.chart-wrap {
  background: #fff; border-radius: 10px; padding: 1rem 1.25rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.07); margin-bottom: 1rem;
  overflow: hidden; position: relative;
}
.chart-title {
  font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; color: #9ca3af; margin-bottom: .875rem;
  border-bottom: 1px solid #f1f5f9; padding-bottom: .5rem;
}

/* ── Dashboard tabs ── */
.dash-tab {
  background: none; border: none; border-bottom: 3px solid transparent;
  padding: .55rem .9rem; font-size: .82rem; font-weight: 600; color: #6b7280;
  cursor: pointer; white-space: nowrap; transition: color .15s, border-color .15s;
}
.dash-tab:hover { color: #374151; }
.dash-tab.active { color: #C92A2A; border-bottom-color: #C92A2A; }

/* ── Empty state ── */
.empty-state { text-align: center; padding: 3rem; color: #aaa; }
.empty-state i { font-size: 2.5rem; display: block; margin-bottom: .5rem; }

/* ── Form ── */
.form-section { background: #fff; border-radius: 10px; padding: 1.5rem; box-shadow: 0 1px 4px rgba(0,0,0,.07); max-width: 700px; }
.form-section h6 { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; color: #888; margin: 1.25rem 0 .875rem; }
.form-section h6:first-child { margin-top: 0; }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9000; }

/* ── Spinner overlay ── */
.page-loading { display: flex; align-items: center; justify-content: center; height: 200px; }

/* ── SLA colors ── */
.sla-ok   { color: #198754; }
.sla-warn { color: #856404; }
.sla-crit { color: #842029; font-weight: 700; }

/* ── Hamburger btn — hidden on desktop ── */
#menuBtn { display: none; }

/* ── Sidebar backdrop ── */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  top: var(--nav-h);
  background: rgba(0,0,0,.45);
  z-index: 999;
}
.sidebar-backdrop.open { display: block; }

/* ── Responsive ── */
@media (max-width: 768px) {
  #menuBtn { display: inline-flex; }

  .sidebar {
    position: fixed;
    top: var(--nav-h);
    left: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,.18);
  }
  .sidebar.open { transform: translateX(0); }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Row status stripe (left border on first cell) ── */
td.status-stripe-pendente   { border-left: 3px solid #856404 !important; }
td.status-stripe-em_analise { border-left: 3px solid #0c9eb5 !important; }
td.status-stripe-aprovado   { border-left: 3px solid #198754 !important; }
td.status-stripe-reprovado  { border-left: 3px solid #dc3545 !important; }
td.status-stripe-cancelado  { border-left: 3px solid #adb5bd !important; }

/* ──────────────────────────────────────────────────────────────
   Liberação de Pagamento — responsivo (tabela → cards no mobile)
   ────────────────────────────────────────────────────────────── */
@media (max-width: 820px) {
  /* Tabela vira cards empilhados, uma coluna */
  .lib-table thead { display: none; }
  .lib-table, .lib-table tbody, .lib-table tr, .lib-table td { display: block; width: 100%; }
  .lib-table tr {
    border: 1px solid #e3e3e3;
    border-radius: 12px;
    margin-bottom: 1rem;
    padding: .85rem 1rem 1rem;
    background: #fff !important;
    box-shadow: 0 1px 4px rgba(0,0,0,.07);
    opacity: 1 !important;            /* não esmaecer cards não-marcados */
  }
  /* Reset total dos estilos inline herdados da tabela (max-width/overflow/nowrap) */
  .lib-table td {
    border: none !important;
    box-shadow: none !important;       /* mata o striping do Bootstrap */
    background: transparent !important;
    padding: .45rem 0 !important;
    max-width: none !important;
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
    text-align: left !important;
  }
  /* Rótulo acima do campo */
  .lib-table td::before {
    content: attr(data-label);
    display: block;
    font-weight: 700;
    color: #8a8a8a;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: .25rem;
  }

  /* Campos ocupam largura total, altura de toque (44px), 16px evita zoom iOS */
  .lib-table td > .form-control,
  .lib-table td > .form-select {
    width: 100%;
    min-height: 44px;
    font-size: 16px;
  }
  /* Célula de pagamento do cartão: 3 campos lado a lado, com wrap */
  .lib-table td > div { display: flex; gap: .4rem; flex-wrap: wrap; }
  .lib-table td > div .form-control { min-height: 44px; font-size: 16px; }
  .lib-table .lib-qt { flex: 0 0 70px; }
  .lib-table .lib-nsu, .lib-table .lib-autorizacao { flex: 1 1 100px; }

  /* Filial = título do card; Valor em destaque */
  .lib-table td[data-label="Filial"] { font-size: 1.02rem; font-weight: 700; color: #222; }
  .lib-table td[data-label="Valor"]  { font-size: 1.1rem; font-weight: 700; color: #198754; }

  /* Checkbox no topo do card, sem rótulo, maior pra toque */
  .lib-table td[data-label="Sel."]::before { display: none; }
  .lib-table td[data-label="Sel."] { padding-bottom: .2rem !important; }
  .lib-table .lib-chk, .lib-table #libChkAll { width: 24px; height: 24px; }

  /* Botão de anexo com área de toque adequada (44px) */
  .lib-table .lib-anexo {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    font-size: 1.25rem;
    margin-left: .35rem;
  }

  /* Barra de ações fixa no rodapé da viewport (thumb zone) */
  .lib-actions {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    background: #fff;
    border-top: 1px solid #e3e3e3;
    padding: .6rem;
    display: flex;
    gap: .5rem;
    z-index: 1050;
    box-shadow: 0 -2px 8px rgba(0,0,0,.08);
    margin: 0 !important;
  }
  .lib-actions .btn { flex: 1; min-height: 48px; font-size: .92rem; }
  .lib-actions .lib-recarregar { flex: 0 0 52px; }
  /* Espaço pra barra fixa não cobrir o último card */
  #libTabela { padding-bottom: 90px; }
}
