:root {
  /* Paleta oficial D4U Immigration - navy + dourado */
  --navy: #1f2a44;
  --navy-dark: #143652;
  --gold: #cfb125;
  --gold-light: #fbf5e0;
  --gold-dark: #b79d59;
  --green: #00bda5;
  --green-light: #e5faf5;
  --red: #f2545b;
  --red-light: #fdedee;
  --amber: #dbab09;
  --purple: #6a78d1;
  --gray-50: #f5f8fa;
  --gray-100: #eef2f7;
  --gray-200: #dfe3eb;
  --gray-300: #cbd6e2;
  --gray-500: #7c98b6;
  --gray-700: #33475b;
  --text: #33475b;
  --shadow: 0 2px 12px rgba(31, 42, 68, 0.08);
  --shadow-lg: 0 8px 30px rgba(31, 42, 68, 0.16);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--gray-50);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}
.hidden { display: none !important; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy), var(--navy-dark));
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.login-logo {
  width: 64px; height: 64px;
  background: var(--navy);
  color: #fff;
  border-radius: 16px;
  border-bottom: 3px solid var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 24px;
  margin: 0 auto 8px;
}
.login-card h1 { font-size: 20px; margin: 0; text-align: center; color: var(--navy); }
.login-sub { text-align: center; color: var(--gray-500); margin: 0 0 16px; font-size: 13px; }
.login-card label { display: flex; flex-direction: column; font-size: 13px; font-weight: 600; color: var(--gray-700); gap: 4px; margin-bottom: 10px; }
.login-emergency-link { display: block; text-align: center; font-size: 12px; color: var(--gray-500); margin-top: 18px; }
.login-emergency-form { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--gray-200); }

/* ---------- Inputs ---------- */
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-light); }
textarea { resize: vertical; min-height: 60px; }
label { font-weight: 600; color: var(--gray-700); font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: filter .15s, background .15s;
  background: var(--gray-100);
  color: var(--gray-700);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--navy); color: #fff; }
