/* ==========================================================================
   WD UI — padrão visual dos sistemas da WD Consultoria
   Versão 1.0 · CSS puro, sem build. Funciona em mobile e desktop.

   Como usar em um sistema novo:
     <link rel="stylesheet" href="/wd-ui/wd-ui.css">
     <script src="/wd-ui/wd-ui.js" defer></script>
     <html data-brand="wd">          → marca WD (vinho/verde) — padrão
     <html data-brand="insights">    → marca WD Insights (turquesa)
   Tema claro/escuro: automático + botão [data-wd-theme-toggle].
   ========================================================================== */

/* ---------- 1. Tokens ---------------------------------------------------- */
:root {
  /* Marca WD (logo: vinho → verde) */
  --wd-brand: #9b1444;          /* vinho — títulos de destaque, ação de destaque */
  --wd-brand-2: #6db33f;        /* verde claro — detalhes */
  --wd-primary: #1e6b31;        /* verde — ação principal (Salvar, Entrar, Filtrar) */
  --wd-primary-hover: #185a29;
  --wd-on-primary: #ffffff;
  --wd-accent-line: linear-gradient(90deg, #9b1444 0%, #6b3a2e 45%, #2e7d32 75%, #6db33f 100%);

  /* Superfícies e texto (tema claro) */
  --wd-bg: #f4f4f2;
  --wd-surface: #ffffff;
  --wd-surface-2: #f8f8f6;
  --wd-surface-hover: #f1f1ee;
  --wd-border: #e2e2dd;
  --wd-border-strong: #c9c9c2;
  --wd-text: #1d1f1c;
  --wd-text-2: #5a5e57;
  --wd-text-3: #868a83;
  --wd-focus: rgba(30, 107, 49, .28);

  /* Estados */
  --wd-ok: #1e7a3c;      --wd-ok-bg: #e8f5ec;     --wd-ok-border: #b9e0c5;
  --wd-warn: #a35f00;    --wd-warn-bg: #fff6e3;   --wd-warn-border: #f2d49b;
  --wd-danger: #b3261e;  --wd-danger-bg: #fdecea; --wd-danger-border: #f3bdb8;
  --wd-info: #1f5fa8;    --wd-info-bg: #eaf2fc;   --wd-info-border: #bcd4f0;

  /* Tipografia */
  --wd-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --wd-mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --wd-fs-xs: .75rem; --wd-fs-sm: .875rem; --wd-fs: .9375rem; --wd-fs-md: 1.0625rem;
  --wd-fs-lg: 1.25rem; --wd-fs-xl: 1.5rem; --wd-fs-2xl: 1.875rem;

  /* Espaçamento, raio, sombra */
  --wd-s1: 4px; --wd-s2: 8px; --wd-s3: 12px; --wd-s4: 16px; --wd-s5: 20px; --wd-s6: 24px; --wd-s8: 32px;
  --wd-r-sm: 6px; --wd-r: 10px; --wd-r-lg: 14px; --wd-r-pill: 999px;
  --wd-shadow-sm: 0 1px 2px rgba(16, 24, 16, .06);
  --wd-shadow: 0 1px 3px rgba(16, 24, 16, .08), 0 4px 14px rgba(16, 24, 16, .05);
  --wd-shadow-lg: 0 10px 40px rgba(16, 24, 16, .18);

  /* Layout */
  --wd-topbar-h: 60px;
  --wd-sidebar-w: 248px;
  --wd-container: 1200px;
  --wd-control-h: 44px;           /* altura de inputs/botões — confortável no toque */

  color-scheme: light;
}

/* Tema escuro */
[data-theme="dark"] {
  --wd-bg: #15161a;
  --wd-surface: #1d1f25;
  --wd-surface-2: #23262d;
  --wd-surface-hover: #292c34;
  --wd-border: #2f323a;
  --wd-border-strong: #41454f;
  --wd-text: #eceef2;
  --wd-text-2: #a9adb7;
  --wd-text-3: #7d828d;
  --wd-brand: #e0507f;
  --wd-primary: #3f9a55;
  --wd-primary-hover: #4aab61;
  --wd-focus: rgba(91, 186, 113, .35);
  --wd-ok: #5cc27a;      --wd-ok-bg: rgba(92,194,122,.12);  --wd-ok-border: rgba(92,194,122,.35);
  --wd-warn: #f0a63a;    --wd-warn-bg: rgba(240,166,58,.12); --wd-warn-border: rgba(240,166,58,.4);
  --wd-danger: #f07167;  --wd-danger-bg: rgba(240,113,103,.12); --wd-danger-border: rgba(240,113,103,.4);
  --wd-info: #6aa8f0;    --wd-info-bg: rgba(106,168,240,.12); --wd-info-border: rgba(106,168,240,.4);
  --wd-shadow-sm: none;
  --wd-shadow: 0 1px 0 rgba(255,255,255,.02);
  --wd-shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  color-scheme: dark;
}

/* Marca WD Insights (turquesa). Mesma base, só muda a cor de ação. */
[data-brand="insights"] {
  --wd-brand: #0e8f9c;
  --wd-primary: #0e8f9c;
  --wd-primary-hover: #0b7a85;
  --wd-on-primary: #ffffff;
  --wd-focus: rgba(14, 143, 156, .3);
  --wd-accent-line: linear-gradient(90deg, #0e8f9c, #33c6d3);
}
[data-brand="insights"][data-theme="dark"] {
  --wd-brand: #33c6d3;
  --wd-primary: #33c6d3;
  --wd-primary-hover: #52d3de;
  --wd-on-primary: #0d2a2e;
  --wd-focus: rgba(51, 198, 211, .35);
}

/* ---------- 2. Base ------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--wd-font);
  font-size: var(--wd-fs);
  line-height: 1.5;
  color: var(--wd-text);
  background: var(--wd-bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: var(--wd-fs-xl); }
h2 { font-size: var(--wd-fs-lg); }
h3 { font-size: var(--wd-fs-md); }
p { margin: 0; }
a { color: var(--wd-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .wd-mono { font-family: var(--wd-mono); font-size: .9em; }
img, svg { max-width: 100%; }
:focus-visible { outline: 3px solid var(--wd-focus); outline-offset: 2px; border-radius: 4px; }
.wd-muted { color: var(--wd-text-2); }
.wd-small { font-size: var(--wd-fs-sm); }
.wd-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wd-icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.wd-stack { display: flex; flex-direction: column; gap: var(--wd-s4); }
.wd-row { display: flex; align-items: center; gap: var(--wd-s3); flex-wrap: wrap; }
.wd-spacer { flex: 1; }

/* ---------- 3. App shell: topbar + sidebar (desktop) / drawer (mobile) --- */
.wd-topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--wd-topbar-h);
  display: flex; align-items: center; gap: var(--wd-s3);
  padding: 0 var(--wd-s4);
  padding-left: max(var(--wd-s4), env(safe-area-inset-left));
  padding-right: max(var(--wd-s4), env(safe-area-inset-right));
  background: var(--wd-surface);
  border-bottom: 1px solid var(--wd-border);
}
.wd-topbar::after {               /* linha da marca */
  content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: var(--wd-accent-line);
}
.wd-brand {
  display: flex; align-items: center; gap: var(--wd-s2); min-width: 0;
  color: var(--wd-text); font-weight: 700; font-size: var(--wd-fs-md); text-decoration: none;
}
.wd-brand:hover { text-decoration: none; }
.wd-brand img, .wd-brand svg { height: 32px; width: auto; flex: none; }
.wd-brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.wd-iconbtn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; flex: none;
  border: 1px solid var(--wd-border); border-radius: var(--wd-r-pill);
  background: var(--wd-surface); color: var(--wd-text-2); cursor: pointer;
}
.wd-iconbtn:hover { background: var(--wd-surface-hover); color: var(--wd-text); }

