/* ==========================================================================
   PMOC · SMS — Design System
   Leve, sem dependências externas. Paleta "ar limpo" (teal/cyan + slate).
   ========================================================================== */

:root {
  --brand-1: #0d9488;   /* teal-600 */
  --brand-2: #0891b2;   /* cyan-600 */
  --brand-ink: #ffffff;

  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;      /* slate-900 */
  --muted: #64748b;     /* slate-500 */
  --border: #e2e8f0;    /* slate-200 */
  --ring: rgba(8,145,178,.35);

  --ok-bg:#dcfce7;  --ok-fg:#15803d;
  --warn-bg:#fef3c7;--warn-fg:#b45309;
  --dang-bg:#fee2e2;--dang-fg:#b91c1c;
  --sec-bg:#e2e8f0; --sec-fg:#475569;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.05);
  --shadow-md: 0 4px 16px rgba(15,23,42,.08);
  --shadow-lg: 0 12px 32px rgba(15,23,42,.14);
  --transition: .18s cubic-bezier(.4,0,.2,1);
  color-scheme: light;
}

/* ---------- Tema escuro ---------- */
:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #131d31;
  --surface-2: #0f1829;
  --text: #e6edf6;
  --muted: #94a3b8;
  --border: #263349;
  --ring: rgba(8,145,178,.45);

  --ok-bg: rgba(34,197,94,.16);   --ok-fg: #4ade80;
  --warn-bg: rgba(234,179,8,.16);  --warn-fg: #fbbf24;
  --dang-bg: rgba(239,68,68,.18);  --dang-fg: #f87171;
  --sec-bg: rgba(148,163,184,.18); --sec-fg: #cbd5e1;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 6px 20px rgba(0,0,0,.5);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.6);
  color-scheme: dark;
}