.btn-microsoft {
  background: #fff; color: var(--navy); border: 1.5px solid var(--gray-300);
  display: flex; align-items: center; justify-content: center; gap: 10px;
}
.btn-microsoft:hover { border-color: var(--navy); filter: none; }
.btn-microsoft svg { flex-shrink: 0; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: var(--red); color: #fff; }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-outline { background: #fff; border-color: var(--gray-300); }
.btn-block { width: 100%; margin-top: 8px; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.form-error { color: var(--red); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 58px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-badge { background: var(--gold); color: var(--navy); border-radius: 6px; padding: 3px 7px; font-size: 13px; font-weight: 800; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  color: #cdd8e8;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav a.active { background: var(--gold); color: var(--navy); }
.user-box { display: flex; align-items: center; gap: 8px; font-size: 13px; white-space: nowrap; }
.user-box .btn-ghost { color: #cdd8e8; }
.user-box .btn-ghost:hover { color: #fff; background: rgba(255,255,255,.08); }
.tag { background: rgba(255,255,255,.15); padding: 2px 8px; border-radius: 20px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }

/* ---------- View / layout ---------- */
.view { max-width: 1120px; margin: 0 auto; padding: 24px 20px 60px; }
.page-title { font-size: 22px; margin: 0 0 4px; color: var(--navy); }
.page-sub { color: var(--gray-500); margin: 0 0 20px; font-size: 14px; }

.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}
.card h2 { font-size: 16px; margin: 0 0 14px; color: var(--navy); }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.field { display: flex; flex-direction: column; gap: 5px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }

/* ---------- Stage picker ---------- */
.stage-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stage-opt {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--gray-200);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  background: var(--gray-50);
}
.stage-opt.selected { border-color: var(--gold); background: var(--gold-light); }
.stage-opt.disabled { opacity: .45; cursor: not-allowed; }
.stage-opt.done { border-color: var(--green); background: var(--green-light); }
.stage-opt input { width: auto; }
.stage-opt .s-num { width: 26px; height: 26px; border-radius: 50%; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.stage-opt .s-name { font-weight: 600; font-size: 13.5px; }
.stage-opt .s-val { margin-left: auto; font-weight: 700; color: var(--navy); font-size: 13px; }
.stage-opt small { color: var(--gray-500); display: block; font-weight: 500; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--gray-200); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--gray-500); background: var(--gray-50); }
tbody tr:hover { background: var(--gray-50); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Badges / chips ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-niw { background: var(--gold-light); color: var(--gold-dark); }
.badge-rfe { background: #fdf0d9; color: var(--amber); }
.badge-refile { background: #efe6fb; color: var(--purple); }
.badge-green { background: var(--green-light); color: var(--green); }
.badge-gray { background: var(--gray-100); color: var(--gray-500); }
.badge-red { background: var(--red-light); color: var(--red); }

/* paleta rotativa para tipos de caso (ilimitados) */
.badge-c0 { background: var(--gold-light); color: var(--gold-dark); }
.badge-c1 { background: #fdf0d9; color: var(--amber); }
.badge-c2 { background: #efe6fb; color: var(--purple); }
.badge-c3 { background: var(--green-light); color: var(--green); }
.badge-c4 { background: #dcf3f4; color: #147a86; }
.badge-c5 { background: #fde4ee; color: #c22e6e; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.stat .label { font-size: 12px; text-transform: uppercase; color: var(--gray-500); letter-spacing: .03em; }
.stat .value { font-size: 26px; font-weight: 800; color: var(--navy); margin-top: 4px; }
.stat .sub { font-size: 12px; color: var(--gray-500); }

/* progress dots for client stages */
.dots { display: flex; gap: 5px; }
.dot { width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; background: var(--gray-100); color: var(--gray-500); border: 1px solid var(--gray-200); }
.dot.on { background: var(--green); color: #fff; border-color: var(--green); }
.dot.na { opacity: .3; }

.empty { text-align: center; color: var(--gray-500); padding: 40px 20px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,33,64,.5);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: 20px;
}
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--gray-200); }
.modal-head h3 { margin: 0; color: var(--navy); font-size: 17px; }
.modal-body { padding: 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy-dark); color: #fff; padding: 12px 20px; border-radius: 10px;
  box-shadow: var(--shadow-lg); z-index: 100; font-weight: 600; font-size: 14px; max-width: 90vw;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }

/* ---------- Rodape ---------- */
.app-footer {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 20px;
  background: #fff; border-top: 1px solid var(--gray-200);
  color: var(--gray-500); font-size: 10px; letter-spacing: .02em;
  pointer-events: none; z-index: 5;
}
.app-footer-version { white-space: nowrap; }

.help {
  background: var(--gold-light); border-left: 4px solid var(--gold);
  padding: 12px 14px; border-radius: 8px; font-size: 13px; color: var(--navy); margin-bottom: 16px;
}

.modal.modal-wide { max-width: 860px; }
th.ctr, td.ctr { text-align: center; }
td.ctr input[type="checkbox"] { width: 18px; height: 18px; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.pill { background: var(--gray-100); color: var(--gray-700); border-radius: 20px; padding: 5px 12px; font-size: 13px; }
a#back { display: inline-block; margin-bottom: 6px; font-size: 13px; }
a#back:hover { text-decoration: underline; }

/* relatório: subtotais e totais */
.visto-row td { background: #eef4fb; font-weight: 700; color: var(--navy); font-size: 12.5px; text-transform: uppercase; letter-spacing: .02em; }
.total-row td { background: var(--gold-light); border-top: 2px solid var(--gold); color: var(--navy); }
.subtotal-row td { background: var(--gray-50); font-size: 13px; color: var(--gray-700); border-top: 1px solid var(--gray-300); }
.group-title { font-size: 15px; color: var(--navy); margin: 20px 0 6px; }
.grand-total { text-align: right; font-size: 17px; font-weight: 800; color: var(--navy); margin-top: 16px; padding-top: 12px; border-top: 2px solid var(--navy); }
@media print {
  .topbar, .nav, #r-gen, #r-csv, #r-csv2, #r-print { display: none !important; }
  .card { box-shadow: none; border-color: var(--gray-300); }
}
.mt { margin-top: 16px; }
.muted { color: var(--gray-500); }
.right { text-align: right; }
.flex-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4, .stage-list { grid-template-columns: 1fr; }
  .nav { order: 3; width: 100%; }
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 14px; }
}
