:root {
  color-scheme: light only;
  --navy: #0a2158;
  --navy-2: #0e2d70;
  --green: #17974a;
  --green-2: #0c7a3a;
  --yellow: #f4b400;
  --yellow-2: #e6a300;
  --blue-dark: #16215c;
  --blue-dark-2: #1c2f7a;
  --blue-light: #4fc3f7;
  --blue-light-2: #29b6f6;
  --bg: #eef0f3;
  --card-white: #ffffff;
  --text: #16213a;
  --text-soft: #63697a;
  --cnh-mint: #cdeccb;
  --cnh-mint-2: #c2e6c0;
  --cnh-red: #c62828;
  --cnh-ink: #1c2a1c;
  --radius-lg: 20px;
  --radius-md: 14px;
  --shadow: 0 6px 18px rgba(10, 33, 88, 0.08);
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input, select {
  font-family: inherit;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
  position: relative;
  box-shadow: 0 0 40px rgba(0,0,0,0.06);
}

.screen {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 18px 16px 20px;
  gap: 12px;
  border-radius: 0 0 22px 22px;
}

.home-header .header-title {
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.5px;
  flex: 1;
}

.back-header .header-title {
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
  flex: 1;
  text-align: left;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
}
.icon-btn:active { background: rgba(255,255,255,0.12); }
.icon-btn.round { background: rgba(255,255,255,0.14); }

.icon { width: 22px; height: 22px; display: inline-flex; }
.icon svg { width: 100%; height: 100%; }

.avatar-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.7);
  background: transparent;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
}

/* ---------- Home ---------- */
.home-main {
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.feature-card {
  border: none;
  border-radius: var(--radius-lg);
  padding: 22px 20px;
  min-height: 128px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.feature-title { font-weight: 800; font-size: 1.3rem; letter-spacing: 0.3px; }
.feature-sub { font-size: 0.95rem; margin-top: 6px; line-height: 1.35; opacity: 0.95; }
.feature-text { color: #fff; position: relative; z-index: 2; }
.feature-text.dark { color: #10213a; }
.feature-icon { width: 68px; height: 68px; color: #fff; position: relative; z-index: 2; flex-shrink: 0; }
.feature-text.dark ~ .feature-icon,
.feature-card .feature-text.dark + .feature-icon { color: #10213a; }

.feature-condutor {
  background: linear-gradient(120deg, var(--green) 0%, var(--green-2) 100%);
}
.feature-veiculos {
  background: linear-gradient(120deg, var(--yellow) 0%, var(--yellow-2) 100%);
}
.feature-infracoes {
  background: linear-gradient(120deg, var(--blue-dark-2) 0%, var(--blue-dark) 100%);
}
.feature-educacao {
  background: linear-gradient(120deg, var(--blue-light) 0%, var(--blue-light-2) 100%);
}

.feature-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 85% 120%, rgba(255,255,255,0.25), transparent 55%),
    repeating-linear-gradient(115deg, rgba(255,255,255,0.10) 0 3px, transparent 3px 40px);
  pointer-events: none;
}

.footer-badges {
  margin-top: auto;
  padding: 28px 16px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.badge { display: flex; align-items: center; gap: 6px; }
.badge-mark {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--navy); color: #fff; font-size: 0.7rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.badge-mark.cnh { background: #12a150; border-radius: 6px; width: auto; padding: 3px 6px; }
.badge-text { font-size: 0.72rem; font-weight: 700; color: var(--text-soft); }
.badge-text.small { font-size: 0.6rem; line-height: 1.25; color: var(--text-soft); }
.badge-text.brasil b { color: var(--navy); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: rgba(16, 21, 40, 0.94);
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 0.88rem;
  max-width: 88vw;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 500;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Hamburger Menu ---------- */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 14, 34, 0);
  z-index: 400;
  display: flex;
  transition: background 0.22s ease;
}
.menu-overlay.open { background: rgba(8, 14, 34, 0.45); }

.menu-panel {
  width: min(82vw, 340px);
  height: 100%;
  background: #fff;
  box-shadow: 12px 0 30px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.24s ease;
}
.menu-overlay.open .menu-panel { transform: translateX(0); }

.menu-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 18px 18px;
  background: linear-gradient(180deg, var(--navy), var(--navy-2));
  color: #fff;
  border-radius: 0 0 18px 0;
}
.menu-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,0.16); display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 1.1rem; border: 2px solid rgba(255,255,255,0.5);
}
.menu-name { font-weight: 800; }
.menu-sub { font-size: 0.72rem; opacity: 0.8; }
.menu-close { margin-left: auto; }

.menu-nav { display: flex; flex-direction: column; padding: 10px; gap: 4px; }
.menu-item {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 14px; border-radius: 12px; text-decoration: none;
  color: var(--text); font-weight: 600; font-size: 0.98rem;
}
.menu-item .icon { color: var(--navy); }
.menu-item:active { background: var(--bg); }

.menu-footer {
  margin-top: auto;
  padding: 16px 18px 22px;
  font-size: 0.72rem;
  color: var(--text-soft);
  line-height: 1.4;
}

/* ---------- Lock screen ---------- */
.lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%);
  opacity: 1;
  transition: opacity 0.18s ease;
}
.lock-overlay.unlocking { opacity: 0; }

