/* Mari Finanças — Identidade Visual Completa (PHP 8 + MySQL)
   Paleta clara acolhedora · PF Verde-Petróleo (#0F766E) · PJ Azul (#1D4ED8) */

:root {
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --surface-muted: #F1F5F9;
  --border: #E2E8F0;
  --ink: #0F172A;
  --ink-muted: #64748B;
  --pf: #0F766E;
  --pf-hover: #115E59;
  --pf-soft: #F0FDFA;
  --pf-border: #99F6E4;
  --pj: #1D4ED8;
  --pj-hover: #1E40AF;
  --pj-soft: #EFF6FF;
  --pj-border: #BFDBFE;
  --success: #047857;
  --success-soft: #ECFDF5;
  --danger: #BE123C;
  --danger-soft: #FFF1F2;
  --warning: #B45309;
  --warning-soft: #FFFBEB;
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: "Plus Jakarta Sans", ui-sans-serif, system-ui, sans-serif;
  --font-sans: "DM Sans", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  margin: 0;
  letter-spacing: -0.02em;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.hidden { display: none !important; }
.muted { color: var(--ink-muted); font-size: 13px; }
.muted-sm { color: var(--ink-muted); font-size: 12px; margin: 2px 0 0; }

/* Auth Screen */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(180deg, #F8FAFC 0%, #EEF2F6 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.05);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--pf) 0%, var(--pj) 100%);
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-title { font-size: 20px; }
.brand-sub { font-size: 12px; color: var(--ink-muted); margin: 2px 0 0; }
.brand-title-sm { font-family: var(--font-display); font-weight: 700; font-size: 15px; }
.brand-sub-sm { font-size: 11px; color: var(--ink-muted); }

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--surface-muted);
  padding: 4px;
  border-radius: 10px;
  margin: 22px 0 18px;
}

