/* ===== Variáveis ===== */
:root {
  --navy:   #1E3A5F;
  --orange: #F97316;
  --dark:   #1F2937;
  --white:  #FFFFFF;
  --gray50: #F9FAFB;
  --gray100:#F3F4F6;
  --gray200:#E5E7EB;
  --gray400:#9CA3AF;
  --gray600:#4B5563;
  --gray800:#1F2937;

  --green:  #16A34A;
  --yellow: #D97706;
  --red:    #DC2626;
  --blue:   #2563EB;

  --sidebar-w: 220px;
  --header-h:  60px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--gray100); color: var(--dark); font-size: 14px; }

/* ===== Layout ===== */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}
.sidebar-logo {
  padding: 14px 12px 12px;
  border-bottom: 1px solid rgba(255,255,255,.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  background: #FFFFFF;
}
/* Logo Educação Adventista — topo, centralizado, maior */
.slogo-adv {
  height: 72px;
  width: auto;
  object-fit: contain;
  display: block;
  margin-bottom: 8px;
}
.sidebar-logo .sub {
  font-size: .64rem;
  color: #6B7280;
  text-align: center;
  line-height: 1.35;
}

.nav-section { padding: 12px 0 4px; }
.nav-label   { font-size: .65rem; font-weight: 700; color: rgba(255,255,255,.4); text-transform: uppercase; letter-spacing: 1px; padding: 0 18px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 18px;
  color: rgba(255,255,255,.75);
  text-decoration: none;
  border-radius: 0;
  cursor: pointer;
  transition: background .15s, color .15s;
  font-size: .85rem;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: var(--white); }
.nav-item.active { background: var(--orange); color: var(--white); font-weight: 600; }
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  gap: 8px;
  background: #FFFFFF;
}
.slogo-footer {
  height: 30px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar-footer-text {
  font-size: .68rem;
  color: #6B7280;
  line-height: 1.4;
}

/* ===== Main ===== */
.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.topbar {
  height: var(--header-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-weight: 700; font-size: 1rem; color: var(--navy); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user  { font-size: .8rem; color: var(--gray600); }
.btn-logout   { background: none; border: 1px solid var(--gray200); border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: .78rem; color: var(--gray600); }
.btn-logout:hover { background: var(--gray100); }

.page-content { padding: 24px; flex: 1; }
.page-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--gray200);
  background: var(--white);
  text-align: center;
  font-size: .72rem;
  color: #9CA3AF;
  line-height: 1.6;
}

/* ===== Cards KPI ===== */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 14px; margin-bottom: 24px; }
.kpi-card {
  background: var(--white);
  border-radius: 10px;
  padding: 16px 18px;
  border-left: 4px solid var(--navy);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.kpi-card.orange { border-color: var(--orange); }
.kpi-card.green  { border-color: var(--green); }
.kpi-card.red    { border-color: var(--red); }
.kpi-card.yellow { border-color: var(--yellow); }
.kpi-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .5px; color: var(--gray400); font-weight: 600; margin-bottom: 6px; }
.kpi-value { font-size: 1.6rem; font-weight: 800; color: var(--dark); line-height: 1; }
.kpi-sub   { font-size: .75rem; color: var(--gray400); margin-top: 4px; }

/* ===== Period selector ===== */
.period-bar {
  background: var(--white);
  border-radius: 10px;
  padding: 14px 18px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.period-label { font-size: .78rem; font-weight: 600; color: var(--gray600); margin-right: 4px; }
.btn-period {
  padding: 5px 12px;
  border: 1px solid var(--gray200);
  border-radius: 20px;
  background: var(--white);
  font-size: .78rem;
  cursor: pointer;
  color: var(--gray600);
  transition: all .15s;
}
.btn-period:hover  { border-color: var(--navy); color: var(--navy); }
.btn-period.active { background: var(--navy); color: var(--white); border-color: var(--navy); }
.period-dates { display: flex; align-items: center; gap: 6px; margin-left: 6px; }
.period-dates input { border: 1px solid var(--gray200); border-radius: 6px; padding: 4px 8px; font-size: .78rem; color: var(--dark); }
.btn-apply { background: var(--orange); color: white; border: none; border-radius: 6px; padding: 5px 14px; font-size: .78rem; cursor: pointer; font-weight: 600; }
.btn-apply:hover { opacity: .9; }

/* ===== Charts grid ===== */
.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 24px; }
.chart-card {
  background: var(--white);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.chart-card.full { grid-column: 1 / -1; }
.chart-title { font-size: .9rem; font-weight: 700; color: var(--navy); margin-bottom: 14px; }
.chart-wrap  { position: relative; height: 260px; }

/* ===== Tabela ===== */
.table-card {
  background: var(--white);
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  overflow-x: auto;
  margin-bottom: 24px;
}
.table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.table-title  { font-size: .9rem; font-weight: 700; color: var(--navy); }

table { width: 100%; border-collapse: collapse; font-size: .8rem; }
thead th {
  background: var(--gray50);
  border-bottom: 2px solid var(--gray200);
  padding: 8px 10px;
  text-align: left;
  font-weight: 700;
  color: var(--gray600);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--navy); }
