/* ==========================================================================
   Icon system — página + módulo (VISUAL-ADDENDUM item 17)
   Namespace: .ch-icon-picker (dialog) + .ch-page-icon / .ch-list-eicon /
   .ch-module-icon (render). Neumórfico com tokens de _tokens.css — zero hex
   cru fora da paleta, zero emoji.
   ========================================================================== */

/* ─── Render: ícone de página (56×56, raised — preview canônico do addendum) */
.ch-page-icon {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: var(--shadow-dark-sm), var(--shadow-light-sm);
  transition: box-shadow var(--motion-fast) var(--ease-out),
              transform var(--motion-fast) var(--ease-out);
}
.ch-page-icon:hover {
  transform: translate3d(0, -1px, 0);
}
.ch-page-icon:active {
  box-shadow: inset var(--shadow-dark-xs), inset var(--shadow-light-xs);
  transform: none;
}
.ch-page-icon:focus-visible {
  outline: 2px solid var(--c-blue);
  outline-offset: 2px;
}
.ch-page-icon .ch-eicon__glyph,
.ch-page-icon svg {
  width: 28px;
  height: 28px;
}
.ch-page-icon .ch-eicon__img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

/* Página de detalhe: ícone + título lado a lado */
.ch-page-head__identity {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  min-width: 0;
}
.ch-page-head__identity > div {
  min-width: 0;
}

/* ─── Render: ícone pequeno em listas (20×20 chip) */
.ch-list-eicon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: -4px;
  margin-right: var(--space-1);
  border-radius: var(--radius-xs, 6px);
  box-shadow: var(--shadow-dark-xs), var(--shadow-light-xs);
}
.ch-list-eicon .ch-eicon__glyph,
.ch-list-eicon svg {
  width: 13px;
  height: 13px;
}
.ch-list-eicon .ch-eicon__img {
  width: 14px;
  height: 14px;
  object-fit: contain;
}

/* Filled = fill suave por cima do stroke (Lucide não tem set filled nativo;
   convenção do addendum: fill currentColor a 20%) */
.ch-eicon__glyph.is-filled,
.is-filled svg,
svg.ch-eicon__glyph.is-filled {
  fill: currentColor;
  fill-opacity: 0.2;
}

/* ─── Render: ícone de módulo customizado (abas + bottomnav) */
.ch-module-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ch-module-icon.has-bg {
  padding: 2px;
  border-radius: var(--radius-xs, 6px);
  background: var(--ch-micon-bg, transparent);
}
.ch-module-icon svg {
  width: 1em;
  height: 1em;
}
.ch-module-icon.is-filled svg {
  fill: currentColor;
  fill-opacity: 0.2;
}
.ch-module-icon .ch-eicon__img {
  width: 1em;
  height: 1em;
  object-fit: contain;
}

/* ─── Dialog */
.ch-icon-picker {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}
.ch-icon-picker[hidden] {
  display: none;
}
.ch-icon-picker__scrim {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--c-ink) 32%, transparent);
}
.ch-icon-picker__panel {
  position: relative;
  width: min(640px, 100%);
  max-height: min(86vh, 720px);
  overflow-y: auto;
  background: var(--surface-app);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-dark-md), var(--shadow-light-md);
}

.ch-icon-picker__head {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}
.ch-icon-picker__title {
  font-family: var(--display);
  font-size: var(--fs-md);
  font-weight: 700;
  color: var(--fg-strong);
  margin: 0;
}
.ch-icon-picker__search {
  flex: 1;
  min-width: 200px;
  border: none;
  background: var(--surface-card);
  box-shadow: inset var(--shadow-dark-xs), inset var(--shadow-light-xs);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-4);
  font-family: var(--sans);
  font-size: var(--fs-sm);
  color: var(--fg-strong);
}
.ch-icon-picker__search::placeholder {
  color: var(--fg-faint);
}
.ch-icon-picker__search:focus {
  outline: none;
  box-shadow: inset var(--shadow-dark-sm), inset var(--shadow-light-sm);
}

.ch-icon-picker__controls {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: flex-end;
  padding-bottom: var(--space-3);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--space-4);
}
.ch-icon-picker__group {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.ch-icon-picker__label {
  font-family: var(--sans);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-muted);
  font-weight: 700;
}

.ch-icon-picker__toggle {
  display: inline-flex;
  background: var(--surface-card);
  box-shadow: inset var(--shadow-dark-xs), inset var(--shadow-light-xs);
  border-radius: var(--radius-pill, 100px);
  padding: 3px;
  gap: 2px;
}
.ch-icon-picker__toggle button {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill, 100px);
  background: transparent;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  font-family: var(--sans);
  font-size: var(--fs-xs);
  font-weight: 600;
}
.ch-icon-picker__toggle button[aria-pressed="true"] {
  background: var(--cta-neon-bg);
  color: var(--c-ink);
  box-shadow: var(--shadow-dark-xs), var(--shadow-light-xs);
}

