/* OldCar Project: sistema visual do redesign mobile-first (spec 2026-10-10, seção 7). */
@layer tokens, base, layout, components, views, auth;

@font-face { font-family: "Saira"; src: url("../fonts/saira-latin-400-normal.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Saira"; src: url("../fonts/saira-latin-500-normal.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Saira Condensed"; src: url("../fonts/saira-condensed-latin-600-normal.woff2") format("woff2"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Saira Condensed"; src: url("../fonts/saira-condensed-latin-700-normal.woff2") format("woff2"); font-weight: 700; font-display: swap; }

@layer tokens {
  :root {
    /* Direção "Automotiva premium" (auditoria UX/UI 2026-10-19): cada cor tem um único papel.
       Contrastes medidos sobre o carbono (#16181C) e o metal (#1F2228). */
    --surface-0: #16181C;      /* fundo (carbono) */
    --surface-1: #1F2228;      /* barras, painéis, sheets (metal) */
    --surface-2: #262A31;      /* hover e elevação */
    --divider: #2C3037;        /* separadores decorativos e trilhos */
    --divider-subtle: #23262C;
    --field-border: #737A86;   /* borda de campo e controle: 4,1:1 / 3,7:1 (WCAG 1.4.11) */
    --text: #EEF0F3;           /* 15,6:1 */
    --text-muted: #C9CED6;     /* cromado, 10,1:1 no metal */
    --accent: #D7262E;         /* ação principal e estado ativo; branco 5,0:1 */
    --accent-press: #B91C24;   /* hover/pressionado escurece; branco 6,5:1 */
    --on-accent: #FFFFFF;
    --alert: #E9A92B;          /* chegando/pendente */
    --ok: #5FA86B;             /* concluído/em dia */
    --danger: #FF7A80;         /* vencido/erro/excluir */
    --focus: #FFFFFF;
    /* Cores dos módulos nos gráficos: nunca usadas como status. */
    --mod-project: var(--text-muted);
    --mod-maintenance: #6FA8DC;
    --mod-fuel: #4FB3A9;
    --mod-expense: #9C8CE0;
    --series-unplanned: #E07A5F;
    --series-missing: #B8862A;   /* "falta" no gráfico de etapas, 4,1:1 sobre o trilho */
    /* Nomes antigos: continuam valendo, apontando para os papéis acima. */
    --graphite: var(--surface-0);
    --plate-metal: var(--surface-1);
    --line: var(--divider);
    --line-subtle: var(--divider-subtle);
    --chrome: var(--text-muted);
    --start-red: var(--accent);
    --on-primary: var(--on-accent);
    --paid-green: var(--ok);
    --pending-amber: var(--alert);
    --plate-white: #FFFFFF;
    --plate-blue: #003399;
    --plate-ink: #111111;
    --plate-gray: #B9BDC3;
    --chart-project: var(--mod-project);
    --font-text: "Saira", system-ui, sans-serif;
    --font-display: "Saira Condensed", "Saira", system-ui, sans-serif;
    --step-1: 0.875rem;
    --step0: 1rem;
    --step1: 1.25rem;
    --step2: 1.75rem;
    --step3: 2.5rem;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --radius: 10px;
    --target: 48px;
    --header-h: 56px;
    --nav-h: 64px;
    --fab: 56px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    color-scheme: dark;
  }
}

@layer base {
  *, *::before, *::after { box-sizing: border-box; }
  html { -webkit-text-size-adjust: 100%; }
  body { margin: 0; min-height: 100dvh; background: var(--graphite); color: var(--text); font-family: var(--font-text); font-size: var(--step0); line-height: 1.5; overflow-wrap: anywhere; -webkit-font-smoothing: antialiased; }
  h1, h2, h3 { margin: 0; font-family: var(--font-display); font-weight: 700; line-height: 1.15; }
  p, dl, dd, figure { margin: 0; }
  a { color: var(--text); text-underline-offset: 3px; }
  button, input, select, textarea { font: inherit; color: inherit; }
  img { max-width: 100%; }
  :focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  [hidden] { display: none !important; }
  .visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
  }
}

@layer layout {
  body.app { padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--space-6)); }
  .app-header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: var(--space-3); min-height: var(--header-h); padding: var(--space-1) var(--space-4); background: var(--graphite); border-bottom: 1px solid var(--line); }
  /* Título da tela no topo do conteúdo (fora do cabeçalho): quebra só entre palavras. */
  .screen-title { font-size: var(--step2); overflow-wrap: break-word; word-break: normal; hyphens: manual; }
  .screen-title:focus { outline: none; }
  .app-view { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--space-5); min-width: 0; }
  .app-view:focus { outline: none; }
  /* Coluna limitada: sem isso, uma palavra longa alarga o grid inteiro além da tela. */
  /* align-content: start — sem isso, em telas curtas no desktop, as linhas esticavam e abriam um vão sob o título. */
  .app-main { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--space-5); width: min(1100px, 100%); margin: 0 auto; padding: var(--space-4) var(--space-4) calc(56px + var(--space-6)); }
  .app-nav { position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; min-height: calc(var(--nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom); background: var(--plate-metal); border-top: 1px solid var(--line); }
  .nav-brand { display: none; }
  .nav-extra { display: none; }
  .nav-link { position: relative; display: grid; justify-items: center; gap: 2px; min-height: var(--target); padding: var(--space-2) 0; color: var(--chrome); font-size: var(--step-1); text-decoration: none; }
  .nav-link[aria-current="page"] { color: var(--text); }
  .nav-link[aria-current="page"] .nav-icon { color: var(--start-red); }
  .nav-link[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 25%; right: 25%; height: 3px; border-radius: 0 0 3px 3px; background: var(--start-red); }
  .nav-label { font-family: var(--font-display); font-weight: 600; white-space: nowrap; letter-spacing: .01em; }
  .nav-badge { position: absolute; top: 2px; right: 12%; width: 16px; height: 16px; border-radius: 999px; background: var(--pending-amber); color: var(--graphite); font-size: 11px; font-weight: 700; line-height: 16px; text-align: center; }
  .nav-badge::after { content: "!"; }
  .nav-icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .fab-add { position: fixed; right: var(--space-4); bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--space-3)); z-index: 9; display: grid; place-items: center; width: var(--fab); height: var(--fab); border: 0; border-radius: 50%; background: var(--start-red); color: var(--on-primary); box-shadow: 0 0 0 4px var(--graphite); cursor: pointer; }
  .fab-add[hidden] { display: none; }
  .fab-add .nav-icon { width: 28px; height: 28px; }

  @media (min-width: 1024px) {
    body.app { display: grid; grid-template-columns: 88px minmax(0, 1fr); grid-template-rows: auto 1fr; padding-bottom: 0; }
    .app-header { grid-column: 2; }
    .app-main { grid-column: 2; padding: var(--space-5) var(--space-5) calc(56px + var(--space-6)); }
    .fab-add { bottom: var(--space-5); right: var(--space-5); }
    .app-nav { position: sticky; top: 0; grid-column: 1; grid-row: 1 / span 2; display: flex; flex-direction: column; gap: var(--space-3); height: 100dvh; padding: var(--space-4) 0; border-top: 0; border-right: 1px solid var(--line); }
    .nav-brand { order: -2; display: block; width: 48px; height: 48px; margin: 0 auto var(--space-2); }
    /* Rodapé do trilho: Meus veículos e Linha do tempo, separados dos 5 módulos. */
    .nav-extra { display: grid; gap: var(--space-3); width: 100%; margin-top: auto; padding-top: var(--space-3); border-top: 1px solid var(--line); }
    .nav-extra .nav-label { white-space: normal; text-align: center; line-height: 1.2; padding-inline: var(--space-1); }
    .nav-extra .nav-link.is-active { color: var(--text); }
    .nav-extra .nav-link.is-active .nav-icon { color: var(--start-red); }
    .nav-link { width: 100%; }
    .nav-link[aria-current="page"]::before { top: 25%; bottom: 25%; left: 0; right: auto; width: 3px; height: auto; border-radius: 0 3px 3px 0; }
  }
}

