/* Design system do BR Confinamentos -- camada comum das tres telas (app, conta, admin).
   Depende de /branding/confinamentos.tokens.css (cores e tema claro/escuro, fonte unica de verdade).
   Regras: contraste AA pelos tokens, alvo de toque >= 44px, foco visivel de 3px, sem cor fixa
   (tudo via var(--token)), movimento reduzido respeitado, area segura em celulares com notch. */

@font-face {
  font-family: "IBM Plex Sans";
  src: url("/branding/assets/IBM-Plex-Sans-latin-400-600.woff2") format("woff2");
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --tap: 44px;
  --shadow-1: 0 1px 2px rgb(0 0 0 / .14);
  --shadow-2: 0 6px 20px rgb(0 0 0 / .2);
  --ease: cubic-bezier(.2, .8, .2, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  /* extensoes de marca para marcacoes do CRM sem token na entrega de identidade */
  --map-base: #0B6E7A;
  --map-custom: #9D2B6B;
}
[data-theme="dark"] {
  --map-visited: #80D8AD;
  --map-client: #8CC8FF;
  --map-base: #6FD0DB;
  --map-custom: #F08CBC;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; color-scheme: light dark; }
html[data-theme="light"] { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5;
  background: var(--surface); color: var(--text-primary);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.25; font-weight: 600; }
h2 { font-size: 18px; line-height: 1.3; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
a { color: var(--link); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img, svg { max-width: 100%; }
[hidden] { display: none !important; }
::selection { background: var(--selection-surface); color: var(--selection-text); }

:focus-visible { outline: var(--focus-width-px) solid var(--focus); outline-offset: 2px; }
:focus:not(:focus-visible) { outline: none; }

.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: fixed; left: 8px; top: -60px; z-index: 9999; padding: 10px 14px; border-radius: var(--r-sm);
  background: var(--action-primary); color: var(--on-action-primary); font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: calc(8px + var(--safe-t)); }

.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 1.2px; text-transform: uppercase; color: var(--text-secondary); }
.muted { color: var(--text-secondary); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Icones (sprite da marca) ---------- */
.ic { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; --icon-surface: var(--surface-elevated); }
.ic-sm { width: 18px; height: 18px; }

/* ---------- Botoes ---------- */
.btn, .btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 8px 16px; border: 1px solid transparent; border-radius: var(--r-sm);
  font-size: 14px; font-weight: 600; line-height: 1.2; text-decoration: none; white-space: nowrap;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), transform .08s var(--ease);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
@media (pointer: coarse) { .btn, .btn-primary, .btn-secondary, .btn-danger, .btn-ghost { min-height: var(--tap); } }
.btn:active, .btn-primary:active, .btn-secondary:active, .btn-danger:active, .btn-ghost:active { transform: translateY(1px); }
.btn:disabled, .btn-primary:disabled, .btn-secondary:disabled, .btn-danger:disabled, button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn, .btn-primary { background: var(--action-primary); color: var(--on-action-primary); }
.btn:hover:not(:disabled), .btn-primary:hover:not(:disabled) { background: var(--action-primary-hover); }
.btn-secondary { background: var(--action-secondary); color: var(--on-action-secondary); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--action-secondary-hover); }
.btn-ghost { background: transparent; color: var(--text-primary); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-muted); }
.btn-danger { background: transparent; color: var(--error-text); border-color: var(--error-border); }
.btn-danger:hover:not(:disabled) { background: var(--error-surface); }
.btn-block { width: 100%; }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 12.5px; }
.btn[aria-busy="true"]::after, .btn-primary[aria-busy="true"]::after {
  content: ""; width: 14px; height: 14px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: var(--tap); height: var(--tap); padding: 0; border-radius: var(--r-sm);
  border: 1px solid var(--border); background: var(--surface-elevated); color: var(--text-primary);
  transition: background-color .15s var(--ease), border-color .15s var(--ease);
  -webkit-tap-highlight-color: transparent; touch-action: manipulation; --icon-surface: var(--surface-elevated);
}
.icon-btn:hover { background: var(--surface-muted); }
.icon-btn.active, .icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] {
  background: var(--action-primary); color: var(--on-action-primary); border-color: var(--action-primary); --icon-surface: var(--action-primary);
}
.icon-btn.borderless { border-color: transparent; background: transparent; }

