/* ============================================================
   SISTEMA FINANCEIRO — Nacional Grupo
   Design: Profissional, limpo, corporativo
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --green-900: #0d3318; --green-800: #1a5c2a; --green-700: #1e7030;
  --green-600: #2d8a3e; --green-500: #3aaa50; --green-100: #e0f4e0; --green-50: #f2fbf2;
  --blue-700: #1d4ed8; --blue-600: #2563eb; --blue-100: #dbeafe; --blue-50: #eff6ff;
  --red-700: #b91c1c; --red-600: #dc2626; --red-100: #fee2e2; --red-50: #fef2f2;
  --yellow-700: #b45309; --yellow-600: #d97706; --yellow-100: #fef3c7;
  --orange-600: #ea580c; --orange-100: #ffedd5;
  --purple-600: #9333ea; --purple-100: #f3e8ff;
  --gray-900: #111827; --gray-800: #1f2937; --gray-700: #374151;
  --gray-600: #4b5563; --gray-500: #6b7280; --gray-400: #9ca3af;
  --gray-300: #d1d5db; --gray-200: #e5e7eb; --gray-100: #f3f4f6; --gray-50: #f9fafb;
  --white: #ffffff; --off-white: #f8f9fa;
  --sidebar-w: 256px; --header-h: 60px;
  --radius-sm: 5px; --radius-md: 8px; --radius-lg: 12px; --radius-xl: 16px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07); --shadow-md: 0 4px 12px rgba(0,0,0,.09); --shadow-lg: 0 10px 30px rgba(0,0,0,.12);
  --font: 'Inter', sans-serif;
}

*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font); background: var(--gray-50); color: var(--gray-800); line-height: 1.6; -webkit-font-smoothing: antialiased; overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font-family: var(--font); font-size: inherit; }

/* ---- LOGIN ---- */
.login-page { min-height: 100vh; display: flex; }
.login-visual { flex: 0 0 42%; background: linear-gradient(150deg, var(--green-900) 0%, var(--green-800) 60%, var(--green-700) 100%); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 3rem 2.5rem; position: relative; overflow: hidden; }
.login-visual::before { content: ''; position: absolute; width: 500px; height: 500px; border-radius: 50%; border: 70px solid rgba(255,255,255,.04); top: -150px; right: -150px; }
.login-visual::after  { content: ''; position: absolute; width: 300px; height: 300px; border-radius: 50%; border: 50px solid rgba(255,255,255,.03); bottom: -80px; left: -80px; }
.login-visual img { width: 200px; margin-bottom: 1.75rem; position: relative; z-index: 1; }
.login-visual p { color: rgba(255,255,255,.55); font-size: .875rem; text-align: center; position: relative; z-index: 1; max-width: 240px; line-height: 1.75; }
.login-visual .login-companies { display: flex; gap: .75rem; margin-top: 2rem; position: relative; z-index: 1; }
.login-visual .co-tag { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.15); color: rgba(255,255,255,.7); font-size: .72rem; padding: .3rem .75rem; border-radius: 20px; font-weight: 500; }
.login-form-area { flex: 1; display: flex; align-items: center; justify-content: center; padding: 3rem 2rem; background: #fff; }
.login-box { width: 100%; max-width: 380px; }
.login-box h1 { font-size: 1.6rem; font-weight: 700; color: var(--gray-900); margin-bottom: .3rem; }
.login-box .subtitle { color: var(--gray-500); font-size: .875rem; margin-bottom: 2rem; }

/* ---- LAYOUT ---- */
.app-layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--green-900); display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 100; }
.sidebar-logo { padding: 1.2rem 1.25rem; border-bottom: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: .65rem; }
.sidebar-logo img { width: 130px; }
.sidebar-system { font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; color: rgba(255,255,255,.35); padding: .1rem 0; }