/* Ícone do botão de tema: mostra lua no claro e sol no escuro */
.wd-theme-ico--dark { display: none; }
[data-theme="dark"] .wd-theme-ico--dark { display: block; }
[data-theme="dark"] .wd-theme-ico--light { display: none; }

/* Menu do usuário (dropdown) */
.wd-usermenu { position: relative; }
.wd-usermenu__btn {
  display: flex; align-items: center; gap: var(--wd-s2);
  height: 40px; padding: 0 var(--wd-s3) 0 4px;
  border: 1px solid var(--wd-border); border-radius: var(--wd-r-pill);
  background: var(--wd-surface); color: var(--wd-text); cursor: pointer; font: inherit; font-size: var(--wd-fs-sm);
}
.wd-usermenu__btn:hover { background: var(--wd-surface-hover); }
.wd-avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--wd-primary); color: var(--wd-on-primary); font-weight: 700; font-size: var(--wd-fs-sm);
}
.wd-usermenu__panel {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 60;
  background: var(--wd-surface); border: 1px solid var(--wd-border); border-radius: var(--wd-r);
  box-shadow: var(--wd-shadow-lg); padding: var(--wd-s2); display: none;
}
.wd-usermenu.is-open .wd-usermenu__panel { display: block; }
.wd-usermenu__panel a, .wd-usermenu__panel button {
  display: flex; align-items: center; gap: var(--wd-s2); width: 100%;
  padding: 10px var(--wd-s3); border: 0; background: none; border-radius: var(--wd-r-sm);
  color: var(--wd-text); font: inherit; text-align: left; cursor: pointer; text-decoration: none;
}
.wd-usermenu__panel a:hover, .wd-usermenu__panel button:hover { background: var(--wd-surface-hover); }
.wd-usermenu__head { padding: var(--wd-s2) var(--wd-s3) var(--wd-s3); border-bottom: 1px solid var(--wd-border); margin-bottom: var(--wd-s2); }

