/* layout-fluido — componentes. Depende de tokens.css. Sem framework: classes curtas, estado em .is-* / [aria-*]. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 400 var(--fs-base)/1.45 var(--font);
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 12% -8%, var(--glow-a), transparent 70%),
    radial-gradient(900px 480px at 100% 0%, var(--glow-b), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; } /* .drawer/.palette têm display próprio */
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }

/* ---------- Casca: barra de ícones flutuante + topo + conteúdo ---------- */
.app { min-height: 100%; padding-left: calc(var(--rail-w) + var(--gutter) * 2); }

.rail {
  position: fixed; z-index: 40;
  left: var(--gutter); top: 50%; transform: translateY(-50%);
  width: var(--rail-w); max-height: calc(100% - var(--gutter) * 2);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 0;
  background: color-mix(in srgb, var(--raised) 78%, transparent);
  backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--line);
  border-radius: calc(var(--rail-w) / 2);
  box-shadow: var(--shadow-pop);
  /* Sem overflow: as dicas (data-tip) saem para fora da barra. Muitos itens? agrupe, não role. */
}
.rail hr { width: 24px; border: 0; border-top: 1px solid var(--line-2); margin: 6px 0; }
.rail__ind { /* pílula de seleção que desliza (motion.indicator) */
  position: absolute; left: 8px; right: 8px; top: 0; height: 44px;
  border-radius: var(--r-tile); background: var(--primary);
  box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--primary) 70%, transparent);
  transition: transform var(--t-3) var(--ease), opacity var(--t-2);
  pointer-events: none;
}
.rail__btn {
  position: relative; z-index: 1;
  width: 44px; height: 44px; flex-shrink: 0;
  display: grid; place-items: center;
  border: 0; border-radius: var(--r-tile); background: none; color: var(--muted);
  transition: color var(--t-2) var(--ease), background var(--t-2), transform var(--t-1) var(--ease);
}
.rail__btn:hover { color: var(--text); background: var(--well); }
.rail__btn.is-active { color: var(--on-primary); background: none; }
.rail__btn svg { width: 20px; height: 20px; }

.badge {
  position: absolute; top: 4px; right: 4px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--r-pill); background: var(--bad); color: #fff;
  font: 600 10px/16px var(--font); text-align: center;
  box-shadow: 0 0 0 2px var(--raised);
}

/* Dica escura ao lado (rail) ou abaixo; texto em data-tip. Sem JS. */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; left: calc(100% + 10px); top: 50%;
  translate: -4px -50%; opacity: 0; pointer-events: none;
  padding: 5px 10px; border-radius: 8px; white-space: nowrap;
  background: #0f141c; color: #f2f5fa; font: 500 var(--fs-xs)/1.2 var(--font);
  box-shadow: var(--shadow-pop);
  transition: opacity var(--t-1), translate var(--t-2) var(--ease);
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; translate: 0 -50%; transition-delay: .25s; }

.top {
  position: sticky; top: 0; z-index: 30;
  height: var(--top-h);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: var(--gap);
  padding: 0 var(--gutter);
  transition: background var(--t-2), box-shadow var(--t-2);
}
.top.is-stuck { background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(14px); box-shadow: 0 1px 0 var(--line); }
.top__end { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: var(--fs-lg); }
.brand small { display: block; font-weight: 500; font-size: var(--fs-2xs); color: var(--muted); }
.brand img, .brand .logo { width: 34px; height: 34px; border-radius: 11px; }

.main { padding: 4px var(--gutter) 96px; max-width: 1480px; }

