:root {
    --sidebar-w: 255px;
    --sidebar-bg: #1a1f2e;
    --topbar-h: 52px;
    --accent: #3b82f6;
    --content-pad: 1.25rem;
}

/* Base font — responsivo via clamp */
html { font-size: clamp(13px, 1.1vw, 16px); }
body { background: #f0f2f7; font-family: 'Segoe UI', system-ui, sans-serif; }

/* ===== SIDEBAR ===== */
.sidebar {
    display: flex;
    flex-direction: column;
    width: var(--sidebar-w);
    min-height: 100vh;
    height: 100vh;
    background: var(--sidebar-bg);
    color: #b0b8c8;
    overflow-y: auto;
    position: sticky;
    top: 0;
    flex-shrink: 0;
    z-index: 1045;
}
.sidebar-brand { color: #fff; font-weight: 700; font-size: 1.1rem; }

.sidebar .nav-link {
    color: #b0b8c8;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: .875rem;
    transition: all .18s;
}
.sidebar .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar .nav-link.active { background: var(--accent); color: #fff; }

.sidebar .nav-sub {
    color: #7a8899;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: .82rem;
}
.sidebar .nav-sub:hover { color: #fff; background: rgba(255,255,255,.05); }
.sidebar .nav-sub.active { color: var(--accent); background: rgba(59,130,246,.15); }

.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); }

/* Backdrop para overlay */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 1044;
}
.sidebar-backdrop.show { display: block; }

/* ===== TOPBAR ===== */
.top-bar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 6px rgba(0,0,0,.07);
}

.topbar-divider {
    width: 1px; height: 22px;
    background: #e5e7eb;
    flex-shrink: 0; margin: 0 4px;
}

.topbar-breadcrumb {
    align-items: center; overflow: hidden;
    text-overflow: ellipsis; white-space: nowrap;
}
.topbar-breadcrumb .breadcrumb-item {
    font-size: .8rem; color: #9ca3af;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-breadcrumb .breadcrumb-item a {
    color: #6b7280; text-decoration: none; transition: color .15s;
}
.topbar-breadcrumb .breadcrumb-item a:hover { color: var(--accent); }
.topbar-breadcrumb .breadcrumb-item + .breadcrumb-item::before {
    color: #d1d5db; font-size: .75rem;
}
.topbar-breadcrumb .breadcrumb-item.active {
    font-size: .9rem; font-weight: 700;
    color: #111827; overflow: hidden; text-overflow: ellipsis;
}

.topbar-right { gap: .5rem; }
.topbar-date {
    font-size: .78rem; color: #9ca3af; font-weight: 500;
    gap: .3rem; background: #f9fafb; border: 1px solid #f0f0f0;
    border-radius: 20px; padding: 3px 10px;
}
.topbar-user-pill {
    display: inline-flex; align-items: center; gap: .4rem;
    background: var(--accent); color: #fff;
    border-radius: 20px; padding: 4px 12px;
    font-size: .8rem; font-weight: 600;
    cursor: default; user-select: none;
}
.topbar-user-pill i { font-size: 1rem; }