.lock-panel {
  width: min(88vw, 340px);
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #fff;
  text-align: center;
}
.lock-panel.shake { animation: lock-shake 0.4s ease; }
@keyframes lock-shake {
  10%, 90% { transform: translateX(-6px); }
  20%, 80% { transform: translateX(6px); }
  30%, 50%, 70% { transform: translateX(-9px); }
  40%, 60% { transform: translateX(9px); }
}

.lock-title { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.02em; margin-bottom: 4px; }
.lock-sub { font-size: 0.88rem; opacity: 0.85; margin-bottom: 22px; }

.lock-dots { display: flex; gap: 16px; margin-bottom: 14px; }
.lock-dot {
  width: 16px; height: 16px; border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.6);
  background: transparent;
  transition: background 0.15s ease;
}
.lock-dot.filled { background: #fff; }

.lock-error {
  font-size: 0.82rem;
  color: #ff8a80;
  min-height: 1.2em;
  margin-bottom: 14px;
}

.lock-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  width: 100%;
}
.lock-key {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.35);
  background: rgba(255,255,255,0.08);
  color: #fff;
  font-size: 1.3rem;
  font-weight: 600;
  cursor: pointer;
}
.lock-key:active { background: rgba(255,255,255,0.22); }
.lock-key-del { font-size: 1.1rem; border: none; background: transparent; }

/* ---------- Condutor ---------- */
.condutor-main { padding: 18px 16px 32px; display: flex; flex-direction: column; gap: 18px; }

.info-card {
  background: var(--card-white);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow);
}
.info-card-title { font-size: 1.05rem; font-weight: 800; margin: 0 0 12px; }
.info-divider { border: none; border-top: 1px solid #e3e6ec; margin: 0 0 16px; }
.info-row { margin-bottom: 16px; }
.info-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.info-row:last-child { margin-bottom: 0; }
.info-label { font-weight: 700; font-size: 0.92rem; margin-bottom: 4px; }
.info-value { color: var(--text); font-size: 1rem; letter-spacing: 0.4px; }
.info-field.full .info-value { font-size: 1.05rem; }

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.action-tile {
  background: var(--card-white);
  border: none;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 22px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  cursor: pointer;
  color: var(--navy);
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.2px;
  min-height: 118px;
}
.action-tile.wide { grid-column: 1 / -1; }
.tile-icon { width: 30px; height: 30px; color: var(--navy); }

/* ---------- Habilitacao ---------- */
.habilitacao-main { padding: 14px 16px 32px; display: flex; flex-direction: column; gap: 14px; }

.qr-note { font-size: 0.85rem; color: var(--text-soft); margin: 2px 0 0; text-align: center; }
.qr-note a { color: var(--navy); font-weight: 700; text-decoration: underline; }

.status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  padding: 12px;
  border-radius: 12px;
  font-weight: 800;
  letter-spacing: 0.4px;
  font-size: 0.95rem;
}
.status-banner.expired { background: var(--yellow); color: #241a00; }
.status-banner.valid { background: #d3f3dd; color: #0c5a2a; }
.status-dot {
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,0.12); font-size: 0.8rem; font-weight: 900;
}

.cnh-flip {
  width: 100%;
  overflow: hidden;
  border-radius: 10px;
  box-shadow: var(--shadow);
  touch-action: pan-y;
}
.cnh-track {
  display: flex;
  width: 100%;
  will-change: transform;
}
.cnh-card-wrap {
  flex: 0 0 100%;
  width: 100%;
  aspect-ratio: 979 / 1372;
  background: var(--cnh-mint);
  overflow: hidden;
}

.cnh-dots { display: flex; justify-content: center; gap: 8px; }
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  border: none; background: #c6cad3; padding: 0; cursor: pointer;
}
.dot.active { background: var(--navy); width: 18px; border-radius: 5px; }

/* CNH card internals */
.cnh-card {
  display: flex;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--cnh-mint) 0%, var(--cnh-mint-2) 100%);
  color: #1a2b1a;
  font-size: 0.62rem;
  overflow: hidden;
}
.cnh-body { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; overflow: hidden; }