/* Layout */
.wd-layout { display: flex; min-height: calc(100vh - var(--wd-topbar-h)); }
.wd-sidebar {
  width: var(--wd-sidebar-w); flex: none;
  background: var(--wd-surface); border-right: 1px solid var(--wd-border);
  display: flex; flex-direction: column;
  position: sticky; top: var(--wd-topbar-h); height: calc(100vh - var(--wd-topbar-h)); overflow-y: auto;
}
.wd-nav { padding: var(--wd-s3); display: flex; flex-direction: column; gap: 2px; }
.wd-nav__group { margin: var(--wd-s4) var(--wd-s3) var(--wd-s1); font-size: var(--wd-fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--wd-text-3); }
.wd-nav__group:first-child { margin-top: var(--wd-s1); }
.wd-nav a {
  display: flex; align-items: center; gap: var(--wd-s3);
  min-height: 42px; padding: 0 var(--wd-s3); border-radius: var(--wd-r-sm);
  color: var(--wd-text-2); font-weight: 500; text-decoration: none;
}
.wd-nav a:hover { background: var(--wd-surface-hover); color: var(--wd-text); }
.wd-nav a.is-active, .wd-nav a[aria-current="page"] {
  background: color-mix(in srgb, var(--wd-brand) 10%, transparent);
  color: var(--wd-brand); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--wd-brand);
}
.wd-nav__count { margin-left: auto; font-size: var(--wd-fs-xs); background: var(--wd-surface-2); border: 1px solid var(--wd-border); padding: 1px 8px; border-radius: var(--wd-r-pill); color: var(--wd-text-2); }
.wd-sidebar__foot { margin-top: auto; padding: var(--wd-s3); border-top: 1px solid var(--wd-border); }

.wd-main { flex: 1; min-width: 0; }
.wd-container {
  max-width: var(--wd-container); margin: 0 auto;
  padding: var(--wd-s6) var(--wd-s6) var(--wd-s8);
}
.wd-container--narrow { max-width: 860px; }
.wd-backdrop { display: none; }
@media (min-width: 1024px) {   /* faixa da barra lateral continua até o fim da página */
  .wd-layout { background: linear-gradient(to right, var(--wd-surface) calc(var(--wd-sidebar-w) - 1px), var(--wd-border) calc(var(--wd-sidebar-w) - 1px), var(--wd-border) var(--wd-sidebar-w), transparent var(--wd-sidebar-w)); }
}
.wd-only-mobile { display: none !important; }