/* ---------- Campos ---------- */
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"],
input[type="date"], input[type="time"], input[type="tel"], input[type="url"], input:not([type]), select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text-primary); font-size: 16px; /* 16px evita zoom automatico no iOS */
}
@media (min-width: 769px) and (pointer: fine) {
  input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="search"],
  input[type="date"], input[type="time"], input[type="tel"], input[type="url"], input:not([type]), select, textarea { font-size: 14px; }
}
@media (pointer: coarse) { input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select { min-height: var(--tap); } }
textarea { min-height: 80px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text-secondary); opacity: .8; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-muted); color: var(--text-disabled); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--action-primary); flex: none; }
input[type="range"] { accent-color: var(--action-primary); }
input[aria-invalid="true"] { border-color: var(--error-border); }
label { font-weight: 600; font-size: 13px; }
.field { display: grid; gap: 6px; }
.field > label { font-size: 13px; }
.field-hint { font-size: 12px; color: var(--text-secondary); font-weight: 400; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 48px; }
.pw-wrap .pw-toggle {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 40px; height: 40px;
  border: 0; background: transparent; color: var(--text-secondary); border-radius: var(--r-sm);
}

/* ---------- Superficies ---------- */
.card {
  background: var(--surface-elevated); border: 1px solid var(--border-subtle); border-radius: var(--r-lg);
  padding: 20px; margin-bottom: 16px;
}
.card h2 { margin-bottom: 14px; }
.tag, .tab-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 3px; font-size: 12px; font-weight: 500;
  border: 1px solid var(--border-subtle); background: var(--surface-muted); color: var(--text-primary);
}
.tag-brand { background: var(--brand-accent-surface); color: var(--on-brand-accent-surface); border-color: transparent; }
.badge-success { background: var(--success-surface); color: var(--success-text); border-color: var(--success-border); }
.badge-error { background: var(--error-surface); color: var(--error-text); border-color: var(--error-border); }
.badge-info { background: var(--info-surface); color: var(--info-text); border-color: var(--info-border); }
.notice {
  padding: 10px 12px; border-left: 3px solid var(--info-border); background: var(--info-surface); color: var(--info-text);
  font-size: 13px; line-height: 1.5; border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.notice-error { border-color: var(--error-border); background: var(--error-surface); color: var(--error-text); }
.notice-success { border-color: var(--success-border); background: var(--success-surface); color: var(--success-text); }
.empty-hint { color: var(--text-secondary); font-size: 13px; padding: 10px 0; }
.error-hint { color: var(--error-text); font-size: 13px; margin: 8px 0; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border-subtle); }
th { color: var(--text-secondary); font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Abas ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border-subtle); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: none; padding: 10px 16px; min-height: 44px; border: 0; border-bottom: 3px solid transparent; background: transparent;
  color: var(--text-secondary); font-weight: 600; font-size: 14px; border-radius: 0;
}
.tab-btn:hover { color: var(--text-primary); background: var(--surface-muted); }
.tab-btn.active { color: var(--action-primary); border-bottom-color: var(--action-primary); }

/* ---------- Interruptor ---------- */
.switch {
  position: relative; flex: none; width: 48px; height: 28px; padding: 0; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface-muted); transition: background-color .2s var(--ease), border-color .2s var(--ease);
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--text-secondary); transition: transform .2s var(--ease), background-color .2s var(--ease);
}
.switch.on { background: var(--action-primary); border-color: var(--action-primary); }
.switch.on::after { transform: translateX(20px); background: var(--on-action-primary); }