.cnh-bar { display: block; height: 100%; width: auto; flex-shrink: 0; }

.cnh-topbar {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 4px 4px 12px;
  flex: 0 0 14.5%;
  box-sizing: border-box;
  min-height: 0;
}
.cnh-top-left { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.cnh-top-text {
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: 0.2px;
  color: var(--cnh-ink);
}
.cnh-top-number {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 2px;
  color: #7c8a7c;
  text-shadow: 0 1px 0 rgba(255,255,255,0.6), 0 -1px 0 rgba(0,0,0,0.18);
}
.cnh-map { width: 23%; max-width: 80px; flex-shrink: 0; margin-left: auto; margin-right: 3%; align-self: center; }
.cnh-back-mark { width: 64px; height: 40px; margin-left: auto; background: #000; border-radius: 4px; padding: 4px; }
.cnh-back-mark svg { width: 100%; height: 100%; }

.cnh-columns {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
  border-top: 1px solid rgba(0,0,0,0.15);
  overflow: hidden;
}
.cnh-col {
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(0,0,0,0.18);
  padding: 4px 2px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.cnh-col:last-child { border-right: none; }

/* Text turned with the document: reads top-to-bottom, glyphs facing right,
   matching a landscape card rotated 90° clockwise. */
.vtext {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  white-space: nowrap;
}

.cnh-field {
  display: flex;
  align-items: flex-start;
  gap: 3px;
  height: 100%;
}
.cnh-label { font-size: 0.4rem; font-weight: 800; letter-spacing: 0.4px; opacity: 0.9; color: var(--cnh-ink); }
.cnh-value { font-family: 'Courier New', Courier, monospace; font-size: 0.55rem; font-weight: 700; letter-spacing: 0.4px; color: #263326; }
.cnh-value.red { color: var(--cnh-red); }

.tiny .cnh-label { font-size: 0.34rem; white-space: normal; }
.tiny .cnh-value { font-size: 0.4rem; white-space: normal; }
.tiny.cnh-field { gap: 1px; }

/* Front: outlined field boxes on a grid matching the rotated document */
.cnh-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 0.95fr 1.05fr 2.7fr 1fr 1fr 1.05fr;
  grid-template-rows: 41fr 31fr 14fr 14fr;
  gap: 5px;
  padding: 4px 8px 10px 10px;
}
.cnh-box {
  border: 1.5px solid #131c12;
  border-radius: 8px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  padding: 5px 2px;
}
.cnh-box.vtext { display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 2px; }

.box-registro { grid-area: 1 / 1 / 2 / 2; }
.box-registro .cnh-value { font-size: 0.6rem; }
.cnh-photo {
  grid-area: 1 / 2 / 2 / 5;
  position: relative;
  container-type: size;
  overflow: hidden;
  background: #fff;
  border-radius: 2px;
}
/* Photo is turned with the document (90° clockwise, head facing right). */
.cnh-photo img {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100cqh;
  height: 100cqw;
  transform: translate(-50%, -50%) rotate(90deg);
  object-fit: contain;
}
@supports not (container-type: size) {
  .cnh-photo img { position: static; width: 100%; height: 100%; transform: none; object-fit: contain; }
}
.box-docid { grid-area: 1 / 5 / 3 / 6; }
.box-docid .cnh-label { white-space: normal; font-size: 0.34rem; line-height: 1.4; }
.box-docid .cnh-value { font-size: 0.5rem; }
.box-nome { grid-area: 1 / 6 / 5 / 7; padding: 5px 1px; }
.box-nome .cnh-label { font-size: 0.44rem; }
.box-validade { grid-area: 2 / 1 / 3 / 2; }
.box-permissao { grid-area: 2 / 2 / 3 / 3; }
.box-filiacao { grid-area: 2 / 3 / 5 / 4; }
.box-filiacao .cnh-value { line-height: 1.7; }
.box-cpf { grid-area: 2 / 4 / 3 / 5; }
.box-primhab { grid-area: 3 / 1 / 5 / 2; }
.box-acc { grid-area: 3 / 2 / 4 / 3; }
.box-nasc { grid-area: 3 / 4 / 5 / 5; }

.box-permissao, .box-acc { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px; }
.holo-fill {
  flex: 1;
  width: 100%;
  min-height: 0;
  border-radius: 4px;
  background: repeating-linear-gradient(45deg, #b7c2b8, #b7c2b8 2px, #99a89b 2px, #99a89b 4px);
}
.box-permissao .cnh-label, .box-acc .cnh-label { font-size: 0.34rem; flex-shrink: 0; }
.box-cat {
  grid-area: 4 / 2 / 5 / 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  padding: 5px 2px;
}
.box-cat .cnh-value { font-size: 0.78rem; font-weight: 800; }
.box-cat .cnh-label { font-size: 0.32rem; }

/* Back card specific */
.col-denatran { flex: 0 0 12%; align-items: center; gap: 4px; padding-top: 8px; }
.redact-bar { width: 60%; height: 26%; background: #111; border-radius: 2px; }
.col-estado { flex: 0 0 16%; align-items: center; justify-content: center; gap: 10px; }
.cnh-field.estado .cnh-value { font-size: 0.85rem; font-weight: 800; }
.cnh-field.caption { gap: 6px; }
.cnh-field.caption .cnh-value { font-size: 0.44rem; }
.cnh-field.caption .cnh-label { font-size: 0.4rem; opacity: 0.7; line-height: 1.3; }

.col-local { flex: 0 0 16%; gap: 2px; }
.col-local .cnh-field { flex: 1 1 0; height: auto; min-height: 0; align-items: center; justify-content: center; border-bottom: 1px solid rgba(0,0,0,0.15); overflow: hidden; }
.col-local .cnh-field:last-child { border-bottom: none; }

.col-assinatura { flex: 1; align-items: center; gap: 6px; padding: 6px 4px; min-width: 60px; }
.col-assinatura > .vtext.cnh-label { font-size: 0.5rem; }
.signature-box {
  flex: 1;
  width: 100%;
  border: 1px solid rgba(0,0,0,0.3);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: rgba(255,255,255,0.25);
}
.signature-img { max-width: 92%; max-height: 92%; transform: rotate(90deg); object-fit: contain; }
.signature-empty { writing-mode: vertical-rl; font-size: 0.5rem; opacity: 0.55; }

.col-obs { flex: 0 0 16%; align-items: center; justify-content: center; }
.col-obs .vtext { font-size: 0.5rem; opacity: 0.7; }

.doc-actions { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.doc-action {
  display: flex; align-items: center; gap: 12px;
  background: var(--card-white); border: none; border-radius: var(--radius-md);
  box-shadow: var(--shadow); padding: 15px 16px; font-weight: 700; font-size: 0.92rem;
  color: var(--navy); cursor: pointer; text-align: left;
}
.doc-action .icon { color: var(--navy); flex-shrink: 0; }

/* ---------- Personalize ---------- */
.personalize-main { padding: 16px 16px 40px; display: flex; flex-direction: column; gap: 16px; }
.personalize-note { font-size: 0.82rem; color: var(--text-soft); background: #e4e9f5; padding: 12px 14px; border-radius: 12px; margin: 0; }

.form-section {
  background: var(--card-white);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.form-section h3 { margin: 0 0 2px; font-size: 0.95rem; font-weight: 800; color: var(--navy); }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.82rem; font-weight: 700; color: var(--text); }
.field input, .field select {
  border: 1.5px solid #dde1ea;
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 0.95rem;
  font-weight: 500;
  background: #fbfcfe;
  color: var(--text);
}
.field input:focus, .field select:focus { outline: none; border-color: var(--navy); background: #fff; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.photo-row { display: flex; align-items: center; gap: 16px; }
.photo-preview {
  width: 72px; height: 92px; border-radius: 10px; background: var(--bg);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  border: 1.5px dashed #c6cad3; color: var(--text-soft); flex-shrink: 0;
}
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.photo-controls { display: flex; flex-direction: column; gap: 8px; flex: 1; }

.btn {
  border: none; border-radius: 12px; padding: 12px 16px; font-weight: 700; font-size: 0.9rem;
  cursor: pointer; text-align: center;
}
.btn.primary { background: var(--navy); color: #fff; }
.btn.secondary { background: #e4e9f5; color: var(--navy); }
.btn.ghost { background: transparent; color: var(--navy); border: 1.5px solid #dde1ea; }
.file-btn { display: inline-flex; align-items: center; justify-content: center; }

.signature-pad-wrap { position: relative; }
#signature-canvas {
  width: 100%;
  height: 150px;
  background: #fbfcfe;
  border: 1.5px dashed #c6cad3;
  border-radius: 10px;
  touch-action: none;
  display: block;
}
.signature-hint {
  position: absolute; bottom: 8px; left: 12px;
  font-size: 0.7rem; color: var(--text-soft); pointer-events: none;
}

.form-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

@media (min-width: 540px) {
  body { display: flex; justify-content: center; }
  #app { box-shadow: 0 0 0 1px #e1e4ea, 0 20px 50px rgba(10,33,88,0.12); }
}