/* ---------- Abas em pílula com indicador deslizante ---------- */
.tabs {
  position: relative; display: inline-flex; gap: 2px; padding: 4px;
  background: var(--raised); border-radius: var(--r-pill);
  box-shadow: inset 0 0 0 1px var(--line-2), var(--shadow);
}
.tabs__ind {
  position: absolute; top: 4px; bottom: 4px; left: 0; width: 0;
  border-radius: var(--r-pill); background: var(--text);
  box-shadow: 0 6px 14px -6px #0006;
  transition: transform var(--t-3) var(--ease), width var(--t-3) var(--ease);
}
.tabs button {
  position: relative; z-index: 1; border: 0; background: none;
  padding: 7px 16px; border-radius: var(--r-pill);
  font-weight: 600; font-size: var(--fs-sm); color: var(--muted);
  transition: color var(--t-2), transform var(--t-1) var(--ease);
}
.tabs button:hover { color: var(--text); }
.tabs button.is-active { color: var(--bg); }
html[data-theme='dark'] .tabs button.is-active { color: #0e1118; }

/* Segmentado pequeno (filtros) — mesmo indicador, em well */
.seg { position: relative; display: inline-flex; padding: 3px; gap: 2px; background: var(--well); border-radius: var(--r-pill); }
.seg .tabs__ind { top: 3px; bottom: 3px; background: var(--raised); box-shadow: var(--shadow); }
.seg button { position: relative; z-index: 1; border: 0; background: none; padding: 4px 12px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; color: var(--muted); }
.seg button.is-active { color: var(--text); }

/* ---------- Cabeçalho de tela ---------- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--gap); margin: 6px 0 18px; flex-wrap: wrap; }
.eyebrow { font-size: var(--fs-xs); color: var(--muted); margin-bottom: 2px; }
.title { margin: 0; font: 600 var(--fs-display)/1.1 var(--font); letter-spacing: -.02em; }
.head__acoes { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cartões ---------- */
.card {
  background: var(--raised); border-radius: var(--r-card);
  box-shadow: var(--shadow); border: 1px solid var(--line);
  padding: 18px 20px;
}
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card__title { margin: 0; font-size: var(--fs-lg); font-weight: 600; }
.grid { display: grid; gap: var(--gap); }
.stats { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: var(--gap); }
.stat { padding: 14px 16px; border-radius: var(--r-tile); background: var(--raised); border: 1px solid var(--line); box-shadow: var(--shadow); }
.stat__label { display: flex; align-items: center; gap: 8px; font-size: var(--fs-xs); color: var(--muted); }
.stat__label .ic { width: 26px; height: 26px; border-radius: 9px; display: grid; place-items: center; background: color-mix(in srgb, var(--c, var(--primary)) var(--soft), transparent); color: var(--c, var(--primary)); }
.stat__val { font: 600 var(--fs-3xl)/1.1 var(--font); margin-top: 8px; font-variant-numeric: tabular-nums; }
.stat__sub { font-size: var(--fs-xs); color: var(--muted); margin-left: 6px; font-weight: 500; }

/* ---------- Botões, chips, campos ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 16px; border-radius: var(--r-pill);
  border: 1px solid var(--line-2); background: var(--raised);
  font-weight: 600; font-size: var(--fs-sm);
  box-shadow: var(--shadow);
  transition: transform var(--t-1) var(--ease), background var(--t-2), box-shadow var(--t-2), opacity var(--t-2);
}
.btn:hover { background: var(--surface-2); }
.kcard, .check, .menu button, .seg button { transition: transform var(--t-1) var(--ease), background-color var(--t-2), border-color var(--t-2); }
.btn--primary { background: var(--primary); color: var(--on-primary); border-color: transparent; box-shadow: 0 8px 18px -10px color-mix(in srgb, var(--primary) 80%, transparent); }
.btn--primary:hover { background: color-mix(in srgb, var(--primary) 88%, #000); }
.btn--ghost { background: none; box-shadow: none; border-color: transparent; }
.btn--ghost:hover { background: var(--well); }
.btn--icon { width: 36px; padding: 0; justify-content: center; }
.btn--sm { height: 28px; padding: 0 12px; font-size: var(--fs-xs); }
.btn:disabled { opacity: .45; pointer-events: none; }

.chip {
  --c: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
  height: 22px; padding: 0 9px; border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--c) var(--soft), transparent); color: var(--c);
  font-size: var(--fs-2xs); font-weight: 600; white-space: nowrap;
}
.chip::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.chip--plain::before { display: none; }
.chip--good { --c: var(--good); } .chip--warn { --c: var(--warn); } .chip--bad { --c: var(--bad); } .chip--info { --c: var(--info); }

.field {
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px;
  border-radius: var(--r-pill); background: var(--well); border: 1px solid transparent;
  transition: border-color var(--t-2), background var(--t-2);
}
.field:focus-within { border-color: var(--primary); background: var(--raised); }
.field input { border: 0; outline: 0; background: none; flex: 1; min-width: 0; }
kbd { font: 600 10px/1 var(--font); padding: 3px 6px; border-radius: 6px; background: var(--raised); border: 1px solid var(--line-2); color: var(--muted); }

.avatar {
  --c: var(--primary);
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; font: 700 var(--fs-2xs)/1 var(--font);
  background: color-mix(in srgb, var(--c) 20%, var(--raised)); color: var(--c);
}

/* Barra de progresso (checklist, uso, estoque) */
.bar { height: 6px; border-radius: var(--r-pill); background: var(--well); overflow: hidden; }
.bar > i { display: block; height: 100%; width: var(--v, 0%); border-radius: inherit; background: var(--c, var(--primary)); transition: width var(--t-4) var(--ease); }

/* ---------- Tabela ---------- */
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th { text-align: left; font-size: var(--fs-2xs); font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; padding: 8px 12px; }
.table td { padding: 11px 12px; border-top: 1px solid var(--line); }
.table tbody tr { transition: background var(--t-1); }
.table tbody tr:hover { background: var(--well); }
.table tbody tr.is-pick { cursor: pointer; }

/* ---------- Quadro (kanban) ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.col { background: color-mix(in srgb, var(--surface-2) 70%, transparent); border: 1px solid var(--line); border-radius: var(--r-card); padding: 10px; min-height: 240px; transition: background var(--t-2), border-color var(--t-2), box-shadow var(--t-2); }
.col.is-over { background: color-mix(in srgb, var(--primary) 8%, var(--surface)); border-color: color-mix(in srgb, var(--primary) 45%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 30%, transparent); }
.col__head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 10px; font-weight: 600; font-size: var(--fs-sm); }
.col__head small { font-weight: 500; color: var(--muted); display: block; font-size: var(--fs-2xs); }
.col__list { display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.kcard { background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-tile); padding: 10px 12px; box-shadow: var(--shadow); cursor: grab; touch-action: none; user-select: none; }
.kcard.is-ghost { opacity: .35; }
.kcard.is-lifted { position: fixed; z-index: 90; pointer-events: none; cursor: grabbing; rotate: 3deg; scale: 1.03; box-shadow: var(--shadow-pop); transition: rotate var(--t-2) var(--ease), scale var(--t-2) var(--ease); }

/* ---------- Gaveta, véu, menu, paleta, aviso ---------- */
.scrim { position: fixed; inset: 0; z-index: 70; background: #0b0f1866; backdrop-filter: blur(2px); }
.drawer {
  position: fixed; z-index: 80; top: var(--gutter); right: var(--gutter); bottom: var(--gutter);
  width: min(460px, calc(100% - var(--gutter) * 2));
  display: flex; flex-direction: column;
  background: var(--raised); border-radius: var(--r-card); box-shadow: var(--shadow-pop);
  overflow: hidden;
}
.drawer__head { display: flex; gap: 12px; align-items: flex-start; padding: 18px 20px 12px; }
.drawer__body { flex: 1; overflow-y: auto; padding: 0 20px 16px; }
.drawer__foot { display: flex; gap: 8px; align-items: center; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--surface); }

.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-tile); border: 1px solid var(--line); background: var(--surface); cursor: pointer; }
.check + .check { margin-top: 8px; }
.check input { appearance: none; width: 18px; height: 18px; margin: 1px 0 0; border-radius: 6px; border: 1.5px solid var(--hair); display: grid; place-items: center; transition: background var(--t-2), border-color var(--t-2); }
.check input::after { content: ''; width: 9px; height: 5px; border: 2px solid var(--on-primary); border-top: 0; border-right: 0; rotate: -45deg; translate: 0 -1px; scale: 0; transition: scale var(--t-2) var(--ease-pop); }
.check input:checked { background: var(--primary); border-color: var(--primary); }
.check input:checked::after { scale: 1; }
.check:has(input:checked) { background: color-mix(in srgb, var(--good) 8%, var(--surface)); border-color: color-mix(in srgb, var(--good) 35%, transparent); }