thead th.sorted { color: var(--navy); }
thead th.sorted::after { content: ' ↓'; }
thead th.sorted.asc::after { content: ' ↑'; }
tbody tr:nth-child(even) { background: var(--gray50); }
tbody td { padding: 8px 10px; border-bottom: 1px solid var(--gray200); white-space: nowrap; }
tbody tr:hover { background: #EFF6FF; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: .72rem;
  font-weight: 700;
}
.badge-blue   { background: #DBEAFE; color: #1D4ED8; }
.badge-green  { background: #DCFCE7; color: #15803D; }
.badge-yellow { background: #FEF9C3; color: #854D0E; }
.badge-red    { background: #FEE2E2; color: #991B1B; }
.badge-rank   { background: var(--navy); color: var(--white); min-width: 24px; text-align: center; }

/* ===== Formulário lançamento ===== */
.form-card {
  background: var(--white);
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  margin-bottom: 24px;
}
.form-title { font-size: 1rem; font-weight: 700; color: var(--navy); margin-bottom: 18px; border-bottom: 2px solid var(--gray200); padding-bottom: 10px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.form-group { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 160px; }
.form-group label { font-size: .78rem; font-weight: 600; color: var(--gray600); }
.form-group input, .form-group select, .form-group textarea {
  border: 1px solid var(--gray200);
  border-radius: 7px;
  padding: 8px 10px;
  font-size: .85rem;
  color: var(--dark);
  background: var(--white);
  transition: border .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--navy);
}
.form-group input.error { border-color: var(--red); }

.grid-lancamento { width: 100%; border-collapse: collapse; margin-top: 8px; }
.grid-lancamento th { background: var(--gray50); padding: 8px 10px; font-size: .78rem; font-weight: 700; color: var(--gray600); text-align: left; border-bottom: 2px solid var(--gray200); }
.grid-lancamento td { padding: 6px 8px; border-bottom: 1px solid var(--gray200); }
.grid-lancamento input[type="number"] { width: 80px; border: 1px solid var(--gray200); border-radius: 6px; padding: 5px 8px; font-size: .82rem; text-align: center; }
.grid-lancamento input[type="number"]:focus { outline: none; border-color: var(--navy); }
.grid-lancamento input[type="text"] { width: 100%; min-width: 140px; border: 1px solid var(--gray200); border-radius: 6px; padding: 5px 8px; font-size: .82rem; }

.btn { padding: 8px 20px; border-radius: 7px; font-size: .85rem; font-weight: 600; cursor: pointer; border: none; transition: opacity .15s, background .15s; }
.btn-primary { background: var(--navy); color: var(--white); }
.btn-primary:hover { opacity: .88; }
.btn-orange  { background: var(--orange); color: var(--white); }
.btn-orange:hover { opacity: .88; }
.btn-outline { background: var(--white); color: var(--navy); border: 1px solid var(--navy); }
.btn-outline:hover { background: var(--gray50); }
.btn-sm { padding: 5px 12px; font-size: .78rem; }
.btn-danger { background: var(--red); color: var(--white); }

/* ===== Parcial do dia ===== */
.parcial-row-neg td { background: #FEF2F2 !important; }
.parcial-row-pos td { background: #F0FDF4 !important; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center; z-index: 200;
}
.modal {
  background: var(--white); border-radius: 12px; padding: 24px;
  max-width: 420px; width: 90%; box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.modal-title { font-size: 1rem; font-weight: 700; color: var(--navy); margin-bottom: 12px; }
.modal-msg   { font-size: .85rem; color: var(--gray600); margin-bottom: 20px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ===== Toast ===== */
#toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 500;
  background: var(--dark); color: var(--white);
  padding: 10px 18px; border-radius: 8px;
  font-size: .83rem; font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  display: none; animation: fadeIn .2s ease;
}
#toast.success { background: var(--green); }
#toast.error   { background: var(--red); }
@keyframes fadeIn { from { opacity:0; transform: translateY(8px); } to { opacity:1; transform: none; } }

/* ===== Login ===== */
.login-bg { min-height: 100vh; background: linear-gradient(135deg,#1E3A5F 0%,#0f2440 100%); display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--white); border-radius: 14px; padding: 36px 32px; width: 340px; box-shadow: 0 8px 32px rgba(0,0,0,.22); }
.login-brand { font-size: 1.4rem; font-weight: 900; letter-spacing: 2px; color: var(--orange); margin-bottom: 2px; }
.login-sub   { font-size: .72rem; color: var(--gray400); margin-bottom: 24px; }
.login-err   { color: var(--red); font-size: .78rem; margin-top: 8px; display: none; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .main-wrap { margin-left: 0; }
  .charts-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .topbar { padding: 0 14px; }
  .page-content { padding: 14px; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
}

.hamburger { display: none; background: none; border: none; cursor: pointer; padding: 4px; }
@media (max-width: 768px) { .hamburger { display: flex; } }
