/* ============================================================
   ERP AGRO — SIDEBAR LAYOUT — TEMA CLARO/ESCURO
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── ICONES (lucide, inline SVG via icone() no Jinja) ──────── */
.icon { display: inline-block; vertical-align: -0.15em; stroke-width: 2; flex-shrink: 0; }
.nav-icon .icon { width: 16px; height: 16px; }
.card-stat-icon .icon { width: 20px; height: 20px; }
.btn .icon { width: 14px; height: 14px; margin-right: 2px; }
.user-menu a .icon { width: 14px; height: 14px; margin-right: 4px; }
#btn-tema .icon { width: 16px; height: 16px; vertical-align: -0.2em; }
#btn-tema .icone-sol, #btn-tema .icone-lua { display: none; }
[data-tema="escuro"] #btn-tema .icone-sol { display: inline-block; }
[data-tema="claro"] #btn-tema .icone-lua { display: inline-block; }

:root {
  --blue:        #2563eb;
  --blue-light:  #eff6ff;
  --blue-dark:   #1d4ed8;
  --green:       #16a34a;
  --green-light: #dcfce7;
  --amber:       #f59e0b;
  --red:         #dc2626;
  --red-light:   #fee2e2;
  --sidebar-w:   240px;

  /* CLARO */
  --bg:          #f1f5f9;
  --bg2:         #e2e8f0;
  --bg3:         #ffffff;
  --dropdown-hl: #e2e8f0;
  --sidebar-bg:  #1e293b;
  --sidebar-bg2: #0f172a;
  --border:      #e2e8f0;
  --border2:     #cbd5e1;
  --text:        #334155;
  --text-muted:  #64748b;
  --text-dim:    #94a3b8;
  --white:       #ffffff;
  --shadow:      0 1px 3px rgba(0,0,0,0.08);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.1);
  --radius:      8px;
  --radius-lg:   10px;
}

/* TEMA ESCURO */
[data-tema="escuro"] {
  --bg:         #0f172a;
  --bg2:        #1e293b;
  --bg3:        #1e293b;
  --dropdown-hl:#0f172a;
  --sidebar-bg: #0d1117;
  --sidebar-bg2:#080d14;
  --border:     #334155;
  --border2:    #475569;
  --text:       #cbd5e1;
  --text-muted: #94a3b8;
  --text-dim:   #475569;
  --white:      #1e293b;
  --shadow:     0 1px 3px rgba(0,0,0,0.3);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.4);
  --blue-light: rgba(37,99,235,0.15);
  --green-light:rgba(22,163,74,0.15);
  --red-light:  rgba(220,38,38,0.15);
}

html, body {
  height: 100%;
  font-family: 'Inter','Segoe UI',system-ui,sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* ── LAYOUT ─────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── SIDEBAR ─────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid rgba(255,255,255,.06);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 100; overflow: hidden;
}

.sidebar-brand {
  padding: 18px 16px 14px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  margin-bottom: 8px;
}
.sidebar-brand-icon { font-size: 20px; }
.sidebar-brand-text { font-size: 15px; font-weight: 700; color: #fff; letter-spacing: -.02em; }
.sidebar-brand-text span { color: #4ade80; }

.sidebar-nav { flex: 1; padding: 4px 8px; overflow-y: auto; }
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 2px; }

.nav-section {
  font-size: 10px; font-weight: 600;
  color: rgba(255,255,255,.25);
  text-transform: uppercase; letter-spacing: .1em;
  padding: 12px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px;
  color: rgba(255,255,255,.5);
  text-decoration: none; font-size: 13px; font-weight: 500;
  transition: all .15s; cursor: pointer; position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.8); }