@layer components {
  .btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: var(--target); padding: 0 var(--space-4); border: 1px solid transparent; border-radius: var(--radius); background: var(--start-red); color: var(--on-primary); font-weight: 500; text-align: center; text-decoration: none; cursor: pointer; }
  .btn:disabled { opacity: .6; cursor: progress; }
  .btn--secondary { background: var(--plate-metal); border-color: var(--field-border); color: var(--text); }
  .btn--ghost { background: transparent; border-color: var(--field-border); color: var(--text); }
  .btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
  .btn--block { width: 100%; }
  .icon-btn { display: grid; place-items: center; flex: none; width: var(--target); height: var(--target); border: 0; border-radius: var(--radius); background: transparent; color: var(--text); cursor: pointer; }
  .icon-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
  .link { display: inline-flex; align-items: center; min-height: var(--target); font-weight: 500; }
  .btn, .icon-btn, .item-main, .stage-row, .menu-link, .choice, .nav-link { transition: background-color 160ms ease-out, border-color 160ms ease-out, color 160ms ease-out; }
  /* Hover só com mouse: escurece o fundo, nunca clareia o texto. */
  @media (hover: hover) {
    .btn:hover { background: var(--accent-press); }
    .btn--secondary:hover { background: var(--surface-2); border-color: var(--text-muted); }
    .btn--ghost:hover { background: var(--surface-2); border-color: var(--text-muted); }
    .btn--danger:hover { background: rgb(255 122 128 / 0.12); border-color: var(--danger); }
    .btn:disabled:hover { background: var(--accent); }
    .btn--secondary:disabled:hover { background: var(--plate-metal); border-color: var(--field-border); }
    .btn--ghost:disabled:hover { background: transparent; border-color: var(--field-border); }
    .btn--danger:disabled:hover { background: transparent; border-color: var(--danger); }
    .icon-btn:hover, .item-main:hover, .stage-row:hover, .menu-link:hover, .choice:hover { background: var(--surface-2); }
    .nav-link:hover { color: var(--text); }
  }

  .plate-button { display: flex; flex: 1 1 auto; align-items: center; gap: var(--space-2); min-width: 0; max-width: none; min-height: var(--target); padding: 0 var(--space-2) 0 0; border: 0; background: transparent; color: var(--text); cursor: pointer; }
  .account-chip { margin-left: auto; display: flex; align-items: center; justify-content: flex-end; gap: var(--space-2); flex-shrink: 1000; min-width: min-content; max-width: 45%; min-height: var(--target); padding: var(--space-1) 0; color: var(--text); text-decoration: none; }
  .account-text { display: grid; grid-template-columns: minmax(0, 1fr); justify-items: end; min-width: 0; }
  .account-menu-icon { flex: none; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; color: var(--chrome); }
  .account-line { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-1); min-width: 0; max-width: 100%; }
  .account-name { grid-column: 2; grid-row: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .account-id { grid-column: 1; grid-row: 1; justify-self: end; color: var(--chrome); font-variant-numeric: tabular-nums; }
  .account-sep { grid-column: 3; grid-row: 1; display: none; color: var(--chrome); }
  .account-email { display: none; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--chrome); font-size: var(--step-1); }
  @media (min-width: 1024px) {
    .account-line { grid-template-columns: minmax(0, 1fr) auto auto; }
    .account-name { grid-column: 1; }
    .account-sep { grid-column: 2; }
    .account-id { grid-column: 3; }
    .account-sep, .account-email { display: block; }
  }
  .plate-nick { overflow: hidden; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
  .plate-caret { display: grid; flex: none; color: var(--chrome); }
  .plate-caret .nav-icon { width: 20px; height: 20px; }
  .check-target--static .nav-icon { width: 22px; height: 22px; }
  .plate { display: inline-grid; grid-template-rows: auto 1fr; flex-shrink: 0; min-width: 84px; overflow: hidden; border: 2px solid var(--plate-ink); border-radius: 5px; background: var(--plate-white); color: var(--plate-ink); font-family: var(--font-display); font-weight: 700; line-height: 1; }
  .plate-band { padding: 1px 0; background: var(--plate-blue); color: var(--plate-white); font-family: var(--font-text); font-size: 0.5rem; letter-spacing: .12em; text-align: center; }
  .plate-chars { display: block; min-height: 1.6em; padding: 3px var(--space-2); font-size: 1.1rem; letter-spacing: .06em; text-align: center; }
  .plate--old { grid-template-rows: 1fr; background: var(--plate-gray); }
  .plate--lg { min-width: 132px; }
  .plate--lg .plate-chars { padding: 6px var(--space-3); font-size: 1.75rem; }
  .plate--lg .plate-band { font-size: 0.65rem; }

  .form { display: grid; gap: var(--space-4); }
  .fieldset { display: grid; gap: var(--space-4); min-width: 0; margin: 0; padding: 0; border: 0; }
  .fieldset legend { padding: 0 0 var(--space-2); font-family: var(--font-display); font-size: var(--step1); font-weight: 700; }
  .field { display: grid; gap: var(--space-1); min-width: 0; }
  .field-label, .field-hint { color: var(--chrome); font-size: var(--step-1); }
  .field-optional { font-weight: 400; }
  .field input, .field select, .field textarea { width: 100%; min-height: var(--target); padding: var(--space-2) var(--space-3); border: 1px solid var(--field-border); border-radius: var(--radius); background: var(--graphite); font-size: var(--step0); }
  .field textarea { min-height: 96px; resize: vertical; }
  .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--text); }
  .field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); }
  .form-actions { display: flex; flex-wrap: wrap; gap: var(--space-3); }
  .form-actions .btn { flex: 1 1 160px; }
  .form-error { color: var(--danger); }
  /* Erro do campo: embaixo dele, ligado por aria-describedby; borda do campo em vermelho. */
  .field-error { color: var(--danger); font-size: var(--step-1); font-weight: 500; }
  .field [aria-invalid="true"] { border-color: var(--danger); }
  .more { border-top: 1px solid var(--line-subtle); }
  .more > summary { display: flex; align-items: center; min-height: var(--target); font-weight: 500; cursor: pointer; }
  .more[open] { display: grid; gap: var(--space-4); }
  /* Aviso: moldura inteira na cor do estado (etapa 4: sem a borda lateral colorida). */
  .notice { padding: var(--space-3) var(--space-4); border: 1px solid var(--pending-amber); border-radius: var(--radius); background: var(--surface-1); }
  .notice--error { border-color: var(--danger); }
  .switch { display: flex; align-items: center; gap: var(--space-3); min-height: var(--target); cursor: pointer; }
  .switch input { flex: none; width: 22px; height: 22px; margin: 0; accent-color: var(--paid-green); }
  .toolbar { display: flex; justify-content: flex-end; }

  .list { margin: 0; padding: 0; list-style: none; }
  .list > li + li { border-top: 1px solid var(--line-subtle); }
  .section { display: grid; gap: var(--space-3); }
  .section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
  .section-title { font-size: var(--step1); }
  .muted, .empty { color: var(--chrome); }
  .empty-state { display: grid; justify-items: start; gap: var(--space-3); padding: var(--space-5) 0; }
  .empty-state h2 { font-size: var(--step2); }
  .group { display: grid; }
  .group-head { position: sticky; top: var(--header-h); z-index: 1; padding: var(--space-2) 0; border-bottom: 1px solid var(--line); background: var(--graphite); color: var(--chrome); font-family: var(--font-text); font-size: var(--step-1); font-weight: 500; overflow-wrap: anywhere; }

  .item-row { display: flex; align-items: stretch; gap: var(--space-1); min-height: 64px; }
  .check-target { display: grid; flex: none; place-items: center; width: var(--target); min-height: var(--target); cursor: pointer; }
  .check-target input { width: 24px; height: 24px; margin: 0; accent-color: var(--paid-green); cursor: pointer; }
  .item-main { display: flex; flex: 1; align-items: center; gap: var(--space-3); min-width: 0; min-height: var(--target); padding: var(--space-2) 0; border: 0; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
  .item-thumb { flex: none; width: 44px; height: 44px; border-radius: 6px; background: var(--plate-metal); object-fit: cover; }
  .item-thumb--lg { width: 96px; height: 96px; }
  .item-text { display: grid; flex: 1; min-width: 0; }
  .item-name { overflow-wrap: anywhere; }
  .item-meta { color: var(--chrome); font-size: var(--step-1); overflow-wrap: anywhere; }
  .item-value { display: grid; flex: none; justify-items: end; font-family: var(--font-display); font-size: var(--step1); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
  .item-value.is-missing { color: var(--pending-amber); font-family: var(--font-text); font-size: var(--step-1); font-weight: 500; }
  .check-target--static { color: var(--paid-green); font-weight: 700; cursor: default; }
  .item-tag { color: var(--paid-green); font-family: var(--font-text); font-size: var(--step-1); font-weight: 500; }
  .item-row.is-done .item-name { color: var(--chrome); text-decoration: line-through; }

  /* Pessoa com acesso (etapa 4): avatar + nome; controles numa segunda linha no celular. */
  .member-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; column-gap: var(--space-3); row-gap: var(--space-2); padding: var(--space-3) 0; }
  .member-row > .badge, .member-row > .btn { justify-self: end; }
  .member-controls { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-2); }
  .member-controls .field { flex: 1 1 160px; }
  .member-controls .btn { flex: none; }
  .avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--surface-2); color: var(--text); font-family: var(--font-display); font-size: var(--step1); font-weight: 700; }
  @media (min-width: 640px) {
    .member-controls { grid-column: auto; flex-wrap: nowrap; }
    .member-controls .field { flex: 0 1 160px; }
  }
  .badge { display: inline-flex; align-items: center; padding: 2px 8px; border: 1px solid var(--field-border); border-radius: 999px; color: var(--chrome); font-size: var(--step-1); }
  .badge--owner { border-color: var(--text-muted); color: var(--text); }
  .search-results { display: grid; gap: var(--space-2); }

  .status { display: inline-flex; align-items: center; gap: var(--space-1); color: var(--chrome); font-size: var(--step-1); }
  .status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--chrome); }
  .status--active::before { background: var(--pending-amber); }
  .status--done::before { background: var(--paid-green); }
  .status--ok::before { background: var(--paid-green); }
  .status--chegando::before { background: var(--pending-amber); }
  .status--vencida::before { background: var(--danger); }
  .progress-text { color: var(--chrome); font-size: var(--step-1); }
  .flag { display: inline-block; flex: none; width: 20px; height: 14px; margin-left: var(--space-2); border: 1px solid var(--chrome); background: repeating-conic-gradient(var(--text) 0 25%, var(--graphite) 0 50%) 0 0 / 7px 7px; vertical-align: middle; }

  .stage-row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; align-items: start; gap: var(--space-3); min-height: var(--target); padding: var(--space-3) 0; color: var(--text); text-decoration: none; }
  .stage-ring { display: block; width: 44px; height: 44px; }
  .stage-body { display: grid; gap: var(--space-1); min-width: 0; }
  .stage-name { display: flex; align-items: center; font-weight: 500; overflow-wrap: anywhere; }
  .stage-note { color: var(--pending-amber); font-size: var(--step-1); }
  .stage-value { font-family: var(--font-display); font-weight: 600; font-variant-numeric: tabular-nums; }

  .values { display: grid; }
  .value-row { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); padding: var(--space-2) 0; border-bottom: 1px solid var(--line-subtle); }
  .value-row dt { color: var(--chrome); }
  .value-row dd { display: grid; justify-items: end; font-family: var(--font-display); font-size: var(--step1); font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
  .values--detail dd { font-family: var(--font-text); font-size: var(--step0); font-weight: 400; }
  .value-note { color: var(--pending-amber); font-family: var(--font-text); font-size: var(--step-1); font-weight: 500; }
  .hero-total { display: grid; gap: var(--space-1); }
  .hero-label { color: var(--chrome); font-family: var(--font-text); font-size: var(--step0); font-weight: 500; }
  .hero-amount { font-family: var(--font-display); font-size: var(--step3); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.05; }
  .hero-note { color: var(--chrome); }

  .segmented { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-1); padding: var(--space-1); border-radius: var(--radius); background: var(--plate-metal); }
  .segmented button { min-height: var(--target); border: 0; border-radius: 8px; background: transparent; color: var(--chrome); font-weight: 500; cursor: pointer; }
  .segmented button[aria-pressed="true"] { background: var(--graphite); color: var(--text); }
  .maint-items { display: grid; gap: var(--space-2); }
  .maint-item { display: grid; gap: var(--space-2); padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius); }
  .menu-list { display: grid; gap: var(--space-2); }
  .menu-link { display: grid; align-content: center; min-height: 64px; padding: var(--space-2) 0; color: var(--text); text-decoration: none; }
  .menu-label { font-weight: 500; }
  .menu-hint { color: var(--chrome); font-size: var(--step-1); }
  .choice { display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 64px; padding: var(--space-2) 0; border: 0; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
  .choice.is-current .choice-text::after { content: " (ativo)"; color: var(--chrome); }

  .card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); gap: var(--space-4); margin: 0; padding: 0; list-style: none; }
  .card { display: grid; align-content: start; gap: var(--space-2); padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius); background: var(--plate-metal); }
  .card.is-current { border-color: var(--chrome); }
  .panel { padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius); background: var(--plate-metal); }
  .eyebrow { color: var(--text-muted); font-size: var(--step-1); font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
  .card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
  .card-title { font-size: var(--step1); overflow-wrap: anywhere; }
  .card-meta { color: var(--chrome); overflow-wrap: anywhere; }
  .card-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); margin-top: var(--space-2); }
  .card-actions .btn { flex: 1 1 120px; }

  /* Os <dialog> não recebem display do autor quando fechados: só [open] define layout. */
  .sheet, .confirm { width: 100%; max-width: 100%; max-height: 92dvh; margin: auto 0 0; padding: 0; overflow: auto; border: 0; border-radius: 16px 16px 0 0; background: var(--plate-metal); color: var(--text); }
  .sheet::backdrop, .confirm::backdrop { background: rgb(0 0 0 / 0.6); }
  .sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-1) var(--space-2) var(--space-1) var(--space-4); border-bottom: 1px solid var(--line); background: var(--plate-metal); }
  .sheet-title { min-width: 0; font-size: var(--step1); overflow-wrap: anywhere; }
  .sheet-body { display: grid; gap: var(--space-4); padding: var(--space-4) var(--space-4) calc(var(--space-5) + var(--safe-bottom)); }
  /* Ação principal fixa no fim do sheet (ex.: "Dar acesso (N)"), sempre ao alcance. */
  .sheet-footer { position: sticky; bottom: 0; z-index: 1; padding: var(--space-3) 0; border-top: 1px solid var(--line); background: var(--plate-metal); }
  .sheet-alternatives { display: grid; gap: var(--space-2); padding-top: var(--space-4); border-top: 1px solid var(--line); }
  /* Escolhas do "+": ícone + rótulo + dica, alvo de 64 px (mesmo desenho do protótipo). */
  .sheet-choices { display: grid; gap: var(--space-2); }
  .choice-btn { display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: 64px; padding: var(--space-2) var(--space-3); border: 1px solid var(--divider); border-radius: var(--radius); background: var(--surface-0); color: var(--text); text-align: left; cursor: pointer; transition: background-color 160ms ease-out, border-color 160ms ease-out; }
  .choice-btn .nav-icon { flex: none; color: var(--text-muted); }
  .choice-btn .choice-text { display: grid; min-width: 0; }
  .choice-label { font-weight: 500; }
  .choice-hint { color: var(--text-muted); font-size: var(--step-1); }
  @media (hover: hover) { .choice-btn:hover { background: var(--surface-2); border-color: var(--field-border); } }
  .confirm[open] { display: grid; gap: var(--space-4); padding: var(--space-5) var(--space-4) calc(var(--space-5) + var(--safe-bottom)); }
  .confirm-title { font-size: var(--step1); }
  @media (min-width: 640px) {
    .sheet, .confirm { width: min(560px, calc(100% - 32px)); max-height: 85dvh; margin: auto; border-radius: 16px; }
  }

  .chart-panel { padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius); background: var(--plate-metal); }
  .chart-figure { position: relative; display: grid; gap: var(--space-3); min-width: 0; }
  /* A tabela .visually-hidden não encolhe a 1px: o invólucro corta para ela não alargar a página. */
  .chart-sr { position: absolute; top: 0; left: 0; width: 1px; height: 1px; overflow: hidden; }
  .chart { display: block; width: 100%; overflow: visible; }
  .chart text { fill: var(--chrome); font-family: var(--font-text); font-size: 13px; }
  .chart .chart-value { fill: var(--text); font-family: var(--font-display); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
  .chart .chart-tick { font-size: 11px; }
  .chart-track { fill: var(--line); }
  .chart-grid { stroke: var(--line); stroke-dasharray: 3 3; }
  .chart-axis { stroke: var(--line); }
  .chart-hit { fill: transparent; }
  .chart-col:hover .chart-hit { fill: var(--line-subtle); }
  .chart-s-bar, .chart-s-project { fill: var(--chart-project); }
  .chart-s-missing { fill: var(--series-missing); }
  .chart-s-maintenance, .chart-s-revisao { fill: var(--mod-maintenance); }
  .chart-s-nao_programada { fill: var(--series-unplanned); }
  .chart-s-fuel { fill: var(--mod-fuel); }
  .chart-s-expense { fill: var(--mod-expense); }
  .chart-line { fill: none; stroke: var(--mod-fuel); stroke-width: 2; }
  .chart-line-dot { fill: var(--mod-fuel); }
  .chart-legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-4); margin: 0; padding: 0; list-style: none; color: var(--chrome); font-size: var(--step-1); }
  .chart-legend li { display: inline-flex; align-items: center; gap: var(--space-2); }
  .chart-swatch { flex: none; }
  .chart-empty { padding: var(--space-2) 0; }
  /* No celular os 12 meses não cabem com rótulo: fica um a cada dois (o mês atual sempre). */
  @media (max-width: 639px) {
    .chart .chart-tick--minor { display: none; }
  }

  .toast { position: fixed; left: var(--space-4); right: var(--space-4); bottom: calc(var(--nav-h) + var(--safe-bottom) + var(--fab) + var(--space-5)); z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: var(--target); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4); border-radius: var(--radius); background: var(--text); color: var(--graphite); }
  .toast--error { background: var(--danger); }
  .toast > span { min-width: 0; }
  .toast-action { flex: none; }
  .toast-action { min-height: var(--target); padding: 0 var(--space-3); border: 0; border-radius: 8px; background: transparent; color: var(--graphite); font-weight: 700; text-decoration: underline; cursor: pointer; }
  @media (min-width: 1024px) {
    .toast { left: auto; right: var(--space-5); width: 420px; bottom: calc(var(--space-5) + var(--fab) + var(--space-4)); }
  }
}

