/**
 * Tickets Workspace (Spec 029) — CSS isolado
 * Não misturar com proc-card / INFRA CODE — evita regressões em deploys de outras views.
 */

/* --- Toolbar busca --- */
.tickets-search-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-bottom: 0.75rem;
}
.tickets-search-input {
  flex: 1 1 220px;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.88rem;
  background: #fff;
}
.tickets-search-hint { margin: 0; }

/* --- KPI strip --- */
.tickets-kpi-strip {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
@media (max-width: 1100px) {
  .tickets-kpi-strip { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .tickets-kpi-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.tickets-kpi {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.55rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  font: inherit;
  color: inherit;
  min-height: 56px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.tickets-kpi-value {
  font-size: 1.05rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
.tickets-kpi-label {
  font-size: 0.68rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.2;
}
.tickets-kpi--live .tickets-kpi-value { color: #059669; }
.tickets-kpi--danger .tickets-kpi-value { color: #dc2626; }
.tickets-kpi--warn .tickets-kpi-value { color: #d97706; }
.tickets-kpi--billing .tickets-kpi-value { color: #2563eb; }
.tickets-kpi--security .tickets-kpi-value { color: #7c3aed; }
.tickets-kpi:hover { border-color: var(--accent); }
.tickets-kpi.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
  background: var(--accent-soft);
}

/* --- Filas chips --- */
.tickets-queue-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.65rem;
}
.tickets-queue-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-right: 0.25rem;
}
.tickets-queue-chip {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-size: 0.74rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.tickets-queue-chip:hover { border-color: var(--accent); }
.tickets-queue-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.tickets-queue-clear {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.72rem;
  cursor: pointer;
  text-decoration: underline;
}

/* --- Lista de cards --- */
#ticket-list {
  min-width: 0;
  width: 100%;
}
.ticket-card-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: 100%;
}
.ticket-card {
  display: grid;
  grid-template-columns: 5px minmax(0, 1fr) auto;
  align-items: stretch;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0;
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.ticket-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow);
}
.ticket-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.ticket-card--live {
  border-color: rgba(16, 185, 129, 0.45);
  background: linear-gradient(90deg, #f0fdf4 0%, #fff 12%);
}
.ticket-card-rail {
  border-radius: 12px 0 0 12px;
  min-height: 100%;
}
.ticket-card-rail--open { background: #f59e0b; }
.ticket-card-rail--assisting { background: #3b82f6; }
.ticket-card-rail--escalated { background: #dc2626; }
.ticket-card-rail--resolved { background: #22c55e; }
.ticket-card-rail--closed { background: #94a3b8; }
.ticket-card-main {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.75rem 0.85rem;
  min-width: 0;
}
.ticket-card-signals {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}
.ticket-signal {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  background: #f1f5f9;
  color: #64748b;
}
.ticket-signal--open { background: #fef3c7; color: #92400e; }
.ticket-signal--assisting { background: #dbeafe; color: #1e40af; }
.ticket-signal--escalated { background: #fee2e2; color: #991b1b; }
.ticket-signal--resolved { background: #dcfce7; color: #166534; }
.ticket-signal--live.is-live {
  background: #d1fae5;
  color: #047857;
}
.ticket-signal--live.is-live i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.35);
  animation: ticket-live-pulse 1.4s ease-in-out infinite;
}
.ticket-signal--live.is-offline { background: #f1f5f9; color: #94a3b8; }
.ticket-signal--phase { background: #f8fafc; color: #475569; }
.ticket-signal--stale { background: #ffedd5; color: #c2410c; }
@keyframes ticket-live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}
.ticket-card-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: #1e293b;
  line-height: 1.35;
  word-break: break-word;
}
.ticket-card-meta {
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.4;
  word-break: break-word;
}
.ticket-card-livepath {
  font-size: 0.72rem;
  color: #059669;
  font-family: ui-monospace, monospace;
}
.ticket-card-icons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.15rem;
}
.ticket-icon-chip {
  font-size: 0.62rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  background: #f1f5f9;
}
.ticket-icon-chip--lead {
  background: #fef3c7;
  color: #92400e;
  font-weight: 700;
}
.ticket-card-aside {
  display: flex;
  align-items: flex-start;
  padding: 0.65rem 0.75rem 0.65rem 0;
  flex-shrink: 0;
}

/* --- Detalhe (painel) --- */
.ticket-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.ticket-detail-tabs {
  display: flex;
  gap: 0.35rem;
  border-bottom: 1px solid var(--border);
  margin: 0.75rem 0 1rem;
  padding-bottom: 0;
}
.ticket-detail-tab {
  border: none;
  background: transparent;
  padding: 0.45rem 0.75rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.ticket-detail-tab:hover { color: #2a2520; }
.ticket-detail-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.ticket-detail-pane[hidden] { display: none !important; }
.ticket-next-action {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.75rem 0.85rem;
  border-radius: 10px;
  margin-bottom: 0.65rem;
  border: 1px solid var(--border);
  flex-wrap: wrap;
}
.ticket-next-action--live { background: #ecfdf5; border-color: rgba(52, 211, 153, 0.4); }
.ticket-next-action--brand { background: #eff6ff; border-color: rgba(59, 130, 246, 0.35); }
.ticket-next-action--stale { background: #fef3e8; border-color: rgba(234, 179, 8, 0.35); }
.ticket-next-action--warn { background: #fef3e8; }
.ticket-next-action--danger { background: #fde8e8; }
.ticket-next-action--billing { background: #eff6ff; }
.ticket-next-action--info { background: #f5f2ed; }
.ticket-next-action-icon {
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 0.1rem;
}
.ticket-next-action-body {
  flex: 1 1 12rem;
  min-width: 0;
  max-width: 100%;
}
.ticket-next-action-body strong {
  display: block;
  font-size: 0.85rem;
  line-height: 1.35;
  word-break: normal;
}
.ticket-next-action-body span {
  display: block;
  font-size: 0.76rem;
  color: var(--muted);
  line-height: 1.45;
  word-break: normal;
  white-space: normal;
}
.ticket-next-action-cta {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}
.ticket-next-action .btn { flex-shrink: 0; white-space: nowrap; }
.ticket-live-presence-card {
  padding: 0.75rem;
  border: 1px solid rgba(52, 211, 153, 0.35);
  border-radius: 8px;
  background: #f0fdf8;
  margin-bottom: 0.75rem;
}
.kv--compact dt { font-size: 0.72rem; }
.kv--compact dd { font-size: 0.82rem; }
.ticket-payload-details { margin-top: 1rem; }
.ticket-payload-details summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--muted);
}

@media (max-width: 1200px) {
  #view-tickets .grid-2 { grid-template-columns: 1fr; }
}

/* --- Painel detalhe (coluna direita) --- */
#view-tickets .grid-2 {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  align-items: start;
}
#ticket-detail {
  min-width: 0;
}
.ticket-detail-shell {
  overflow: hidden;
}
.ticket-detail-shell .assist-panel {
  margin-top: 1rem;
  padding: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #faf7f2;
}
.ticket-detail-shell .assist-panel h4 {
  margin: 0 0 0.35rem;
  font-size: 0.92rem;
}
.ticket-detail-shell .assist-panel .actions {
  margin-top: 0.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.ticket-detail-shell .assist-console-actions,
.ticket-detail-shell .assist-console-links {
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px dashed var(--border);
}
.ticket-detail-shell .assist-console-actions h5,
.ticket-detail-shell .assist-console-links h5 {
  margin: 0 0 0.45rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
}
.ticket-detail-shell .kv {
  grid-template-columns: minmax(88px, 110px) minmax(0, 1fr);
}