.ch-icon-picker__swatches {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.ch-icon-picker__swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: var(--radius-full, 9999px);
  border: 2px solid transparent;
  cursor: pointer;
  box-shadow: var(--shadow-dark-xs), var(--shadow-light-xs);
  transition: transform var(--motion-fast) var(--ease-out);
}
.ch-icon-picker__swatch:hover {
  transform: scale(1.1);
}
.ch-icon-picker__swatch.is-active {
  border-color: var(--c-ink);
  transform: scale(1.1);
}
.ch-icon-picker__swatch--line {
  border: 1px solid var(--line-strong);
}
.ch-icon-picker__swatch--line.is-active {
  border: 2px solid var(--c-ink);
}
.ch-icon-picker__swatch--custom {
  position: relative;
  overflow: hidden;
  background: conic-gradient(
    var(--c-danger), var(--c-warn), var(--c-pollen),
    var(--c-green-d), var(--c-blue), var(--c-navy), var(--c-danger)
  );
}
.ch-icon-picker__swatch--custom input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.ch-icon-picker__upload {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--surface-card);
  box-shadow: var(--shadow-dark-xs), var(--shadow-light-xs);
  border: none;
  color: var(--fg-default);
  font-family: var(--sans);
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
  transition: box-shadow var(--motion-fast) var(--ease-out);
}
.ch-icon-picker__upload:hover {
  box-shadow: inset var(--shadow-dark-xs), inset var(--shadow-light-xs);
  color: var(--c-blue);
}
.ch-icon-picker__upload svg {
  width: 14px;
  height: 14px;
}

/* Grid — repeat(auto-fill, 36px) + justify-content start (addendum item 17) */
.ch-icon-picker__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 36px);
  justify-content: start;
  gap: var(--space-2);
  max-height: 280px;
  overflow-y: auto;
  padding: var(--space-2);
}
.ch-icon-picker__cell {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-xs, 6px);
  background: var(--surface-card);
  /* Explicit fg so the cell never inherits the UA dark-form-control white
     text on a light card when OS scheme != in-app theme (icon-picker blocker). */
  color: var(--fg-default);
  box-shadow: var(--shadow-dark-xs), var(--shadow-light-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow var(--motion-fast) var(--ease-out),
              transform var(--motion-fast) var(--ease-out);
}
.ch-icon-picker__cell:hover {
  box-shadow: var(--shadow-dark-sm), var(--shadow-light-sm);
  transform: translate3d(0, -1px, 0);
}
.ch-icon-picker__cell.is-active {
  box-shadow: inset var(--shadow-dark-xs), inset var(--shadow-light-xs),
              0 0 0 2px var(--c-blue);
  transform: none;
}
.ch-icon-picker__cell svg {
  width: 20px;
  height: 20px;
}
.ch-icon-picker__cell[hidden] {
  display: none;
}

/* Preview — 56×56 raised + config canônico textual + ações */
.ch-icon-picker__preview {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--surface-card-2, var(--c-paper));
  border-radius: var(--radius-sm);
  box-shadow: inset var(--shadow-dark-xs), inset var(--shadow-light-xs);
  margin-top: var(--space-4);
  flex-wrap: wrap;
}
.ch-icon-picker__preview-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-dark-sm), var(--shadow-light-sm);
}
.ch-icon-picker__preview-icon svg {
  width: 28px;
  height: 28px;
}
.ch-icon-picker__preview-icon .ch-eicon__img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}
.ch-icon-picker__preview-meta {
  flex: 1;
  min-width: 140px;
}
.ch-icon-picker__preview-name {
  font-family: var(--sans);
  font-size: var(--fs-sm);
  color: var(--fg-strong);
  font-weight: 600;
  margin: 0;
}
.ch-icon-picker__preview-config {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--fg-muted);
  margin: 2px 0 0;
  word-break: break-all;
}
.ch-icon-picker__actions {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.ch-icon-picker__btn {
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-xs, 6px);
  font-family: var(--sans);
  font-size: var(--fs-xs);
  font-weight: 700;
  cursor: pointer;
  border: none;
}
.ch-icon-picker__btn--primary {
  background: var(--cta-neon-bg);
  color: var(--c-ink);
  box-shadow: var(--shadow-dark-xs), var(--shadow-light-xs);
}
.ch-icon-picker__btn--primary:active {
  box-shadow: inset var(--shadow-dark-xs), inset var(--shadow-light-xs);
}
.ch-icon-picker__btn--ghost {
  background: transparent;
  color: var(--fg-muted);
}
.ch-icon-picker__btn--ghost:hover {
  color: var(--fg-default);
}

@media (max-width: 720px) {
  .ch-icon-picker {
    padding: var(--space-2);
    align-items: flex-end;
  }
  .ch-icon-picker__panel {
    max-height: 92vh;
  }
  .ch-page-icon {
    width: 48px;
    height: 48px;
  }
  .ch-page-icon .ch-eicon__glyph,
  .ch-page-icon svg {
    width: 24px;
    height: 24px;
  }
}