/* Mobile/tablet: sidebar vira gaveta (drawer) */
@media (max-width: 1023.98px) {
  .wd-only-mobile { display: inline-grid !important; }
  .wd-hide-mobile { display: none !important; }
  .wd-sidebar {
    position: fixed; z-index: 50; top: 0; left: 0; bottom: 0; height: 100%;
    width: min(86vw, 300px);
    transform: translateX(-100%); transition: transform .22s ease;
    box-shadow: var(--wd-shadow-lg); border-right: 0;
    padding-top: env(safe-area-inset-top);
  }
  .wd-nav-open .wd-sidebar { transform: none; }
  .wd-backdrop {
    display: block; position: fixed; inset: 0; z-index: 45;
    background: rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .wd-nav-open .wd-backdrop { opacity: 1; pointer-events: auto; }
  .wd-nav-open { overflow: hidden; }
  .wd-sidebar__head { display: flex !important; }
}
.wd-sidebar__head { display: none; align-items: center; justify-content: space-between; gap: var(--wd-s2); padding: var(--wd-s3) var(--wd-s3) var(--wd-s3) var(--wd-s4); border-bottom: 1px solid var(--wd-border); }

@media (max-width: 640px) {
  .wd-container { padding: var(--wd-s4) var(--wd-s4) calc(var(--wd-s8) + 72px); }
  .wd-brand span { font-size: var(--wd-fs); }
  .wd-usermenu__name { display: none; }
  .wd-usermenu__btn { padding-right: 4px; }
}

/* ---------- 4. Cabeçalho de página -------------------------------------- */
.wd-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--wd-s4); flex-wrap: wrap; margin-bottom: var(--wd-s5); }
.wd-page-head p { color: var(--wd-text-2); margin-top: 4px; }
.wd-page-head__actions { display: flex; gap: var(--wd-s2); flex-wrap: wrap; }
@media (max-width: 640px) {
  .wd-page-head { align-items: stretch; }
  .wd-page-head__actions { width: 100%; }
  .wd-page-head__actions .wd-btn { flex: 1; }
}

