:root {
  --bg: #0b1220;
  --bg-soft: #111b2e;
  --panel: #16233a;
  --panel-2: #1c2c47;
  --line: #26374f;
  --text: #e8eef7;
  --muted: #93a4bb;
  --accent: #f5a524;
  --accent-2: #ffcc66;
  --danger: #ff6b6b;
  --ok: #38d39f;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 15% -10%, #182741 0%, var(--bg) 55%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); }

.root { min-height: 100vh; }

/* ---------------------------------------------------------------- login */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 11px;
  background: linear-gradient(145deg, var(--accent), #d97706);
  color: #1a1204;
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: -.5px;
}

.brand-name {
  font-weight: 800;
  letter-spacing: .08em;
  font-size: 15px;
}

.brand-sub { color: var(--muted); font-size: 12.5px; }

.login-card h1 { font-size: 22px; margin: 18px 0 4px; }
.login-card p.hint { color: var(--muted); margin: 0 0 20px; font-size: 13.5px; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.cnh-check { display: flex; align-items: flex-start; gap: 8px; color: var(--text); font-size: 13.5px; text-transform: none; letter-spacing: 0; }
.cnh-check input { width: auto; margin-top: 3px; }

input, select, textarea {
  width: 100%;
  background: #0e1728;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 165, 36, .16);
}

button {
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 10px;
  padding: 9px 14px;
  transition: transform .05s, background .15s, border-color .15s;
}

button:hover { border-color: #3a5275; }
button:active { transform: translateY(1px); }
button.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: #d97706;
  color: #1a1204;
  font-weight: 700;
}
button.ghost { background: transparent; }
button.danger { background: #3a1d24; border-color: #5a2b36; color: #ffb4b4; }
button.block { width: 100%; padding: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

.error {
  background: #3a1d24;
  border: 1px solid #5a2b36;
  color: #ffc0c0;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13.5px;
  margin-bottom: 12px;
}

/* ---------------------------------------------------------------- app shell */

.shell {
  display: grid;
  grid-template-columns: 236px 1fr;
  grid-template-rows: 64px 1fr;
  min-height: 100vh;
}

.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 18, 32, .85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar .spacer { flex: 1; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.role-badge {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  color: var(--accent-2);
}

.lang-toggle { display: flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.lang-toggle button { border: 0; border-radius: 0; padding: 6px 11px; background: transparent; font-size: 12px; }
.lang-toggle button.on { background: var(--panel-2); color: var(--accent-2); }

.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  background: rgba(17, 27, 46, .5);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: .04em;
  font-size: 12.5px;
  margin-bottom: 4px;
}

a.nav-item { text-decoration: none; }
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.on { background: var(--panel); border-color: var(--line); color: var(--text); }
.nav-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.nav-item.on .dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(245, 165, 36, .12); }

.main { padding: 26px 28px 60px; overflow-x: auto; }

.page-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 24px; letter-spacing: -.01em; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 22px; }
.card {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; }
.card .value { font-size: 28px; font-weight: 800; margin-top: 4px; }
.card .value.accent { color: var(--accent-2); }

.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}
.panel h2 { margin: 0 0 4px; font-size: 16px; }
.panel p.sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.placeholder {
  border: 1px dashed #33486a;
  border-radius: var(--radius);
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
}
.placeholder strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }
.phase-badge {
  display: inline-block;
  margin-top: 12px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--accent-2);
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; }
td input, td select { padding: 7px 9px; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.inline .field { margin-bottom: 0; min-width: 160px; }
.muted { color: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.small { font-size: 12px; }

.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.96);
  z-index: 9999;
  background: linear-gradient(150deg, var(--navy) 0%, var(--navy-2) 58%, var(--navy-3) 100%);
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #fff;
  padding: 16px 22px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: min(520px, 92vw);
  font-size: 16.9px;
  font-weight: 600;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast.err { border-color: rgba(255, 255, 255, 0.18); color: #fff; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: 60px auto 1fr; }
  .sidebar { display: flex; gap: 6px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px; }
  .nav-item { width: auto; white-space: nowrap; margin: 0; }
  .main { padding: 18px 14px 50px; }
  .grid-2 { grid-template-columns: 1fr; }
  .topbar { padding: 0 14px; gap: 10px; }
  .user-chip .name { display: none; }
}

/* ---------------------------------------------------------------- captação pública */

.public-body { background: radial-gradient(900px 500px at 50% -10%, #1b2c49 0%, var(--bg) 60%); }
.public-wrap { width: min(860px, 100%); margin: 0 auto; padding: 22px 16px 60px; }
.public-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.public-card {
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 26px;
}
.public-card h1 { margin: 0 0 4px; font-size: 24px; }
.form-section { border-top: 1px solid var(--line); padding-top: 18px; margin-top: 20px; }
.form-section h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent-2); margin: 0 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.radio-row { display: flex; gap: 18px; padding: 6px 0; }
.radio-row label, .check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.radio-row input, .check input { width: auto; }
.check { align-items: flex-start; line-height: 1.4; }
.check input { margin-top: 3px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.form-actions { margin-top: 22px; }
.success { text-align: center; padding: 26px 10px; }
.success-mark {
  width: 64px; height: 64px; border-radius: 50%;
  background: rgba(56, 211, 159, .14); border: 1px solid rgba(56, 211, 159, .5);
  color: var(--ok); font-size: 32px; display: grid; place-items: center; margin: 0 auto 16px;
}
.success h1 { font-size: 24px; }
.success p { color: var(--muted); max-width: 520px; margin: 8px auto; }
.success-id { margin: 18px auto; padding: 12px 16px; border: 1px dashed var(--line); border-radius: 10px; display: inline-block; }
.success-id strong { color: var(--accent-2); font-size: 20px; letter-spacing: .08em; }
.button-like {
  display: inline-block; margin-top: 18px; padding: 10px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text); text-decoration: none;
}
.public-foot { text-align: center; margin-top: 18px; }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(4, 8, 15, .72); display: grid; place-items: center;
  padding: 18px; z-index: 50;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: min(620px, 100%); max-height: 86vh; overflow: auto;
  background: linear-gradient(180deg, var(--panel), var(--bg-soft));
  border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 22px;
}
.modal h2 { margin: 0 0 4px; font-size: 19px; }
.detail-list { display: grid; grid-template-columns: 180px 1fr; gap: 8px 14px; margin-top: 16px; font-size: 14px; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; }
.login-foot { margin-top: 18px; text-align: center; font-size: 13px; }

@media (max-width: 760px) {
  .grid-3 { grid-template-columns: 1fr; }
  .public-card { padding: 18px; }
  .detail-list { grid-template-columns: 1fr; gap: 2px; }
  .detail-list dd { margin-bottom: 8px; }
}

/* Pré-visualização de documentos do driver */
.file-preview-modal {
  width: min(920px, 100%);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
.file-preview-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.file-preview-head h2 { margin: 0 0 3px; font-size: 18px; overflow-wrap: anywhere; }
.file-preview-head p { margin: 0; }
.file-preview-body {
  flex: 1;
  min-height: 220px;
  max-height: 68vh;
  display: grid;
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #070d18;
}
.file-preview-body img {
  display: block;
  max-width: 100%;
  max-height: 66vh;
  object-fit: contain;
  border-radius: 8px;
}
.file-preview-body iframe {
  display: block;
  width: 100%;
  height: 66vh;
  border: 0;
  background: #fff;
  border-radius: 8px;
}
.file-preview-body .preview-fallback {
  max-width: 480px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}
.file-preview-actions {
  margin-top: 14px;
  align-items: center;
}
.file-preview-actions .button-like { margin: 0; }
.file-link {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: #3d587d;
  text-underline-offset: 2px;
  cursor: pointer;
}
.file-link:hover { color: var(--accent-2); text-decoration-color: var(--accent); }
@media (max-width: 760px) {
  .file-preview-modal { max-height: 94vh; }
  .file-preview-body { max-height: 62vh; min-height: 180px; }
  .file-preview-body img { max-height: 60vh; }
  .file-preview-body iframe { height: 60vh; }
}

/* Menu lateral em cascata */
.nav-groups { display: flex; flex-direction: column; gap: 2px; }
.nav-group { display: flex; flex-direction: column; }
.nav-group-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 11px 12px;
  border-radius: 10px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: .04em;
  font-size: 12.5px;
  cursor: pointer;
}
.nav-group-toggle:hover { background: var(--panel); color: var(--text); }
.nav-group-toggle .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.nav-group.open > .nav-group-toggle { color: var(--text); }
.nav-group.open > .nav-group-toggle .dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(245, 165, 36, .12); }
.nav-chevron { margin-left: auto; font-size: 16px; line-height: 1; color: var(--muted); transform: rotate(0deg); transition: transform .15s ease; }
.nav-group.open > .nav-group-toggle .nav-chevron { transform: rotate(90deg); color: var(--accent); }
.nav-sub { display: none; flex-direction: column; gap: 2px; margin: 2px 0 8px 18px; padding-left: 10px; border-left: 1px solid var(--line); }
.nav-group.open > .nav-sub { display: flex; }
.nav-sub-item {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
}
.nav-sub-item:hover { background: var(--panel); color: var(--text); }
.nav-sub-item.on { background: var(--panel); color: var(--text); box-shadow: inset 3px 0 0 var(--accent); }