.auth-tab {
  border: none;
  background: transparent;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  border-radius: 8px;
  cursor: pointer;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.auth-hint {
  text-align: center;
  font-size: 11px;
  color: var(--ink-muted);
  margin: 18px 0 0;
}

/* App Shell */
.app-shell {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: 248px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
  z-index: 40;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 18px;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px 0;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: 9px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  color: #475569;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover { background: var(--surface-muted); color: var(--ink); }
.nav-item.active { background: var(--ink); color: #fff; font-weight: 600; }

.nav-dot {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: #CBD5E1;
}
.nav-item.active .nav-dot { background: #2DD4BF; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-box { padding: 0 4px; }
.user-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.user-email { font-size: 11px; color: var(--ink-muted); overflow: hidden; text-overflow: ellipsis; }

.main-column {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.profile-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--surface-muted);
  padding: 4px;
  border-radius: 10px;
}

.profile-btn {
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
}

.profile-btn strong { font-size: 12px; }
.profile-btn.active { background: var(--surface); color: var(--ink); border-color: var(--border); }
.profile-btn.pf.active { background: var(--pf-soft); color: var(--pf); border-color: var(--pf-border); }
.profile-btn.pj.active { background: var(--pj-soft); color: var(--pj); border-color: var(--pj-border); }

.main-content {
  padding: 24px;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Buttons & Forms */
.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 15px;
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.btn-primary { background: var(--pf); color: #fff; }
.btn-primary:hover { background: var(--pf-hover); }
.btn-pj { background: var(--pj); color: #fff; }
.btn-pj:hover { background: var(--pj-hover); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: #1E293B; }
.btn-light { background: var(--surface-muted); color: #334155; }
.btn-light:hover { background: #E2E8F0; }
.btn-danger-ghost { background: transparent; color: var(--danger); padding: 5px 8px; font-size: 12px; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-full { width: 100%; }

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.form-stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: #334155; }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid #CBD5E1;
  border-radius: 8px;
  padding: 9px 11px;
  font-family: var(--font-sans);
  font-size: 13px;
  color: var(--ink);
  background: var(--surface);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid #99F6E4;
  border-color: var(--pf);
}

.checkbox-field { justify-content: flex-end; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
  padding: 8px 0;
}

.alert-error {
  margin: 0;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #FECDD3;
}

/* Cards & Grids */
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.page-header h1 { font-size: 22px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.card-title { font-size: 15px; font-weight: 700; }

.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  border-top: 3px solid var(--border);
}
.kpi-card.pf { border-top-color: var(--pf); }
.kpi-card.pj { border-top-color: var(--pj); }
.kpi-card.income { border-top-color: var(--success); }
.kpi-card.expense { border-top-color: var(--danger); }

.kpi-label { font-size: 12px; font-weight: 600; color: var(--ink-muted); }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 6px; }
.kpi-sub { font-size: 11px; color: var(--ink-muted); margin-top: 4px; }

/* Profile Tags */
.tag-pf { color: var(--pf); font-weight: 700; font-size: 11px; }
.tag-pj { color: var(--pj); font-weight: 700; font-size: 11px; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

/* Progress Bars (Orçamentos & Metas) */
.progress-track {
  width: 100%;
  height: 8px;
  background: var(--surface-muted);
  border-radius: 99px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-fill { height: 100%; border-radius: 99px; transition: width 0.25s; }
.progress-fill.pf { background: var(--pf); }
.progress-fill.pj { background: var(--pj); }
.progress-fill.warn { background: #D97706; }
.progress-fill.over { background: var(--danger); }

.budget-row {
  padding: 12px 0;
  border-bottom: 1px solid #F1F5F9;
}
.budget-row:last-child { border-bottom: none; }
.budget-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13px;
}

.agenda-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}
.agenda-item-content { flex: 1 1 190px; min-width: 0; }
.agenda-title { display: flex; align-items: baseline; gap: 6px; overflow-wrap: anywhere; }
.agenda-title span { flex-shrink: 0; }
.agenda-title strong { min-width: 0; }
.agenda-company {
  display: inline-block;
  max-width: 100%;
  margin-bottom: 6px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.agenda-company-0 { color: #1E40AF; background: #DBEAFE; }
.agenda-company-1 { color: #065F46; background: #D1FAE5; }
.agenda-company-2 { color: #6B21A8; background: #F3E8FF; }
.agenda-company-3 { color: #9A3412; background: #FFEDD5; }
.agenda-company-4 { color: #9F1239; background: #FFE4E6; }
.agenda-company-5 { color: #155E75; background: #CFFAFE; }
.agenda-item-value { flex-shrink: 0; font-weight: 600; }
.agenda-item-actions { display: flex; flex-shrink: 0; gap: 4px; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: #F8FAFC;
}
td {
  padding: 11px 12px;
  border-bottom: 1px solid #F1F5F9;
  vertical-align: middle;
}
tr:hover td { background: #FAFBFD; }
.text-right { text-align: right; }

/* Segmented Controls */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--surface-muted);
  padding: 4px;
  border-radius: 9px;
}
.seg-btn {
  border: none;
  background: transparent;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #475569;
  border-radius: 7px;
  cursor: pointer;
}
.seg-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08); }
.seg-btn.active.pf { background: var(--pf); color: #fff; }
.seg-btn.active.pj { background: var(--pj); color: #fff; }
.seg-btn.active.danger { background: var(--danger); color: #fff; }
.seg-btn.active.success { background: var(--success); color: #fff; }

/* Calendar Grid */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}
.cal-head {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
  padding: 6px 0;
}
.cal-cell {
  min-height: 78px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.cal-cell.empty { background: #F8FAFC; border-style: dashed; }
.cal-cell.today { border-color: var(--pf); background: var(--pf-soft); }
.cal-day { font-size: 11px; font-weight: 700; color: #475569; }
.cal-event {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 5px;
  border-radius: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-event.pf { background: var(--pf-soft); color: var(--pf); border: 1px solid var(--pf-border); }
.cal-event.pj { background: var(--pj-soft); color: var(--pj); border: 1px solid var(--pj-border); }
.cal-event.done { opacity: 0.55; text-decoration: line-through; }

/* Sticky Notes ("Stiks") */
.stiks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}
.stik-card {
  border-radius: 12px;
  padding: 16px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stik-butter { background: #FEF9C3; }
.stik-mint { background: #DCFCE7; }
.stik-sky { background: #E0F2FE; }
.stik-rose { background: #FFE4E6; }
.stik-title { font-size: 15px; font-weight: 700; }
.stik-body { font-size: 13px; color: #334155; white-space: pre-wrap; line-height: 1.5; flex: 1; }
.stik-footer { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: #475569; }

/* Modal & Toast */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
}
.modal-card {
  width: 100%;
  max-width: 540px;
  background: var(--surface);
  border-radius: 14px;
  padding: 22px;
  border: 1px solid var(--border);
  max-height: 92vh;
  overflow-y: auto;
}
.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--ink);
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  z-index: 80;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
}

.mobile-only { display: none; }
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  z-index: 35;
}

/* Responsividade */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: 1fr; }
}

@media (max-width: 820px) {
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .topbar { padding: 10px 14px; flex-wrap: wrap; }
  .main-content { padding: 16px; }
  .grid-2, .grid-4 { grid-template-columns: 1fr; }
  .calendar-grid { gap: 4px; }
  .cal-cell { min-height: 58px; }
}

/* Impressão / Salvar Relatório em PDF */
@media print {
  .sidebar, .topbar, .btn, .no-print { display: none !important; }
  .main-content { padding: 0; max-width: 100%; }
  .card { break-inside: avoid; border: 1px solid #CBD5E1; }
}