/* ---------- 5. Botões ---------------------------------------------------- */
.wd-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--wd-s2);
  min-height: var(--wd-control-h); padding: 0 var(--wd-s5);
  border: 1px solid transparent; border-radius: var(--wd-r);
  font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none; white-space: nowrap;
  cursor: pointer; transition: background .15s, border-color .15s, color .15s;
  background: var(--wd-surface); color: var(--wd-text); border-color: var(--wd-border-strong);
}
.wd-btn:hover { background: var(--wd-surface-hover); text-decoration: none; }
.wd-btn:disabled, .wd-btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.wd-btn--primary { background: var(--wd-primary); color: var(--wd-on-primary); border-color: var(--wd-primary); }
.wd-btn--primary:hover { background: var(--wd-primary-hover); border-color: var(--wd-primary-hover); }
.wd-btn--brand { background: var(--wd-brand); color: #fff; border-color: var(--wd-brand); }
.wd-btn--brand:hover { filter: brightness(.92); background: var(--wd-brand); }
.wd-btn--ghost { background: transparent; border-color: transparent; color: var(--wd-primary); }
.wd-btn--ghost:hover { background: var(--wd-surface-hover); }
.wd-btn--danger { background: var(--wd-danger); color: #fff; border-color: var(--wd-danger); }
.wd-btn--sm { min-height: 34px; padding: 0 var(--wd-s3); font-size: var(--wd-fs-sm); border-radius: var(--wd-r-sm); }
.wd-btn--block { width: 100%; }
.wd-linkbtn { border: 0; background: none; padding: 4px 2px; font: inherit; font-size: var(--wd-fs-sm); color: var(--wd-primary); cursor: pointer; }
.wd-linkbtn:hover { text-decoration: underline; }

/* ---------- 6. Cards e KPIs --------------------------------------------- */
.wd-card { background: var(--wd-surface); border: 1px solid var(--wd-border); border-radius: var(--wd-r-lg); box-shadow: var(--wd-shadow-sm); padding: var(--wd-s5); }
.wd-card--flush { padding: 0; overflow: hidden; }
.wd-card__title { font-size: var(--wd-fs-md); font-weight: 700; margin-bottom: var(--wd-s3); }

.wd-kpis { display: grid; gap: var(--wd-s3); grid-template-columns: repeat(6, 1fr); margin-bottom: var(--wd-s5); }
@media (max-width: 1199.98px) { .wd-kpis { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 640px)     { .wd-kpis { grid-template-columns: repeat(2, 1fr); gap: var(--wd-s2); } }
.wd-kpi {
  position: relative; display: block; text-decoration: none; color: inherit;
  background: var(--wd-surface); border: 1px solid var(--wd-border); border-radius: var(--wd-r);
  padding: var(--wd-s3) var(--wd-s4); box-shadow: var(--wd-shadow-sm);
}
a.wd-kpi:hover { border-color: var(--wd-border-strong); text-decoration: none; }
.wd-kpi__label { font-size: var(--wd-fs-sm); color: var(--wd-text-2); }
.wd-kpi__value { font-size: 1.75rem; font-weight: 700; line-height: 1.15; margin-top: 2px; font-variant-numeric: tabular-nums; }
/* Cor só quando pede atenção */
.wd-kpi--warn, .wd-kpi--danger { box-shadow: inset 4px 0 0 var(--wd-kpi-c); }
.wd-kpi--warn   { --wd-kpi-c: var(--wd-warn); }
.wd-kpi--danger { --wd-kpi-c: var(--wd-danger); }
.wd-kpi--warn .wd-kpi__value   { color: var(--wd-warn); }
.wd-kpi--danger .wd-kpi__value { color: var(--wd-danger); }
.wd-kpi.is-zero { box-shadow: var(--wd-shadow-sm); }
.wd-kpi.is-zero .wd-kpi__value { color: var(--wd-text-3); }

/* ---------- 7. Alertas, badges ------------------------------------------ */
.wd-alert {
  display: flex; gap: var(--wd-s3); align-items: flex-start;
  padding: var(--wd-s3) var(--wd-s4); border-radius: var(--wd-r);
  border: 1px solid var(--wd-info-border); background: var(--wd-info-bg); color: var(--wd-text);
  margin-bottom: var(--wd-s4); font-size: var(--wd-fs-sm);
}
.wd-alert .wd-icon { color: var(--wd-info); margin-top: 1px; }
.wd-alert strong { color: var(--wd-info); }
.wd-alert--warn   { border-color: var(--wd-warn-border); background: var(--wd-warn-bg); }
.wd-alert--warn .wd-icon, .wd-alert--warn strong { color: var(--wd-warn); }
.wd-alert--danger { border-color: var(--wd-danger-border); background: var(--wd-danger-bg); }
.wd-alert--danger .wd-icon, .wd-alert--danger strong { color: var(--wd-danger); }
.wd-alert--ok     { border-color: var(--wd-ok-border); background: var(--wd-ok-bg); }
.wd-alert--ok .wd-icon, .wd-alert--ok strong { color: var(--wd-ok); }

.wd-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 10px; border-radius: var(--wd-r-pill);
  font-size: var(--wd-fs-xs); font-weight: 600; white-space: nowrap;
  background: var(--wd-surface-2); color: var(--wd-text-2); border: 1px solid var(--wd-border);
}
.wd-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.wd-badge--plain::before { display: none; }
.wd-badge--ok     { color: var(--wd-ok);     background: var(--wd-ok-bg);     border-color: var(--wd-ok-border); }
.wd-badge--warn   { color: var(--wd-warn);   background: var(--wd-warn-bg);   border-color: var(--wd-warn-border); }
.wd-badge--danger { color: var(--wd-danger); background: var(--wd-danger-bg); border-color: var(--wd-danger-border); }
.wd-badge--info   { color: var(--wd-info);   background: var(--wd-info-bg);   border-color: var(--wd-info-border); }

/* ---------- 8. Formulários ---------------------------------------------- */
.wd-form { display: grid; gap: var(--wd-s4); }
.wd-form-grid { display: grid; gap: var(--wd-s4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.wd-form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.wd-form-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.wd-col-full { grid-column: 1 / -1; }
@media (max-width: 900px) { .wd-form-grid--3, .wd-form-grid--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .wd-form-grid, .wd-form-grid--3, .wd-form-grid--4 { grid-template-columns: 1fr; } }

.wd-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.wd-label { font-size: var(--wd-fs-sm); font-weight: 600; color: var(--wd-text); }
.wd-label small { font-weight: 400; color: var(--wd-text-3); margin-left: 4px; }
.wd-hint { font-size: var(--wd-fs-xs); color: var(--wd-text-3); }
.wd-hint code { font-size: .95em; }
.wd-field--error .wd-input, .wd-field--error .wd-select, .wd-field--error .wd-textarea { border-color: var(--wd-danger); }
.wd-field--error .wd-hint { color: var(--wd-danger); }

.wd-input, .wd-select, .wd-textarea {
  width: 100%; min-height: var(--wd-control-h);
  padding: 10px var(--wd-s3);
  border: 1px solid var(--wd-border-strong); border-radius: var(--wd-r);
  background: var(--wd-surface); color: var(--wd-text);
  font: inherit; font-size: 16px;   /* 16px evita zoom automático no iPhone */
  transition: border-color .15s, box-shadow .15s;
}
.wd-input::placeholder, .wd-textarea::placeholder { color: var(--wd-text-3); }
.wd-input:focus, .wd-select:focus, .wd-textarea:focus { outline: none; border-color: var(--wd-primary); box-shadow: 0 0 0 3px var(--wd-focus); }
.wd-textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.wd-select {
  appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23868a83' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.wd-input-group { position: relative; }
.wd-input-group .wd-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--wd-text-3); width: 18px; height: 18px; }
.wd-input-group .wd-input { padding-left: 38px; }
@media (min-width: 641px) { .wd-input, .wd-select, .wd-textarea { font-size: var(--wd-fs); } }

/* Chips de seleção (ex.: dias da semana) */
.wd-chips { display: flex; flex-wrap: wrap; gap: var(--wd-s2); }
.wd-chip { position: relative; }
.wd-chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.wd-chip span {
  display: inline-flex; align-items: center; justify-content: center; min-width: 52px; height: 38px; padding: 0 var(--wd-s3);
  border: 1px solid var(--wd-border-strong); border-radius: var(--wd-r-pill);
  font-size: var(--wd-fs-sm); font-weight: 600; color: var(--wd-text-2); background: var(--wd-surface);
  user-select: none; transition: all .15s;
}
.wd-chip input:checked + span { background: var(--wd-primary); border-color: var(--wd-primary); color: var(--wd-on-primary); }
.wd-chip input:focus-visible + span { box-shadow: 0 0 0 3px var(--wd-focus); }

/* Interruptor (liga/desliga) */
.wd-switch { display: inline-flex; align-items: center; gap: var(--wd-s3); cursor: pointer; }
.wd-switch input { appearance: none; -webkit-appearance: none; width: 42px; height: 24px; border-radius: 12px; background: var(--wd-border-strong); position: relative; cursor: pointer; transition: background .15s; margin: 0; flex: none; }
.wd-switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.wd-switch input:checked { background: var(--wd-primary); }
.wd-switch input:checked::after { transform: translateX(18px); }

/* Upload de arquivos */
.wd-upload {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: var(--wd-s5); text-align: center;
  border: 2px dashed var(--wd-border-strong); border-radius: var(--wd-r);
  background: var(--wd-surface-2); color: var(--wd-text-2); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.wd-upload:hover, .wd-upload.is-drag { border-color: var(--wd-primary); background: color-mix(in srgb, var(--wd-primary) 6%, var(--wd-surface)); }
.wd-upload input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.wd-upload .wd-icon { width: 28px; height: 28px; color: var(--wd-primary); }
.wd-upload strong { color: var(--wd-text); }
.wd-upload__files { list-style: none; margin: var(--wd-s2) 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.wd-upload__files li { display: flex; align-items: center; gap: var(--wd-s2); padding: 8px var(--wd-s3); background: var(--wd-surface); border: 1px solid var(--wd-border); border-radius: var(--wd-r-sm); font-size: var(--wd-fs-sm); }
.wd-upload__files li span:last-child { margin-left: auto; color: var(--wd-text-3); }

/* ---------- 9. Seções recolhíveis (padrão das telas de cadastro) -------- */
.wd-sections-toolbar { display: flex; justify-content: flex-end; gap: var(--wd-s3); margin-bottom: var(--wd-s2); }
.wd-section {
  background: var(--wd-surface); border: 1px solid var(--wd-border); border-radius: var(--wd-r-lg);
  box-shadow: var(--wd-shadow-sm); margin-bottom: var(--wd-s3); overflow: hidden;
}
.wd-section > summary {
  list-style: none; cursor: pointer; user-select: none;
  display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: var(--wd-s3);
  padding: var(--wd-s4) var(--wd-s5);
}
.wd-section > summary::-webkit-details-marker { display: none; }
.wd-section > summary:hover { background: var(--wd-surface-2); }
.wd-section > summary::before {
  content: ""; width: 10px; height: 10px; justify-self: center;
  border-right: 2px solid var(--wd-text-2); border-bottom: 2px solid var(--wd-text-2);
  transform: rotate(-45deg); transition: transform .15s;
}
.wd-section[open] > summary::before { transform: rotate(45deg) translate(-2px, -2px); }
.wd-section__title { font-weight: 700; font-size: var(--wd-fs-md); color: var(--wd-text); }
.wd-section__meta { font-size: var(--wd-fs-sm); color: var(--wd-text-2); text-align: right; }
.wd-section__body { padding: var(--wd-s5); border-top: 1px solid var(--wd-border); }
.wd-section__desc { color: var(--wd-text-2); font-size: var(--wd-fs-sm); margin-bottom: var(--wd-s4); }
@media (max-width: 640px) {
  .wd-section > summary { grid-template-columns: 20px 1fr; padding: var(--wd-s4); row-gap: 2px; }
  .wd-section__meta { grid-column: 2; text-align: left; }
  .wd-section__body { padding: var(--wd-s4); }
}

/* ---------- 10. Painel de filtros --------------------------------------- */
.wd-filters { background: var(--wd-surface); border: 1px solid var(--wd-border); border-radius: var(--wd-r-lg); margin-bottom: var(--wd-s4); box-shadow: var(--wd-shadow-sm); }
.wd-filters > summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: var(--wd-s2);
  padding: var(--wd-s3) var(--wd-s4); font-weight: 600; user-select: none;
}
.wd-filters > summary::-webkit-details-marker { display: none; }
.wd-filters > summary .wd-icon { color: var(--wd-text-2); }
.wd-filters__count { display: none; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--wd-primary); color: var(--wd-on-primary); font-size: var(--wd-fs-xs); align-items: center; justify-content: center; }
.wd-filters__count.is-on { display: inline-flex; }
.wd-filters__chev { margin-left: auto; transition: transform .15s; }
.wd-filters[open] .wd-filters__chev { transform: rotate(180deg); }
.wd-filters__body { padding: 0 var(--wd-s4) var(--wd-s4); }
.wd-filters__grid { display: grid; gap: var(--wd-s3); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.wd-filters__grid .wd-field--wide { grid-column: span 2; }
.wd-filters__actions { display: flex; justify-content: flex-end; gap: var(--wd-s2); margin-top: var(--wd-s3); }
@media (max-width: 1023.98px) { .wd-filters__grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) {
  .wd-filters__grid { grid-template-columns: 1fr; }
  .wd-filters__grid .wd-field--wide { grid-column: auto; }
  .wd-filters__actions .wd-btn { flex: 1; }
}

/* ---------- 11. Tabelas (viram cartões no celular) ---------------------- */
.wd-table-wrap { background: var(--wd-surface); border: 1px solid var(--wd-border); border-radius: var(--wd-r-lg); overflow: hidden; box-shadow: var(--wd-shadow-sm); }
.wd-table { width: 100%; border-collapse: collapse; font-size: var(--wd-fs-sm); }
.wd-table th { text-align: left; font-weight: 600; color: var(--wd-text-2); background: var(--wd-surface-2); padding: 10px var(--wd-s4); border-bottom: 1px solid var(--wd-border); white-space: nowrap; font-size: var(--wd-fs-xs); text-transform: uppercase; letter-spacing: .04em; }
.wd-table td { padding: 12px var(--wd-s4); border-bottom: 1px solid var(--wd-border); vertical-align: middle; }
.wd-table tbody tr:last-child td { border-bottom: 0; }
.wd-table tbody tr:hover td { background: var(--wd-surface-2); }
.wd-table tr[data-href] { cursor: pointer; }
.wd-table .wd-cell-title { font-weight: 600; color: var(--wd-text); }
.wd-table .wd-cell-sub { color: var(--wd-text-3); font-size: var(--wd-fs-xs); }
@media (max-width: 760px) {
  .wd-table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .wd-table thead { display: none; }
  .wd-table, .wd-table tbody, .wd-table tr, .wd-table td { display: block; width: 100%; }
  .wd-table tr { background: var(--wd-surface); border: 1px solid var(--wd-border); border-radius: var(--wd-r); margin-bottom: var(--wd-s2); padding: var(--wd-s2) 0; }
  .wd-table td { display: flex; justify-content: space-between; gap: var(--wd-s3); border: 0; padding: 6px var(--wd-s4); text-align: right; }
  .wd-table td::before { content: attr(data-label); color: var(--wd-text-3); font-size: var(--wd-fs-xs); text-align: left; flex: none; padding-top: 2px; }
  .wd-table td[data-primary] { display: block; text-align: left; padding-bottom: var(--wd-s2); }
  .wd-table td[data-primary]::before { display: none; }
  .wd-table tbody tr:hover td { background: none; }
}

/* ---------- 12. Barra de ações fixa (salvar) ---------------------------- */
.wd-actionbar {
  position: sticky; bottom: 0; z-index: 30;
  display: flex; align-items: center; gap: var(--wd-s3); flex-wrap: wrap;
  margin-top: var(--wd-s4); padding: var(--wd-s3) var(--wd-s4);
  padding-bottom: max(var(--wd-s3), env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--wd-surface) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--wd-border); border-radius: var(--wd-r-lg); box-shadow: var(--wd-shadow-lg);
}
.wd-actionbar__text { flex: 1; min-width: 180px; font-size: var(--wd-fs-sm); color: var(--wd-text-2); }
@media (max-width: 640px) {
  .wd-actionbar { margin-left: calc(-1 * var(--wd-s4)); margin-right: calc(-1 * var(--wd-s4)); border-radius: 0; border-left: 0; border-right: 0; }
  .wd-actionbar__text { display: none; }
  .wd-actionbar .wd-btn { flex: 1; }
}

/* ---------- 13. Login / telas de acesso --------------------------------- */
.wd-auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: var(--wd-s6) var(--wd-s4); position: relative; }
.wd-auth__card { width: 100%; max-width: 420px; background: var(--wd-surface); border: 1px solid var(--wd-border); border-radius: var(--wd-r-lg); box-shadow: var(--wd-shadow-lg); padding: var(--wd-s8) var(--wd-s6); position: relative; overflow: hidden; }
.wd-auth__card::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 4px; background: var(--wd-accent-line); }
.wd-auth__logo { display: block; margin: 0 auto var(--wd-s4); max-height: 96px; }
.wd-auth__title { text-align: center; font-size: var(--wd-fs-xl); }
.wd-auth__sub { text-align: center; color: var(--wd-text-2); margin: 4px 0 var(--wd-s6); }
.wd-auth__foot { text-align: center; color: var(--wd-text-3); font-size: var(--wd-fs-xs); margin-top: var(--wd-s4); }
.wd-auth__theme { position: absolute; top: var(--wd-s4); right: var(--wd-s4); }
@media (max-width: 480px) { .wd-auth__card { padding: var(--wd-s6) var(--wd-s5); box-shadow: var(--wd-shadow); } }

/* ---------- 14. Estado vazio, toast ------------------------------------- */
.wd-empty { text-align: center; padding: var(--wd-s8) var(--wd-s4); color: var(--wd-text-2); }
.wd-empty .wd-icon { width: 40px; height: 40px; color: var(--wd-text-3); margin-bottom: var(--wd-s2); }
.wd-empty h3 { color: var(--wd-text); margin-bottom: 4px; }

.wd-toasts { position: fixed; z-index: 100; bottom: max(16px, env(safe-area-inset-bottom)); right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; }
.wd-toast { pointer-events: auto; max-width: 420px; padding: 12px 16px; border-radius: var(--wd-r); background: #1d1f1c; color: #fff; box-shadow: var(--wd-shadow-lg); font-size: var(--wd-fs-sm); animation: wd-in .2s ease; border-left: 4px solid var(--wd-primary); }
.wd-toast--danger { border-left-color: var(--wd-danger); }
.wd-toast--warn { border-left-color: var(--wd-warn); }
@media (max-width: 640px) { .wd-toasts { align-items: stretch; } }
@keyframes wd-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- 15. Grade de módulos (tela inicial) ------------------------- */
.wd-modules { display: grid; gap: var(--wd-s3); grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.wd-module { display: flex; gap: var(--wd-s4); align-items: flex-start; padding: var(--wd-s5); background: var(--wd-surface); border: 1px solid var(--wd-border); border-radius: var(--wd-r-lg); color: inherit; text-decoration: none; transition: border-color .15s, transform .15s; }
.wd-module:hover { border-color: var(--wd-primary); text-decoration: none; transform: translateY(-1px); }
.wd-module__icon { display: grid; place-items: center; width: 48px; height: 48px; flex: none; border-radius: var(--wd-r); background: color-mix(in srgb, var(--wd-primary) 14%, transparent); color: var(--wd-primary); }
.wd-module h3 { margin-bottom: 4px; }
.wd-module p { color: var(--wd-text-2); font-size: var(--wd-fs-sm); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