/* ---------- Modal / folha (dialogos) ---------- */
.modal-backdrop, .overlay {
  display: none; position: fixed; inset: 0; z-index: 2000; background: var(--overlay);
  align-items: center; justify-content: center; padding: 16px; overscroll-behavior: contain;
}
.modal-backdrop.open, .overlay.open { display: flex; }
.modal, .dialog {
  background: var(--surface-elevated); color: var(--text-primary); border: 1px solid var(--border-subtle); border-radius: var(--r-lg);
  box-shadow: var(--shadow-2); width: min(520px, 100%); max-height: 90dvh; overflow-y: auto; padding: 24px;
  animation: pop .18s var(--ease);
}
.modal h3 { margin-bottom: 14px; font-size: 17px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@media (max-width: 640px) {
  .modal-backdrop, .overlay { align-items: flex-end; padding: 0; }
  .modal, .dialog { width: 100%; max-height: 92dvh; border-radius: var(--r-lg) var(--r-lg) 0 0; padding-bottom: calc(24px + var(--safe-b)); animation: sheet-up .22s var(--ease); }
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }

/* ---------- Aviso rapido (toast) ---------- */
#toasts { position: fixed; z-index: 9000; left: 50%; transform: translateX(-50%); bottom: calc(16px + var(--safe-b)); display: grid; gap: 8px; width: min(420px, calc(100% - 24px)); pointer-events: none; }
.toast {
  pointer-events: auto; padding: 12px 14px; border-radius: var(--r-md); background: var(--action-primary); color: var(--on-action-primary);
  box-shadow: var(--shadow-2); font-size: 14px; animation: pop .18s var(--ease);
}
.toast-error { background: var(--action-destructive); color: var(--on-action-destructive); }

/* ---------- Carregando ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-muted) 25%, var(--border-subtle) 37%, var(--surface-muted) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--r-sm); min-height: 16px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Tela de login (compartilhada) ---------- */
.login-shell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); min-height: 100dvh; background: var(--surface); }
.login-art {
  position: relative; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between;
  padding: 48px 56px; background: var(--brand-primary-700); color: #fff;
}
.login-art .brand-grid { position: absolute; right: -30px; bottom: 30px; width: 70%; max-width: 460px; opacity: .13; pointer-events: none; }
.login-art .copy { position: relative; z-index: 1; }
.login-art h1 { font-size: clamp(30px, 3.4vw, 46px); max-width: 520px; margin-top: 12px; }
.login-art p { max-width: 440px; margin-top: 18px; color: var(--brand-primary-100); font-size: 17px; }
.login-art .eyebrow { color: var(--brand-primary-100); }
.login-art .logo { width: min(320px, 100%); height: auto; }
.login-art .foot { position: relative; z-index: 1; font-size: 14px; color: var(--brand-primary-100); }
.login-pane { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.login-box { width: 100%; max-width: 380px; }
.login-box h1 { margin: 10px 0 8px; }
.login-box form { display: grid; gap: 16px; margin: 28px 0 8px; }
.login-error { min-height: 20px; color: var(--error-text); font-size: 13px; font-weight: 500; }
.login-mobile-logo { display: none; }
@media (max-width: 860px) {
  .login-shell { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .login-pane { align-items: flex-start; padding: calc(28px + var(--safe-t)) 20px 28px; }
  .login-mobile-logo { display: block; width: 220px; margin-bottom: 28px; }
}

/* ---------- Seletor de tema ---------- */
.theme-toggle .ic-moon { display: none; }
[data-theme="dark"] .theme-toggle .ic-sun { display: none; }
[data-theme="dark"] .theme-toggle .ic-moon { display: block; }

/* Logos alternam por tema (positiva no claro, negativa no escuro) */
[data-theme="dark"] .logo-light { display: none; }
html:not([data-theme="dark"]) .logo-dark { display: none; }

/* ---------- Movimento reduzido ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
@media print { .no-print { display: none !important; } body { background: #fff; color: #000; } }

/* nome da marca: "BR" no verde da marca + "Confinamentos" */
.brand-name { font-weight: 600; font-size: 17px; letter-spacing: -.01em; color: var(--action-primary); white-space: nowrap; }
.brand-name .br, .eyebrow .br { color: var(--brand-green); font-weight: 800; }
.login-mobile-brand { align-items: center; gap: 10px; width: auto; }
@media (max-width: 860px) { .login-mobile-brand { display: flex; width: auto; } }