/* Menu principal flat */
.sidebar { display: flex; flex-direction: column; }
.nav-label { flex: 1; min-width: 0; }
.nav-phase {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid rgba(245, 165, 36, .35);
  border-radius: 999px;
  padding: 2px 6px;
  white-space: nowrap;
}
.nav-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--line); }

/* Dashboard: progresso por etapa */
.dash-chart { display: flex; flex-direction: column; gap: 6px; }
.dash-row {
  display: grid;
  grid-template-columns: 34px minmax(150px, 240px) 1fr 44px;
  align-items: center;
  gap: 10px;
  font-size: 12.5px;
}
.dash-stage { color: var(--muted); font: 11px ui-monospace, monospace; text-align: right; }
.dash-label { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-bar { height: 16px; border-radius: 6px; background: var(--panel); overflow: hidden; }
.dash-bar i { display: block; height: 100%; min-width: 2px; border-radius: 6px; background: linear-gradient(90deg, var(--accent), #d97706); }
.dash-row strong { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 720px) {
  .dash-row { grid-template-columns: 28px 1fr 40px; }
  .dash-bar { grid-column: 1 / -1; }
}

.button-like.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: #d97706;
  color: #1a1204;
  font-weight: 700;
}
.button-like.primary:hover { filter: brightness(1.04); }

/* Sub-abas de Configurações + Guia IA */
.settings-tabs {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  margin-bottom: 18px;
  border-radius: 11px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}
.settings-tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
}
.settings-tab:hover { color: var(--text); }
.settings-tab.active {
  background: var(--accent);
  color: #fff;
}
.ai-guide-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.ai-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(56, 189, 248, .12);
  color: #7dd3fc;
  border: 1px solid rgba(56, 189, 248, .28);
}
.ai-badge.custom {
  background: rgba(245, 158, 11, .14);
  color: #fcd34d;
  border-color: rgba(245, 158, 11, .32);
}
.ai-facts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  margin: 14px 0 18px;
}
.ai-fact {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(7, 13, 24, .55);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.ai-fact span { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.ai-fact strong { font-size: 13px; color: var(--text); }
.ai-guide-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.ai-guide-toolbar .button-like { margin: 0; }
.ai-char-count { margin-left: auto; }
.ai-guide-editor {
  width: 100%;
  min-height: 540px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 13px;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre-wrap;
}
