/* Triune AV Planner — base
   Reset enxuto + tipografia + regras de toque mobile. */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--txt-2);
  font-weight: 400;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

a { color: inherit; text-decoration: none; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

img, svg { display: block; max-width: 100%; }

/* DEV6: evita zoom no iOS, mas oferece design compacto em desktop */
input, select, textarea {
  font-family: inherit;
  font-size: 13.5px;
  background: var(--bg-3);
  color: var(--txt-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 7px 11px;
  width: 100%;
}

/* Selects custom — fim do quadrado branco padrão do navegador.
   Remove aparência nativa, adiciona chevron SVG, fundo dark coerente. */
select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%238A9BB0' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m1 1.5 5 5 5-5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}
select:hover { border-color: var(--line-3); }
/* As <option> ficam refém do SO, mas em browsers modernos (Chrome 121+, FF 130+)
   suportam color-scheme — segue o tema do <html> (dark/light) pra ficar coerente. */
:root[data-theme="dark"] select { color-scheme: dark; }
:root[data-theme="light"] select { color-scheme: light; }
option { background: var(--bg-2); color: var(--txt-2); padding: 8px; }
optgroup { background: var(--bg); color: var(--txt-3); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}

::selection { background: var(--red-soft); color: var(--txt); }

/* Scrollbar custom (espelha o protótipo) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: var(--txt-4); }
::-webkit-scrollbar-track { background: transparent; }

/* ============================================================
   COMPONENTES COMPARTILHADOS DE PÁGINA (DEV-UX, jun/26)
   Toolbar unificada usada por Projetos, Biblioteca, Estoque.
   Substitui os headers ad-hoc (.proj-bar/.lib-bar/.est-bar) por
   um padrão coeso. A ação primária de cada página vai pro topbar
   (#topActions) via setTopActions() — aqui fica só filtro+busca.
   ============================================================ */

/* Toolbar: linha única, filtros à esquerda, busca à direita */
.tbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.tbar-spacer { flex: 1 1 auto; min-width: 8px; }

/* Segmented control (tabs/filtros tipo iOS) */
.seg {
  display: inline-flex;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 14px;
  border: none; border-radius: var(--r-sm);
  background: transparent;
  color: var(--txt-3);
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.seg-btn:hover { color: var(--txt-2); }
.seg-btn.is-active { background: var(--bg-3); color: var(--txt); box-shadow: var(--sh-1); }
.seg-count {
  font-size: 11px; font-weight: 600; color: var(--txt-4);
  font-family: var(--font-mono);
}
.seg-btn.is-active .seg-count { color: var(--red); }

/* Search pill — consistente em toda a app */
.search {
  position: relative;
  display: flex; align-items: center;
  min-width: 200px;
}
.search svg {
  position: absolute; left: 11px;
  color: var(--txt-4); pointer-events: none;
}
.search input {
  width: 100%;
  height: 38px;
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 0 12px 0 34px;
  color: var(--txt-2);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.search input::placeholder { color: var(--txt-4); }
.search input:hover { border-color: var(--line); }
.search input:focus {
  background: var(--bg);
  border-color: var(--red);
  box-shadow: 0 0 0 3px var(--red-soft);
}

/* Select estilizado como "chip" (filtro de categoria etc.) */
.chip-select {
  position: relative; display: inline-flex; align-items: center;
}
.chip-select select {
  height: 38px;
  width: auto;
  min-width: 180px;
  /* background-color (não shorthand) pra não apagar o chevron do select base */
  background-color: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: 0 36px 0 14px;
  color: var(--txt-2);
  font-size: 13.5px; font-weight: 500;
  cursor: pointer;
}
.chip-select select:hover { border-color: var(--line); }

/* Botão primário no topbar — leve destaque vs. ghost */
.topbar .top-actions .btn { height: 38px; }

/* KPI cards — métricas no topo (Estoque, Dashboard) */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.kpi {
  background: var(--bg-2);
  border: 1px solid var(--line-2);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 8px;
  transition: border-color 0.15s, transform 0.12s;
}
.kpi:hover { border-color: var(--line); }
.kpi-head { display: flex; align-items: center; gap: 8px; }
.kpi-ico {
  width: 30px; height: 30px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--bg-3);
}
.kpi-lbl { font-size: 12px; font-weight: 400; color: var(--txt-3); }
.kpi-val { font-size: 26px; font-weight: 700; line-height: 1; font-family: var(--font-mono); }

@media (max-width: 768px) {
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .search { min-width: 0; flex: 1 1 100%; order: 99; }
  .tbar { gap: 8px; }
}

/* Swatches de cor (modais de criar categoria/função) */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.swatch {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer; padding: 0;
  transition: transform 0.1s, border-color 0.12s;
}
.swatch:hover { transform: scale(1.12); }
.swatch.is-on { border-color: var(--txt); box-shadow: 0 0 0 2px var(--bg-2), 0 0 0 4px currentColor; }
.swatch-custom {
  width: 32px; height: 28px; padding: 2px; border-radius: 6px;
  background: var(--bg-3); border: 1px solid var(--line); cursor: pointer;
}

/* ============================================================
   COMBOBOX CUSTOM (BACKLOG #12 — conectores com glyph)
   Combobox custom que mostra GLYPH ao lado do nome, agrupado por
   categoria, com busca. Substitui <select> nos casos onde o glyph
   visual é importante (conectores físicos).
   ============================================================ */
.cb { position: relative; display: block; width: 100%; }
.cb-btn {
  display: inline-flex; align-items: center; gap: 8px;
  width: 100%; height: 38px; padding: 0 10px 0 8px;
  background-color: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--txt-2);
  font: inherit; font-size: 13.5px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.12s, background-color 0.12s;
}
.cb-btn:hover { border-color: var(--line-3); }
.cb-btn[aria-expanded="true"] { border-color: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.cb-btn-glyph {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; flex-shrink: 0;
}
.cb-btn-glyph-empty {
  display: inline-block; width: 18px; height: 18px;
  border: 1px dashed var(--txt-4); border-radius: 50%;
}
.cb-btn-lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cb-btn-chev { color: var(--txt-4); flex-shrink: 0; }

/* Popup absoluto (no body, position:fixed via JS) */
.cb-pop {
  z-index: 9999;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--sh-3);
  max-height: 360px;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.cb-menu { display: flex; flex-direction: column; min-height: 0; }
.cb-search {
  position: relative; padding: 10px;
  border-bottom: 1px solid var(--line-2);
  display: flex; align-items: center;
}
.cb-search svg { position: absolute; left: 19px; color: var(--txt-4); pointer-events: none; }
.cb-search-input {
  width: 100%; height: 32px;
  background: var(--bg-3); border: 1px solid var(--line-2);
  border-radius: 6px; padding: 0 10px 0 28px;
  color: var(--txt); font-size: 13px;
  outline: none;
}
.cb-search-input:focus { border-color: var(--red); box-shadow: 0 0 0 2px var(--red-soft); }

.cb-list { overflow-y: auto; padding: 6px; flex: 1; }
.cb-grp { margin-bottom: 4px; }
.cb-grp-h {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--txt-4);
  padding: 8px 8px 4px;
}
.cb-opt {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 7px 8px;
  background: transparent; border: none; border-radius: 6px;
  color: var(--txt-2); font: inherit; font-size: 13px;
  text-align: left; cursor: pointer;
}
.cb-opt:hover { background: var(--bg-3); color: var(--txt); }
.cb-opt.is-selected { background: var(--red-soft); color: var(--red); font-weight: 500; }
.cb-opt-glyph {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; flex-shrink: 0;
}
.cb-opt-glyph-empty {
  display: inline-block; width: 16px; height: 16px;
  border: 1px dashed var(--txt-4); border-radius: 50%;
}
.cb-opt-lbl { flex: 1; }

/* Bolinha colorida do tipo de sinal (combobox de sinal) */
.cb-sinal-dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 1.5px solid rgba(0,0,0,0.25);
}

/* ============================================================
   TRANSIÇÃO ENTRE ROTAS (#6 — micro polimento)
   Cada view entra com fade-in + leve translate-up. Mantém a sensação
   "Linear" — discreto, não atrapalha quem navega rápido.
   ============================================================ */
.view {
  transition: opacity 0.18s ease-out, transform 0.18s ease-out;
}
.view.is-routing {
  opacity: 0;
  transform: translateY(4px);
}
.view.is-routed {
  opacity: 1;
  transform: translateY(0);
}
/* Respeita preferência de redução de movimento (a11y) */
@media (prefers-reduced-motion: reduce) {
  .view, .view.is-routing, .view.is-routed {
    transition: none !important;
    transform: none !important;
  }
}

/* ============================================================
   EMPTY STATES ILUSTRADOS (#6)
   Padrão pra qualquer lista vazia: ícone grande monocromático,
   título amigável, hint discreto, CTA opcional. Usar via:
   <div class="empty"><span class="empty-ico">[SVG]</span>
     <h3 class="empty-t">Título</h3><p class="empty-d">descrição</p>
     <button class="btn btn-primary">CTA</button></div>
   ============================================================ */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  padding: 48px 24px;
  text-align: center;
  background: var(--bg-2);
  border: 1px dashed var(--line-2);
  border-radius: var(--r-lg);
}
.empty-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 64px; height: 64px;
  border-radius: 50%;
  background: var(--bg-3);
  color: var(--txt-4);
  margin-bottom: 4px;
}
.empty-ico svg { width: 28px; height: 28px; }
.empty-t {
  font-size: 16px; font-weight: 600; color: var(--txt);
  margin: 0;
}
.empty-d {
  font-size: 13px; font-weight: 300; color: var(--txt-3);
  max-width: 420px;
  margin: 0;
  line-height: 1.55;
}
.empty .btn { margin-top: 4px; }