.btn-sidebar-toggle {
    display: inline-flex; align-items: center;
    background: none; border: none; padding: 6px 8px;
    border-radius: 8px; color: #374151; font-size: 1.3rem;
    line-height: 1; cursor: pointer; transition: background .15s, color .15s;
}
.btn-sidebar-toggle:hover { background: #f3f4f6; color: var(--accent); }

/* ===== MAIN ===== */
.main-content { min-height: 100vh; background: #f0f2f7; overflow-x: hidden; }

/* Content padding — usa variável para facilitar override */
.content-wrapper {
    padding: var(--content-pad);
    flex-grow: 1;
}

/* ===== CARDS ===== */
.card { border: none; border-radius: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.card-header { background: transparent; border-bottom: 1px solid #f0f2f7; padding: .75rem 1.1rem; }

/* ===== KPI ===== */
.kpi-label { color: #6b7280; font-size: .82rem; margin-bottom: 4px; }
.kpi-value { font-size: 1.55rem; font-weight: 700; color: #111827; margin: 0; }
.kpi-icon { width: 44px; height: 44px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; }
.kpi-card { transition: transform .2s; cursor: default; }
.kpi-card:hover { transform: translateY(-2px); }

/* ===== PAGE TITLE ===== */
.page-title {
  font-size: 1.3rem; font-weight: 700; color: #111827;
  margin: 0 0 1.25rem; padding-bottom: .5rem;
  border-bottom: 2px solid #e5e7eb;
  display: flex; align-items: center; gap: .5rem;
}
.page-title::before {
  content: ''; display: inline-block;
  width: 4px; height: 1.3rem;
  background: var(--accent); border-radius: 2px; flex-shrink: 0;
}

/* ===== LOGIN ===== */
.login-page { background: linear-gradient(135deg, #1a1f2e 0%, #2d3748 100%); }
.login-card { background: #fff; border-radius: 16px; padding: 2.5rem; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }

/* ===== CALC BOXES ===== */
.calc-box { background: #f8f9fa; border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px 12px; text-align: center; }

/* ===== TABLES ===== */
.table thead th { font-weight: 600; font-size: .85rem; }
.table-warning { background: rgba(251,191,36,.08) !important; }
.dataTables_wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* DataTables — length menu estilizado */
div.dataTables_length label {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .82rem;
}
div.dataTables_length select {
    border: 1px solid #dee2e6; border-radius: 6px;
    padding: .25rem .5rem .25rem .6rem; font-size: .82rem;
    appearance: none; -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5' viewBox='0 0 8 5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%236b7280'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right .45rem center;
    background-size: 8px 5px; padding-right: 1.4rem; min-width: 56px;
}
div.dataTables_length select:focus { outline: none; border-color: #0d6efd; box-shadow: 0 0 0 3px rgba(13,110,253,.15); }
div.dataTables_filter label { font-size: .82rem; }
div.dataTables_info { font-size: .82rem; padding-top: .4rem; }

/* ===== BADGES ===== */
.badge { font-weight: 500; }

/* ===== MOBILE BOTTOM NAV ===== */
.mobile-bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 1046; background: var(--sidebar-bg);
  border-top: 1px solid rgba(255,255,255,.1);
  height: 56px; align-items: stretch;
  box-shadow: 0 -2px 12px rgba(0,0,0,.25);
}
.mobile-nav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: #7a8899; text-decoration: none;
  font-size: .6rem; font-weight: 500; gap: 3px; padding: 4px 2px;
  transition: color .15s, background .15s;
  border: none; background: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mobile-nav-item i { font-size: 1.25rem; line-height: 1; }
.mobile-nav-item span { line-height: 1; white-space: nowrap; }
.mobile-nav-item.active { color: var(--accent); }
.mobile-nav-item:hover, .mobile-nav-item:active { color: #fff; background: rgba(255,255,255,.05); }

/* Sidebar fechar btn */
.sidebar-close-btn {
  display: inline-flex;
  background: rgba(255,255,255,.08); border: none; border-radius: 8px;
  color: #b0b8c8; font-size: 1.1rem; width: 32px; height: 32px;
  flex-shrink: 0; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s, color .15s;
}
.sidebar-close-btn:hover { background: rgba(255,255,255,.15); color: #fff; }

/* Desktop: sidebar recolhido */
body.sidebar-collapsed .sidebar { display: none !important; }

/* ===== TOUCH: botões maiores em toque ===== */
@media (pointer: coarse) {
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; }
  .form-control, .form-select { min-height: 42px; }
  .form-control-sm, .form-select-sm { min-height: 36px; }
  .nav-link { padding-top: 10px !important; padding-bottom: 10px !important; }
}

/* ===== COMPACT DESKTOP — notebooks e telas até 1400px ===== */
@media (max-width: 1400px) {
  :root { --sidebar-w: 235px; --content-pad: 1.1rem; }
}

/* ===== SMALL DESKTOP / 720p + 125% scaling (≤ 1280px) ===== */
/* Sidebar vira overlay — libera 100% da largura pro conteúdo */
@media (max-width: 1280px) {
  :root { --content-pad: 1rem; }

  .sidebar {
    display: none !important;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: 250px;
    min-height: unset;
    z-index: 1045;
    overflow-y: auto;
  }
  .sidebar.show {
    display: flex !important;
    box-shadow: 4px 0 20px rgba(0,0,0,.3);
    animation: slideInLeft .2s ease;
  }
  body.sidebar-collapsed .sidebar { display: none !important; }

  /* Topbar */
  .top-bar { padding-left: .75rem !important; padding-right: .75rem !important; }

  /* Page title um pouco menor */
  .page-title { font-size: 1.2rem; margin-bottom: 1rem; }

  /* Cards: header mais compacto */
  .card-header { padding: .65rem .9rem; }
}

/* ===== TABLETS (≤ 991px) ===== */
@media (max-width: 991px) {
  :root { --content-pad: .875rem; }
  .kpi-value { font-size: 1.3rem; }
  .page-title { font-size: 1.1rem; }
}

/* ===== MOBILE (≤ 767px) ===== */
@media (max-width: 767px) {
  :root { --content-pad: .75rem; }

  /* Main ocupa tela toda + espaço para bottom nav */
  .main-content { margin-left: 0 !important; width: 100%; padding-bottom: 56px; }

  /* Bottom nav visível */
  .mobile-bottom-nav { display: flex; }

  /* Page title menor */
  .page-title { font-size: 1rem; margin-bottom: .75rem; }

  /* Header row com título + ações */
  .d-flex.justify-content-between.mb-4,
  .d-flex.justify-content-between.mb-3 {
    flex-wrap: wrap; gap: .5rem;
  }
  .d-flex.justify-content-between.mb-4 .page-title,
  .d-flex.justify-content-between.mb-3 .page-title {
    margin-bottom: 0;
  }

  /* KPI */
  .kpi-value { font-size: 1.2rem; }
  .kpi-icon { width: 38px; height: 38px; font-size: 1.1rem; }

  /* Cards */
  .card-header { padding: .65rem .85rem; }

  /* Formulários de filtro: empilhar */
  .row.g-2 > [class*="col-md-"],
  .row.g-3 > [class*="col-md-"] { flex: 0 0 100%; max-width: 100%; }
  .row.g-2 > [class*="col-md-"] .btn,
  .row.g-3 > [class*="col-md-"] .btn { width: 100%; }

  /* Ocultar colunas secundárias nas tabelas */
  .dt-hide-mobile { display: none !important; }

  /* Modal: largura total */
  .modal-dialog { margin: 0; max-width: 100%; }
  .modal-dialog .modal-content { border-radius: 0; min-height: 100vh; }
  .modal-dialog-scrollable { height: 100%; }
  .modal-dialog-scrollable .modal-content { max-height: 100vh; border-radius: 0; }

  /* Breadcrumb menor */
  .breadcrumb { font-size: .75rem; }
  .breadcrumb-item + .breadcrumb-item::before { padding: 0 4px; }

  /* Topbar direita: simplificar */
  .topbar-user-pill span { display: none; }
  .topbar-user-pill { padding: 4px 8px; }
  .topbar-date { display: none !important; }

  /* Flex row */
  .d-flex.gap-2.flex-wrap { gap: .4rem !important; }

  /* Login */
  .login-card { padding: 1.5rem; margin: 1rem; }
}

/* ===== SMALL MOBILE (≤ 480px) ===== */
@media (max-width: 480px) {
  :root { --content-pad: .6rem; }
  .page-title { font-size: .95rem; }
  .btn { font-size: .82rem; }
  .table { font-size: .8rem; }
  .card-header h5, .card-header .fw-semibold { font-size: .88rem; }
}

/* ===== SLIDE-IN ANIMATION ===== */
@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}