.menu {
  position: fixed; z-index: 95; min-width: 180px; padding: 6px;
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-tile); box-shadow: var(--shadow-pop);
  transform-origin: top left;
}
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; border: 0; background: none; padding: 8px 10px; border-radius: 9px; text-align: left; font-size: var(--fs-sm); }
.menu button:hover, .menu button:focus-visible { background: var(--well); outline: 0; }
.menu button[aria-checked='true']::after { content: '✓'; margin-left: auto; color: var(--primary); font-weight: 700; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }

.palette { position: fixed; z-index: 85; left: 50%; top: 14vh; translate: -50% 0; width: min(560px, calc(100% - 32px)); background: var(--raised); border-radius: var(--r-card); box-shadow: var(--shadow-pop); overflow: hidden; }
.palette__in { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.palette__in input { flex: 1; border: 0; outline: 0; background: none; font-size: var(--fs-xl); }
.palette__list { max-height: 50vh; overflow-y: auto; padding: 8px; }
.palette__grp { font-size: var(--fs-2xs); font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; padding: 10px 10px 4px; }
.palette__item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; }
.palette__item[aria-selected='true'] { background: var(--well); }
.palette__item mark { background: color-mix(in srgb, var(--primary) 22%, transparent); color: inherit; border-radius: 3px; }