/* Ao imprimir, força cores claras mesmo no modo escuro */
@media print {
  :root[data-theme="dark"] { --bg:#fff; --surface:#fff; --surface-2:#fff; --text:#000; --muted:#333; --border:#ccc; }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Fundo suave para páginas "lite" (login / página pública do QR) */
body.lite {
  background:
    radial-gradient(1200px 500px at 100% -10%, rgba(8,145,178,.16), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(13,148,136,.16), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

a { color: var(--brand-2); }

/* ---------- Topbar / Navbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2));
  color: var(--brand-ink);
  box-shadow: var(--shadow-md);
}
.topbar-inner {
  width: 100%; margin: 0; padding: 12px 28px;
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: #fff; text-decoration: none; font-weight: 800; letter-spacing: .3px;
}
.brand .brand-logo {
  height: 34px; width: 34px; object-fit: contain;
  background: #fff; border-radius: 9px; padding: 3px; box-shadow: var(--shadow-sm);
}
.brand .brand-name { font-size: 18px; line-height: 1; }
.brand .brand-name small { display: block; font-size: 10px; font-weight: 600; opacity: .85; letter-spacing: 2px; }

.nav { display: flex; gap: 4px; margin-left: 6px; flex-wrap: wrap; }
.nav a {
  display: inline-flex; align-items: center; gap: 7px;
  color: rgba(255,255,255,.9); text-decoration: none; font-size: 14px; font-weight: 600;
  padding: 7px 13px; border-radius: 999px;
  transition: background var(--transition), color var(--transition), transform var(--transition), box-shadow var(--transition);
  animation: navIn .45s cubic-bezier(.4,0,.2,1) both;
}
.nav a:hover { background: rgba(255,255,255,.16); color: #fff; transform: translateY(-2px); }
.nav a:active { transform: translateY(0) scale(.96); }
.nav a.active { background: #fff; color: var(--brand-1); box-shadow: var(--shadow-sm); }

.nav .nav-ico { flex-shrink: 0; opacity: .95; transition: transform var(--transition); }
.nav a:hover .nav-ico { transform: scale(1.15) rotate(-8deg); }
.nav a.active .nav-ico { animation: navIcoPop .35s cubic-bezier(.34,1.56,.64,1); }

/* entrada escalonada dos itens do menu */
@keyframes navIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes navIcoPop { 0% { transform: scale(.6); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }
.nav a:nth-child(1) { animation-delay: .04s; }
.nav a:nth-child(2) { animation-delay: .09s; }
.nav a:nth-child(3) { animation-delay: .14s; }
.nav a:nth-child(4) { animation-delay: .19s; }
.nav a:nth-child(5) { animation-delay: .24s; }
.nav a:nth-child(6) { animation-delay: .29s; }

/* Grupo à direita da navbar: usuário + botão de tema, lado a lado */
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.user { display: flex; align-items: center; gap: 10px; font-size: 13px; color: rgba(255,255,255,.95); }

/* Botão de tema (sol/lua) */
.theme-toggle {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 50%; border: 1px solid rgba(255,255,255,.35); background: rgba(255,255,255,.12);
  color: #fff; cursor: pointer; display: grid; place-items: center; position: relative; overflow: hidden;
  transition: background var(--transition), transform var(--transition);
}
.theme-toggle:hover { background: rgba(255,255,255,.22); transform: rotate(18deg); }
.theme-toggle:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }
.theme-toggle svg { position: absolute; width: 20px; height: 20px;
  transition: transform .5s cubic-bezier(.34,1.56,.64,1), opacity .4s ease; }
.theme-toggle .i-sun  { opacity: 1; transform: rotate(0) scale(1); }
.theme-toggle .i-moon { opacity: 0; transform: rotate(-90deg) scale(.4); }
:root[data-theme="dark"] .theme-toggle .i-sun  { opacity: 0; transform: rotate(90deg) scale(.4); }
:root[data-theme="dark"] .theme-toggle .i-moon { opacity: 1; transform: rotate(0) scale(1); }
.user .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: rgba(255,255,255,.22); display: grid; place-items: center;
  font-weight: 700; font-size: 12px; color: #fff;
}
.user .u-name { font-weight: 600; }
.user .u-role { font-size: 11px; opacity: .8; }
.user a.logout { color: #fff; text-decoration: none; opacity: .9; border: 1px solid rgba(255,255,255,.4); padding: 4px 10px; border-radius: 999px; transition: background var(--transition); }
.user a.logout:hover { background: rgba(255,255,255,.18); }

/* ---------- Layout ---------- */
.container { width: 100%; margin: 24px 0; padding: 0 28px; }
h1 { font-size: 24px; font-weight: 800; letter-spacing: -.02em; margin: 0 0 18px; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; border: 0; border-radius: 10px; cursor: pointer;
  font-size: 14px; font-weight: 600; font-family: inherit; text-decoration: none;
  background: linear-gradient(120deg, var(--brand-1), var(--brand-2)); color: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); filter: saturate(1.05); }
.btn:active { transform: translateY(0); }
.btn.sec { background: #fff; color: var(--text); border: 1px solid var(--border); box-shadow: none; }
.btn.sec:hover { background: var(--surface-2); border-color: #cbd5e1; }
.btn.danger { background: linear-gradient(120deg, #ef4444, #dc2626); color: #fff; }
.btn.danger:hover { filter: saturate(1.1) brightness(1.03); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; color: #334155; margin: 14px 0 5px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; font-size: 14px; font-family: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--ring);
}
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }
select { appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 34px; }

.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 200px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
thead th {
  background: var(--surface-2); color: #475569; font-weight: 600; font-size: 12.5px;
  text-transform: uppercase; letter-spacing: .04em; text-align: left;
  padding: 11px 14px; border-bottom: 1px solid var(--border);
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background var(--transition); }
tbody tr:hover td { background: var(--surface-2); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; line-height: 1.6;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.badge.success { background: var(--ok-bg); color: var(--ok-fg); }
.badge.warning { background: var(--warn-bg); color: var(--warn-fg); }
.badge.danger  { background: var(--dang-bg); color: var(--dang-fg); }
.badge.secondary { background: var(--sec-bg); color: var(--sec-fg); }

/* ---------- Alerts ---------- */
.alert { padding: 13px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: 14px; border: 1px solid transparent; }
.alert.err { background: var(--dang-bg); color: var(--dang-fg); border-color: #fecaca; }
.alert.ok  { background: var(--ok-bg); color: var(--ok-fg); border-color: #bbf7d0; }
.alert.warn { background: var(--warn-bg); color: var(--warn-fg); border-color: #fde68a; }

/* ---------- Dashboard stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; position: relative; overflow: hidden; box-shadow: var(--shadow-sm);
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--sec-fg); }
.stat.s-vencido::before { background: var(--dang-fg); }
.stat.s-pendente::before { background: var(--sec-fg); }
.stat.s-a_vencer::before { background: var(--warn-fg); }
.stat.s-em_dia::before  { background: var(--ok-fg); }
.stat .stat-num { font-size: 34px; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.stat .stat-label { margin-top: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }

/* ---------- Auth / public "lite" pages ---------- */
.auth-wrap { max-width: 420px; margin: 7vh auto 0; padding: 0 18px; }
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 30px; box-shadow: var(--shadow-lg); }
.auth-logo { display: grid; place-items: center; margin-bottom: 14px; }
.auth-logo img { height: 60px; }

/* ---------- Utilities ---------- */
.muted { color: var(--muted); font-size: 13px; }
.toolbar-actions { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.spacer { flex: 1; }
.text-strong { font-weight: 700; }
.empty {
  text-align: center; color: var(--muted); padding: 34px 16px;
}
.empty .empty-emoji { font-size: 34px; display: block; margin-bottom: 8px; }

/* ---------- Animações gerais ---------- */
@keyframes fadeUp   { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes popIn    { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes slideDown{ from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes float    { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes pulseDanger { 0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,0); } 50% { box-shadow: 0 0 0 4px rgba(220,38,38,.16); } }

/* Cards entram suavemente */
.card { animation: fadeUp .5s cubic-bezier(.4,0,.2,1) both; }

/* Tiles do dashboard entram em cascata com leve "bounce" */
.stat { animation: popIn .5s cubic-bezier(.34,1.56,.64,1) both; }
.stat:nth-child(1) { animation-delay: .05s; }
.stat:nth-child(2) { animation-delay: .12s; }
.stat:nth-child(3) { animation-delay: .19s; }
.stat:nth-child(4) { animation-delay: .26s; }

/* Alertas deslizam ao aparecer */
.alert { animation: slideDown .4s cubic-bezier(.4,0,.2,1) both; }

/* Badge de vencido pulsa discretamente (chama atenção) */
.badge.danger { animation: pulseDanger 2.2s ease-in-out infinite; }

/* Botões com brilho ao passar o mouse */
.btn { position: relative; overflow: hidden; }
.btn::after {
  content: ""; position: absolute; top: 0; left: -130%; width: 55%; height: 100%;
  background: linear-gradient(120deg, transparent, rgba(255,255,255,.35), transparent);
  transform: skewX(-20deg); transition: left .55s ease; pointer-events: none;
}
.btn:hover::after { left: 140%; }

/* Login: cartão entra e logo flutua */
.auth-card { animation: popIn .55s cubic-bezier(.34,1.56,.64,1) both; }
.auth-logo img { animation: float 3.5s ease-in-out infinite; }

/* Estado vazio: emoji flutuando */
.empty .empty-emoji { display: inline-block; animation: float 2.6s ease-in-out infinite; }

/* ---------- Animação de troca de tema (sol ↔ lua) ---------- */
.theme-cosmos { position: fixed; inset: 0; z-index: 9999; display: grid; place-items: center; pointer-events: none; background: none; }
.theme-cosmos .cosmo { grid-area: 1 / 1; width: 120px; height: 120px; will-change: transform, opacity; }
.theme-cosmos .cosmo svg { width: 100%; height: 100%; display: block; }
.theme-cosmos .sun  { filter: drop-shadow(0 0 26px rgba(250,204,21,.95)); }
.theme-cosmos .moon { filter: drop-shadow(0 0 22px rgba(226,232,240,.75)); }

/* ---------- Fundo de partículas (páginas lite) ---------- */
#tsparticles { position: fixed; inset: 0; z-index: 0; }
body.lite .topbar, body.lite .container { position: relative; z-index: 1; }

/* ---------- Toast (feedback de sucesso) ---------- */
.toast {
  position: fixed; top: 18px; left: 50%; transform: translate(-50%, -20px);
  background: #0f172a; color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); z-index: 9999;
  opacity: 0; transition: opacity .35s ease, transform .35s cubic-bezier(.34,1.56,.64,1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Micro-interações extras ---------- */
.brand .brand-logo { transition: transform var(--transition); }
.brand:hover .brand-logo { transform: rotate(-6deg) scale(1.06); }
.user .avatar { transition: transform var(--transition); }
.user:hover .avatar { transform: scale(1.08); }

/* Acessibilidade: desativa animações para quem prefere menos movimento */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---------- Utilitários de toque / mobile ---------- */
.btn-lg { padding: 14px 22px; font-size: 16px; border-radius: 12px; min-height: 48px; }
.tabela-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
input[type="radio"], input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--brand-2); }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .topbar-inner { gap: 10px; padding: 10px 14px; }
  .container { padding: 0 14px; margin: 16px 0; }
  .user .u-name, .user .u-role { display: none; }
  h1 { font-size: 20px; }
  .card { padding: 16px; border-radius: 12px; }
}

/* Celular: alvos de toque grandes, campos empilhados, sem zoom no iOS */
@media (max-width: 640px) {
  input, select, textarea { font-size: 16px; padding: 12px; }   /* 16px evita zoom no iOS */
  .btn { width: 100%; justify-content: center; min-height: 46px; }
  .btn.sm { width: auto; min-height: 0; }
  .row { gap: 12px; }
  .row > div { flex: 1 1 100%; min-width: 0; }
  table { font-size: 13px; }
  thead th, tbody td { padding: 9px 8px; }
  .nav { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .nav a { white-space: nowrap; }
}

/* Formulário de vistoria no celular: componentes com toque confortável */
@media (max-width: 640px) {
  #form-vistoria table th, #form-vistoria table td { padding: 10px 6px; }
  #form-vistoria input[type="radio"] { width: 24px; height: 24px; }
}