/* Company switcher */
.company-switcher { padding: .65rem 1rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.co-select { width: 100%; background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.1); border-radius: var(--radius-sm); color: rgba(255,255,255,.85); font-size: .78rem; padding: .4rem .65rem; cursor: pointer; outline: none; }
.co-select option { background: var(--green-900); color: #fff; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .6rem 0; }
.sidebar-nav a { display: flex; align-items: center; gap: .6rem; padding: .55rem 1.1rem; color: rgba(255,255,255,.55); font-size: .825rem; font-weight: 500; transition: all .2s; position: relative; }
.sidebar-nav a:hover { color: #fff; background: rgba(255,255,255,.06); }
.sidebar-nav a.active { color: #fff; background: rgba(255,255,255,.1); }
.sidebar-nav a.active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--green-400); border-radius: 0 3px 3px 0; }
.sidebar-nav a svg { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-section { padding: .25rem 1.1rem .1rem; font-size: .65rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: rgba(255,255,255,.25); margin-top: .35rem; }
.sidebar-footer { padding: .75rem 1.1rem; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-user { display: flex; align-items: center; gap: .6rem; margin-bottom: .5rem; }
.sidebar-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--green-600); display: flex; align-items: center; justify-content: center; font-size: .72rem; font-weight: 700; color: #fff; flex-shrink: 0; }
.sidebar-user-name { font-size: .78rem; font-weight: 600; color: #fff; line-height: 1.2; }
.sidebar-user-role { font-size: .65rem; color: rgba(255,255,255,.4); }
.btn-logout { display: flex; align-items: center; gap: .5rem; width: 100%; padding: .42rem .7rem; background: rgba(255,255,255,.06); border: none; border-radius: var(--radius-sm); color: rgba(255,255,255,.5); font-size: .75rem; cursor: pointer; transition: all .2s; }
.btn-logout:hover { background: rgba(255,255,255,.12); color: #fff; }
.btn-logout svg { width: 14px; height: 14px; }

.main-content { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.topbar { height: var(--header-h); background: #fff; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; padding: 0 1.5rem; gap: 1rem; position: sticky; top: 0; z-index: 50; }
.topbar-title { font-size: .95rem; font-weight: 600; color: var(--gray-900); flex: 1; }
.topbar-company { display: flex; align-items: center; gap: .5rem; font-size: .78rem; font-weight: 600; color: var(--green-800); background: var(--green-50); border: 1px solid var(--green-100); padding: .3rem .75rem; border-radius: 20px; }
.topbar-company::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--green-500); flex-shrink: 0; }
.page-body { padding: 1.5rem; flex: 1; }

/* ---- CARDS & STATS ---- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 1rem; }
.stat-card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius-lg); padding: 1.1rem 1.25rem; box-shadow: var(--shadow-sm); }
.stat-card .st-label { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--gray-500); margin-bottom: .5rem; }
.stat-card .st-val { font-size: 1.5rem; font-weight: 700; line-height: 1; color: var(--gray-900); }
.stat-card .st-val.green { color: var(--green-700); }
.stat-card .st-val.red   { color: var(--red-600); }
.stat-card .st-val.blue  { color: var(--blue-600); }
.stat-card .st-sub { font-size: .72rem; color: var(--gray-400); margin-top: .35rem; }
.stat-card.border-green { border-left: 3px solid var(--green-500); }
.stat-card.border-red   { border-left: 3px solid var(--red-500); }
.stat-card.border-blue  { border-left: 3px solid var(--blue-500); }
.stat-card.border-yellow{ border-left: 3px solid var(--yellow-600); }

/* ---- CARD ---- */
.card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-header { padding: .85rem 1.25rem; border-bottom: 1px solid var(--gray-100); display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.card-title { font-size: .9rem; font-weight: 600; color: var(--gray-900); }
.card-body { padding: 1.25rem; }

/* ---- BUTTONS ---- */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .48rem .95rem; border-radius: var(--radius-sm); border: none; cursor: pointer; font-size: .825rem; font-weight: 500; transition: all .18s; line-height: 1; white-space: nowrap; }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn-primary   { background: var(--green-800); color: #fff; } .btn-primary:hover   { background: var(--green-900); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1px solid var(--gray-200); } .btn-secondary:hover { background: var(--gray-200); }
.btn-success   { background: var(--green-100); color: var(--green-800); } .btn-success:hover { background: #c8e6c9; }
.btn-danger    { background: var(--red-100); color: var(--red-600); } .btn-danger:hover { background: #fecaca; }
.btn-blue      { background: var(--blue-100); color: var(--blue-600); } .btn-blue:hover { background: #bfdbfe; }
.btn-sm  { padding: .3rem .65rem; font-size: .75rem; }
.btn-lg  { padding: .65rem 1.35rem; font-size: .9rem; }
.btn-icon { padding: .35rem; border-radius: var(--radius-sm); background: var(--gray-50); border: 1px solid var(--gray-200); color: var(--gray-500); cursor: pointer; transition: all .18s; display: inline-flex; align-items: center; justify-content: center; }
.btn-icon:hover { background: var(--gray-100); color: var(--gray-800); }
.btn-icon svg { width: 14px; height: 14px; display: block; }

/* ---- FORMS ---- */
.form-group { margin-bottom: .85rem; }
.form-label { display: block; font-size: .72rem; font-weight: 600; color: var(--gray-700); margin-bottom: .28rem; text-transform: uppercase; letter-spacing: .04em; }
.form-label .req { color: var(--red-600); margin-left: 2px; }
.form-control { width: 100%; padding: .52rem .8rem; background: #fff; border: 1.5px solid var(--gray-200); border-radius: var(--radius-sm); color: var(--gray-800); font-size: .875rem; transition: border-color .18s, box-shadow .18s; outline: none; }
.form-control:focus { border-color: var(--green-500); box-shadow: 0 0 0 3px rgba(58,170,80,.1); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 70px; }
.form-hint { font-size: .7rem; color: var(--gray-400); margin-top: .2rem; }
.form-row { display: grid; gap: .85rem; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.form-section-title { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .09em; color: var(--green-700); padding-bottom: .45rem; border-bottom: 2px solid var(--green-100); margin: 1.1rem 0 .85rem; }

/* ---- TABLE ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .825rem; }
thead th { background: var(--gray-50); padding: .6rem 1rem; text-align: left; font-size: .69rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--gray-500); border-bottom: 1px solid var(--gray-200); white-space: nowrap; }
tbody td { padding: .65rem 1rem; border-bottom: 1px solid var(--gray-100); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }

/* ---- BADGES ---- */
.badge { display: inline-flex; align-items: center; padding: .18rem .55rem; border-radius: 20px; font-size: .68rem; font-weight: 600; white-space: nowrap; }
.badge-green  { background: var(--green-100); color: var(--green-800); }
.badge-blue   { background: var(--blue-100);  color: var(--blue-700); }
.badge-red    { background: var(--red-100);   color: var(--red-700); }
.badge-yellow { background: var(--yellow-100);color: var(--yellow-700); }
.badge-orange { background: var(--orange-100);color: var(--orange-600); }
.badge-purple { background: var(--purple-100);color: var(--purple-600); }
.badge-gray   { background: var(--gray-100);  color: var(--gray-600); }

/* ---- ALERTS ---- */
.alert { padding: .7rem 1rem; border-radius: var(--radius-md); font-size: .825rem; margin-bottom: 1rem; display: flex; align-items: flex-start; gap: .5rem; }
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--green-100); color: var(--green-800); border: 1px solid var(--green-100); }
.alert-danger  { background: var(--red-100);   color: var(--red-700);   border: 1px solid #fecaca; }
.alert-warning { background: var(--yellow-100);color: var(--yellow-700);border: 1px solid #fde68a; }

/* ---- PAGE HEADER ---- */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.35rem; gap: 1rem; flex-wrap: wrap; }
.page-header-left h2 { font-size: 1.1rem; font-weight: 700; color: var(--gray-900); }
.page-header-left p  { font-size: .78rem; color: var(--gray-500); margin-top: .1rem; }
.filters-bar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.filters-bar .form-control { padding: .4rem .7rem; }
.search-input { max-width: 240px !important; }

/* ---- MODAL ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 9999; display: none; align-items: center; justify-content: center; padding: 1rem; }
.modal-overlay.open { display: flex; }
.modal { background: #ffffff !important; border-radius: var(--radius-lg); box-shadow: 0 20px 60px rgba(0,0,0,.25); width: 100%; max-width: 540px; max-height: 90vh; overflow-y: auto; }
.modal-lg { max-width: 720px; }
.modal-header { padding: .9rem 1.25rem; border-bottom: 1px solid var(--gray-100); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: #fff; z-index: 1; }
.modal-title { font-size: .9rem; font-weight: 600; color: var(--gray-900); }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.25rem; color: var(--gray-400); line-height: 1; padding: 2px; }
.modal-body { padding: 1.25rem; }
.modal-footer { padding: .75rem 1.25rem; border-top: 1px solid var(--gray-100); display: flex; justify-content: flex-end; gap: .5rem; background: #fff; }

/* ---- EMPTY STATE ---- */
.empty-state { text-align: center; padding: 3rem 1.5rem; color: var(--gray-400); }
.empty-state svg { width: 44px; height: 44px; margin: 0 auto 1rem; display: block; color: var(--gray-300); }
.empty-state h3 { font-size: .9rem; font-weight: 600; color: var(--gray-600); margin-bottom: .3rem; }
.empty-state p { font-size: .8rem; }

/* ---- UTILS ---- */
.d-flex { display: flex; } .align-center { align-items: center; } .justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; } .flex-1 { flex: 1; }
.gap-1 { gap: .5rem; } .gap-2 { gap: 1rem; }
.fw-500 { font-weight: 500; } .fw-600 { font-weight: 600; } .fw-700 { font-weight: 700; }
.text-sm { font-size: .8rem; } .text-xs { font-size: .72rem; }
.text-muted { color: var(--gray-500); } .text-green { color: var(--green-700); } .text-red { color: var(--red-600); } .text-right { text-align: right; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }

/* ---- AMOUNTS ---- */
.amount-positive { color: var(--green-700); font-weight: 600; }
.amount-negative { color: var(--red-600); font-weight: 600; }
.amount-neutral  { color: var(--gray-700); font-weight: 500; }

/* ---- VENCIMENTO ---- */
.due-today    { color: var(--orange-600); font-weight: 600; }
.due-overdue  { color: var(--red-600); font-weight: 700; }
.due-upcoming { color: var(--gray-700); }

/* ---- PROGRESS BAR ---- */
.progress-bar { background: var(--gray-200); border-radius: 3px; height: 5px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 3px; transition: width .4s; }
.progress-fill.green { background: var(--green-500); }
.progress-fill.red   { background: var(--red-500); }

/* ---- CASHFLOW CHART ---- */
.cashflow-bar { display: flex; align-items: flex-end; gap: 2px; height: 80px; }
.cf-bar { flex: 1; border-radius: 2px 2px 0 0; min-width: 6px; transition: height .3s; }
.cf-bar.income  { background: var(--green-400); }
.cf-bar.expense { background: var(--red-400); }

/* ---- ATTACHMENTS ---- */
.attach-list { display: flex; flex-direction: column; gap: .5rem; }
.attach-item { display: flex; align-items: center; gap: .65rem; padding: .55rem .85rem; background: var(--gray-50); border: 1px solid var(--gray-200); border-radius: var(--radius-sm); font-size: .8rem; }
.attach-item svg { color: var(--red-600); flex-shrink: 0; width: 16px; height: 16px; }
.attach-item .attach-name { flex: 1; color: var(--gray-700); font-weight: 500; }
.attach-item .attach-size { color: var(--gray-400); font-size: .7rem; }

/* ---- BORDERÔ TABLE ---- */
.bordero-table thead th { background: var(--green-800); color: #fff; font-size: .68rem; }
.bordero-table tfoot td { background: var(--green-50); font-weight: 700; border-top: 2px solid var(--green-200); }

/* ---- RESPONSIVE ---- */
@media (max-width: 900px) { .sidebar { transform: translateX(-100%); } .sidebar.open { transform: translateX(0); } .main-content { margin-left: 0; } .cols-3,.cols-4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 600px) { .login-visual { display: none; } .cols-2,.cols-3,.cols-4 { grid-template-columns: 1fr; } .page-body { padding: 1rem; } }


/* Correções finais — Nacional Fertilizantes */
body.modal-open { overflow: hidden; }
.modal-overlay.open { display: flex !important; visibility: visible !important; opacity: 1 !important; pointer-events: auto !important; }
.modal-overlay.open > .modal { display: block !important; visibility: visible !important; opacity: 1 !important; position: relative !important; z-index: 10000 !important; transform: none !important; background: #fff !important; color: var(--gray-900) !important; }
.sidebar-logo-text { color: #fff; font-weight: 800; letter-spacing: .04em; line-height: 1.05; font-size: .95rem; }
.sidebar-logo-text span { display:block; color: rgba(255,255,255,.62); font-weight: 700; font-size: .68rem; letter-spacing: .12em; margin-top:.18rem; }

/* Modal v5 - correção para tela escurecendo sem exibir formulário */
.modal-overlay { display:none; visibility:hidden; opacity:0; }
.modal-overlay.open { display:block !important; visibility:visible !important; opacity:1 !important; position:fixed !important; inset:0 !important; z-index:2147483000 !important; background:rgba(0,0,0,.45) !important; }
.modal-overlay > .modal { display:none; }
.modal-overlay.open > .modal { display:block !important; visibility:visible !important; opacity:1 !important; position:fixed !important; left:50% !important; top:50% !important; transform:translate(-50%,-50%) !important; z-index:2147483001 !important; background:#fff !important; color:#111827 !important; width:calc(100vw - 32px) !important; max-width:540px !important; max-height:calc(100vh - 32px) !important; overflow:auto !important; border-radius:12px !important; box-shadow:0 24px 80px rgba(0,0,0,.35) !important; }
.modal-overlay.open > .modal.modal-lg { max-width:720px !important; }


/* Modal v6 - modal sempre acima e fora de qualquer stacking context */
body.modal-open { overflow:hidden !important; }
body > .modal-overlay.open { display:flex !important; visibility:visible !important; opacity:1 !important; position:fixed !important; inset:0 !important; z-index:2147483000 !important; align-items:center !important; justify-content:center !important; padding:16px !important; background:rgba(0,0,0,.45) !important; }
body > .modal-overlay.open > .modal { display:block !important; visibility:visible !important; opacity:1 !important; position:relative !important; z-index:2147483001 !important; background:#fff !important; color:#111827 !important; width:100% !important; max-width:540px !important; max-height:calc(100vh - 32px) !important; overflow:auto !important; border-radius:12px !important; box-shadow:0 24px 80px rgba(0,0,0,.35) !important; }
body > .modal-overlay.open > .modal.modal-lg { max-width:720px !important; }