.nav-item.active { background: rgba(255,255,255,.1); color: #fff; }
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: #4ade80; border-radius: 0 3px 3px 0;
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-arrow { margin-left: auto; font-size: 9px; transition: transform .15s; color: rgba(255,255,255,.25); }
.nav-item.open .nav-arrow { transform: rotate(180deg); }

.nav-submenu { display: none; padding-left: 18px; margin-bottom: 2px; }
.nav-submenu.open { display: block; }
.nav-submenu a {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 6px;
  color: rgba(255,255,255,.4); text-decoration: none; font-size: 12px;
  transition: all .15s;
}
.nav-submenu a::before { content: ''; width: 4px; height: 4px; border-radius: 50%; background: rgba(255,255,255,.2); flex-shrink: 0; }
.nav-submenu a:hover { color: rgba(255,255,255,.7); background: rgba(255,255,255,.05); }
.nav-submenu a.active { color: #4ade80; }
.nav-submenu a.active::before { background: #4ade80; }

.sidebar-user {
  padding: 10px 12px; border-top: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; gap: 10px; cursor: pointer;
}
.sidebar-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255,255,255,.1);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 12px; font-weight: 600; color: rgba(255,255,255,.8); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { font-size: 11px; color: rgba(255,255,255,.35); }
.sidebar-user-arrow { color: rgba(255,255,255,.25); font-size: 9px; }

/* ── MAIN ────────────────────────────────────────────────── */
.main-wrap { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  height: 54px; background: var(--bg3);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 12px;
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.topbar-title { font-size: 14px; font-weight: 600; color: var(--text-muted); flex: 1; }
.topbar-welcome { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.topbar-welcome strong { color: var(--text); font-weight: 600; }

#btn-tema {
  margin-left: 8px; background: transparent;
  border: 1px solid var(--border2); border-radius: 7px;
  padding: 5px 10px; cursor: pointer; font-size: 15px;
  color: var(--text-muted); transition: all .15s;
}
#btn-tema:hover { background: var(--bg2); }

.container { padding: 24px; flex: 1; }

/* ── ALERTAS ─────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; border-left: 3px solid; display: flex; align-items: center; gap: 8px; cursor: pointer; }
.alert-success { background: var(--green-light); color: #166534; border-color: var(--green); }
.alert-danger  { background: var(--red-light);   color: #991b1b; border-color: var(--red); }
.alert-warning { background: #fef9c3;            color: #92400e; border-color: var(--amber); }
[data-tema="escuro"] .alert-success { color: #86efac; }
[data-tema="escuro"] .alert-danger  { color: #fca5a5; }
[data-tema="escuro"] .alert-warning { color: #fde68a; }

/* ── PAGINA ──────────────────────────────────────────────── */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-title { font-size: 20px; font-weight: 700; color: var(--text); letter-spacing: -.02em; }
.page-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

/* ── BOTOES ──────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--radius); border: 1px solid var(--border2); cursor: pointer; font-size: 13px; font-weight: 500; text-decoration: none; transition: all .15s; background: var(--bg3); color: var(--text); font-family: inherit; }
.btn:hover { background: var(--bg2); border-color: var(--border2); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
.btn-danger { color: var(--red); border-color: var(--border); background: transparent; }
.btn-danger:hover { background: var(--red-light); border-color: var(--red); }
.btn-sm { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; justify-content: center; padding: 9px; }
.btn-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── CARDS STAT ──────────────────────────────────────────── */
.cards-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 12px; margin-bottom: 20px; }
.card-stat { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 16px; display: flex; align-items: flex-start; gap: 14px; box-shadow: var(--shadow); }
.card-stat-icon { width: 42px; height: 42px; border-radius: var(--radius); background: var(--blue-light); color: var(--blue); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.card-stat-icon.red   { background: var(--red-light); color: var(--red); }
.card-stat-icon.green { background: var(--green-light); color: var(--green); }
.card-stat-icon.amber { background: #fef9c3; color: #b45309; }
.card-stat-body { flex: 1; }
.stat-num { font-size: 24px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-num.red   { color: var(--red); }
.stat-num.blue  { color: var(--blue); }
.stat-num.green { color: var(--green); }
.stat-label { font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; margin-top: 4px; }
.stat-bar { height: 3px; background: var(--bg2); border-radius: 2px; margin-top: 12px; overflow: hidden; }
.stat-bar-fill { height: 100%; border-radius: 2px; background: var(--blue); }

/* ── TABLE BOX ───────────────────────────────────────────── */
.table-box { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; margin-bottom: 12px; box-shadow: var(--shadow); }
.table-box-header { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.table-box-title { font-size: 13px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; }
.row-danger td  { background: rgba(220,38,38,.06)  !important; }
.row-success td { background: rgba(22,163,74,.06)  !important; }
.row-warning td { background: rgba(245,158,11,.06) !important; }
[data-tema="escuro"] .row-success td { background: rgba(74,222,128,.04) !important; }
[data-tema="escuro"] .row-danger  td { background: rgba(220,38,38,.06)  !important; }
[data-tema="escuro"] .row-warning td { background: rgba(245,158,11,.05) !important; }

/* ── TABELA ──────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; background: transparent; }
.table th { padding: 9px 16px; text-align: left; font-size: 11px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--border); background: var(--bg); }
.table td { padding: 10px 16px; border-bottom: 1px solid var(--border); color: var(--text); font-size: 13px; vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none !important; }
[data-tema="escuro"] .table td { border-bottom-color: rgba(255,255,255,.05); }
[data-tema="escuro"] .table th { border-bottom-color: rgba(255,255,255,.08); background: rgba(0,0,0,.2); }
.table tbody tr:hover td { background: var(--bg); }
.table tfoot td { background: var(--bg); font-weight: 600; border-top: 1px solid var(--border); padding: 10px 16px; }
.row-danger td  { background: var(--red-light)   !important; }
.row-success td { background: rgba(22,163,74,.06) !important; }
.row-success td:first-child { border-left: 3px solid var(--green) !important; }
.row-warning td { background: rgba(245,158,11,.06) !important; }
[data-tema="escuro"] .row-success td { background: rgba(74,222,128,.05) !important; }
[data-tema="escuro"] .row-danger  td { background: rgba(220,38,38,.06)  !important; }
[data-tema="escuro"] .row-warning td { background: rgba(245,158,11,.05) !important; }
.actions { white-space: nowrap; }
.actions .btn { vertical-align: middle; }
.actions .btn + .btn { margin-left: 4px; }

/* ── BADGES ──────────────────────────────────────────────── */
.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.badge-ativo,.badge-pago        { background: var(--green-light); color: #166534; }
.badge-pendente,.badge-blue     { background: var(--blue-light);  color: #1e40af; }
.badge-atrasado,.badge-red      { background: var(--red-light);   color: #991b1b; }
.badge-gray,.badge-encerrado,.badge-suspenso { background: var(--bg2); color: var(--text-muted); }
.badge-pago_parcial,.badge-orange { background: #fef9c3; color: #92400e; }
.badge-PF   { background: var(--blue-light); color: #1e40af; }
.badge-PJ   { background: #f5f3ff; color: #5b21b6; }
.badge-master  { background: #fdf4ff; color: #7e22ce; }
.badge-usuario { background: var(--bg2); color: var(--text-muted); }
[data-tema="escuro"] .badge-ativo,[data-tema="escuro"] .badge-pago { color: #86efac; }
[data-tema="escuro"] .badge-pendente,[data-tema="escuro"] .badge-blue { color: #93c5fd; }
[data-tema="escuro"] .badge-atrasado,[data-tema="escuro"] .badge-red { color: #fca5a5; }
[data-tema="escuro"] .badge-PF { color: #93c5fd; }
[data-tema="escuro"] .badge-PJ { background: rgba(139,92,246,.15); color: #c4b5fd; }
[data-tema="escuro"] .badge-master { background: rgba(167,139,250,.15); color: #c4b5fd; }

/* ── FORMULARIOS ─────────────────────────────────────────── */
.form-section { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; margin-bottom: 12px; box-shadow: var(--shadow); }
.form-section h3 { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 16px; padding-bottom: 10px; border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: .05em; }

/* Realce padrao dos itens de dropdown: faixa mais escura + negrito (hover e navegacao por seta) */
.dropdown-item { transition: background .12s; }
.dropdown-item:hover,
.dropdown-item.dropdown-ativo {
  background: var(--dropdown-hl) !important;
  font-weight: 700;
}
.form-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.form-group { display: flex; flex-direction: column; min-width: 100px; }
.form-group label { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .05em; }
.form-group label .obrig { color: var(--red); margin-left: 2px; }
.form-control { padding: 8px 10px; border: 1px solid var(--border2); border-radius: var(--radius); font-size: 14px; color: var(--text); background: var(--bg3); width: 100%; transition: border-color .15s, box-shadow .15s; font-family: inherit; }
.form-control:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,235,0.08); }
.form-control[readonly], .form-control:disabled { background: var(--bg2); color: var(--text-muted); cursor: not-allowed; }
.form-control.campo-erro { border-color: var(--red); background: var(--red-light); }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%2364748b' d='M5 7L1 3h8z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; padding-right: 26px; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; }
.help-text { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.align-end { justify-content: flex-end; }

/* GRID COLS */
.col-1{flex:0 0 calc(1/12*100% - 10px)}.col-2{flex:0 0 calc(2/12*100% - 10px)}.col-3{flex:0 0 calc(3/12*100% - 10px)}.col-4{flex:0 0 calc(4/12*100% - 10px)}.col-5{flex:0 0 calc(5/12*100% - 10px)}.col-6{flex:0 0 calc(6/12*100% - 10px)}.col-7{flex:0 0 calc(7/12*100% - 10px)}.col-8{flex:0 0 calc(8/12*100% - 10px)}.col-12{flex:0 0 100%}

/* ── SEARCH ──────────────────────────────────────────────── */
.search-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.search-input { flex: 1; min-width: 200px; }

/* ── MODAL ───────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 500; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
[data-tema="escuro"] .modal-overlay { background: rgba(0,0,0,.65); }
.modal-box { position: relative; background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 24px; width: 100%; max-width: 520px; box-shadow: var(--shadow-md); }
.modal-box h3 { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 16px; }

/* ── DETALHE ─────────────────────────────────────────────── */
.detalhe-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); gap: 12px; margin-bottom: 16px; }
.detalhe-card { background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 14px; box-shadow: var(--shadow); }
.detalhe-card h4 { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); font-weight: 600; margin-bottom: 6px; }
.big-num { font-size: 22px; font-weight: 700; color: var(--text); }

/* ── PARTE CONTRATO ──────────────────────────────────────── */
.parte-row { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; margin-bottom: 6px; }
.rateio-total { margin-top: 8px; font-weight: 600; font-size: 14px; }

/* ── USER MENU ───────────────────────────────────────────── */
.user-menu { position: fixed; bottom: 80px; left: 10px; width: 220px; background: var(--bg3); border: 1px solid var(--border2); border-radius: var(--radius-lg); padding: 6px; box-shadow: var(--shadow-md); z-index: 200; display: none; }
.user-menu.open { display: block; }
.user-menu a { display: block; padding: 8px 12px; color: var(--text-muted); text-decoration: none; border-radius: 6px; font-size: 13px; transition: all .15s; }
.user-menu a:hover { background: var(--bg2); color: var(--text); }
.user-menu a.danger { color: var(--red); }
.user-menu a.danger:hover { background: var(--red-light); }
.user-menu-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── FOOTER ──────────────────────────────────────────────── */
.main-footer { text-align: center; padding: 16px 24px; font-size: 12px; color: var(--text-dim); border-top: 1px solid var(--border); }

/* ── UTILS ───────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-success { color: var(--green); }
.text-danger { color: var(--red); }

@media (max-width: 900px) {
  .col-1,.col-2,.col-3,.col-4,.col-5,.col-6,.col-7,.col-8 { flex: 0 0 100%; }
  .sidebar { transform: translateX(-100%); }
  .main-wrap { margin-left: 0; }
}