@layer components {
  /* Esqueleto de carregamento: blocos no lugar do conteúdo (sem animação com reduced-motion). */
  .skeleton-screen { display: grid; gap: var(--space-3); }
  .skeleton { display: block; border-radius: var(--radius); background: var(--surface-2); animation: skeleton-pulse 1.2s ease-in-out infinite; }
  .skeleton--hero { height: 72px; }
  .skeleton--panel { height: 160px; border-radius: 16px; }
  .skeleton--row { height: 56px; }
  @keyframes skeleton-pulse { 50% { opacity: .5; } }
}

@layer views {
  /* Etapa 4 do redesign: painel de instrumentos. Mostradores sempre com o valor em texto. */
  .screen-title--eyebrow { margin-bottom: calc(-1 * var(--space-3)); color: var(--text-muted); font-family: var(--font-text); font-size: var(--step-1); font-weight: 500; letter-spacing: .08em; text-transform: uppercase; }

  .gauge { display: block; width: 100%; max-width: 132px; height: auto; overflow: visible; }
  .gauge-track, .gauge-fill { fill: none; stroke-width: 10; stroke-linecap: round; }
  .gauge-track { stroke: var(--divider); }
  .gauge-fill { stroke: var(--text-muted); }
  .gauge--ok .gauge-fill { stroke: var(--ok); }
  .gauge--alert .gauge-fill { stroke: var(--alert); }
  .gauge--danger .gauge-fill { stroke: var(--danger); }
  .gauge-tick { stroke: var(--field-border); stroke-width: 2; stroke-linecap: round; }
  .ring { display: block; width: 44px; height: 44px; overflow: visible; }
  .ring-track, .ring-fill { fill: none; stroke-width: 4; }
  .ring-track { stroke: var(--divider); }
  .ring-fill { stroke: var(--text-muted); stroke-linecap: round; }
  .ring--done .ring-fill { stroke: var(--ok); }
  .ring-num { fill: var(--text); font-family: var(--font-display); font-size: 17px; font-weight: 700; }
  .dial-value { font-family: var(--font-display); font-size: clamp(1.75rem, 6vw, 2.25rem); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.05; white-space: nowrap; }
  .dial-caption { color: var(--text-muted); font-size: var(--step-1); }
  .dial-caption--alert { color: var(--alert); font-weight: 500; }
  .dial-caption--danger { color: var(--danger); font-weight: 500; }
  .dial-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); }
  .dial-gauge { flex: 0 0 132px; }
  .dial-text { display: grid; gap: var(--space-1); min-width: 0; }

  /* Resumo: cabeçalho, avisos, indicadores; no celular etapas e valores antes dos gráficos. */
  .resumo-grid, .resumo-main, .resumo-side, .resumo-alerts, .resumo-charts { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; gap: var(--space-5); }
  .resumo-alerts { gap: var(--space-3); }
  .resumo-charts[hidden] { display: none; }
  .resumo-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); }
  .vehicle-hero { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4); }
  .vehicle-name { font-size: var(--step3); overflow-wrap: anywhere; }
  .vehicle-model { color: var(--chrome); }
  .alert-banner { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-4); border: 1px solid var(--alert); border-radius: var(--radius); background: var(--surface-1); }
  .alert-banner .alert-icon { flex: none; margin-top: 2px; color: var(--alert); }
  .alert-body .link { display: inline; min-height: 0; }
  .alert-banner--danger { border-color: var(--danger); }
  .alert-banner--danger .alert-icon { color: var(--danger); }
  .alert-body { display: grid; gap: var(--space-1); min-width: 0; }
  .alert-title { font-size: var(--step1); }
  .kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
  .kpi { container-type: inline-size; display: grid; align-content: start; gap: var(--space-1); min-width: 0; padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--radius); background: var(--plate-metal); color: var(--text); text-decoration: none; }
  .kpi--hero { grid-column: 1 / -1; }
  .kpi-label { color: var(--text-muted); font-family: var(--font-text); font-size: var(--step-1); font-weight: 500; letter-spacing: .02em; }
  .kpi-gauge { display: block; max-width: 112px; }
  .kpi-value { overflow: hidden; font-family: var(--font-display); font-size: clamp(1.25rem, 16cqi, 2rem); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }
  .kpi--hero .kpi-value { font-size: clamp(2rem, 11cqi, 2.75rem); }
  .kpi-note { color: var(--text-muted); font-size: var(--step-1); }
  .kpi-note--alert { color: var(--alert); font-weight: 500; }
  .kpi-note--danger { color: var(--danger); font-weight: 500; }
  a.kpi { transition: background-color 160ms ease-out, border-color 160ms ease-out; }
  @media (hover: hover) { a.kpi:hover { background: var(--surface-2); border-color: var(--field-border); } }
  .more-charts { justify-content: space-between; }
  .more-charts-caret { transition: transform 200ms ease-out; }
  .more-charts[aria-expanded="true"] .more-charts-caret { transform: rotate(180deg); }
  .event { display: grid; gap: 2px; padding: var(--space-2) 0; overflow-wrap: anywhere; }
  .event time, .event-meta { color: var(--chrome); font-size: var(--step-1); }
  .day-title { padding: var(--space-3) 0 var(--space-1); color: var(--chrome); font-family: var(--font-text); font-size: var(--step-1); font-weight: 500; }

  /* Etapa: mostrador de progresso ao lado da situação e das ações. */
  .stage-hero { display: grid; gap: var(--space-4); }
  .stage-hero-top { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4) var(--space-5); }
  .stage-dial { display: grid; justify-items: center; gap: var(--space-1); flex: 0 0 148px; text-align: center; }
  .stage-dial .gauge { max-width: 148px; }
  .stage-dial .dial-value { margin-top: calc(-1 * var(--space-6)); }
  .stage-hero-info { display: grid; gap: var(--space-2); flex: 1 1 240px; min-width: 0; }
  .stage-hero-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-3); }
  .stage-hint { color: var(--ok); font-weight: 500; }

  /* Consumo: os três números do painel. */
  .fuel-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(140px, 100%), 1fr)); gap: var(--space-3); }
  .stat { display: grid; align-content: start; gap: 2px; padding: var(--space-3); border-radius: var(--radius); background: var(--surface-0); }
  .stat-label { color: var(--text-muted); font-size: var(--step-1); font-weight: 500; }
  .stat-value { font-family: var(--font-display); font-size: var(--step2); font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; white-space: nowrap; }
  .stat-note { color: var(--text-muted); font-size: var(--step-1); }

  /* Gastos: total do período e filtros. */
  .expense-total { gap: var(--space-1); }
  .expense-filters { display: grid; gap: var(--space-3); }
  .chip-group { display: flex; flex-wrap: wrap; gap: var(--space-2); }
  .chip { min-width: var(--target); min-height: var(--target); padding: 0 var(--space-4); border: 1px solid var(--field-border); border-radius: 999px; background: transparent; color: var(--text); font-weight: 500; cursor: pointer; transition: background-color 160ms ease-out, border-color 160ms ease-out; }
  .chip[aria-pressed="true"] { border-color: var(--text); background: var(--text); color: var(--surface-0); }
  @media (hover: hover) { .chip[aria-pressed="false"]:hover { background: var(--surface-2); border-color: var(--text-muted); } }
  .empty-state--compact { padding: var(--space-3) 0; }

  /* Meus veículos: papel de quem está logado separado do proprietário do documento. */
  .vehicle-card { gap: var(--space-3); }
  .vehicle-card-title { display: grid; gap: 2px; }
  .pills { display: flex; flex-wrap: wrap; gap: var(--space-2); }
  .pill { display: inline-flex; align-items: center; min-height: 24px; padding: 0 var(--space-2); border: 1px solid var(--field-border); border-radius: 999px; color: var(--text-muted); font-size: var(--step-1); font-weight: 500; }
  .pill--current { border-color: var(--ok); color: var(--ok); }
  .facts { display: grid; gap: var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--line); }
  .fact { display: grid; gap: 2px; }
  .fact dt { color: var(--text-muted); font-size: var(--step-1); }
  .fact dd { display: grid; justify-items: start; gap: 2px; overflow-wrap: anywhere; }
  .fact-note { color: var(--text-muted); font-size: var(--step-1); }
  .role { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: 500; }
  .role::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
  .role--owner::before { background: var(--accent); }
  .role--editor::before { background: var(--alert); }
  .role--viewer::before { background: var(--mod-maintenance); }

  /* Admin: tabelas no desktop, listas no celular. */
  .admin-row { display: grid; gap: 2px; padding: var(--space-3) 0; overflow-wrap: anywhere; }
  .admin-row .form-actions { margin-top: var(--space-2); }
  .table-wrap { min-width: 0; }
  .data-table { width: 100%; border-collapse: collapse; }
  .data-table th { padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--line); color: var(--text-muted); font-size: var(--step-1); font-weight: 500; text-align: left; }
  .data-table td { padding: var(--space-3); border-bottom: 1px solid var(--line-subtle); vertical-align: middle; overflow-wrap: anywhere; }
  .data-table th:first-child, .data-table td:first-child { padding-left: 0; }
  .data-table td.nowrap { white-space: nowrap; }
  .data-table td.actions { width: 1%; white-space: nowrap; }
  .data-table td.actions .form-actions { flex-wrap: nowrap; }
  .data-table td.actions .btn { flex: none; }
  .data-table .item-meta { display: block; }
  @media (hover: hover) { .data-table tbody tr:hover { background: var(--surface-1); } }
  .invite-link { width: 100%; min-height: 96px; padding: var(--space-2) var(--space-3); border: 1px solid var(--line); border-radius: var(--radius); background: var(--graphite); font-size: var(--step0); overflow-wrap: anywhere; }

  @media (min-width: 1024px) {
    .resumo-grid { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); grid-template-areas: "head head" "kpis kpis" "main side" "main activity"; grid-template-rows: auto auto auto 1fr; align-items: start; gap: var(--space-5) var(--space-6); }
    .resumo-grid--alerts { grid-template-areas: "head head" "alerts alerts" "kpis kpis" "main side" "main activity"; grid-template-rows: auto auto auto auto 1fr; }
    .resumo-head { grid-area: head; }
    .resumo-alerts { grid-area: alerts; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
    .kpis { grid-area: kpis; grid-template-columns: 1.4fr repeat(3, minmax(0, 1fr)); }
    .kpi--hero { grid-column: auto; }
    .resumo-main { grid-area: main; }
    .resumo-side { grid-area: side; }
    .resumo-activity { grid-area: activity; }
  }
}