.toasts { position: fixed; z-index: 99; left: 50%; bottom: 24px; translate: -50% 0; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px;
  padding: 8px 8px 8px 16px; border-radius: var(--r-pill);
  background: #10151e; color: #eef2f8; font-size: var(--fs-sm); box-shadow: var(--shadow-pop);
}
html[data-theme='dark'] .toast { background: #f1f4f9; color: #10151e; }
.toast .btn { height: 28px; }

/* ---------- Barra de rolagem fina (Windows). Não use scrollbar-color aqui: no Chromium ≥121 desliga estas regras. ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track, ::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-button { display: none; }
::-webkit-scrollbar-thumb { border-radius: 999px; border: 3px solid transparent; background: color-mix(in srgb, var(--muted) 35%, transparent) padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: color-mix(in srgb, var(--muted) 60%, transparent); }
:not(:hover)::-webkit-scrollbar-thumb { background-color: color-mix(in srgb, var(--muted) 18%, transparent); }

/* ---------- Troca de tema em círculo (motion.theme) e troca de tela ---------- */
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
.rail { view-transition-name: rail; }

/* Pressionado único (padroes/gesto.md, regra 4): responde no pointerdown, sem transição na entrada; a volta usa a transição do controle.
   Fica no fim e com :active duplo para vencer os :hover que redefinem `background`. */
:is(.btn, .rail__btn, .tabs button, .seg button, .check, .menu button, .kcard:not(.is-lifted, .is-ghost, :has(button:active, a:active, input:active))):active:active {
  transform: scale(var(--gesto-pressionado)); transition-duration: 0s;
  background-image: linear-gradient(var(--gesto-realce), var(--gesto-realce));
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; }
}
html[data-motion='off'] *, html[data-motion='off'] *::before, html[data-motion='off'] *::after { transition: none !important; animation: none !important; }
