/*
  Wortic macOS UI Kit — Agent components
  wm-agent — cobre Agent Card, Agent Status, Agent Activity, Thinking
  State, Tool Call, Execution Row, Step, Timeline, Permission Request,
  Context Meter, Token Meter, Model Selector.

  Glowup 2026 "Liquid Glass": cards flutuando com sombra em camadas,
  avatar com gradiente da marca, timeline com markers refinados e glow
  discreto no estado running.
*/

@layer components {
  /* ---------- Agent Card ---------- */
  .wm-agent-card {
    /* ---- knobs locais (light) ---- */
    --wm-agent-card-shadow:
      0 0 0 0.5px rgba(0, 0, 0, 0.06),
      0 1px 2px rgba(0, 0, 0, 0.04),
      0 6px 18px -8px rgba(0, 0, 0, 0.1);
    --wm-agent-card-shadow-hover:
      0 0 0 0.5px rgba(0, 0, 0, 0.07),
      0 2px 5px rgba(0, 0, 0, 0.05),
      0 12px 28px -10px rgba(0, 0, 0, 0.14);

    display: flex;
    align-items: center;
    gap: var(--wm-space-5);
    padding: var(--wm-space-6) var(--wm-space-7);
    border-radius: var(--wm-radius-xl);
    background: var(--wm-surface-elevated);
    box-shadow: var(--wm-agent-card-shadow);
    transition:
      box-shadow var(--wm-duration-normal) var(--wm-ease-emphasized),
      transform var(--wm-duration-normal) var(--wm-ease-emphasized);
  }
  .wm-agent-card:hover {
    box-shadow: var(--wm-agent-card-shadow-hover);
    transform: translateY(-1px);
  }

  /* Avatar do agente — momento-assinatura: gradiente da marca */
  .wm-agent-card__avatar {
    flex: none;
    width: 36px;
    height: 36px;
    border-radius: var(--wm-radius-lg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(
      135deg,
      var(--wm-brand-blue) 0%,
      var(--wm-brand-cyan) 100%
    );
    color: #ffffff;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.25),
      0 0 0 0.5px rgba(0, 68, 238, 0.12),
      0 3px 8px -2px rgba(0, 68, 238, 0.35);
  }
  .wm-agent-card__avatar .wm-icon {
    width: var(--wm-icon-lg);
    height: var(--wm-icon-lg);
  }
  .wm-agent-card__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
  }

  .wm-agent-card__body {
    flex: 1 1 auto;
    min-width: 0;
  }
  .wm-agent-card__name {
    font-size: var(--wm-font-size-body);
    font-weight: var(--wm-font-weight-semibold);
    letter-spacing: var(--wm-letter-spacing-tight);
    color: var(--wm-label-primary);
  }
  .wm-agent-card__desc {
    font-size: var(--wm-font-size-caption);
    color: var(--wm-label-tertiary);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .wm-agent-card__trailing {
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--wm-space-3);
  }

  /* ---------- Thinking state ---------- */
  .wm-agent-thinking {
    display: inline-flex;
    align-items: center;
    gap: var(--wm-space-3);
    font-size: var(--wm-font-size-subheadline);
    color: var(--wm-label-secondary);
  }
  .wm-agent-thinking .wm-icon {
    color: var(--wm-accent);
    animation: wm-thinking-pulse 1.6s ease-in-out infinite;
  }
  @keyframes wm-thinking-pulse {
    0%,
    100% {
      opacity: 1;
      transform: scale(1);
    }
    50% {
      opacity: 0.35;
      transform: scale(0.92);
    }
  }

  /* ---------- Tool call / Execution row / Step ---------- */
  .wm-agent-steps {
    display: flex;
    flex-direction: column;
  }

  .wm-agent-step {
    display: flex;
    gap: var(--wm-space-5);
    position: relative;
    padding-block: var(--wm-space-4);
    padding-inline-start: var(--wm-space-1);
  }
  /* linha vertical da timeline — hairline quase invisível */
  .wm-agent-step::before {
    content: "";
    position: absolute;
    left: 12px;
    top: 30px;
    bottom: -2px;
    width: var(--wm-border-width-hairline);
    background: var(--wm-separator);
  }
  .wm-agent-step:last-child::before {
    display: none;
  }

  .wm-agent-step__marker {
    flex: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--wm-surface-elevated);
    color: var(--wm-label-tertiary);
    box-shadow:
      0 0 0 0.5px var(--wm-separator),
      0 1px 2px rgba(0, 0, 0, 0.05);
    z-index: 1;
    transition:
      background var(--wm-duration-normal) var(--wm-ease-standard),
      color var(--wm-duration-normal) var(--wm-ease-standard),
      box-shadow var(--wm-duration-normal) var(--wm-ease-standard);
  }
  .wm-agent-step__marker .wm-icon {
    width: 12px;
    height: 12px;
  }

  .wm-agent-step--done .wm-agent-step__marker {
    background: var(--wm-success-fill);
    color: var(--wm-success);
    box-shadow: 0 0 0 0.5px rgba(26, 158, 76, 0.22);
  }
  /* Running: glow discreto pulsando ao redor do marker */
  .wm-agent-step--running .wm-agent-step__marker {
    background: var(--wm-accent-fill);
    color: var(--wm-accent);
    box-shadow:
      0 0 0 0.5px var(--wm-accent-fill-strong),
      0 0 0 var(--wm-focus-halo-width) var(--wm-accent-fill),
      0 0 14px -2px var(--wm-accent-fill-strong);
    animation: wm-step-glow 2s var(--wm-ease-standard) infinite;
  }
  @keyframes wm-step-glow {
    0%,
    100% {
      box-shadow:
        0 0 0 0.5px var(--wm-accent-fill-strong),
        0 0 0 var(--wm-focus-halo-width) var(--wm-accent-fill),
        0 0 10px -2px var(--wm-accent-fill-strong);
    }
    50% {
      box-shadow:
        0 0 0 0.5px var(--wm-accent-fill-strong),
        0 0 0 var(--wm-focus-halo-width) var(--wm-accent-fill),
        0 0 18px -2px var(--wm-accent-fill-strong);
    }
  }
  .wm-agent-step--running .wm-agent-step__marker .wm-icon {
    animation: wm-spin 1s linear infinite;
  }
  .wm-agent-step--running .wm-agent-step__title {
    color: var(--wm-accent);
    font-weight: var(--wm-font-weight-medium);
  }
  .wm-agent-step--error .wm-agent-step__marker {
    background: var(--wm-error-fill);
    color: var(--wm-error);
    box-shadow: 0 0 0 0.5px rgba(217, 54, 43, 0.25);
  }

  .wm-agent-step__body {
    flex: 1 1 auto;
    min-width: 0;
    padding-top: 3px;
  }
  .wm-agent-step__title {
    font-size: var(--wm-font-size-subheadline);
    color: var(--wm-label-primary);
  }
  .wm-agent-step__title code {
    font-family: var(--wm-font-family-mono);
    font-size: 11px;
    background: var(--wm-fill-secondary);
    box-shadow: inset 0 0 0 0.5px var(--wm-separator);
    padding: 1px 5px;
    border-radius: var(--wm-radius-xs);
  }
  .wm-agent-step__detail {
    font-size: var(--wm-font-size-caption);
    color: var(--wm-label-tertiary);
    font-variant-numeric: tabular-nums;
    margin-top: 1px;
  }
  .wm-agent-step__time {
    flex: none;
    padding-top: 3px;
    font-size: var(--wm-font-size-caption);
    color: var(--wm-label-quaternary);
    font-variant-numeric: tabular-nums;
  }

  /* ---------- Permission request ---------- */
  .wm-agent-permission {
    display: flex;
    flex-direction: column;
    gap: var(--wm-space-5);
    padding: var(--wm-space-7);
    border-radius: var(--wm-radius-xl);
    background: linear-gradient(
      180deg,
      var(--wm-warning-fill) 0%,
      transparent 160%
    );
    background-color: var(--wm-surface-elevated);
    box-shadow:
      inset 0 0 0 0.5px rgba(183, 121, 27, 0.28),
      0 1px 3px rgba(0, 0, 0, 0.04),
      0 8px 22px -10px rgba(183, 121, 27, 0.2);
  }
  .wm-agent-permission__header {
    display: flex;
    align-items: center;
    gap: var(--wm-space-3);
    font-size: var(--wm-font-size-subheadline);
    font-weight: var(--wm-font-weight-semibold);
    letter-spacing: var(--wm-letter-spacing-tight);
    color: var(--wm-warning);
  }
  .wm-agent-permission__message {
    font-size: var(--wm-font-size-subheadline);
    line-height: var(--wm-line-height-relaxed);
    color: var(--wm-label-primary);
  }
  .wm-agent-permission__message code {
    font-family: var(--wm-font-family-mono);
    font-size: 11px;
    background: var(--wm-fill-secondary);
    box-shadow: inset 0 0 0 0.5px var(--wm-separator);
    padding: 1px 5px;
    border-radius: var(--wm-radius-xs);
  }
  .wm-agent-permission__actions {
    display: flex;
    gap: var(--wm-space-3);
  }

  /* ---------- Context / Token meter ---------- */
  .wm-context-meter {
    display: flex;
    flex-direction: column;
    gap: var(--wm-space-3);
  }
  .wm-context-meter__header {
    display: flex;
    justify-content: space-between;
    font-size: var(--wm-font-size-caption);
    color: var(--wm-label-tertiary);
  }
  .wm-context-meter__value {
    font-variant-numeric: tabular-nums;
    font-weight: var(--wm-font-weight-medium);
    color: var(--wm-label-secondary);
  }
  .wm-context-meter__track {
    height: 4px;
    border-radius: var(--wm-radius-pill);
    background: var(--wm-fill-primary);
    box-shadow: inset 0 0.5px 1px rgba(0, 0, 0, 0.06);
    overflow: hidden;
  }
  .wm-context-meter__fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(
      90deg,
      var(--wm-accent) 0%,
      var(--wm-accent-hover) 100%
    );
    box-shadow: 0 0 6px -1px var(--wm-accent-fill-strong);
    transition: width var(--wm-duration-slow) var(--wm-ease-emphasized);
  }
  .wm-context-meter--warning .wm-context-meter__fill {
    background: var(--wm-warning);
    box-shadow: 0 0 6px -1px var(--wm-warning-fill);
  }
  .wm-context-meter--critical .wm-context-meter__fill {
    background: var(--wm-error);
    box-shadow: 0 0 6px -1px var(--wm-error-fill);
  }

  /* ---------- Model selector ---------- */
  .wm-model-selector {
    display: inline-flex;
    align-items: center;
    gap: var(--wm-space-3);
    height: var(--wm-control-height-sm);
    padding-inline: var(--wm-space-5);
    border-radius: var(--wm-radius-pill);
    background: var(--wm-surface-elevated);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.15),
      0 0 0 0.5px var(--wm-separator),
      0 1px 2px rgba(0, 0, 0, 0.05);
    font-size: var(--wm-font-size-caption);
    font-weight: var(--wm-font-weight-medium);
    color: var(--wm-label-secondary);
    border: none;
    cursor: pointer;
    transition:
      box-shadow var(--wm-duration-fast) var(--wm-ease-standard),
      color var(--wm-duration-fast) var(--wm-ease-standard),
      transform var(--wm-duration-fast) var(--wm-ease-standard);
  }
  .wm-model-selector:hover {
    color: var(--wm-label-primary);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.15),
      0 0 0 0.5px var(--wm-separator),
      0 2px 6px rgba(0, 0, 0, 0.08);
  }
  .wm-model-selector:active {
    transform: scale(var(--wm-scale-pressed, 0.98));
    box-shadow:
      inset 0 1px 2px rgba(0, 0, 0, 0.06),
      0 0 0 0.5px var(--wm-separator);
  }
  .wm-model-selector .wm-icon {
    color: var(--wm-accent);
  }
  .wm-model-selector .wm-icon:last-child {
    color: var(--wm-label-quaternary);
  }

  /* ---- Dark mode: sombras mais profundas, highlights mais tímidos ---- */
  :root[data-theme="dark"] .wm-agent-card {
    --wm-agent-card-shadow:
      inset 0 0.5px 0 rgba(255, 255, 255, 0.06),
      0 0 0 0.5px rgba(0, 0, 0, 0.4),
      0 2px 5px rgba(0, 0, 0, 0.28),
      0 10px 26px -10px rgba(0, 0, 0, 0.5);
    --wm-agent-card-shadow-hover:
      inset 0 0.5px 0 rgba(255, 255, 255, 0.08),
      0 0 0 0.5px rgba(0, 0, 0, 0.45),
      0 3px 8px rgba(0, 0, 0, 0.32),
      0 16px 36px -12px rgba(0, 0, 0, 0.58);
  }
  :root[data-theme="dark"] .wm-agent-step__marker {
    box-shadow:
      inset 0 0.5px 0 rgba(255, 255, 255, 0.08),
      0 0 0 0.5px var(--wm-separator),
      0 1px 2px rgba(0, 0, 0, 0.3);
  }
  :root[data-theme="dark"] .wm-model-selector {
    box-shadow:
      inset 0 0.5px 0 rgba(255, 255, 255, 0.09),
      0 0 0 0.5px var(--wm-separator),
      0 1px 2px rgba(0, 0, 0, 0.3);
  }
  :root[data-theme="dark"] .wm-agent-permission {
    box-shadow:
      inset 0 0 0 0.5px rgba(226, 165, 61, 0.3),
      0 2px 6px rgba(0, 0, 0, 0.3),
      0 10px 26px -12px rgba(0, 0, 0, 0.5);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .wm-agent-card {
      --wm-agent-card-shadow:
        inset 0 0.5px 0 rgba(255, 255, 255, 0.06),
        0 0 0 0.5px rgba(0, 0, 0, 0.4),
        0 2px 5px rgba(0, 0, 0, 0.28),
        0 10px 26px -10px rgba(0, 0, 0, 0.5);
      --wm-agent-card-shadow-hover:
        inset 0 0.5px 0 rgba(255, 255, 255, 0.08),
        0 0 0 0.5px rgba(0, 0, 0, 0.45),
        0 3px 8px rgba(0, 0, 0, 0.32),
        0 16px 36px -12px rgba(0, 0, 0, 0.58);
    }
    :root:not([data-theme="light"]) .wm-agent-step__marker {
      box-shadow:
        inset 0 0.5px 0 rgba(255, 255, 255, 0.08),
        0 0 0 0.5px var(--wm-separator),
        0 1px 2px rgba(0, 0, 0, 0.3);
    }
    :root:not([data-theme="light"]) .wm-model-selector {
      box-shadow:
        inset 0 0.5px 0 rgba(255, 255, 255, 0.09),
        0 0 0 0.5px var(--wm-separator),
        0 1px 2px rgba(0, 0, 0, 0.3);
    }
    :root:not([data-theme="light"]) .wm-agent-permission {
      box-shadow:
        inset 0 0 0 0.5px rgba(226, 165, 61, 0.3),
        0 2px 6px rgba(0, 0, 0, 0.3),
        0 10px 26px -12px rgba(0, 0, 0, 0.5);
    }
  }

  /* [hidden] SEMPRE vence o display das classes. Sem estes seletores
     explícitos, o display:flex/inline-flex acima ganharia do
     [hidden]{display:none} da UA e esconder qualquer peça da família
     com o atributo hidden não esconderia nada — foi exatamente o bug
     do ícone duplicado que varreu o kit inteiro. */
  .wm-agent-card[hidden],
  .wm-agent-card__avatar[hidden],
  .wm-agent-card__trailing[hidden],
  .wm-agent-thinking[hidden],
  .wm-agent-steps[hidden],
  .wm-agent-step[hidden],
  .wm-agent-step__marker[hidden],
  .wm-agent-permission[hidden],
  .wm-agent-permission__header[hidden],
  .wm-agent-permission__actions[hidden],
  .wm-context-meter[hidden],
  .wm-context-meter__header[hidden],
  .wm-model-selector[hidden] {
    display: none;
  }

  @media (prefers-reduced-motion: reduce) {
    .wm-agent-thinking .wm-icon,
    .wm-agent-step--running .wm-agent-step__marker,
    .wm-agent-step--running .wm-agent-step__marker .wm-icon {
      animation: none;
    }
    .wm-agent-card,
    .wm-agent-step__marker,
    .wm-model-selector {
      transition: none;
    }
    .wm-agent-card:hover {
      transform: none;
    }
  }
}