@layer auth {
  body.auth { display: grid; place-items: center; padding: var(--space-4); }
  .auth-shell { display: grid; gap: var(--space-5); width: min(960px, 100%); }
  .auth-brand { display: grid; place-items: center; }
  .auth-brand img { width: min(220px, 60vw); height: auto; }
  .auth-card { display: grid; gap: var(--space-4); padding: var(--space-5) var(--space-4); border: 1px solid var(--line); border-radius: 16px; background: var(--plate-metal); }
  .auth-card h1 { font-size: var(--step2); }
  .auth-intro, .auth-credit { color: var(--chrome); }
  .auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-1); padding: var(--space-1); border-radius: var(--radius); background: var(--graphite); }
  .auth-tabs button { min-height: var(--target); border: 0; border-radius: 8px; background: transparent; color: var(--chrome); font-weight: 500; cursor: pointer; }
  .auth-tabs button[aria-selected="true"] { background: var(--plate-metal); color: var(--text); }
  .auth-panel { display: grid; gap: var(--space-4); }
  .auth-credit { font-size: var(--step-1); text-align: center; }
  .result { padding: var(--space-3); border-left: 3px solid var(--paid-green); background: var(--line-subtle); }
  @media (min-width: 900px) {
    .auth-shell { grid-template-columns: 1fr minmax(360px, 420px); align-items: center; }
    .auth-brand img { width: min(440px, 100%); }
  }
}
